fix micro_acc_steps - #138
Merged
Merged
Conversation
luciaquirke
force-pushed
the
fix/micro-acc-steps
branch
from
July 16, 2026 03:31
588ee90 to
90f3772
Compare
`micro_acc_steps` has been a no-op since #60 (Support end-to-end training). That PR removed the loop that chunked the activations, but kept the `acc_steps = grad_acc_steps * micro_acc_steps` denominator that the loop existed to compensate for. The result was worse than the flag simply being ignored: setting micro_acc_steps=N saved no memory at all, while still dividing the loss by an extra factor of N, silently scaling down the gradients. Restore the chunking loop, so the existing `acc_steps`/`denom` factors are correct again. Chunking is only wired up for the `fvu` loss, where the backward pass happens inside the hook; the `ce`/`kl` losses are computed on the model's logits and need the full reconstruction in one piece, so combining them with micro_acc_steps > 1 now raises instead of being quietly ignored. Note that chunking is exact only in the limit of large chunks: FVU normalizes by `total_variance`, a sum over the batch, computed per chunk against that chunk's own y.mean(0). Tiny chunks therefore diverge from an unchunked step (~22% of the update norm at 32 tokens/chunk, ~9% at 256), converging to float-noise exact by ~1024 tokens/chunk -- far below any realistic training config. The added test asserts this equivalence at 1024 tokens/chunk.
luciaquirke
force-pushed
the
fix/micro-acc-steps
branch
from
July 16, 2026 03:33
90f3772 to
959030d
Compare
Each chunk was computing total_variance from its own local y.mean(0), which biased the FVU/auxk/multi-topk loss scale relative to an unchunked run (verified failing test_micro_acc_steps_matches_unchunked_update: ~3% off even at 1024 tokens/chunk, not shrinking with chunk size). SparseCoder.forward() now accepts an optional total_variance override; Trainer computes it once from the full pre-chunk batch and shares it across all chunks. Also carries the embed_skip config/SparseCoder/Trainer plumbing this branch's own test_micro_acc_steps_with_embed_skip depends on, which wasn't committed here yet.
for more information, see https://pre-commit.ci
… fix The previous commit accidentally bundled the embed_skip feature (an unrelated, separate piece of work) in with the total_variance fix. This branch should only contain the micro_acc_steps chunking fix plus the total_variance normalization fix on top of it.
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.
micro_acc_stepshas been a no-op since #60 (accidental removal).Restore the chunking loop, so the existing
acc_steps/denomfactors are correct again. Chunking is only wired up for thefvuloss. Thece/kllosses are computed on the model's logits and need the full reconstruction, so combining them with micro_acc_steps > 1 raises.Note that chunking is exact only in the limit of realistically large chunks - the added test asserts equivalence at 1024 tokens/chunk, below this beware.