Repository navigation
fix(visco): per-shot gbar for batched models - #124
Merged
Merged
Conversation
The frozen NCQ exponent was averaged over the whole batch, coupling per-shot models with different Q (#123). Average per batch element and let the CUDA filter take (B, nz, nx) grids; shared models unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes the cross-shot coupling of
ViscoAcousticwith per-shot batched models(B, nz, nx)found while answering #123.Problem
prepare_modelsfroze the fractional exponent atgbar = mean(gamma)over the whole batch, so each shot's|k|^(2*gbar+1)/|k|^(2*gbar+2)filters depended on the other shots' Q. With Q different across the batch, batched vs one-shot-at-a-time differed by ~1.7e-3 (data) and ~8e-4 (gradient), on bothimpl='eager'andimpl='c'.Fix
ViscoAcoustic._average_exponent: onegbarper batch element for per-shot models ((B, 1, 1, 1)), each the same reduction a single-shot run takes. Shared models keep the scalar; a shared model that the C path repeats across the batch (all per-element means equal) keeps the historical whole-batch mean bit-for-bit.c_eq_aux: builds(B, nz, nx)D_loss/D_fracgrids when the exponents differ (D_k2stays(nz, nx)).visco_acoustic2d/kernels.cuh,backward.cu): the grid check accepts(nz, nx)or(B, nz, nx);lop_into/cmul_gridindex the grid modulo its own size (unchangednz*nxfor a shared grid), with a check that a grid is either one plane or the whole batch.Tests
New
test/test_visco_acoustic_batched_models.py(Q different per shot):Plus a CPU unit test of the per-element exponent and a check that a shared model on
impl='c'keeps(nz, nx)grids and equals an identical per-shot batch bit-for-bit.Shared-model A/B against
dev(c full / c default / eager / eager compiled × the threephase_shift/amplitude_dampingcombinations, V100, core rebuilt from this branch): all records bit-identical; the gradients that differ betweendevand this branch are exactly those that already differ between twodevruns (atomic accumulation), at the same magnitude.Existing
test_visco_acoustic.py,test_visco_acoustic_cuda.py,test_visco_acoustic_jax.py,test_elastic_batched_models.py,test_backward_scratch_from_pool.py: 107 passed.🤖 Generated with Claude Code