Fix batchless accumulated residual normalization - #1678
Open
emerardd wants to merge 1 commit into
Open
Conversation
emerardd
marked this pull request as ready for review
August 15, 2026 10:57
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
Fix
ActivationCache.accumulated_resid(..., apply_ln=True)for caches whose batch dimension has been removed before selecting a scalar position.The final-normalization recomputation path previously inferred batch and position semantics only from tensor rank. A batchless scalar residual stack has shape
[components, d_model], so each component reachedln_finalas a one-dimensional tensor and then failed when the code attemptedsqueeze(1).accumulated_resid()now forwards the cache's explicithas_batch_dimstate. The recomputation path temporarily restores the structural batch and position dimensions expected byln_final, then reshapes each result back to its original component shape.The new download-free regression matrix uses tiny native LN and RMS models. It compares batchless outputs against the corresponding row of the batched result across scalar, sliced, and unsliced positions, with and without normalization, for both cached-scale and final-normalization recomputation paths.
Fixes #1677
Type of change
Validation
66 passedacross the new unit regression matrix and the existingtests/acceptance/test_activation_cache.pysurfacemypy .: success across 434 source filesgit diff --check: cleanChecklist:
No documentation text changes are required because this restores the existing batchless
ActivationCacheshape contract without changing the public API.