Skip to content

[MoE][4/n] deprecate expert tensor parallel (ETP) - #3167

Merged
acisseJZhong merged 6 commits into
mainfrom
gh/acisseJZhong/11/head
Apr 30, 2026
Merged

acisseJZhong merged 6 commits into
mainfrom
gh/acisseJZhong/11/head

Conversation

@acisseJZhong

@acisseJZhong acisseJZhong commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Stacked on #3125

Summary

Removes expert tensor parallelism (ETP). With the trend toward fine-grained experts, sharding already-skinny expert weights with TP is impractical — the shapes become too small for efficient GEMMs. Additionally, when ETP>1 all TP ranks within the same EP group perform redundant all-to-all communication, wasting bandwidth (see discussion).

This removes the ExpertTensorParallel classes, the etp mesh axis, the expert_tensor_parallel_degree / expert_parallel_comm_backend config fields, and all ETP references across models and experiments.

Test plan

  • pre-commit run --all-files passes
NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama4' --baseline-config='llama4_debugmodel' --baseline-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 4 --parallelism.tensor_parallel_degree 1 --parallelism.expert_parallel_degree 2" --baseline-ngpus=4 --test-module='llama4' --test-config='llama4_debugmodel' --test-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 4 --parallelism.tensor_parallel_degree 1 --parallelism.expert_parallel_degree 2 --parallelism.expert_tensor_parallel_degree 1" --test-ngpus=4 --assert-equal --no-seed-checkpoint

Stacked on #3125

Now that #3125 consolidated EP=1 and EP>1 to all use
All2AllTokenDispatcher, ETP is no longer needed. This PR removes:

- `expert_tensor_parallel` config option and related config fields
- ETP application logic from all model parallelize functions
  (llama4, deepseek_v3, gpt_oss, qwen3, qwen3_vl)
- ETP helper functions from `torchtitan/distributed/expert_parallel.py`
- ETP references from experiments (graph_trainer, autoparallel, rl)

[ghstack-poisoned]
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 29, 2026
Stacked on #3125

## Summary

Removes expert tensor parallelism (ETP). With the trend toward fine-grained experts, sharding already-skinny expert weights with TP is impractical — the shapes become too small for efficient GEMMs. Additionally, when ETP>1 all TP ranks within the same EP group perform redundant all-to-all communication, wasting bandwidth (see [discussion](#2842 (comment))). 

This removes the `ExpertTensorParallel` classes, the `etp` mesh axis, the `expert_tensor_parallel_degree` / `expert_parallel_comm_backend` config fields, and all ETP references across models and experiments.

## Test plan
- [ ] `pre-commit run --all-files` passes
- [ ] Existing EP integration tests pass (ETP=1 was the common config, which is now the only path)

[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Apr 29, 2026
Stacked on #3125

Now that #3125 consolidated EP=1 and EP>1 to all use
All2AllTokenDispatcher, ETP is no longer needed. This PR removes:

- `expert_tensor_parallel` config option and related config fields
- ETP application logic from all model parallelize functions
  (llama4, deepseek_v3, gpt_oss, qwen3, qwen3_vl)
- ETP helper functions from `torchtitan/distributed/expert_parallel.py`
- ETP references from experiments (graph_trainer, autoparallel, rl)

ghstack-source-id: 84700a0
Pull Request resolved: #3167
Stacked on #3125

## Summary

Removes expert tensor parallelism (ETP). With the trend toward fine-grained experts, sharding already-skinny expert weights with TP is impractical — the shapes become too small for efficient GEMMs. Additionally, when ETP>1 all TP ranks within the same EP group perform redundant all-to-all communication, wasting bandwidth (see [discussion](#2842 (comment))). 

This removes the `ExpertTensorParallel` classes, the `etp` mesh axis, the `expert_tensor_parallel_degree` / `expert_parallel_comm_backend` config fields, and all ETP references across models and experiments.

## Test plan
- [ ] `pre-commit run --all-files` passes
- [ ] Existing EP integration tests pass (ETP=1 was the common config, which is now the only path)

[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Apr 29, 2026
Stacked on #3125

Now that #3125 consolidated EP=1 and EP>1 to all use
All2AllTokenDispatcher, ETP is no longer needed. This PR removes:

- `expert_tensor_parallel` config option and related config fields
- ETP application logic from all model parallelize functions
  (llama4, deepseek_v3, gpt_oss, qwen3, qwen3_vl)
- ETP helper functions from `torchtitan/distributed/expert_parallel.py`
- ETP references from experiments (graph_trainer, autoparallel, rl)

ghstack-source-id: 32a03ae
Pull Request resolved: #3167
Comment thread tests/integration_tests/models.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to this PR: this flag doesn't make sense, as there's no TP axis

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, I will just remove this flag for this EP test.

Comment thread tests/integration_tests/models.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove this test, as we don't aim to support dualpipe overlapping

Comment thread torchtitan/config/configs.py Outdated
Comment on lines 224 to 225
Note that this is still an experimental feature. Some constraints will be
relaxed soon when we have more flexible DeviceMesh support.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this comment

"""
Expert parallelism degree. 1 means disabled. No effect for non-MoE models.

Currently, etp is either 1 or is the same as tp.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add notes on the constraint, about
dense dp_shard x cp x tp == sparse efsdp (implicit) x ep

comm_backend = parallelism.expert_parallel_comm_backend
if comm_backend in ("deepep", "hybridep"):
if not parallel_dims.ep_enabled:
raise ValueError(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we still need to error out right? Not sure if it was added in previous PR, but if not, we should error out in update_from_configs of MoE models model.py. It is where you get both model config and CLI override of parallelism configs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's safe to delete this assertion. If EP=1 and we are using EP dispatcher, it will error out here as EP group is not set.

assert self.ep_mesh is not None, (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are two levels of assertion. The one here should be ValueError (user mistake), that one should be assertion (system mistake). So we should still error out in config (which is cheaper).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that makes sense. We should def error out invalid config before run starts.

Stacked on #3125

## Summary

Removes expert tensor parallelism (ETP). With the trend toward fine-grained experts, sharding already-skinny expert weights with TP is impractical — the shapes become too small for efficient GEMMs. Additionally, when ETP>1 all TP ranks within the same EP group perform redundant all-to-all communication, wasting bandwidth (see [discussion](#2842 (comment))). 

This removes the `ExpertTensorParallel` classes, the `etp` mesh axis, the `expert_tensor_parallel_degree` / `expert_parallel_comm_backend` config fields, and all ETP references across models and experiments.

## Test plan
- [ ] `pre-commit run --all-files` passes
```
NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama4' --baseline-config='llama4_debugmodel' --baseline-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 4 --parallelism.tensor_parallel_degree 1 --parallelism.expert_parallel_degree 2" --baseline-ngpus=4 --test-module='llama4' --test-config='llama4_debugmodel' --test-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 4 --parallelism.tensor_parallel_degree 1 --parallelism.expert_parallel_degree 2 --parallelism.expert_tensor_parallel_degree 1" --test-ngpus=4 --assert-equal --no-seed-checkpoint
```

[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Apr 30, 2026
Stacked on #3125

Now that #3125 consolidated EP=1 and EP>1 to all use
All2AllTokenDispatcher, ETP is no longer needed. This PR removes:

- `expert_tensor_parallel` config option and related config fields
- ETP application logic from all model parallelize functions
  (llama4, deepseek_v3, gpt_oss, qwen3, qwen3_vl)
- ETP helper functions from `torchtitan/distributed/expert_parallel.py`
- ETP references from experiments (graph_trainer, autoparallel, rl)

ghstack-source-id: 05540b8
Pull Request resolved: #3167
Stacked on #3125

## Summary

Removes expert tensor parallelism (ETP). With the trend toward fine-grained experts, sharding already-skinny expert weights with TP is impractical — the shapes become too small for efficient GEMMs. Additionally, when ETP>1 all TP ranks within the same EP group perform redundant all-to-all communication, wasting bandwidth (see [discussion](#2842 (comment))). 

This removes the `ExpertTensorParallel` classes, the `etp` mesh axis, the `expert_tensor_parallel_degree` / `expert_parallel_comm_backend` config fields, and all ETP references across models and experiments.

## Test plan
- [ ] `pre-commit run --all-files` passes
```
NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama4' --baseline-config='llama4_debugmodel' --baseline-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 4 --parallelism.tensor_parallel_degree 1 --parallelism.expert_parallel_degree 2" --baseline-ngpus=4 --test-module='llama4' --test-config='llama4_debugmodel' --test-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 4 --parallelism.tensor_parallel_degree 1 --parallelism.expert_parallel_degree 2 --parallelism.expert_tensor_parallel_degree 1" --test-ngpus=4 --assert-equal --no-seed-checkpoint
```

[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Apr 30, 2026
Stacked on #3125

Now that #3125 consolidated EP=1 and EP>1 to all use
All2AllTokenDispatcher, ETP is no longer needed. This PR removes:

- `expert_tensor_parallel` config option and related config fields
- ETP application logic from all model parallelize functions
  (llama4, deepseek_v3, gpt_oss, qwen3, qwen3_vl)
- ETP helper functions from `torchtitan/distributed/expert_parallel.py`
- ETP references from experiments (graph_trainer, autoparallel, rl)

ghstack-source-id: e24c20d
Pull Request resolved: #3167
Stacked on #3125

## Summary

Removes expert tensor parallelism (ETP). With the trend toward fine-grained experts, sharding already-skinny expert weights with TP is impractical — the shapes become too small for efficient GEMMs. Additionally, when ETP>1 all TP ranks within the same EP group perform redundant all-to-all communication, wasting bandwidth (see [discussion](#2842 (comment))). 

This removes the `ExpertTensorParallel` classes, the `etp` mesh axis, the `expert_tensor_parallel_degree` / `expert_parallel_comm_backend` config fields, and all ETP references across models and experiments.

## Test plan
- [ ] `pre-commit run --all-files` passes
```
NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama4' --baseline-config='llama4_debugmodel' --baseline-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 4 --parallelism.tensor_parallel_degree 1 --parallelism.expert_parallel_degree 2" --baseline-ngpus=4 --test-module='llama4' --test-config='llama4_debugmodel' --test-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 4 --parallelism.tensor_parallel_degree 1 --parallelism.expert_parallel_degree 2 --parallelism.expert_tensor_parallel_degree 1" --test-ngpus=4 --assert-equal --no-seed-checkpoint
```

[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request Apr 30, 2026
Stacked on #3125

Now that #3125 consolidated EP=1 and EP>1 to all use
All2AllTokenDispatcher, ETP is no longer needed. This PR removes:

- `expert_tensor_parallel` config option and related config fields
- ETP application logic from all model parallelize functions
  (llama4, deepseek_v3, gpt_oss, qwen3, qwen3_vl)
- ETP helper functions from `torchtitan/distributed/expert_parallel.py`
- ETP references from experiments (graph_trainer, autoparallel, rl)

ghstack-source-id: 6fa5fc2
Pull Request resolved: #3167
layer_cfg.moe.router._debug_force_load_balance = (
debug.moe_force_load_balance
)
comm_backend = getattr(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious is there's any specific reason gpt-oss doesn't support deepep / hybridep. If not maybe it's low hanging fruit to enable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not very sure why there's no deepep/hybridep support. @wwwjn @shuhuayu in case you have more context. I can add one if no technical gaps.

@acisseJZhong
acisseJZhong changed the base branch from gh/acisseJZhong/11/base to main April 30, 2026 07:01
@acisseJZhong
acisseJZhong merged commit c4b409a into main Apr 30, 2026
15 of 18 checks passed
saforem2 pushed a commit to saforem2/torchtitan that referenced this pull request Apr 30, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack) (oldest at
bottom):
* __->__ pytorch#3167

Stacked on pytorch#3125

## Summary

Removes expert tensor parallelism (ETP). With the trend toward
fine-grained experts, sharding already-skinny expert weights with TP is
impractical — the shapes become too small for efficient GEMMs.
Additionally, when ETP>1 all TP ranks within the same EP group perform
redundant all-to-all communication, wasting bandwidth (see
[discussion](pytorch#2842 (comment))).

This removes the `ExpertTensorParallel` classes, the `etp` mesh axis,
the `expert_tensor_parallel_degree` / `expert_parallel_comm_backend`
config fields, and all ETP references across models and experiments.

## Test plan
- [ ] `pre-commit run --all-files` passes
```
NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama4' --baseline-config='llama4_debugmodel' --baseline-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 4 --parallelism.tensor_parallel_degree 1 --parallelism.expert_parallel_degree 2" --baseline-ngpus=4 --test-module='llama4' --test-config='llama4_debugmodel' --test-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 4 --parallelism.tensor_parallel_degree 1 --parallelism.expert_parallel_degree 2 --parallelism.expert_tensor_parallel_degree 1" --test-ngpus=4 --assert-equal --no-seed-checkpoint
```
saforem2 added a commit to saforem2/torchtitan that referenced this pull request Apr 30, 2026
Upstream c4b409a deleted ExpertTensorParallel, the etp mesh axis, and
the expert_parallel_comm_backend / expert_tensor_parallel_degree config
fields. Replays the same removals into experiments/ezpz/moe and updates
docs/upstream-sync.md with the 26th-sync entry.

- moe/parallelize.py: drop ExpertTensorParallel import; drop etp_mesh /
  ep_etp_mesh args from apply_moe_ep_tp() signature and call site;
  collapse experts_mesh selection to the two surviving cases (TP-shard
  when EP disabled, ExpertParallel when EP enabled).
- moe/model.py: read comm_backend off layer_cfg.moe.experts.token_dispatcher
  (matches upstream deepseek_v3.model after pytorch#3167); raise ValueError when
  deepep/hybridep is selected with expert_parallel_degree==1.
syed-ahmed added a commit to syed-ahmed/torchtitan that referenced this pull request Apr 30, 2026
…Config

expert_parallel_comm_backend was removed from ParallelismConfig in
pytorch#3167 (ETP deprecation). Read comm_backend from the model's token
dispatcher config instead, which is set by moe_comm_backend in
model_registry / config factories.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
syed-ahmed added a commit to syed-ahmed/torchtitan that referenced this pull request Apr 30, 2026
…Config

expert_parallel_comm_backend was removed from ParallelismConfig in
pytorch#3167 (ETP deprecation). Read comm_backend from the model's token
dispatcher config instead, which is set by moe_comm_backend in
model_registry / config factories.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
syed-ahmed added a commit that referenced this pull request Apr 30, 2026
…Config (#3177)

`expert_parallel_comm_backend` was removed from
#3167.
#3007 didn't take it into
account and broke graph trainer CI.

- This PR reads comm backend from the model config to initialize
hybridep buffers.
- Also restores non_blocking_capacity_factor default value for the
concrete model flavors, since some tests call the concrete flavors
directly.

Tested locally:
```
  + NGPU=4                                                                                                                                                                                                                                                 
  + export LOG_RANK=0                                                                                                                                                                                                                                      
  + LOG_RANK=0                                                                                                                                                                                                                                             
  + MODULE=graph_trainer.deepseek_v3                                                                                                                                                                                                                       
  + CONFIG=graph_trainer_deepseek_v3_debugmodel_hybridep                                                                                                                                                                                                   
  + COMM_MODE=                                                                                                                                                                                                                                             
  + TORCHFT_LIGHTHOUSE=http://localhost:29510                                                                                                                                                                                                              
  + '[' -n '' ']'                        
  + PYTORCH_ALLOC_CONF=expandable_segments:True                                                                                                                                                                                                            
  + TORCHFT_LIGHTHOUSE=http://localhost:29510                                                                                                                                                                                                              
  + torchrun --nproc_per_node=4 --rdzv_backend c10d --rdzv_endpoint=localhost:0 --local-ranks-filter 0 --role rank --tee 3 -m torchtitan.train --module graph_trainer.deepseek_v3 --config graph_trainer_deepseek_v3_debugmodel_hybridep --compile.mode
  aot_fx_trace --parallelism.data_parallel_shard_degree=2 --parallelism.tensor_parallel_degree=2 --parallelism.expert_parallel_degree=2 --training.steps=3                                                                                                 
  [rank0]:[titan] 2026-04-30 09:24:36,606 - root - INFO - torchtitan version: 0.2.2                                                  
  [rank0]:[titan] 2026-04-30 09:24:37,184 - root - INFO - Building device mesh with parallelism: pp=1, dp_replicate=1, dp_shard=2, cp=1, tp=2, ep=2                                                                                                        
  [rank0]:[titan] 2026-04-30 09:24:37,204 - root - INFO - Successfully created meshes with active dimensions: ['batch', 'loss', 'fsdp', 'tp', 'ep', 'efsdp']                                                                                               
  [rank0]:[titan] 2026-04-30 09:24:38,881 - root - INFO - Building graph_trainer/deepseek_v3 debugmodel                                                                                                                                                    
  [rank0]:[titan] 2026-04-30 09:24:38,924 - root - INFO - CUDA capacity: NVIDIA GB200 with 184.00GiB memory                                                                                                                                                
  [rank0]:[titan] 2026-04-30 09:24:38,942 - root - INFO - Total parameter count: dense 23,173,376, sparse 9,840,640, active 28,098,816                                                                                                                     
  [rank0]:[titan] 2026-04-30 09:24:38,942 - root - INFO - Model graph_trainer/deepseek_v3 debugmodel size: 33,014,016 total parameters                                                                                                                     
  [rank0]:[titan] 2026-04-30 09:24:39,022 - root - INFO - Applied Data Parallel (simple_fsdp) (dp mode=fully_shard) to the model                                                                                                                           
  [rank0]:[titan] 2026-04-30 09:24:39,817 - root - INFO - Pre-initialized HybridEP buffer (hidden_dim=256, num_tokens=16384, num_local_experts=4)                                                                                                          
  [rank0]:[titan] 2026-04-30 09:24:39,817 - root - INFO - aot_fx_trace compile mode: graph capture will happen at training time                                                                                                                            
  [rank0]:[titan] 2026-04-30 09:24:40,725 - root - INFO - Peak FLOPS used for computing MFU: 2.500e+15                                                                                                                                                     
  [rank0]:[titan] 2026-04-30 09:24:40,725 - root - INFO - CUDA memory usage for model: 0.04GiB(0.02%)                                                                                                                                                      
  [rank0]:[titan] 2026-04-30 09:24:42,931 - root - INFO - Trainer is initialized with local batch size 8, global batch size 16, gradient accumulation steps 1, sequence length 2048, total steps 3 (warmup 2)                                              
  [rank0]:[titan] 2026-04-30 09:24:42,931 - root - INFO - Training starts at step 1                                                                                                                                                                        
  [rank0]:[titan] 2026-04-30 09:24:47,646 - root - INFO - Removed 62 aten.detach.default node(s) from the graph                                                                                                                                            
  [rank0]:[titan] 2026-04-30 09:24:47,708 - root - INFO - Removed 669 identity view/reshape node(s) from the graph                                                                                                                                         
  [rank0]:[titan] 2026-04-30 09:24:47,709 - root - INFO - Removed 66 identity slice node(s)                                                                                                                                                                
  [rank0]:[titan] 2026-04-30 09:24:47,880 - root - INFO - Applied selective activation checkpointing (SAC) graph pass.                                                                                                                                     
  [rank0]:[titan] 2026-04-30 09:24:47,880 - root - INFO -   Forced 5 nodes to MUST_SAVE at layer boundaries                                                                                                                                                
  [rank0]:[titan] 2026-04-30 09:24:47,880 - root - INFO -   Layer non-layer: 2 MUST_SAVE, 62 PREFER_RECOMPUTE                                                                                                                                              
  [rank0]:[titan] 2026-04-30 09:24:47,880 - root - INFO -   Layer 0: 10 MUST_SAVE, 90 PREFER_RECOMPUTE                                                                                                                                                     
  [rank0]:[titan] 2026-04-30 09:24:47,880 - root - INFO -   Layer 1: 13 MUST_SAVE, 120 PREFER_RECOMPUTE                                                                                                                                                    
  [rank0]:[titan] 2026-04-30 09:24:47,880 - root - INFO -   Layer 2: 13 MUST_SAVE, 120 PREFER_RECOMPUTE                              
  [rank0]:[titan] 2026-04-30 09:24:47,880 - root - INFO -   Layer 3: 13 MUST_SAVE, 120 PREFER_RECOMPUTE                                                                                                                                                    
  [rank0]:[titan] 2026-04-30 09:24:47,880 - root - INFO -   Layer 4: 13 MUST_SAVE, 120 PREFER_RECOMPUTE
  [rank0]:[titan] 2026-04-30 09:24:47,880 - root - INFO -   Layer 5: 13 MUST_SAVE, 120 PREFER_RECOMPUTE                                                                                                                                                    
  [rank0]:[titan] 2026-04-30 09:24:50,157 - root - INFO - Applied cudagraph pass.                                                    
  [rank0]:[titan] 2026-04-30 09:25:00,187 - root - INFO - step:  1  loss:  4.03640  grad_norm:  3.3902  memory:  1.93GiB(1.05%)  tps: 386  tflops: 0.21  mfu: 0.01%
  [rank0]:[titan] 2026-04-30 09:25:00,345 - root - INFO - step:  2  loss:  3.05691  grad_norm:  4.5189  memory:  1.93GiB(1.05%)  tps: 52,168  tflops: 28.32  mfu: 1.13%
  [rank0]:[titan] 2026-04-30 09:25:00,389 - root - INFO - step:  3  loss:  2.46308  grad_norm:  2.7644  memory:  1.93GiB(1.05%)  tps: 186,611  tflops: 101.32  mfu: 4.05%
  [rank0]:[titan] 2026-04-30 09:25:02,389 - root - INFO - Training completed                                                                                                                                                                               
  [rank0]:[titan] 2026-04-30 09:25:03,816 - root - INFO - Process group destroyed 
```

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
acisseJZhong added a commit that referenced this pull request May 13, 2026
…ared/routed experts"


<img width="1041" height="641" alt="image" src="https://github.com/user-attachments/assets/4d913288-7447-45f3-9b9c-d4f1939e0184" />

https://excalidraw.com/#json=2abKr0m2s26fc6lyoF9Qq,MqMzUIoXWYJIfckHNOB7Sw

Previous stack: #3167

## Summary

Refactor MoE parallelization to establish clean DTensor boundaries:
- **Router**: gate weights Replicate, input all-gathered to Replicate (via `NoParallel`), compute on DTensor, output converted to local via `to_local(grad_placements=Partial)`
- **Shared experts**: weights TP-sharded (via `ColwiseParallel`/`RowwiseParallel`), input all-gathered to Replicate inside `ColwiseParallel`, compute on DTensor, output local via `to_local` (Partial placement, `use_local_output=True`)
- **Routed experts**: input converted to local via `to_local` at `GroupedExperts` boundary, EP-partitioned weights on local tensors, dispatch/compute/combine all local

Key changes:
- Move `shared_experts` computation from inside `TokenDispatcher.combine()` to `MoE.forward()`
- Move `to_local` from `MoE.forward()` into `GroupedExperts.forward()`, with proper `grad_placements` based on placement type (Shard vs Replicate)
- Replace `ColwiseParallelWithGradPlacement` with standard `ColwiseParallel` using `input_layouts`
- Remove `shared_experts` parameter from all token dispatchers, replace with `initial_output` buffer
- For EP+SP, keep `Shard(1)` as desired MoE input layout (avoid redundant all-gather at MoE boundary); for TP-only, keep `Replicate()` (required for TP-sharded expert weight reduction)

### Trade-offs
- Removes async overlap between `shared_experts` and the all-to-all combine. Previously `shared_experts` ran while the combine A2A was in flight on the NCCL stream. A follow-up can restore overlap using CUDA streams.

## Test plan
- [X] TP=1 EP=1 runs, losses different than main starting step1. 
- [X] TP=2 EP=1 runs, losses different than main starting step1.  
- [X] TP=1 EP=2 runs, losses different than main starting step1. 
- [X] TP=2 EP=2 runs, losses different than main starting step1. 

Loss is expected to diverge compared to main due to different reduction pattern, and shared expert computation changes place. This is also reflected in the fact that loss only diverges on step1(matches in step0). 

single run
```
NCCL_NVLS_ENABLE=0 NGPU=4 MODULE='llama4' CONFIG='llama4_debugmodel' ./run_train.sh \
    --parallelism.pipeline_parallel_degree 1 \
    --parallelism.data_parallel_shard_degree 2 \
    --parallelism.tensor_parallel_degree 2 \
    --parallelism.expert_parallel_degree 2 \
    --debug.deterministic --debug.seed=42
```
Compare loss
```
NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama4' --baseline-config='llama4_debugmodel' --baseline-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 2" --baseline-ngpus=4 --test-module='llama4' --test-config='llama4_debugmodel' --test-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 2" --test-ngpus=4 --assert-equal --no-seed-checkpoint
```

[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request May 13, 2026
…oundaries for shared/routed experts"


<img width="1041" height="641" alt="image" src="https://github.com/user-attachments/assets/4d913288-7447-45f3-9b9c-d4f1939e0184" />

https://excalidraw.com/#json=2abKr0m2s26fc6lyoF9Qq,MqMzUIoXWYJIfckHNOB7Sw

Previous stack: #3167

## Summary

Refactor MoE parallelization to establish clean DTensor boundaries:
- **Router**: gate weights Replicate, input all-gathered to Replicate (via `NoParallel`), compute on DTensor, output converted to local via `to_local(grad_placements=Partial)`
- **Shared experts**: weights TP-sharded (via `ColwiseParallel`/`RowwiseParallel`), input all-gathered to Replicate inside `ColwiseParallel`, compute on DTensor, output local via `to_local` (Partial placement, `use_local_output=True`)
- **Routed experts**: input converted to local via `to_local` at `GroupedExperts` boundary, EP-partitioned weights on local tensors, dispatch/compute/combine all local

Key changes:
- Move `shared_experts` computation from inside `TokenDispatcher.combine()` to `MoE.forward()`
- Move `to_local` from `MoE.forward()` into `GroupedExperts.forward()`, with proper `grad_placements` based on placement type (Shard vs Replicate)
- Replace `ColwiseParallelWithGradPlacement` with standard `ColwiseParallel` using `input_layouts`
- Remove `shared_experts` parameter from all token dispatchers, replace with `initial_output` buffer
- For EP+SP, keep `Shard(1)` as desired MoE input layout (avoid redundant all-gather at MoE boundary); for TP-only, keep `Replicate()` (required for TP-sharded expert weight reduction)

### Trade-offs
- Removes async overlap between `shared_experts` and the all-to-all combine. Previously `shared_experts` ran while the combine A2A was in flight on the NCCL stream. A follow-up can restore overlap using CUDA streams.

## Test plan
- [X] TP=1 EP=1 runs, losses different than main starting step1. 
- [X] TP=2 EP=1 runs, losses different than main starting step1.  
- [X] TP=1 EP=2 runs, losses different than main starting step1. 
- [X] TP=2 EP=2 runs, losses different than main starting step1. 

Loss is expected to diverge compared to main due to different reduction pattern, and shared expert computation changes place. This is also reflected in the fact that loss only diverges on step1(matches in step0). 

single run
```
NCCL_NVLS_ENABLE=0 NGPU=4 MODULE='llama4' CONFIG='llama4_debugmodel' ./run_train.sh \
    --parallelism.pipeline_parallel_degree 1 \
    --parallelism.data_parallel_shard_degree 2 \
    --parallelism.tensor_parallel_degree 2 \
    --parallelism.expert_parallel_degree 2 \
    --debug.deterministic --debug.seed=42
```
Compare loss
```
NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama4' --baseline-config='llama4_debugmodel' --baseline-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 2" --baseline-ngpus=4 --test-module='llama4' --test-config='llama4_debugmodel' --test-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 2" --test-ngpus=4 --assert-equal --no-seed-checkpoint
```

[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request May 13, 2026
…ared/routed experts"


<img width="1041" height="641" alt="image" src="https://github.com/user-attachments/assets/4d913288-7447-45f3-9b9c-d4f1939e0184" />

https://excalidraw.com/#json=2abKr0m2s26fc6lyoF9Qq,MqMzUIoXWYJIfckHNOB7Sw

Previous stack: #3167

## Summary

Refactor MoE parallelization to establish clean DTensor boundaries:
- **Router**: gate weights Replicate, input all-gathered to Replicate (via `NoParallel`), compute on DTensor, output converted to local via `to_local(grad_placements=Partial)`
- **Shared experts**: weights TP-sharded (via `ColwiseParallel`/`RowwiseParallel`), input all-gathered to Replicate inside `ColwiseParallel`, compute on DTensor, output local via `to_local` (Partial placement, `use_local_output=True`)
- **Routed experts**: input converted to local via `to_local` at `GroupedExperts` boundary, EP-partitioned weights on local tensors, dispatch/compute/combine all local

Key changes:
- Move `shared_experts` computation from inside `TokenDispatcher.combine()` to `MoE.forward()`
- Move `to_local` from `MoE.forward()` into `GroupedExperts.forward()`, with proper `grad_placements` based on placement type (Shard vs Replicate)
- Replace `ColwiseParallelWithGradPlacement` with standard `ColwiseParallel` using `input_layouts`
- Remove `shared_experts` parameter from all token dispatchers, replace with `initial_output` buffer
- For EP+SP, keep `Shard(1)` as desired MoE input layout (avoid redundant all-gather at MoE boundary); for TP-only, keep `Replicate()` (required for TP-sharded expert weight reduction)

### Trade-offs
- Removes async overlap between `shared_experts` and the all-to-all combine. Previously `shared_experts` ran while the combine A2A was in flight on the NCCL stream. A follow-up can restore overlap using CUDA streams.

## Test plan
- [X] TP=1 EP=1 runs, losses different than main starting step1. 
- [X] TP=2 EP=1 runs, losses different than main starting step1.  
- [X] TP=1 EP=2 runs, losses different than main starting step1. 
- [X] TP=2 EP=2 runs, losses different than main starting step1. 

Loss is expected to diverge compared to main due to different reduction pattern, and shared expert computation changes place. This is also reflected in the fact that loss only diverges on step1(matches in step0). 

single run
```
NCCL_NVLS_ENABLE=0 NGPU=4 MODULE='llama4' CONFIG='llama4_debugmodel' ./run_train.sh \
    --parallelism.pipeline_parallel_degree 1 \
    --parallelism.data_parallel_shard_degree 2 \
    --parallelism.tensor_parallel_degree 2 \
    --parallelism.expert_parallel_degree 2 \
    --debug.deterministic --debug.seed=42
```
Compare loss
```
NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama4' --baseline-config='llama4_debugmodel' --baseline-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 2" --baseline-ngpus=4 --test-module='llama4' --test-config='llama4_debugmodel' --test-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 2" --test-ngpus=4 --assert-equal --no-seed-checkpoint
```

[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request May 14, 2026
…oundaries for shared/routed experts"


<img width="1041" height="641" alt="image" src="https://github.com/user-attachments/assets/4d913288-7447-45f3-9b9c-d4f1939e0184" />

https://excalidraw.com/#json=2abKr0m2s26fc6lyoF9Qq,MqMzUIoXWYJIfckHNOB7Sw

Previous stack: #3167

## Summary

Refactor MoE parallelization to establish clean DTensor boundaries:
- **Router**: gate weights Replicate, input all-gathered to Replicate (via `NoParallel`), compute on DTensor, output converted to local via `to_local(grad_placements=Partial)`
- **Shared experts**: weights TP-sharded (via `ColwiseParallel`/`RowwiseParallel`), input all-gathered to Replicate inside `ColwiseParallel`, compute on DTensor, output local via `to_local` (Partial placement, `use_local_output=True`)
- **Routed experts**: input converted to local via `to_local` at `GroupedExperts` boundary, EP-partitioned weights on local tensors, dispatch/compute/combine all local

Key changes:
- Move `shared_experts` computation from inside `TokenDispatcher.combine()` to `MoE.forward()`
- Move `to_local` from `MoE.forward()` into `GroupedExperts.forward()`, with proper `grad_placements` based on placement type (Shard vs Replicate)
- Replace `ColwiseParallelWithGradPlacement` with standard `ColwiseParallel` using `input_layouts`
- Remove `shared_experts` parameter from all token dispatchers, replace with `initial_output` buffer
- For EP+SP, keep `Shard(1)` as desired MoE input layout (avoid redundant all-gather at MoE boundary); for TP-only, keep `Replicate()` (required for TP-sharded expert weight reduction)

### Trade-offs
- Removes async overlap between `shared_experts` and the all-to-all combine. Previously `shared_experts` ran while the combine A2A was in flight on the NCCL stream. A follow-up can restore overlap using CUDA streams.

## Test plan
- [X] TP=1 EP=1 runs, losses different than main starting step1. 
- [X] TP=2 EP=1 runs, losses different than main starting step1.  
- [X] TP=1 EP=2 runs, losses different than main starting step1. 
- [X] TP=2 EP=2 runs, losses different than main starting step1. 

Loss is expected to diverge compared to main due to different reduction pattern, and shared expert computation changes place. This is also reflected in the fact that loss only diverges on step1(matches in step0). 

single run
```
NCCL_NVLS_ENABLE=0 NGPU=4 MODULE='llama4' CONFIG='llama4_debugmodel' ./run_train.sh \
    --parallelism.pipeline_parallel_degree 1 \
    --parallelism.data_parallel_shard_degree 2 \
    --parallelism.tensor_parallel_degree 2 \
    --parallelism.expert_parallel_degree 2 \
    --debug.deterministic --debug.seed=42
```
Compare loss
```
NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama4' --baseline-config='llama4_debugmodel' --baseline-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 2" --baseline-ngpus=4 --test-module='llama4' --test-config='llama4_debugmodel' --test-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 2" --test-ngpus=4 --assert-equal --no-seed-checkpoint
```

[ghstack-poisoned]
acisseJZhong added a commit that referenced this pull request May 14, 2026
…ared/routed experts"


<img width="1041" height="641" alt="image" src="https://github.com/user-attachments/assets/4d913288-7447-45f3-9b9c-d4f1939e0184" />

https://excalidraw.com/#json=2abKr0m2s26fc6lyoF9Qq,MqMzUIoXWYJIfckHNOB7Sw

Previous stack: #3167

## Summary

Refactor MoE parallelization to establish clean DTensor boundaries:
- **Router**: gate weights Replicate, input all-gathered to Replicate (via `NoParallel`), compute on DTensor, output converted to local via `to_local(grad_placements=Partial)`
- **Shared experts**: weights TP-sharded (via `ColwiseParallel`/`RowwiseParallel`), input all-gathered to Replicate inside `ColwiseParallel`, compute on DTensor, output local via `to_local` (Partial placement, `use_local_output=True`)
- **Routed experts**: input converted to local via `to_local` at `GroupedExperts` boundary, EP-partitioned weights on local tensors, dispatch/compute/combine all local

Key changes:
- Move `shared_experts` computation from inside `TokenDispatcher.combine()` to `MoE.forward()`
- Move `to_local` from `MoE.forward()` into `GroupedExperts.forward()`, with proper `grad_placements` based on placement type (Shard vs Replicate)
- Replace `ColwiseParallelWithGradPlacement` with standard `ColwiseParallel` using `input_layouts`
- Remove `shared_experts` parameter from all token dispatchers, replace with `initial_output` buffer
- For EP+SP, keep `Shard(1)` as desired MoE input layout (avoid redundant all-gather at MoE boundary); for TP-only, keep `Replicate()` (required for TP-sharded expert weight reduction)

### Trade-offs
- Removes async overlap between `shared_experts` and the all-to-all combine. Previously `shared_experts` ran while the combine A2A was in flight on the NCCL stream. A follow-up can restore overlap using CUDA streams.

## Test plan
- [X] TP=1 EP=1 runs, losses different than main starting step1. 
- [X] TP=2 EP=1 runs, losses different than main starting step1.  
- [X] TP=1 EP=2 runs, losses different than main starting step1. 
- [X] TP=2 EP=2 runs, losses different than main starting step1. 

Loss is expected to diverge compared to main due to different reduction pattern, and shared expert computation changes place. This is also reflected in the fact that loss only diverges on step1(matches in step0). 

single run
```
NCCL_NVLS_ENABLE=0 NGPU=4 MODULE='llama4' CONFIG='llama4_debugmodel' ./run_train.sh \
    --parallelism.pipeline_parallel_degree 1 \
    --parallelism.data_parallel_shard_degree 2 \
    --parallelism.tensor_parallel_degree 2 \
    --parallelism.expert_parallel_degree 2 \
    --debug.deterministic --debug.seed=42
```
Compare loss
```
NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama4' --baseline-config='llama4_debugmodel' --baseline-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 2" --baseline-ngpus=4 --test-module='llama4' --test-config='llama4_debugmodel' --test-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 2" --test-ngpus=4 --assert-equal --no-seed-checkpoint
```

[ghstack-poisoned]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants