Repository navigation
Conversation
The in-layer dropless fallback was only wired up for ring of experts. On the ragged all-to-all path (use_ring_of_experts=False), ragged_buffer_factor > 0 caps each EP shard's receive buffer, and tokens beyond it were silently dropped. With moe_dropless_fallback=layer, each MoE layer now checks (from the router's top-k, before the all-to-all) whether any EP shard would overflow. If so, it takes a dropless branch that runs the layer over sequence chunks in a lax.scan, each chunk with a worst-case receive buffer. get_dropless_fallback_num_chunks picks the chunk count so that buffer is no larger than the capped one. The scan body is checkpointed, so the backward recomputes one chunk at a time and accumulates the expert-weight gradients in the carry. moe_dropless_fallback=step still requires use_ring_of_experts=True.
4 tasks done
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This branch has not been deployed
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.
Description
Support
moe_dropless_fallback=layeron the ragged all-to-all MoE path (use_ring_of_experts=False). Before, the in-layer dropless fallback was ring-of-experts only and config validation rejected it otherwise.This PR is required by #5785.
Why. With
ragged_buffer_factor > 0, each EP shard's all-to-all receive buffer is capped atfactor x balanced, and tokens beyond it are silently dropped. Without a cap (-1), the buffer is sized for the worst case:EP x local tokens. At EP16 that doesn't fit: 121 GiB of HBM for this recipe (available: 95.7 GiB).How.
_check_ragged_overflow(the same check the ring path uses) computes from the router's top-k whether any EP shard would receive more than its buffer.lax.condthen picks a branch:_a2a_dropless_chunksruns the layer overget_dropless_fallback_num_chunkssequence chunks. Each chunk has a worst-case (force_dropless) receive buffer, which is no larger than the capped one, so peak HBM doesn't grow.lax.scanwith ajax.checkpoint(nothing_saveable) body. A Python-unrolled chunk loop like the ring path uses OOMed (116 GiB): the backward kept every chunk's f32 expert-weight gradient alive at once. With the scan, the backward recomputes one chunk at a time and accumulates the weight gradients in the carry (87.4 GiB).ra2a_and_routenow honoursforce_dropless(worst-case buffer).route()passes it through.moe_dropless_fallback=stepstill requiresuse_ring_of_experts=True. Ring-of-experts code paths are unchanged.Shortcomings.
n_chunks× slower for that step (8× for EP16 / factor 2).log_required_ragged_buffer_factoris still ring-only, so the all-to-all path only reports whether the fallback ran (learning/moe_dropless_fallback_layers), not the required factor.Tests
Unit tests
test_layer_dropless_fallback_matches_droplessandtest_layer_dropless_fallback_asymmetric_shard_overfloware now parameterized overring_of_experts/all_to_all.ragged_buffer_factor=0.1forces overflow; the test checks that the capped model diverges from dropless.layer, outputs and gradients match the dropless model, and the fallback flag fires on every device even when only one EP shard overflows.test_force_dropless_matches_droplessstill passes.test_moe_dropless_fallback_modesnow also checks thatlayeris accepted andsteprejected without ring-of-experts.End-to-end
Llama4-Maverick on v5p-256 at FSDP8 x EP16 (full 48 layers,
per_device_batch_size=4,max_target_length=8192, synthetic data, average of steps 16-19). Full recipe and results in #5785.ragged_buffer_factor=2.0,moe_dropless_fallback=layerThe fallback never triggered in this run (synthetic data, no "overflow detected" log lines), so it measures the cost of the overflow check, which is negligible.
AOT HBM (
train_compile,compile_topology=v5p-256, libtpu 0.0.46):ragged_buffer_factor=2.0ragged_buffer_factor=2.0,moe_dropless_fallback=layer(scan)Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.