-
Notifications
You must be signed in to change notification settings - Fork 47
Improve keep_intermediate to enable keeping IR after each pass #1791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤑 If I had a dollar every time I wanted this I would've been a millionaire. Thank you!!
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1791 +/- ##
=======================================
Coverage 96.60% 96.61%
=======================================
Files 82 82
Lines 9221 9241 +20
Branches 872 877 +5
=======================================
+ Hits 8908 8928 +20
Misses 254 254
Partials 59 59 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@@ -95,6 +95,14 @@ | |||
performance by eliminating indirect conversion. | |||
[(#1738)](https://github.com/PennyLaneAI/catalyst/pull/1738) | |||
|
|||
* The `keep_intermediate` argument in the `qjit` decorator now accepts a new value that allows for | |||
saving intermediate files after each pass. The updated possible options for this argument are: | |||
* `False` or `0` or `"none"`: No intermediate files are kept. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, is it the string "none"
or the python None
?
if options.keep_intermediate >= KeepIntermediateLevel.PASS: | ||
extra_args += ["--save-ir-after-each=pass"] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes more sense to put the two if options.keep_intermediate
blocks together
:attr:`~.QJIT.mlir`, :attr:`~.QJIT.mlir_opt`, :attr:`~.QJIT.jaxpr`, | ||
and :attr:`~.QJIT.qir`, representing different stages in the optimization process. | ||
keep_intermediate (Union[str, int, bool]): Level controlling intermediate file generation. | ||
- ``False`` or ``0`` or ``"none"`` (default): No intermediate files are kept. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, is this the string or the python None
?
case _: | ||
raise ValueError( | ||
f"Invalid value for keep_intermediate: {level}. " | ||
"Valid values are True, False, 0, 1, 2, 'none', 'pipeline', 'pass'." | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, does the python None
come to this error case? Since the above is matching for the string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also are booleans parsed here? 🤔
assert "--save-ir-after-each=pass" not in flags | ||
assert flags.count("--save-ir-after-each=pass") <= 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why check this twice? 😅
assert "--save-ir-after-each=pass" in flags | ||
assert flags.count("--save-ir-after-each=pass") == 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-approving as long as these concerns are addressed 🥇
Context:
keep_intermediate
is a boolean flag that if enabled, keeps the intermediate IR files after each pipeline. However, it is quite common that a developer needs the IR after a specific pass, which is not accessible in the current format viakeep_intermediate
.Description of the Change:
Added a third level to the
keep_intermediate
that enables accessing the IR in a more fine grained format i.e. after each pass.Note that this is not a breaking change, meaning that the current behaviour of
keep_intermediate
is kept intact.With this PR, the user can provide three different levels of printing:
False
or0
or"none"
(default): No intermediate files are kept.True
or1
or"basic"
: Standard intermediate files are kept (IR after each pipeline).2
or"debug"
: Standard intermediate files are kept, and IR is saved after each pass.Benefits:
easier development and debugging
Possible Drawbacks:
Related GitHub Issues: