-
Notifications
You must be signed in to change notification settings - Fork 23
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
[MLIR] Specialize active callbacks to their own function #735
[MLIR] Specialize active callbacks to their own function #735
Conversation
de89893
to
09d4f02
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #735 +/- ##
=======================================
Coverage 98.04% 98.04%
=======================================
Files 69 69
Lines 9536 9538 +2
Branches 762 763 +1
=======================================
+ Hits 9350 9352 +2
Misses 151 151
Partials 35 35 ☔ View full report in Codecov by Sentry. |
09d4f02
to
e1a1cc4
Compare
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.
Thanks Erick, looks good! Regarding reusing the transformation from results into arguments and memrefs into struct pointers, is that something that would be applicable to this PR?
"specialize-active-callback-pass", | ||
"annotate-function", | ||
"lower-mitigation", | ||
"lower-gradients", |
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.
Should this go directly before gradient lowering?
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?
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 I was tying the callbacks to gradients because of the registration with enzyme. I was also thinking what is the lowest point in the pipeline it is first needed.
Is there a reason it should be the first thing in the pipeline?
@@ -142,6 +142,7 @@ def run_writing_command(command: List[str], compile_options: Optional[CompileOpt | |||
QUANTUM_COMPILATION_PASS = ( | |||
"QuantumCompilationPass", | |||
[ | |||
"specialize-active-callback-pass", | |||
"annotate-function", |
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.
Unrelated to this PR but I cannot tell at all what this pass is for or related to (from its name) 😅
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.
Do you have a different name that you prefer? Would outline-active-callback-pass
make more sense?
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.
Oh I was referring to annotate-function
@@ -110,8 +110,47 @@ struct BufferizePythonCallOp : public OpConversionPattern<PythonCallOp> { | |||
bufferArgs.push_back(newBuffer); | |||
} |
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.
An inactive callback has no results right?
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.
Ah maybe I got this wrong because I though debug.callback -> inactive_callback, but I guess the active_callback also calls the inactive callback.
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 am not sure if you were saying that I should get rid of the results in the InactiveCallbackOp. I just did. The reason why I didn't get rid of it is because I was still exploring different ways to implement this. To be honest, I have a better way in mind now 😅 but I will prioritize getting this PR in and subsequent PRs will focus on cleaning up.
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.
but I will prioritize getting this PR in and subsequent PRs will focus on cleaning up
Generally I will say that I don't much like the practice of splitting up PRs along a "rough first implementation" / "cleanup" line, because it makes it almost impossible to track the deficiencies of the first PR and make sure they all got addressed in the second PR.
A split along functionality is much more sensible imo.
This PR is fine but something to keep in mind for the future.
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 agree with you, but it is difficult to reconcile the "please close tickets before the end of iteration" with "no rough draft implementation PRs" when:
- we did not have time to design the whole epic in advance to forsee everything in each story
- stories build upon previous stories that may not be used until later.
I do not know if it would be possible to have tickets that do not correspond to merging of PRs but instead to just get the implementation. And a final ticket for merging the implementation.
That to me, seems appropriate for large features like this one. It would satisfy the opinion of:
- Small PRs are better (as it help for reviews)
- No draft PRs (as everything is already finished except for merging)
But would put a lower priority on "close tickets before the end of the story" and "each ticket must be a PR"
…s-to-their-own-function
No. But maybe a future PR might change this. I'm thinking whether using memrefs directly in the specialization and later undergoing the pointer-to-struct ABI transform would be good in terms of readability / invariants. I think so, but I will implement it in a different PR. |
Closing in favour of #782 |
Context: Enzyme allows one to specify custom gradients for specific functions. In order to specify custom gradients for callbacks, callbacks need to be specialized to their own specific functions. E.g., instead of having the following code:
And be unable to register custom gradients for
@callback
. Specialize callbacks to their identifiers like so:And now we can register a custom gradient for
callback_123
and any othercallback_456
.Description of the Change:
[sc-60494]