Fix gradient propagation for period parameter and add validation suite#94
Open
gevero wants to merge 6 commits intokc-ml2:mainfrom
Open
Fix gradient propagation for period parameter and add validation suite#94gevero wants to merge 6 commits intokc-ml2:mainfrom
gevero wants to merge 6 commits intokc-ml2:mainfrom
Conversation
…ends - In PyTorch backend, fixed 'period' setter to avoid creating new leaf tensors, ensuring gradients propagate correctly. - In JAX backend, fixed 'period' setter to correctly handle scalar Tracers/Arrays by checking 'ndim' instead of relying on 'len()', which fails for scalars.
…eck example - Added detailed comments to 'period' setters in JAX and PyTorch backends explaining the fixes. - Added 'examples/gradient_check_period.py' which tests the gradient of the 'period' parameter for both backends, in 1D and 2D modes, across all supported input formats (scalar, vector, list).
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.
Description
This PR resolves an issue where gradients with respect to the period parameter were not correctly propagating in both the JAX and PyTorch backends. Additionally, it introduces a comprehensive example script to validate these gradients against numerical finite difference results.
Changes
Core Library Fixes
Validation Suite
Verification Results
Validated the fixes using the new examples/gradient_check_period.py script. In all tested configurations (1D/2D, JAX/Torch, multiple Fourier orders), the AD gradients match the FD results with a precision of approximately$10^{-5}$ to $10^{-6}$ .
Disclaimer: This pull request and the associated code modifications were prepared with the assistance of gemini-cli.