Repository navigation
[config] Skip the parallel-axes check for configs that declare no layouts - #6359
Conversation
…outs The transformers backend builds its MoE and its sharding layouts at parallelize time, so its config declares no layouts and no MoE.Config when validate_model_training_config runs. The parallel-axes check added in fb1d2ba then read EP > 1 on it as "no routed experts" and rejected every transformers-backend MoE run with expert parallelism. Return early when the config declares no layouts. Native TorchTitan model configs all declare layouts, so their checks are unchanged. A dense transformers-backend model with EP > 1 passes validation again, as before fb1d2ba. A TODO in parallelize_hf_transformers records the check that should reject it there.
|
Reply from claude: @claude review |
|
Claude finished @felipemello1's task in 2m 15s —— View job Verdict: Approve -- please address the items before merging (fill in the human-written summary; the dense-model EP TODO can likely become a 4-line raise). A maintainer still needs to review. See review |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The early return changes behavior only for configs that declare no layouts, and the only check it skips for them is the "no routed experts" raise. The PR touches core (torchtitan/config/validation.py), so a maintainer still needs to review it.
What this PR does. _validate_declared_parallel_axes now collects layouts once and returns early when there are none. When a config has no layouts, the per-layout loop was already a no-op. So the only behavior that changes is the EP > 1 "has no routed experts" raise, and that now runs only for configs that declare at least one layout. All native models declare layouts even with every degree at 1, so their checks don't change. The transformers backend declares its layouts at parallelize time, so it bypasses the check.
Example.
HFTransformerModel.Config("debugmodel_moe"), parallelism.expert_parallel_degree=2
main: ValueError "HFTransformerModel.Config has no routed experts" (0 layouts, no MoE.Config)
this PR: passes; MoE + layouts are built in parallelize_hf_transformers
Flux / llama3 debugmodel, EP=2
main: ValueError (32 / 195 layouts declared, no MoE.Config)
this PR: same ValueError
deepseek_v3 debugmodel built at EP=1, validated at EP=2
main/PR: ValueError "declares no 'ep' sharding" (test_ep_off_built_moe_rejects_ep_gt1)
Must fix
- PR description -- "Summary (human-written)" is empty. The author fills it in; agents leave it alone (
CONTRIBUTING.md, AI-assisted contributions).
Should consider
torchtitan/experiments/transformers_modeling_backend/parallelize.py:138-- the TODO says the dense-model EP check can't be done because of PP. Butmodel.model.config.is_moegives the full-model answer on every PP stage, so the roughly 4-line raise could replace the TODO (see the inline comment).
Details
- Layer: the check lives in core, and the HF backend builds its MoE and its sharding on purpose once the parallelism context is known (
moe_replacement.py). Gating on "nothing declared" is the smallest change that doesn't teach core about the experiment. A core branch onHFTransformerModel.Configwould break principle 5. - Tradeoff: any future native model that declares no layouts at all also skips the EP check. Today that can't happen: every model in
torchtitan/modelsdeclares at least 32 layouts with every degree at 1, according to the description. - Test: it builds only the config, not the model, and runs in the CPU suite, so it's cheap. It guards the exact regression that went unnoticed because the 8-GPU workflow's path filter left out
torchtitan/config/**. Core CPU tests already import experiments (test_embedding.py,test_tokenizer.py), andtransformersis inrequirements-dev.txt, so the placement and the missing skip guard are fine. - Overlap: the description already mentions fegin's draft that edits the same lines.
Not verified: the GPU run (fsdp+tp+ep+cp on 8x A10G with transformers 5.9.0) and the is_moe suggestion under PP.
| # TODO: raise when expert_parallel_degree > 1 and no layer of the full model is MoE: | ||
| # a dense model trains with EP unused. Under PP, model.layers holds one stage only. |
There was a problem hiding this comment.
The reason this TODO gives for deferring the check doesn't seem to hold. model.layers is per stage under PP, but each stage is a deepcopy of the whole model (pipeline.py:198). So model.model.config is the full HFTransformerModel.Config on every stage, and its is_moe (set in Config.__init__, model.py:299) is the full-model answer. It is also the same flag that gates probe_native_moe_params.
Without the check, a dense HF model with EP > 1 trains while ignoring the EP degree. That is the silent fallback principle 8 rules out. The raise is about 4 lines, so it could replace the TODO here:
if parallelism.expert_parallel_degree > 1 and not model.model.config.is_moe:
raise ValueError(
"expert_parallel_degree > 1 requires an MoE flavor (TitanMoeModelConfig); "
f"got {parallelism.expert_parallel_degree} for a dense model."
)Unverified: I haven't run this under PP. If is_moe can disagree with the per-layer moe_enabled detection (for example, an MoE HF checkpoint loaded with a dense flavor), please say so in the TODO instead.
There was a problem hiding this comment.
Reply from claude: Done in 3b0a828: the TODO is now this raise, reading model.model.config.is_moe. Checked:
- PP: each stage is a deepcopy of the whole model (
pipeline_parallel.py:664), so the config is the full one. is_moecan't disagree in a way that matters:_native_moe_paramsis set only byprobe_native_moe_params, which runs only whenconfig.is_moe(model.py:885), andbuild_and_swap_native_moeskips layers without it (moe_replacement.py:127). So withis_moeFalse, no Titan MoE is built and EP would go unused.- Dense debug recipe at EP = 2 on 2 GPUs now raises the new ValueError at parallelize (it trained with EP unused before this commit).
|
Reply from claude: @claude review |
|
Claude finished @felipemello1's task in 57s —— View job Verdict: Approve -- please address the items before merging (fill in the human-written summary; the dense-model EP raise from the last review is resolved). A maintainer still needs to review. See review |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging. The new commit replaces the TODO with a raise, and that raise is correct. The only item left is the empty human-written summary. The PR touches core (torchtitan/config/validation.py), so a maintainer still needs to review it.
Changes since the last review (3b0a828). parallelize_hf_transformers now raises when expert_parallel_degree > 1 and model.model.config.is_moe is False.
Example.
HF dense debugmodel, expert_parallel_degree=2
main: ValueError at config load ("has no routed experts", from the core check)
a62d25c (commit 1): would train with EP unused (the core check is skipped, nothing else raises)
3b0a828 (HEAD): ValueError at parallelize ("needs an MoE flavor")
HF debugmodel_moe, expert_parallel_degree=2
main: ValueError at config load HEAD: passes; MoE + layouts built in parallelize
Earlier items
- Resolved: the dense-model EP TODO in
parallelize.py.is_moeis set from the flavor type (model.py:299), and it is the same flag that gatesprobe_native_moe_params(model.py:885). The HF model holds the same config object it was built from (model.py:853), and PP's deepcopy keeps the instance attribute. So every stage sees the full-model answer. - Still open: see Must fix.
Must fix
- PR description: "Summary (human-written)" is still the template placeholder. The author fills it in; agents leave it alone (
CONTRIBUTING.md, AI-assisted contributions).
Details
- Tradeoff: for HF configs, the "dense model + EP" error moves from config load to parallelize. Principle 8 prefers config time. But only the experiment knows
is_moe, and itsConfig.__post_init__doesn't seeparallelism. Adding an HF-specific branch to core validation would break principle 5. Raising at parallelize, before any MoE swap or sharding, is the earliest point the experiment owns. - No new problems in the new hunk.
Not verified: the 8x A10G CI run with transformers 5.9.0.
…parallel_degree > 1 Only MoE flavors build Titan MoE: probe_native_moe_params runs only when config.is_moe. A dense model with expert_parallel_degree > 1 trained with EP unused. Raise in parallelize_hf_transformers instead. The check reads model.model.config.is_moe, not the layers: under PP, model.layers holds only one stage's layers, while each stage keeps a deepcopy of the full config.
3b0a828 to
0f17083
Compare
|
Reply from claude: @bantianyue, the EP check from #5995 rejects every transformers-backend MoE run with EP > 1, because that backend builds its MoE at parallelize time. So the Transformers Modeling Backend 8 GPU job has been red since 11-18. This PR fixes it. Could you please take a look? |
|
Thanks for catching this, and thanks for the fix. #5995's config-time EP check assumed layouts and |
Summary (human-written)
Agent details
TLDR:
Transformers Modeling Backend 8 GPU Integration Testshas been red on main since 2026-11-18: 15 of 15 completed runs. Its MoE test (fsdp+tp+ep+cp) fails at config load withHFTransformerModel.Config has no routed experts; set parallelism.expert_parallel_degree to 1 (got 2).It broke with #5995 ("[config] Reject unsupported TP/EP degrees for FLUX"). @bantianyue, could you please take a look? This PR skips the parallel-axes check when a model config declares no sharding layouts. Native TorchTitan models all declare layouts, so their checks don't change. A dense transformers-backend model with EP > 1 now gets a clear error at parallelize time.Problem
_validate_declared_parallel_axeschecks the sharding layouts that the model config declares. It finds the routed experts by looking forMoE.Configin the config tree.MoE.Config, it raises "has no routed experts". Commit fb1d2ba ("Reject unsupported TP/EP degrees for FLUX") added this.parallelize_hf_transformers(build_and_swap_native_moe, thenset_hf_sharding_configs). When the check runs, its config declares 0 layouts and has noMoE.Config.torchtitan/experiments/transformers_modeling_backend/**changes. So the commit that added the check never ran it. The 12-hour schedule caught it.Solution
_collect_model_layoutson eachdebugmodel): Flux 32, Llama3 195, DeepSeek-V3 311, Qwen3.5 379, Kimi K3 1406, Kimi K3.1 1416. All 15 models intorchtitan/modelshave at least 32. The transformers-backend MoE and dense debug configs have 0.test_hf_moe_config_accepts_ep_gt1. It builds the transformers-backend MoE debug config from a localQwen3MoeConfig(no network) and validates it at EP = 2. It runs inCPU Unit Test, so the next change tovalidation.pygets checked against this case.parallelize_hf_transformersraises whenexpert_parallel_degree > 1and the flavor is dense (config.is_moeis False). Only MoE flavors build Titan MoE, so EP would go unused. It reads the config, notmodel.layers: under PP each stage keeps only its own layers, but a full copy of the config.Results
You may ask:
moe_replacement.py).torchtitan/config/**to the workflow's path filter? Many core files can break this backend. A CPU test on every PR is cheaper than an 8-GPU job.NOTE: The GPU run above used 4 GB300s and transformers 5.23. CI uses 8 A10Gs (dp_shard = 2) and transformers 5.9.0. CI runs the 8-GPU workflow on this PR only once it is out of draft.
NOTE: fegin's open draft "[dist_moe] Keep the output postprocess weights on the dense FSDP mesh" edits the same lines of
_validate_declared_parallel_axes. It adds the samelayouts = _collect_model_layouts(model)line, so whichever lands second needs a small rebase.NOTE: Two red checks here come from main.
CPU Unit Testshows the profiler-close test's 3 failures until its fix lands.lintfails on a pyrefly error intorchtitan/models/kimi_k3/dsa.pyuntil the Kimi K3.1 FLOPs fix lands.Test plan
pre-commit run --files (SKIP=pyrefly-check): all hooks pass. pyrefly check torchtitan/config/validation.py: 0 errors.
Full core CPU suite (
pytest tests/unit_tests/cpu) on main 34ac322 + both CI fixes, local CPU: 2099 passed, 7 failed. The same 7 also fail on plain main in this local venv (older torch nightly, no torchao). CI at 34ac322 passed 5 of them and skips the other 2's file.