-
Notifications
You must be signed in to change notification settings - Fork 27
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] Enzyme-driven gradients #244
Conversation
…adient architecture
- WIP conversion to DPS of all generated functions - Change tape type of custom grad to null ptr vs struct (was causing Enzyme to crash) - Read values from param vec within the withparams modified QNode (was causing segfaults from dereferencing poison vals)
…ng the per-QNode lowering patterns
… a device is present
… tests with method=defer
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.
Amazing job 🥇 Happy to approve the PR but I would like @dime10 to review it as well before merging
This is great work @pengmai! Super excited to have it in 🎉 A quick question: will we also need to update https://docs.pennylane.ai/projects/catalyst/en/latest/dev/quick_start.html#calculating-quantum-gradients? |
Thanks Josh!
This PR should be totally backwards compatible and thus the quick start shouldn't require any changes to work, unless you wanted to highlight the new features. |
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.
This is amazing work 💯
A few comments and questions from my side, but nothing major!
Because this PR is so beefy though, I think it might be really helpful if the PR description contained a bullet point list of what was changed in existing code, what was added, and what are some quirks or compromises of the implantation, .... Doesn't need a lot of explanation, but just so we have a quick overview of everything that was undertaken.
…e-gradient-architecture
- Also update comment around BackpropOp copying cotangents
Co-authored-by: David Ittah <dime10@users.noreply.github.com>
…neAI/catalyst into jmp/enzyme-gradient-architecture
Co-authored-by: David Ittah <dime10@users.noreply.github.com>
Thanks for the overview in the description, very helpful 💯 |
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.
🧬
**Context:** This PR implements some documentation changes that follow up on #244, particularly [this comment](#244 (comment)). **Description of the Change:** Update the docstrings for `grad` and `jacobian`, rename `"defer"` to `"auto"` --------- Co-authored-by: David Ittah <dime10@users.noreply.github.com>
Context: The current gradient architecture does not support exact computation of hybrid programs with classical postprocessing or multiple QNodes.
Description of the Change: A reworking of Catalyst's gradient architecture to be driven by Enzyme. Quantum functions are split into their purely classical preprocessing and quantum parts as before, but now the differentiation of the end-to-end circuit is done by Enzyme with registered quantum gradients as custom gradients.
Overview of changes
.preprocess
function that contains the classical preprocessing (just like the argmap function) and the.quantum
function that contains the actual quantum computation. The.preprocess
function ends in a call to the.quantum
function, meaning it can replace QNodes and leave the hybrid graph connected.GradOp
s are lowered to one or moreBackpropOp
s of the entire hybrid computation (one for each result entry).quantum
split out QNodes.EinsumLinalgGeneric
to support both memref args (in addition to tensor args) and dynamic shapes. This is used in the custom gradient of quantum functions.GradOp
s..qgrad
,.adjoint
) to the custom gradients across both thelower-gradients
andconvert-gradient-to-llvm
passes.catalyst.grad
functions while also preserving the same verification as before (return value of a QNode withdiff_method="adjoint"
must be an expval, etc)The important implementation quirks are documented on Notion.
Benefits: This new architecture supports differentiation of circuits with classical postprocessing, hybrid programs with multiple QNodes, and purely classical programs.
[sc-41364]
[sc-41375]
[sc-42856]