Skip to content

Enable functools/jacrev#20

Merged
reverendbedford merged 2 commits into
mainfrom
enable_jacrev
Apr 14, 2026
Merged

Enable functools/jacrev#20
reverendbedford merged 2 commits into
mainfrom
enable_jacrev

Conversation

@reverendbedford

Copy link
Copy Markdown
Collaborator

Slight changes needed to get jacrev to work. Includes a rather annoying example of how you need to wrap the model to get the model to "functionalize" correctly.

@github-actions

github-actions Bot commented Mar 10, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-04-14 18:51 UTC

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the adjoint autograd wrapper to be compatible with torch.func transforms (notably jacrev) and adds a regression test demonstrating how to wrap the solver/module so functional_call + jacrev work correctly.

Changes:

  • Refactor AdjointWrapper to use the newer setup_context API so forward no longer takes ctx.
  • Add a jacrev-based test that compares jacrev(functional_call(solver)) vs jacrev through solve_adjoint via a wrapper module.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pyzag/nonlinear.py Refactors the custom torch.autograd.Function to be torch.func-compatible via setup_context.
test/test_adjoint.py Adds a jacrev/functional_call regression test and a wrapper nn.Module to exercise the adjoint path under torch.func.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/test_adjoint.py
Comment thread pyzag/nonlinear.py
@reverendbedford reverendbedford merged commit 674caf8 into main Apr 14, 2026
7 checks passed
@reverendbedford reverendbedford deleted the enable_jacrev branch April 14, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants