Skip to content

EMo causal pools: float64 prefix sum (on #916) - #952

Merged
jason718 merged 1 commit into
jasonr/olmo35-mixed-midtrainingfrom
jasonr/emo-causal-pool-fp64
Nov 7, 2026
Merged

jason718 merged 1 commit into
jasonr/olmo35-mixed-midtrainingfrom
jasonr/emo-causal-pool-fp64

Conversation

@jason718

@jason718 jason718 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #948, from Akshita's review of it.

Problem

ops.doc_prefix_sum computes each token's per-document running sum the way MaxText emo_causal_pool does:

  • One cumsum over the whole row.
  • Each document then subtracts the total before its start.

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:

  • The pool changed for 0.25% of tokens.
  • The selected top-16 changed for 0.035%.
  • All were near-ties, and none were a document's first tokens.

Change

doc_prefix_sum accumulates in float64 and returns per_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:

  • Setup: a 262,144-token row with 32 experts and documents of 1–4,096 tokens. The prefix sums must match exact per-document float64 cumsums to 1e-6, and the pool masks (P=8) must agree on more than 99.99% of tokens.
  • With the float32 cumsum, the test fails: 66.7% of the sums are off by more than 1e-6, with a max error of 8.9e-4, and the pool changes for 0.10% of tokens. That's consistent with Akshita's 0.25% at 512 experts.
  • 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's emo_causal_pool has the same float32 cumsum and may want the same change, so the two implementations stay in step.

🤖 Generated with Claude Code

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.
@jason718
jason718 marked this pull request as ready for review November 7, 2026 23:54
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T23:56:38.865090Z 1de4638 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jason718
jason718 merged commit 1a46ed1 into jasonr/olmo35-mixed-midtraining Nov 7, 2026
1 check passed
@jason718
jason718 deleted the jasonr/emo-causal-pool-fp64 branch November 7, 2026 23:54

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/olmo_core/ops/moe.py
Comment on lines 539 to +540
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

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