Fix BatchLM vmap+jacfwd failures caused by in-place tensor mutations#301
Draft
Fix BatchLM vmap+jacfwd failures caused by in-place tensor mutations#301
Conversation
Agent-Logs-Url: https://github.com/Autostronomy/AstroPhot/sessions/d13bb976-bdfb-4fba-8140-58687f11e916 Co-authored-by: ConnorStoneAstro <78555321+ConnorStoneAstro@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Autostronomy/AstroPhot/sessions/d13bb976-bdfb-4fba-8140-58687f11e916 Co-authored-by: ConnorStoneAstro <78555321+ConnorStoneAstro@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Autostronomy/AstroPhot/sessions/d13bb976-bdfb-4fba-8140-58687f11e916 Co-authored-by: ConnorStoneAstro <78555321+ConnorStoneAstro@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix in-place operations handling in BatchLM
Fix BatchLM vmap+jacfwd failures caused by in-place tensor mutations
Apr 4, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #301 +/- ##
==========================================
+ Coverage 91.23% 91.48% +0.25%
==========================================
Files 113 114 +1
Lines 6198 6216 +18
==========================================
+ Hits 5655 5687 +32
+ Misses 543 529 -14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
BatchLMusesvmap(jacfwd(...))to compute batched Jacobians. PyTorch's forward-mode AD cannot trace through in-place tensor mutations, causing failures when anyintegrate_modeother than"none"was used.Core fix: backend index operations
_fill_at_indices_torchand_add_at_indices_torchnow usetorch.index_put(functional, out-of-place) for LongTensor indices — the path taken bytopk-based adaptive integration. Bool/tuple/slice indices fall back toclone()+ in-place, which preserves compatibility for non-differentiated callers.Sweep for bool-mask in-place operations in brightness functions
vmapadditionally rejects operations that produce dynamic shapes (bool-indexed selection). Fixed in three places:spline.py— extrapolation boundary: replacedfill_at_indices(I, R > profR[-1], 0)withbackend.where(R > profR[-1], zeros, I).WedgeMixin.polar_model— replacedadd_at_indices(model, bool_mask, iradial_model(s, R[mask]))withmodel + where(mask, iradial_model(s, R), zeros). The radial model is now evaluated over the full pixel array; the mask is applied viawhereto maintain static shapes.RayMixin.polar_model— same pattern for cosine-weighted segment accumulation.New tests
Added
BatchLM-specific tests intest_fit.pycovering:integrate_modevalues:"none","bright","curvature"sampling_modevalues:"midpoint","simpsons","quad:3"