Skip to content

Retry with rbf = -1 if tokens are dropped - #5080

Open
Shuwen-Fang wants to merge 1 commit into
mainfrom
token_dropping
Open

Retry with rbf = -1 if tokens are dropped#5080
Shuwen-Fang wants to merge 1 commit into
mainfrom
token_dropping

Conversation

@Shuwen-Fang

@Shuwen-Fang Shuwen-Fang commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Description

Start with a short description of what the PR does and how this is a change from
the past.

The rest of the description includes relevant details and context, examples:

  • why is this change being made,
  • the problem being solved and any relevant context,
  • why this is a good solution,
  • some information about the specific implementation,
  • shortcomings of the solution and possible future improvements.

If the change fixes a bug or a Github issue, please include a link, e.g.,:
FIXES: b/123456
FIXES: #123456

You can also provide a comma-separated list. If you don't want to close a bug but
simply to reference it, use BUGS, e.g.:
BUGS: b/555278394

Notice 1: Once all tests pass, the "pull ready" label will automatically be assigned.
This label is used for administrative purposes. Please do not add it manually.

Notice 2: For external contributions, our settings currently require an approval from a MaxText maintainer to trigger CI tests.

Tests

Please describe how you tested this change, and include any instructions and/or
commands to reproduce.

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code. For an optional AI review, add the gemini-review label.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed, including adding new documentation pages to the relevant Table of Contents (toctree directive) as explained in our documentation.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a retry mechanism (retry_when_tokens_dropped) for Mixture of Experts (MoE) training, allowing the training step to be retried with a dropless buffer capacity if tokens are dropped due to ragged sort buffer overflow. The changes span configuration files, MoE routing layers, training loops, and unit tests. The review feedback highlights several critical issues: a performance regression caused by host-device synchronization on every step, a logging bug where metrics are overwritten during a retry, compatibility issues with pure NNX models due to the use of self.sow, a trivial unit test that does not actually execute the retry logic, and a JAX tracing anti-pattern when collecting intermediate metrics.

Comment thread src/maxtext/trainers/pre_train/train.py Outdated
Comment thread src/maxtext/layers/moe.py Outdated
Comment thread tests/unit/moe_test.py Outdated
Comment thread src/maxtext/trainers/pre_train/train.py Outdated
@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.54545% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/maxtext/trainers/pre_train/train.py 20.00% 6 Missing and 2 partials ⚠️
src/maxtext/layers/moe.py 86.66% 3 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@Shuwen-Fang
Shuwen-Fang force-pushed the token_dropping branch 2 times, most recently from 5148c64 to 3f95504 Compare September 2, 2026 02:09
RoutedMoE now falls back to a dropless (worst-case) ragged buffer and
redoes just that layer's route+compute via jax.lax.cond when the tuned
ragged_buffer_factor would otherwise drop tokens, gated behind
retry_when_tokens_dropped. Also validates against num_moe_emb_chunks>0
(not supported), and surfaces overflow via a gated log line in
training_loop_iteration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant