Skip to content

fix micro_acc_steps - #138

Merged
luciaquirke merged 5 commits into
mainfrom
fix/micro-acc-steps
Jul 16, 2026
Merged

fix micro_acc_steps#138
luciaquirke merged 5 commits into
mainfrom
fix/micro-acc-steps

Conversation

@luciaquirke

Copy link
Copy Markdown
Contributor

micro_acc_steps has been a no-op since #60 (accidental removal).

Restore the chunking loop, so the existing acc_steps/denom factors are correct again. Chunking is only wired up for the fvu loss. The ce/kl losses 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.

@luciaquirke
luciaquirke force-pushed the fix/micro-acc-steps branch from 588ee90 to 90f3772 Compare July 16, 2026 03:31
`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
luciaquirke force-pushed the fix/micro-acc-steps branch from 90f3772 to 959030d Compare July 16, 2026 03:33
luciaquirke and others added 4 commits July 16, 2026 04:01
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.
… 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.
@luciaquirke
luciaquirke merged commit fc07793 into main Jul 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant