Repository navigation
Skip MoMaFFN in the tensor-parallel plan, so no MoMa plan key goes unresolved - #777
Merged
Merged
Conversation
amazloumi
self-requested a review
December 5, 2026 16:50
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 6 files with indirect coverage changes 🚀 New features to boost your workflow:
|
amazloumi
requested changes
Dec 5, 2026
amazloumi
left a comment
Member
There was a problem hiding this comment.
The plan now skips MoMaFFN like MoEMLP, the sharded parameters and their placements are unchanged from main at tp=2 and tp=4, the unresolved-key warnings are gone, and the new tests fail on main's code. just resolve the comment below and it will good to go.
Merged
5 of 7 tasks
This was referenced Dec 5, 2026
amazloumi
approved these changes
Dec 6, 2026
amazloumi
left a comment
Member
There was a problem hiding this comment.
Approve. The docstring point is fixed, and on a merge with current main the sharded parameters and their placements still match main at tp=2 and tp=4, the unresolved-key warnings are gone, and the new tests pass and fail on main's code.
5 of 7 tasks
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.
Summary
_build_mlp_tp_plan(kempnerforge/distributed/tensor_parallel.py) gave a MoMa block'smlp, aMoMaFFN, the dense MLP entriesmlp.up_proj(column-parallel) andmlp.down_proj(row-parallel). AMoMaFFNkeeps its experts underexperts.<modality>.experts.<i>and has neither child, so for every MoMa blockparallelize_modulewarnedParallelize plan key 'up_proj' could not be resolved: ... skipping this plan entry, the same fordown_proj, and sharded nothing there._build_mlp_tp_plannow returns no entries for aMoMaFFN, as it already does for anMoEMLP. Its docstring says why: the experts sit in per-modality groups with noup_projordown_projof their own, and the groups stay whole on every TP rank. The new import adds no cycle:tensor_parallel.pyalready importskempnerforge.model.moe, and loading that package runskempnerforge/model/__init__.py, which importstransformer.py, which importsmoma.py.tp > 1no longer prints the warnings "Parallelize plan key 'up_proj' could not be resolved" and "Parallelize plan key 'down_proj' could not be resolved" at startup.parallelize_moduleissued both for every MoMa block, and Python shows each identical warning once, so every rank printed the pair once. Nothing else changes. The skipped entries matched nothing, so the same parameters are sharded as before (each block's four attention projections), and the model computes the same result.tests/unit/test_distributed.py: newTestBuildBlockTPPlan::test_moma_block_plan_has_only_the_attention_projections. AMoMaBlock's plan without SequenceParallel is exactlyattention.q_proj,k_proj,v_projando_proj, and with SequenceParallel on it still has nomlp.*entry.tests/unit/test_moma.py: newTestMoMaTensorParallel::test_the_attention_is_sharded_and_the_expert_groups_stay_whole, on 2 gloo CPU ranks withtp = 2and tied embeddings (MoMa's only way to turn SequenceParallel off).apply_tensor_parallelon a 2-layer MoMa model raises no "could not be resolved" warning. The DTensor parameters are exactly the 8 attention projections (Q/K/VShard(0), OShard(1)), so the routers and every expert stay plain tensors. The logits and every parameter's full gradient match an unsharded copy. Before this, no unit test ran a MoMa model under tensor parallelism, althoughdocs/configuration/validation-rules.mdsays it matches an unsharded model.docs/distributed/tensor-parallelism.md(VLM architectures) now says that a MoMa block's plan holds only its attention projections. The page anddocs/configuration/validation-rules.mdalready said that MoMa's expert groups stay whole on every TP rank, which is still exact.codebase-map.json: an entry fortests/unit/test_moma.py, which had none;TestBuildBlockTPPlan(8), plus the twotest_distributed.pyclasses the entry was missing (TestApplyTensorParallelSequenceParallel(3)andTestApplyFsdp2GuardedAttributes(3)), so its count is 45; andTestApplyTensorParallelSequenceParallelandTestMoMaTensorParallelintensor_parallel.py'stested_by.kempnerforge/distributed/parallel.pynow listsTestApplyFsdp2GuardedAttributesamong its tests.What remains of #769 is the full sharding of MoMa's expert groups:
gate_projandup_projcolumn-parallel,down_projrow-parallel, with replicated input and output; the routers stay replicated), amodel.computed_expert_ffn_hidden_dim % tpcheck beside the cross-attention one inJobConfig.validate, a parity test with Gumbel noise on, and the docs.k_echoice identical on every TP rank: rely on the TP ranks' shared seed (seed + pp_rank,kempnerforge/distributed/setup.py:135) and pin it with a test, or draw the Gumbel noise once and broadcast it over the TP group. Second, run one all-reduce per expert (a row-paralleldown_projon each) or one perMoMaFFN(sum the partial expert outputs, then reduce once).Testing
uv run ruff check .passesuv run ruff format --check .passesuv run pyright kempnerforge/passes (0 errors)uv run pytest tests/unit/ -v --timeout=60passes at 67bd965 (b786c49 after it changes only a test and the map), apart from 48 failures this node also gives main, none in a file this branch touches (6568 passed, 14 skipped, 72 min): 38 intest_vlm_dataset.py(35) andtest_video_dataset.py(3), which need thegpt2tokenizer missing from this node's offline Hugging Face cache; 9test_streaming_resume.pytests that ran out of time under load, 8 at the 60 s limit and 1 whose child process passed its own 50 s limit (test_streaming_resume.py's worker and multi-rank tests need more than the unit tier's 60 s on cluster CPU nodes #754, closed as not planned; the file passes alone at--timeout=300: 41 passed); and 1test_convert_checkpoint.pycase that hit the netscratchOSError: [Errno 39] Directory not emptywhile removing its temp directory (the file passes alone: 143 passed).uv run torchrun --nproc_per_node=4 -m pytest tests/distributed/ -v: not run.tensor_parallel.pychanged, but that suite needs GPUs and this branch was tested on CPU only. The new gloo test runs the changed plan on 2 CPU ranks instead.uv run pytest tests/e2e/ --e2e -v: not run, for the same reason (the e2e tests need GPUs).Failing first, on main (d5befc5) with this branch's two test files:
test_moma_block_plan_has_only_the_attention_projections:AssertionError: assert {'attention.k...'mlp.up_proj'} == {'attention.k...ntion.v_proj'}, with'mlp.up_proj'and'mlp.down_proj'as the extra itemstest_the_attention_is_sharded_and_the_expert_groups_stay_whole:AssertionError: ["Parallelize plan key 'up_proj' could not be resolved", "Parallelize plan key 'down_proj' could not be resolved", "Parallelize plan key 'up_proj' could not be resolved", "Parallelize plan key 'down_proj' could not be resolved"], raised on rank 0.MoMaFFNonly without SequenceParallel fails the plan test:AssertionError: assert not ['mlp.up_proj', 'mlp.down_proj'].Also checked:
sphinx -W --keep-going -b html docsbuilds with no warnings._build_mlp_tp_plan's docstring, which no longer names an issue: ruff passes and the two touched test files pass (118 passed).codebase-map.jsonparses, and its counts match except main's knowntest_moe.pyandtest_dataloader_iter.pyentries.codebase-map.jsonparses with only those two known mismatches. The two touched test files pass at b786c49 (118 passed) and on the merge of 67bd965 with 275fee3 (118 passed).Contribution terms
Part of #769: the full sharding of MoMa's expert groups, described above, remains.