Repository navigation
Conversation
With expert parallelism, non-routed weights (attention, dense MLP, shared experts) are sharded over
('fsdp', ..., 'expert') on their embed-like dims. The explicit FSDP all-gather only gathered
'fsdp', so it bailed out to an untagged reshard and XLA inserted a second, un-prefetched gather over
'expert' before each consumer.
Gather every FSDP co-sharding axis ('fsdp', 'fsdp_transpose', 'context', 'context_usp_ulysses',
'expert') from the first FSDP axis of a dimension onward as one tagged xla_explicit_fsdp gather.
Dimensions without an FSDP axis (the routed-expert dim) and axes before the first FSDP axis keep
their sharding.
darisoy
requested review from
A9isha,
NuojCheng,
RissyRan,
SurbhiJainUSC,
abhinavclemson,
aireenmei,
bvandermoon,
dipannita08,
gagika,
gobbleturk,
hengtaoguo,
huytransformer,
igorts-git,
jiangjy1982,
khatwanimohit,
parambole,
richjames0,
shralex,
shuningjin,
vipannalla and
xibinliu
as code owners
October 19, 2026 19:57
There was a problem hiding this comment.
Code Review
This pull request introduces support for gathering co-sharded axes (such as 'expert' and 'context') alongside FSDP axes during FSDP prefetching in MaxText. It adds helper functions _fsdp_axes_for_dim and _remove_fsdp_from_sharding to identify and strip these co-sharded axes from the sharding specifications, and updates the FSDP all-gather logic accordingly. Additionally, comprehensive unit tests have been added to verify the behavior for co-sharded, routed, and compound dimensions. No review comments were provided, and the implementation looks solid, so there is no additional feedback.
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
FSDP weight prefetching (
prefetch_fsdp_weights=True) did not prefetch most weights under expert parallelism.With
ici_expert_parallelism > 1, the non-routed weights (MLA attention, dense MLP, shared experts) are sharded over('fsdp', ..., 'expert')on their embed-like dims (embed,embed_attn,q_lora,kv_lorainbase.yml)._explicit_fsdp_all_gatheronly looked forfsdp/fsdp_transpose, so it requiredfsdpto be the minor-most axis of the dimension, foundexpertafter it, and returnedNone. That made it fall back to an untagged reshard overfsdp, and XLA then added a second, un-prefetched all-gather overexpertright before each consumer.This PR treats
expert,contextandcontext_usp_ulyssesas FSDP co-sharding axes when they come after an FSDP axis on the same dimension:_fsdp_axes_for_dim(entry): if a dimension has an FSDP axis, returns every co-sharding axis from the first FSDP axis onward._remove_fsdp_from_sharding()strips exactly those axes to get the gathered sharding, and_explicit_fsdp_all_gather()gathers them as onexla_explicit_fsdp-tagged all-gather (e.g. 128-way over('fsdp','expert')).'expert') and axes before the first FSDP axis (e.g.'expert'in('expert','fsdp')) keep their sharding, so routed experts stay EP-sharded and only gatherfsdp.FSDP-only (
expert=1) is unchanged: size-1 axes are dropped before the gather axes are computed, and an EP=1 AoT compile gives the same set of tagged all-gathers (146 total / 144 tagged, identical shapes, axes and dims) before and after this change.Tests
Unit tests: 3 new tests in
tests/unit/fsdp_prefetch_test.py:('fsdp','expert')co-sharded dim gathered together, routed-expert'expert'dim preserved, and leading'expert'in a compound('expert','fsdp')dim preserved. All 11 tests pass.AoT compile (DSv3 15L/128E,
gf=4x4x4,fsdp=32 x expert=4): tagged FSDP all-gathers go from 32 to 144 (every decoder weight gather), and the 132 un-prefetched in-layerexpertgathers are gone.End-to-end, GhostFish 4x4x4: DSv3 15L, 256 experts,
ici_expert_parallelism=4,per_device_batch_size=1, top-k 4,remat_policy=custom; prefetch runs use--xla_tpu_enable_fsdp_latency_hiding_scheduler=true --xla_tpu_explicit_fsdp_dedicated_sparse_core_id=0:The dedicated SparseCore is needed with EP. Without
xla_tpu_explicit_fsdp_dedicated_sparse_core_id, the prefetched gathers queue behind the layer's ragged-all-to-all and other SparseCore work, and the step time is 1955.7 ms (-1.7%) (xid/301803674).Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.