Repository navigation
EMo causal pools: float64 prefix sum (on #916) - #952
Conversation
doc_prefix_sum runs one cumsum over the whole row and subtracts each document's preceding total; in float32 that subtraction loses precision late in a long row (Akshita's review of #948: at 256K the pool changed for 0.25% of tokens, top-16 for 0.035%, all near-ties). Accumulate in float64 and return per_token's dtype.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1de463849a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| before = csum.gather(1, (start - 1).clamp_min(0).unsqueeze(-1).expand_as(csum)) | ||
| return csum - torch.where((start == 0).unsqueeze(-1), torch.zeros_like(before), before) | ||
| sums = csum - torch.where((start == 0).unsqueeze(-1), torch.zeros_like(before), before) |
There was a problem hiding this comment.
Avoid four full-size float64 temporaries
At the intended 256K-token × 512-expert causal-pool shape, each full-size float64 tensor is 1 GiB. Here csum and before remain live while zeros_like(before), the torch.where result, and then the subtraction result are allocated, producing a roughly 4 GiB peak in double buffers alone rather than the two-buffer cost described in the commit; memory-tight long-context training can therefore OOM. Masking/reusing before, subtracting into an existing buffer, and using the cumsum(dtype=...) argument would preserve the precision improvement without these extra full-size allocations.
Useful? React with 👍 / 👎.
Follow-up to #948, from Akshita's review of it.
Problem
ops.doc_prefix_sumcomputes each token's per-document running sum the way MaxTextemo_causal_pooldoes:In float32 that subtraction loses precision late in a long row, because both terms are large there. Akshita's check against exact per-document sums at 256K found:
Change
doc_prefix_sumaccumulates in float64 and returnsper_token's dtype (fp32 scores in the router). Nothing else changes, and whole-document EMo (doc_sum_scatter) is untouched.Cost (estimated, not measured): at 256K tokens × 512 experts, the float64 cumsum and its gathered copy are about 1 GiB each, compared with 0.5 GiB in float32. They're freed right after the pool mask is built, once per MoE layer. Time-wise it's a memory-bound scan, small next to the pool mask's two argsorts. I haven't measured it on GPU yet; the next run that turns causal pools on will show the step-time effect.
Tests
New
test_doc_prefix_sum_is_exact_over_long_rows:emo_router_v2_test.py+emo_document_pool_test.py: 17 passed, 5 skipped (GPU-only). Black and ruff are clean.Not affecting the running job
The EMo causal-pool hero run (
olmoe3-810m-cx2-mm-hero-mt-lc-256k-emocausal-lm1e4) keeps float32, the same as MaxText. This applies to later runs only. MaxText'semo_causal_poolhas the same float32 cumsum and may want the same change, so the two implementations stay in step.🤖 Generated with Claude Code