Feature: optional forward diff mode#14
Open
mattia-spider wants to merge 1 commit into
Open
Conversation
|
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
Member
|
Great! Could you try removing your I think I've fixed the bug affecting the Jacobian. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add optional forward-mode autodiff to diff() for cases where dim(input) << dim(output).
Selectable via mode="fwd" (default "rev", so existing uses like force computation are unchanged). Forward mode drastically reduces memory overhead when differentiating w.r.t. a low-dimensional input (e.g. the 3-component external field for NMR tensors), since it needs O(n_input) passes instead of O(n_output).
Memory impact, same architecture on qm9-nmr:
80GB H100 (with batch size 8): peak_MiB: 35477 (rev) → peak_MiB: 4849 (fwd)
8GB GPU: max batch 3 (rev) → 11 (fwd)
80GB H100: max batch 8 (rev) → 40 (fwd)
Correctness: fwd and rev give the same Jacobian, max abs diff ~3e-6 (float32), ~1e-15 (float64).
TODO (lines 297-303): forward mode breaks e3nn IrrepsArray's shape invariant (jacfwd appends the tangent axis, colliding with the irreps dim on rewrap). Worked around with value = base.as_array(value), active only in fwd mode. Proper fix belongs upstream in e3nn; remove workaround once resolved.