Repository navigation
GraphTrainer spmd_types backend - #4325
Conversation
[ghstack-poisoned]
[ghstack-poisoned]
## Changes
- Reuse GraphTrainer's DTensor-backed SimpleFSDP implementation with an
`spmd_types` model-parallel backend.
- Preserve each parameter's `SpmdType` through FSDP wrapping and materialize
replicated non-DP axes with `spmd.redistribute`.
- Pass concrete mesh inputs through tracing and precompile so functional
collectives resolve runtime process groups.
## Test environment
| Item | Value |
| --- | --- |
| Test commit | This temporary commit |
| Baseline | `main` (`partial_dtensor`) |
| GPUs | 8x NVIDIA H100 80 GB |
| Numerics | `--debug.seed=42 --debug.deterministic` |
| Performance | 8-GPU sweep: 20 steps, discard 1-5, 3 repeats; Qwen control: 100 steps, discard 1-20 |
## Numerics
Both backends loaded the same seed checkpoint. Values were read from
TensorBoard rather than rounded stdout.
| Model | Parallelism | Steps | Max loss diff | Max grad-norm diff | Result |
| --- | --- | ---: | ---: | ---: | --- |
| Llama3 | FSDP4 + TP2 | 10 | 0 | 0 | Bitwise equal |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | 10 | 0 | 0 | Bitwise equal |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | 10 | `6.198883e-05` | `1.537800e-04` | Within expected EP all-to-all variation |
| Llama3 precompiled | FSDP4 + TP2 | 10 | 0 | 0 | `partial_dtensor` and `spmd_types` artifacts bitwise equal |
DeepSeek V3 required disabling
`joint_transformer_block_bucketing_reordering_pass` on both backends. The
baseline otherwise fails before step 1 with `stable topological sort of region
failed`, matching the disabled integration-test configuration.
## Performance
The 8-GPU results use 20 steps, discard steps 1-5, and pool the 45 remaining
samples from three runs. The Qwen result uses concurrent 4-GPU jobs, 100 steps,
metrics every 10 steps, a shared seed checkpoint, and discards steps 1-20.
These are debug-model measurements.
| Model | Parallelism | Backend | Inductor | CUDA graph | Run median TPS | Median TPS | Peak GPU memory |
| --- | --- | --- | --- | --- | --- | ---: | ---: |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | off | 113869, 113036, 128761 | 120050 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | off | 113059, 122464, 126526 | 120610 (+0.47%) | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | on | 122355, 111723, 117532 | 117532 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | on | 116173, 105596, 117504 | 113715 (-3.25%) | 0.45 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `partial_dtensor` | regional | off | 69576 | 69576 | 3.29 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `spmd_types` | regional | off | 70268 | 70268 (+0.99%) | 3.29 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `partial_dtensor` | regional | off | 68334, 61409, 65488 | 65146 | 1.60 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `spmd_types` | regional | off | 56253, 70177, 56928 | 63973 (-1.80%) | 1.60 GiB |
Qwen backends ran concurrently on disjoint four-GPU sets and were then swapped.
The table reports GPUs 0-3. Results from GPUs 4-7 were excluded because GPU 4
reported sustained thermal throttling and produced severe throughput stalls.
The DeepSeek result has high run-to-run variance and should be treated as
provisional on this host.
## Graph parity
The serialized precompile graphs are not node-for-node identical. Node targets
were normalized across generated callable addresses before comparison. CUDA
graph capture runs after artifact load, so the Llama CUDA-graph-on and -off
artifacts have the same pre-capture graph.
| Configuration | Nodes, partial / SPMD | AG | RS | AR | A2A | Compiled regions | Exact node sequence |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | --- |
| Llama3 FSDP4 + TP2, CUDA graph off | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Llama3 FSDP4 + TP2, CUDA graph on | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Qwen3 MoE FSDP4 + TP2 + EP4 | 5797 / 5603 | 222 / 206 | 44 / 44 | 12 / 12 | 40 / 40 | 16 / 16 | No |
| DeepSeek V3 FSDP4 + TP2 + EP4 | 4694 / 4468 | 225 / 215 | 116 / 116 | 54 / 54 | 25 / 25 | 12 / 12 | No |
| MuseGlimmer FSDP4 + TP2 | 4546 / 4453 | 254 / 254 | 52 / 52 | 12 / 12 | 0 / 0 | 16 / 16 | No |
DeepSeek graphs were compared with the bucketing pass removed from both sides
because the partial-DTensor precompile path hits the known topological-sort
failure. This comparison required analysis-only pass filtering: precompile does
not currently propagate `compile.disable_passes` to `apply_graph_passes`. No
workaround for that issue is included in this commit.
The SPMD graphs contain fewer process-group lookups and no additional
reduce-scatter, all-reduce, or all-to-all collectives. The main extra work is a
BF16 -> FP32 cast pair before FSDP gradient reduction for parameters replicated
on a non-DP axis:
| Model | Extra SPMD cast pairs | PG lookup delta | All-gather delta |
| --- | ---: | ---: | ---: |
| Llama3 | 13 | -39 | 0 |
| Qwen3 MoE | 49 | -75 | -16 |
| DeepSeek V3 | 35 | -66 | -10 |
| MuseGlimmer | 33 | -67 | 0 |
These casts are produced by composing the `spmd.redistribute(I -> R)` backward
dtype conversion with SimpleFSDP's FP32 gradient reduction. Under regional
Inductor they remain outside the compiled attention regions. The Kineto traces
have effectively identical profiled step times, and the healthy-device Qwen
control shows no measurable regression, so there is no evidence that these
casts materially affect runtime. DeepSeek's run medians range from 56.3K to
70.2K TPS, while its pooled steady-state median is only 1.8% below the baseline.
## Precompile
Artifact generation and distributed load/run used explicit mesh inputs and
mesh-coordinate registration.
| Model | Parallelism | CUDA graph | Artifact generation | 8-GPU load/run |
| --- | --- | --- | --- | --- |
| Llama3 | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
| Llama3 | FSDP4 + TP2 | on | Pass | Pass, 3 steps |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| MuseGlimmer | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
DeepSeek V3 and MuseGlimmer emitted non-fatal TritonBundler warnings for cached
FlexAttention cubins that were absent at load time; both jobs completed.
## Model and feature coverage
| Test | Result |
| --- | --- |
| MuseGlimmer FSDP4 + TP2, 3 steps | Pass |
| Llama3 FSDP4 + TP2, full Inductor | Pass |
| Llama3 FSDP4 + TP2, no optional graph passes | Pass |
| Llama3 FSDP4 + TP2, full recompute | Pass |
| Llama3 FSDP4 + TP2, SAC + CPU offload | Pass |
| Llama3 FSDP4 + TP2, FSDP AG/RS overlap | Pass |
| Llama3 FSDP4 + TP2, numerics-changing optimizations | Pass |
| Llama3 DCP save at step 2 and resume through step 4 | Pass |
| DeepSeek V3 FSDP4 + TP2 + EP4 DCP save/resume | Pass |
| Focused SimpleFSDP and precompile unit tests | 27 passed |
## Blocked coverage
| Test | `partial_dtensor` | `spmd_types` | Classification |
| --- | --- | --- | --- |
| Llama3 FSDP2 + TP2 + CP2 | Rejected by configuration: CP requires `spmd_types` | FlexAttention trace fails with `FunctionalTensor on its own` | CP/FlexAttention limitation; only reachable with SPMD |
| DeepSeek V3 GraphPP Interleaved1F1B | Pass, 3 steps | Fails before partitioning on unresolved enum axes `(DP, CP)` | SPMD-specific integration gap; all schedules share this path |
| DeepSeek V3 EP-overlap eager chunking | Trace fails: block mask is larger than chunked query | Not reached in comparison | Backend-independent eager-chunk test failure |
| DeepSeek V3 graph EP overlap | CUDA device-side assert during expert-bias update | Same CUDA device-side assert | Backend-independent |
| DeepSeek V3 default FSDP bucketing | Stable-topological-sort assertion | Passes precompile/load/run | Existing `partial_dtensor` failure |
## Commands
### Concurrent Qwen performance
Run both commands concurrently, then swap the two `CUDA_VISIBLE_DEVICES`
assignments:
```bash
CUDA_VISIBLE_DEVICES=<four GPUs> NGPU=4 \
MODULE=graph_trainer.qwen3 CONFIG=graph_trainer_qwen3_debugmodel_moe \
./run_train.sh \
--training.steps=100 --training.disable_cuda_graphs --metrics.log_freq=10 \
--compile.mode=aot_fx_trace --compile.inductor_compilation=regional \
--compile.disable_passes=cudagraph_pass \
--parallelism.spmd_backend=<partial_dtensor|spmd_types> \
--parallelism.data_parallel_shard_degree=2 \
--parallelism.tensor_parallel_degree=2 \
--parallelism.expert_parallel_degree=2 \
--checkpoint.enable --checkpoint.load_only \
--checkpoint.initial_load_path=<seed-checkpoint> \
--debug.seed=42
```
### Backend numerics
```bash
python scripts/loss_compare.py main <spmd-commit> \
--baseline-module graph_trainer.<model> \
--baseline-config <config> \
--test-module graph_trainer.<model> \
--test-config <config> \
--baseline-options='<common options> --parallelism.spmd_backend partial_dtensor' \
--test-options='<common options> --parallelism.spmd_backend spmd_types' \
--steps 10 --metrics loss,grad_norm \
--baseline-ngpus 8 --test-ngpus 8
```
Common Llama options:
```text
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
```
Common Qwen3 MoE options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
Common DeepSeek V3 options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes joint_transformer_block_bucketing_reordering_pass,cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
### Precompile
```bash
python -m torchtitan.experiments.graph_trainer.precompile_main \
--module graph_trainer.<model> --config <config> \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
NGPU=8 MODULE=graph_trainer.<model> CONFIG=<config> \
./torchtitan/experiments/graph_trainer/run_train_precompile.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
```
### Feature smoke
```bash
NGPU=8 MODULE=graph_trainer.llama3 CONFIG=graph_trainer_llama3_debugmodel \
./run_train.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.disable_passes cudagraph_pass \
--parallelism.spmd_backend spmd_types \
--parallelism.data_parallel_shard_degree 4 \
--parallelism.tensor_parallel_degree 2 \
<one of:
--compile.inductor_compilation full
--compile.no-enable_passes
--compile.memory_policy full
--compile.memory_policy sac_and_offload
--compile.enable_fsdp_ag_rs_overlap
--compile.numerics_changing_optim>
```
### Unit tests
```bash
pytest -q \
torchtitan/experiments/graph_trainer/tests/test_simple_fsdp.py \
torchtitan/experiments/graph_trainer/tests/test_precompile.py
```
Lint and GraphTrainer type checking were not run.
ghstack-source-id: 1984878
Pull-Request: #4325
## Changes
- Reuse GraphTrainer's DTensor-backed SimpleFSDP implementation with an
`spmd_types` model-parallel backend.
- Preserve each parameter's `SpmdType` through FSDP wrapping and materialize
replicated non-DP axes with `spmd.redistribute`.
- Pass concrete mesh inputs through tracing and precompile so functional
collectives resolve runtime process groups.
## Test environment
| Item | Value |
| --- | --- |
| Test commit | This temporary commit |
| Baseline | `main` (`partial_dtensor`) |
| GPUs | 8x NVIDIA H100 80 GB |
| Numerics | `--debug.seed=42 --debug.deterministic` |
| Performance | 8-GPU sweep: 20 steps, discard 1-5, 3 repeats; Qwen control: 100 steps, discard 1-20 |
## Numerics
Both backends loaded the same seed checkpoint. Values were read from
TensorBoard rather than rounded stdout.
| Model | Parallelism | Steps | Max loss diff | Max grad-norm diff | Result |
| --- | --- | ---: | ---: | ---: | --- |
| Llama3 | FSDP4 + TP2 | 10 | 0 | 0 | Bitwise equal |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | 10 | 0 | 0 | Bitwise equal |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | 10 | `6.198883e-05` | `1.537800e-04` | Within expected EP all-to-all variation |
| Llama3 precompiled | FSDP4 + TP2 | 10 | 0 | 0 | `partial_dtensor` and `spmd_types` artifacts bitwise equal |
DeepSeek V3 required disabling
`joint_transformer_block_bucketing_reordering_pass` on both backends. The
baseline otherwise fails before step 1 with `stable topological sort of region
failed`, matching the disabled integration-test configuration.
## Performance
The 8-GPU results use 20 steps, discard steps 1-5, and pool the 45 remaining
samples from three runs. The Qwen result uses concurrent 4-GPU jobs, 100 steps,
metrics every 10 steps, a shared seed checkpoint, and discards steps 1-20.
These are debug-model measurements.
| Model | Parallelism | Backend | Inductor | CUDA graph | Run median TPS | Median TPS | Peak GPU memory |
| --- | --- | --- | --- | --- | --- | ---: | ---: |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | off | 113869, 113036, 128761 | 120050 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | off | 113059, 122464, 126526 | 120610 (+0.47%) | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | on | 122355, 111723, 117532 | 117532 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | on | 116173, 105596, 117504 | 113715 (-3.25%) | 0.45 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `partial_dtensor` | regional | off | 69576 | 69576 | 3.29 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `spmd_types` | regional | off | 70268 | 70268 (+0.99%) | 3.29 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `partial_dtensor` | regional | off | 68334, 61409, 65488 | 65146 | 1.60 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `spmd_types` | regional | off | 56253, 70177, 56928 | 63973 (-1.80%) | 1.60 GiB |
Qwen backends ran concurrently on disjoint four-GPU sets and were then swapped.
The table reports GPUs 0-3. Results from GPUs 4-7 were excluded because GPU 4
reported sustained thermal throttling and produced severe throughput stalls.
The DeepSeek result has high run-to-run variance and should be treated as
provisional on this host.
## Graph parity
The serialized precompile graphs are not node-for-node identical. Node targets
were normalized across generated callable addresses before comparison. CUDA
graph capture runs after artifact load, so the Llama CUDA-graph-on and -off
artifacts have the same pre-capture graph.
| Configuration | Nodes, partial / SPMD | AG | RS | AR | A2A | Compiled regions | Exact node sequence |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | --- |
| Llama3 FSDP4 + TP2, CUDA graph off | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Llama3 FSDP4 + TP2, CUDA graph on | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Qwen3 MoE FSDP4 + TP2 + EP4 | 5797 / 5603 | 222 / 206 | 44 / 44 | 12 / 12 | 40 / 40 | 16 / 16 | No |
| DeepSeek V3 FSDP4 + TP2 + EP4 | 4694 / 4468 | 225 / 215 | 116 / 116 | 54 / 54 | 25 / 25 | 12 / 12 | No |
| MuseGlimmer FSDP4 + TP2 | 4546 / 4453 | 254 / 254 | 52 / 52 | 12 / 12 | 0 / 0 | 16 / 16 | No |
DeepSeek graphs were compared with the bucketing pass removed from both sides
because the partial-DTensor precompile path hits the known topological-sort
failure. This comparison required analysis-only pass filtering: precompile does
not currently propagate `compile.disable_passes` to `apply_graph_passes`. No
workaround for that issue is included in this commit.
The SPMD graphs contain fewer process-group lookups and no additional
reduce-scatter, all-reduce, or all-to-all collectives. The main extra work is a
BF16 -> FP32 cast pair before FSDP gradient reduction for parameters replicated
on a non-DP axis:
| Model | Extra SPMD cast pairs | PG lookup delta | All-gather delta |
| --- | ---: | ---: | ---: |
| Llama3 | 13 | -39 | 0 |
| Qwen3 MoE | 49 | -75 | -16 |
| DeepSeek V3 | 35 | -66 | -10 |
| MuseGlimmer | 33 | -67 | 0 |
These casts are produced by composing the `spmd.redistribute(I -> R)` backward
dtype conversion with SimpleFSDP's FP32 gradient reduction. Under regional
Inductor they remain outside the compiled attention regions. The Kineto traces
have effectively identical profiled step times, and the healthy-device Qwen
control shows no measurable regression, so there is no evidence that these
casts materially affect runtime. DeepSeek's run medians range from 56.3K to
70.2K TPS, while its pooled steady-state median is only 1.8% below the baseline.
## Precompile
Artifact generation and distributed load/run used explicit mesh inputs and
mesh-coordinate registration.
| Model | Parallelism | CUDA graph | Artifact generation | 8-GPU load/run |
| --- | --- | --- | --- | --- |
| Llama3 | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
| Llama3 | FSDP4 + TP2 | on | Pass | Pass, 3 steps |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| MuseGlimmer | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
DeepSeek V3 and MuseGlimmer emitted non-fatal TritonBundler warnings for cached
FlexAttention cubins that were absent at load time; both jobs completed.
## Model and feature coverage
| Test | Result |
| --- | --- |
| MuseGlimmer FSDP4 + TP2, 3 steps | Pass |
| Llama3 FSDP4 + TP2, full Inductor | Pass |
| Llama3 FSDP4 + TP2, no optional graph passes | Pass |
| Llama3 FSDP4 + TP2, full recompute | Pass |
| Llama3 FSDP4 + TP2, SAC + CPU offload | Pass |
| Llama3 FSDP4 + TP2, FSDP AG/RS overlap | Pass |
| Llama3 FSDP4 + TP2, numerics-changing optimizations | Pass |
| Llama3 DCP save at step 2 and resume through step 4 | Pass |
| DeepSeek V3 FSDP4 + TP2 + EP4 DCP save/resume | Pass |
| Focused SimpleFSDP and precompile unit tests | 27 passed |
## Blocked coverage
| Test | `partial_dtensor` | `spmd_types` | Classification |
| --- | --- | --- | --- |
| Llama3 FSDP2 + TP2 + CP2 | Rejected by configuration: CP requires `spmd_types` | FlexAttention trace fails with `FunctionalTensor on its own` | CP/FlexAttention limitation; only reachable with SPMD |
| DeepSeek V3 GraphPP Interleaved1F1B | Pass, 3 steps | Fails before partitioning on unresolved enum axes `(DP, CP)` | SPMD-specific integration gap; all schedules share this path |
| DeepSeek V3 EP-overlap eager chunking | Trace fails: block mask is larger than chunked query | Not reached in comparison | Backend-independent eager-chunk test failure |
| DeepSeek V3 graph EP overlap | CUDA device-side assert during expert-bias update | Same CUDA device-side assert | Backend-independent |
| DeepSeek V3 default FSDP bucketing | Stable-topological-sort assertion | Passes precompile/load/run | Existing `partial_dtensor` failure |
## Commands
### Concurrent Qwen performance
Run both commands concurrently, then swap the two `CUDA_VISIBLE_DEVICES`
assignments:
```bash
CUDA_VISIBLE_DEVICES=<four GPUs> NGPU=4 \
MODULE=graph_trainer.qwen3 CONFIG=graph_trainer_qwen3_debugmodel_moe \
./run_train.sh \
--training.steps=100 --training.disable_cuda_graphs --metrics.log_freq=10 \
--compile.mode=aot_fx_trace --compile.inductor_compilation=regional \
--compile.disable_passes=cudagraph_pass \
--parallelism.spmd_backend=<partial_dtensor|spmd_types> \
--parallelism.data_parallel_shard_degree=2 \
--parallelism.tensor_parallel_degree=2 \
--parallelism.expert_parallel_degree=2 \
--checkpoint.enable --checkpoint.load_only \
--checkpoint.initial_load_path=<seed-checkpoint> \
--debug.seed=42
```
### Backend numerics
```bash
python scripts/loss_compare.py main <spmd-commit> \
--baseline-module graph_trainer.<model> \
--baseline-config <config> \
--test-module graph_trainer.<model> \
--test-config <config> \
--baseline-options='<common options> --parallelism.spmd_backend partial_dtensor' \
--test-options='<common options> --parallelism.spmd_backend spmd_types' \
--steps 10 --metrics loss,grad_norm \
--baseline-ngpus 8 --test-ngpus 8
```
Common Llama options:
```text
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
```
Common Qwen3 MoE options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
Common DeepSeek V3 options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes joint_transformer_block_bucketing_reordering_pass,cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
### Precompile
```bash
python -m torchtitan.experiments.graph_trainer.precompile_main \
--module graph_trainer.<model> --config <config> \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
NGPU=8 MODULE=graph_trainer.<model> CONFIG=<config> \
./torchtitan/experiments/graph_trainer/run_train_precompile.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
```
### Feature smoke
```bash
NGPU=8 MODULE=graph_trainer.llama3 CONFIG=graph_trainer_llama3_debugmodel \
./run_train.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.disable_passes cudagraph_pass \
--parallelism.spmd_backend spmd_types \
--parallelism.data_parallel_shard_degree 4 \
--parallelism.tensor_parallel_degree 2 \
<one of:
--compile.inductor_compilation full
--compile.no-enable_passes
--compile.memory_policy full
--compile.memory_policy sac_and_offload
--compile.enable_fsdp_ag_rs_overlap
--compile.numerics_changing_optim>
```
### Unit tests
```bash
pytest -q \
torchtitan/experiments/graph_trainer/tests/test_simple_fsdp.py \
torchtitan/experiments/graph_trainer/tests/test_precompile.py
```
Lint and GraphTrainer type checking were not run.
ghstack-source-id: 1984878
Pull-Request: #4325
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.12.0) (oldest at bottom): * #4325 * #4311 * __->__ #4265
## Changes
- Reuse GraphTrainer's DTensor-backed SimpleFSDP implementation with an
`spmd_types` model-parallel backend.
- Preserve each parameter's `SpmdType` through FSDP wrapping and materialize
replicated non-DP axes with `spmd.redistribute`.
- Pass concrete mesh inputs through tracing and precompile so functional
collectives resolve runtime process groups.
## Test environment
| Item | Value |
| --- | --- |
| Test commit | This temporary commit |
| Baseline | `main` (`partial_dtensor`) |
| GPUs | 8x NVIDIA H100 80 GB |
| Numerics | `--debug.seed=42 --debug.deterministic` |
| Performance | 8-GPU sweep: 20 steps, discard 1-5, 3 repeats; Qwen control: 100 steps, discard 1-20 |
## Numerics
Both backends loaded the same seed checkpoint. Values were read from
TensorBoard rather than rounded stdout.
| Model | Parallelism | Steps | Max loss diff | Max grad-norm diff | Result |
| --- | --- | ---: | ---: | ---: | --- |
| Llama3 | FSDP4 + TP2 | 10 | 0 | 0 | Bitwise equal |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | 10 | 0 | 0 | Bitwise equal |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | 10 | `6.198883e-05` | `1.537800e-04` | Within expected EP all-to-all variation |
| Llama3 precompiled | FSDP4 + TP2 | 10 | 0 | 0 | `partial_dtensor` and `spmd_types` artifacts bitwise equal |
DeepSeek V3 required disabling
`joint_transformer_block_bucketing_reordering_pass` on both backends. The
baseline otherwise fails before step 1 with `stable topological sort of region
failed`, matching the disabled integration-test configuration.
## Performance
The 8-GPU results use 20 steps, discard steps 1-5, and pool the 45 remaining
samples from three runs. The Qwen result uses concurrent 4-GPU jobs, 100 steps,
metrics every 10 steps, a shared seed checkpoint, and discards steps 1-20.
These are debug-model measurements.
| Model | Parallelism | Backend | Inductor | CUDA graph | Run median TPS | Median TPS | Peak GPU memory |
| --- | --- | --- | --- | --- | --- | ---: | ---: |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | off | 113869, 113036, 128761 | 120050 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | off | 113059, 122464, 126526 | 120610 (+0.47%) | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | on | 122355, 111723, 117532 | 117532 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | on | 116173, 105596, 117504 | 113715 (-3.25%) | 0.45 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `partial_dtensor` | regional | off | 69576 | 69576 | 3.29 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `spmd_types` | regional | off | 70268 | 70268 (+0.99%) | 3.29 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `partial_dtensor` | regional | off | 68334, 61409, 65488 | 65146 | 1.60 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `spmd_types` | regional | off | 56253, 70177, 56928 | 63973 (-1.80%) | 1.60 GiB |
Qwen backends ran concurrently on disjoint four-GPU sets and were then swapped.
The table reports GPUs 0-3. Results from GPUs 4-7 were excluded because GPU 4
reported sustained thermal throttling and produced severe throughput stalls.
The DeepSeek result has high run-to-run variance and should be treated as
provisional on this host.
## Graph parity
The serialized precompile graphs are not node-for-node identical. Node targets
were normalized across generated callable addresses before comparison. CUDA
graph capture runs after artifact load, so the Llama CUDA-graph-on and -off
artifacts have the same pre-capture graph.
| Configuration | Nodes, partial / SPMD | AG | RS | AR | A2A | Compiled regions | Exact node sequence |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | --- |
| Llama3 FSDP4 + TP2, CUDA graph off | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Llama3 FSDP4 + TP2, CUDA graph on | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Qwen3 MoE FSDP4 + TP2 + EP4 | 5797 / 5603 | 222 / 206 | 44 / 44 | 12 / 12 | 40 / 40 | 16 / 16 | No |
| DeepSeek V3 FSDP4 + TP2 + EP4 | 4694 / 4468 | 225 / 215 | 116 / 116 | 54 / 54 | 25 / 25 | 12 / 12 | No |
| MuseGlimmer FSDP4 + TP2 | 4546 / 4453 | 254 / 254 | 52 / 52 | 12 / 12 | 0 / 0 | 16 / 16 | No |
DeepSeek graphs were compared with the bucketing pass removed from both sides
because the partial-DTensor precompile path hits the known topological-sort
failure. This comparison required analysis-only pass filtering: precompile does
not currently propagate `compile.disable_passes` to `apply_graph_passes`. No
workaround for that issue is included in this commit.
The SPMD graphs contain fewer process-group lookups and no additional
reduce-scatter, all-reduce, or all-to-all collectives. The main extra work is a
BF16 -> FP32 cast pair before FSDP gradient reduction for parameters replicated
on a non-DP axis:
| Model | Extra SPMD cast pairs | PG lookup delta | All-gather delta |
| --- | ---: | ---: | ---: |
| Llama3 | 13 | -39 | 0 |
| Qwen3 MoE | 49 | -75 | -16 |
| DeepSeek V3 | 35 | -66 | -10 |
| MuseGlimmer | 33 | -67 | 0 |
These casts are produced by composing the `spmd.redistribute(I -> R)` backward
dtype conversion with SimpleFSDP's FP32 gradient reduction. Under regional
Inductor they remain outside the compiled attention regions. The Kineto traces
have effectively identical profiled step times, and the healthy-device Qwen
control shows no measurable regression, so there is no evidence that these
casts materially affect runtime. DeepSeek's run medians range from 56.3K to
70.2K TPS, while its pooled steady-state median is only 1.8% below the baseline.
## Precompile
Artifact generation and distributed load/run used explicit mesh inputs and
mesh-coordinate registration.
| Model | Parallelism | CUDA graph | Artifact generation | 8-GPU load/run |
| --- | --- | --- | --- | --- |
| Llama3 | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
| Llama3 | FSDP4 + TP2 | on | Pass | Pass, 3 steps |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| MuseGlimmer | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
DeepSeek V3 and MuseGlimmer emitted non-fatal TritonBundler warnings for cached
FlexAttention cubins that were absent at load time; both jobs completed.
## Model and feature coverage
| Test | Result |
| --- | --- |
| MuseGlimmer FSDP4 + TP2, 3 steps | Pass |
| Llama3 FSDP4 + TP2, full Inductor | Pass |
| Llama3 FSDP4 + TP2, no optional graph passes | Pass |
| Llama3 FSDP4 + TP2, full recompute | Pass |
| Llama3 FSDP4 + TP2, SAC + CPU offload | Pass |
| Llama3 FSDP4 + TP2, FSDP AG/RS overlap | Pass |
| Llama3 FSDP4 + TP2, numerics-changing optimizations | Pass |
| Llama3 DCP save at step 2 and resume through step 4 | Pass |
| DeepSeek V3 FSDP4 + TP2 + EP4 DCP save/resume | Pass |
| Focused SimpleFSDP and precompile unit tests | 27 passed |
## Blocked coverage
| Test | `partial_dtensor` | `spmd_types` | Classification |
| --- | --- | --- | --- |
| Llama3 FSDP2 + TP2 + CP2 | Rejected by configuration: CP requires `spmd_types` | FlexAttention trace fails with `FunctionalTensor on its own` | CP/FlexAttention limitation; only reachable with SPMD |
| DeepSeek V3 GraphPP Interleaved1F1B | Pass, 3 steps | Fails before partitioning on unresolved enum axes `(DP, CP)` | SPMD-specific integration gap; all schedules share this path |
| DeepSeek V3 EP-overlap eager chunking | Trace fails: block mask is larger than chunked query | Not reached in comparison | Backend-independent eager-chunk test failure |
| DeepSeek V3 graph EP overlap | CUDA device-side assert during expert-bias update | Same CUDA device-side assert | Backend-independent |
| DeepSeek V3 default FSDP bucketing | Stable-topological-sort assertion | Passes precompile/load/run | Existing `partial_dtensor` failure |
## Commands
### Concurrent Qwen performance
Run both commands concurrently, then swap the two `CUDA_VISIBLE_DEVICES`
assignments:
```bash
CUDA_VISIBLE_DEVICES=<four GPUs> NGPU=4 \
MODULE=graph_trainer.qwen3 CONFIG=graph_trainer_qwen3_debugmodel_moe \
./run_train.sh \
--training.steps=100 --training.disable_cuda_graphs --metrics.log_freq=10 \
--compile.mode=aot_fx_trace --compile.inductor_compilation=regional \
--compile.disable_passes=cudagraph_pass \
--parallelism.spmd_backend=<partial_dtensor|spmd_types> \
--parallelism.data_parallel_shard_degree=2 \
--parallelism.tensor_parallel_degree=2 \
--parallelism.expert_parallel_degree=2 \
--checkpoint.enable --checkpoint.load_only \
--checkpoint.initial_load_path=<seed-checkpoint> \
--debug.seed=42
```
### Backend numerics
```bash
python scripts/loss_compare.py main <spmd-commit> \
--baseline-module graph_trainer.<model> \
--baseline-config <config> \
--test-module graph_trainer.<model> \
--test-config <config> \
--baseline-options='<common options> --parallelism.spmd_backend partial_dtensor' \
--test-options='<common options> --parallelism.spmd_backend spmd_types' \
--steps 10 --metrics loss,grad_norm \
--baseline-ngpus 8 --test-ngpus 8
```
Common Llama options:
```text
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
```
Common Qwen3 MoE options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
Common DeepSeek V3 options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes joint_transformer_block_bucketing_reordering_pass,cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
### Precompile
```bash
python -m torchtitan.experiments.graph_trainer.precompile_main \
--module graph_trainer.<model> --config <config> \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
NGPU=8 MODULE=graph_trainer.<model> CONFIG=<config> \
./torchtitan/experiments/graph_trainer/run_train_precompile.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
```
### Feature smoke
```bash
NGPU=8 MODULE=graph_trainer.llama3 CONFIG=graph_trainer_llama3_debugmodel \
./run_train.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.disable_passes cudagraph_pass \
--parallelism.spmd_backend spmd_types \
--parallelism.data_parallel_shard_degree 4 \
--parallelism.tensor_parallel_degree 2 \
<one of:
--compile.inductor_compilation full
--compile.no-enable_passes
--compile.memory_policy full
--compile.memory_policy sac_and_offload
--compile.enable_fsdp_ag_rs_overlap
--compile.numerics_changing_optim>
```
### Unit tests
```bash
pytest -q \
torchtitan/experiments/graph_trainer/tests/test_simple_fsdp.py \
torchtitan/experiments/graph_trainer/tests/test_precompile.py
```
Lint and GraphTrainer type checking were not run.
ghstack-source-id: 1984878
Pull-Request: #4325
[ghstack-poisoned]
- Reuse GraphTrainer's DTensor-backed SimpleFSDP implementation with an
`spmd_types` model-parallel backend.
- Preserve each parameter's `SpmdType` through FSDP wrapping and materialize
replicated non-DP axes with `spmd.redistribute`.
- Pass concrete mesh inputs through tracing and precompile so functional
collectives resolve runtime process groups.
| Item | Value |
| --- | --- |
| Test commit | This temporary commit |
| Baseline | `main` (`partial_dtensor`) |
| GPUs | 8x NVIDIA H100 80 GB |
| Numerics | `--debug.seed=42 --debug.deterministic` |
| Performance | 8-GPU sweep: 20 steps, discard 1-5, 3 repeats; Qwen control: 100 steps, discard 1-20 |
Both backends loaded the same seed checkpoint. Values were read from
TensorBoard rather than rounded stdout.
| Model | Parallelism | Steps | Max loss diff | Max grad-norm diff | Result |
| --- | --- | ---: | ---: | ---: | --- |
| Llama3 | FSDP4 + TP2 | 10 | 0 | 0 | Bitwise equal |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | 10 | 0 | 0 | Bitwise equal |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | 10 | `6.198883e-05` | `1.537800e-04` | Within expected EP all-to-all variation |
| Llama3 precompiled | FSDP4 + TP2 | 10 | 0 | 0 | `partial_dtensor` and `spmd_types` artifacts bitwise equal |
DeepSeek V3 required disabling
`joint_transformer_block_bucketing_reordering_pass` on both backends. The
baseline otherwise fails before step 1 with `stable topological sort of region
failed`, matching the disabled integration-test configuration.
The 8-GPU results use 20 steps, discard steps 1-5, and pool the 45 remaining
samples from three runs. The Qwen result uses concurrent 4-GPU jobs, 100 steps,
metrics every 10 steps, a shared seed checkpoint, and discards steps 1-20.
These are debug-model measurements.
| Model | Parallelism | Backend | Inductor | CUDA graph | Run median TPS | Median TPS | Peak GPU memory |
| --- | --- | --- | --- | --- | --- | ---: | ---: |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | off | 113869, 113036, 128761 | 120050 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | off | 113059, 122464, 126526 | 120610 (+0.47%) | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | on | 122355, 111723, 117532 | 117532 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | on | 116173, 105596, 117504 | 113715 (-3.25%) | 0.45 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `partial_dtensor` | regional | off | 69576 | 69576 | 3.29 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `spmd_types` | regional | off | 70268 | 70268 (+0.99%) | 3.29 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `partial_dtensor` | regional | off | 68334, 61409, 65488 | 65146 | 1.60 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `spmd_types` | regional | off | 56253, 70177, 56928 | 63973 (-1.80%) | 1.60 GiB |
Qwen backends ran concurrently on disjoint four-GPU sets and were then swapped.
The table reports GPUs 0-3. Results from GPUs 4-7 were excluded because GPU 4
reported sustained thermal throttling and produced severe throughput stalls.
The DeepSeek result has high run-to-run variance and should be treated as
provisional on this host.
The serialized precompile graphs are not node-for-node identical. Node targets
were normalized across generated callable addresses before comparison. CUDA
graph capture runs after artifact load, so the Llama CUDA-graph-on and -off
artifacts have the same pre-capture graph.
| Configuration | Nodes, partial / SPMD | AG | RS | AR | A2A | Compiled regions | Exact node sequence |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | --- |
| Llama3 FSDP4 + TP2, CUDA graph off | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Llama3 FSDP4 + TP2, CUDA graph on | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Qwen3 MoE FSDP4 + TP2 + EP4 | 5797 / 5603 | 222 / 206 | 44 / 44 | 12 / 12 | 40 / 40 | 16 / 16 | No |
| DeepSeek V3 FSDP4 + TP2 + EP4 | 4694 / 4468 | 225 / 215 | 116 / 116 | 54 / 54 | 25 / 25 | 12 / 12 | No |
| MuseGlimmer FSDP4 + TP2 | 4546 / 4453 | 254 / 254 | 52 / 52 | 12 / 12 | 0 / 0 | 16 / 16 | No |
DeepSeek graphs were compared with the bucketing pass removed from both sides
because the partial-DTensor precompile path hits the known topological-sort
failure. This comparison required analysis-only pass filtering: precompile does
not currently propagate `compile.disable_passes` to `apply_graph_passes`. No
workaround for that issue is included in this commit.
The SPMD graphs contain fewer process-group lookups and no additional
reduce-scatter, all-reduce, or all-to-all collectives. The main extra work is a
BF16 -> FP32 cast pair before FSDP gradient reduction for parameters replicated
on a non-DP axis:
| Model | Extra SPMD cast pairs | PG lookup delta | All-gather delta |
| --- | ---: | ---: | ---: |
| Llama3 | 13 | -39 | 0 |
| Qwen3 MoE | 49 | -75 | -16 |
| DeepSeek V3 | 35 | -66 | -10 |
| MuseGlimmer | 33 | -67 | 0 |
These casts are produced by composing the `spmd.redistribute(I -> R)` backward
dtype conversion with SimpleFSDP's FP32 gradient reduction. Under regional
Inductor they remain outside the compiled attention regions. The Kineto traces
have effectively identical profiled step times, and the healthy-device Qwen
control shows no measurable regression, so there is no evidence that these
casts materially affect runtime. DeepSeek's run medians range from 56.3K to
70.2K TPS, while its pooled steady-state median is only 1.8% below the baseline.
Artifact generation and distributed load/run used explicit mesh inputs and
mesh-coordinate registration.
| Model | Parallelism | CUDA graph | Artifact generation | 8-GPU load/run |
| --- | --- | --- | --- | --- |
| Llama3 | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
| Llama3 | FSDP4 + TP2 | on | Pass | Pass, 3 steps |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| MuseGlimmer | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
DeepSeek V3 and MuseGlimmer emitted non-fatal TritonBundler warnings for cached
FlexAttention cubins that were absent at load time; both jobs completed.
| Test | Result |
| --- | --- |
| MuseGlimmer FSDP4 + TP2, 3 steps | Pass |
| Llama3 FSDP4 + TP2, full Inductor | Pass |
| Llama3 FSDP4 + TP2, no optional graph passes | Pass |
| Llama3 FSDP4 + TP2, full recompute | Pass |
| Llama3 FSDP4 + TP2, SAC + CPU offload | Pass |
| Llama3 FSDP4 + TP2, FSDP AG/RS overlap | Pass |
| Llama3 FSDP4 + TP2, numerics-changing optimizations | Pass |
| Llama3 DCP save at step 2 and resume through step 4 | Pass |
| DeepSeek V3 FSDP4 + TP2 + EP4 DCP save/resume | Pass |
| Focused SimpleFSDP and precompile unit tests | 27 passed |
| Test | `partial_dtensor` | `spmd_types` | Classification |
| --- | --- | --- | --- |
| Llama3 FSDP2 + TP2 + CP2 | Rejected by configuration: CP requires `spmd_types` | FlexAttention trace fails with `FunctionalTensor on its own` | CP/FlexAttention limitation; only reachable with SPMD |
| DeepSeek V3 GraphPP Interleaved1F1B | Pass, 3 steps | Fails before partitioning on unresolved enum axes `(DP, CP)` | SPMD-specific integration gap; all schedules share this path |
| DeepSeek V3 EP-overlap eager chunking | Trace fails: block mask is larger than chunked query | Not reached in comparison | Backend-independent eager-chunk test failure |
| DeepSeek V3 graph EP overlap | CUDA device-side assert during expert-bias update | Same CUDA device-side assert | Backend-independent |
| DeepSeek V3 default FSDP bucketing | Stable-topological-sort assertion | Passes precompile/load/run | Existing `partial_dtensor` failure |
Run both commands concurrently, then swap the two `CUDA_VISIBLE_DEVICES`
assignments:
```bash
CUDA_VISIBLE_DEVICES=<four GPUs> NGPU=4 \
MODULE=graph_trainer.qwen3 CONFIG=graph_trainer_qwen3_debugmodel_moe \
./run_train.sh \
--training.steps=100 --training.disable_cuda_graphs --metrics.log_freq=10 \
--compile.mode=aot_fx_trace --compile.inductor_compilation=regional \
--compile.disable_passes=cudagraph_pass \
--parallelism.spmd_backend=<partial_dtensor|spmd_types> \
--parallelism.data_parallel_shard_degree=2 \
--parallelism.tensor_parallel_degree=2 \
--parallelism.expert_parallel_degree=2 \
--checkpoint.enable --checkpoint.load_only \
--checkpoint.initial_load_path=<seed-checkpoint> \
--debug.seed=42
```
```bash
python scripts/loss_compare.py main <spmd-commit> \
--baseline-module graph_trainer.<model> \
--baseline-config <config> \
--test-module graph_trainer.<model> \
--test-config <config> \
--baseline-options='<common options> --parallelism.spmd_backend partial_dtensor' \
--test-options='<common options> --parallelism.spmd_backend spmd_types' \
--steps 10 --metrics loss,grad_norm \
--baseline-ngpus 8 --test-ngpus 8
```
Common Llama options:
```text
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
```
Common Qwen3 MoE options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
Common DeepSeek V3 options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes joint_transformer_block_bucketing_reordering_pass,cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
```bash
python -m torchtitan.experiments.graph_trainer.precompile_main \
--module graph_trainer.<model> --config <config> \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
NGPU=8 MODULE=graph_trainer.<model> CONFIG=<config> \
./torchtitan/experiments/graph_trainer/run_train_precompile.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
```
```bash
NGPU=8 MODULE=graph_trainer.llama3 CONFIG=graph_trainer_llama3_debugmodel \
./run_train.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.disable_passes cudagraph_pass \
--parallelism.spmd_backend spmd_types \
--parallelism.data_parallel_shard_degree 4 \
--parallelism.tensor_parallel_degree 2 \
<one of:
--compile.inductor_compilation full
--compile.no-enable_passes
--compile.memory_policy full
--compile.memory_policy sac_and_offload
--compile.enable_fsdp_ag_rs_overlap
--compile.numerics_changing_optim>
```
```bash
pytest -q \
torchtitan/experiments/graph_trainer/tests/test_simple_fsdp.py \
torchtitan/experiments/graph_trainer/tests/test_precompile.py
```
Lint and GraphTrainer type checking were not run.
ghstack-source-id: 798fbd0
Pull Request resolved: #4325
[ghstack-poisoned]
- Reuse GraphTrainer's DTensor-backed SimpleFSDP implementation with an
`spmd_types` model-parallel backend.
- Preserve each parameter's `SpmdType` through FSDP wrapping and materialize
replicated non-DP axes with `spmd.redistribute`.
- Pass concrete mesh inputs through tracing and precompile so functional
collectives resolve runtime process groups.
| Item | Value |
| --- | --- |
| Test commit | This temporary commit |
| Baseline | `main` (`partial_dtensor`) |
| GPUs | 8x NVIDIA H100 80 GB |
| Numerics | `--debug.seed=42 --debug.deterministic` |
| Performance | 8-GPU sweep: 20 steps, discard 1-5, 3 repeats; Qwen control: 100 steps, discard 1-20 |
Both backends loaded the same seed checkpoint. Values were read from
TensorBoard rather than rounded stdout.
| Model | Parallelism | Steps | Max loss diff | Max grad-norm diff | Result |
| --- | --- | ---: | ---: | ---: | --- |
| Llama3 | FSDP4 + TP2 | 10 | 0 | 0 | Bitwise equal |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | 10 | 0 | 0 | Bitwise equal |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | 10 | `6.198883e-05` | `1.537800e-04` | Within expected EP all-to-all variation |
| Llama3 precompiled | FSDP4 + TP2 | 10 | 0 | 0 | `partial_dtensor` and `spmd_types` artifacts bitwise equal |
DeepSeek V3 required disabling
`joint_transformer_block_bucketing_reordering_pass` on both backends. The
baseline otherwise fails before step 1 with `stable topological sort of region
failed`, matching the disabled integration-test configuration.
The 8-GPU results use 20 steps, discard steps 1-5, and pool the 45 remaining
samples from three runs. The Qwen result uses concurrent 4-GPU jobs, 100 steps,
metrics every 10 steps, a shared seed checkpoint, and discards steps 1-20.
These are debug-model measurements.
| Model | Parallelism | Backend | Inductor | CUDA graph | Run median TPS | Median TPS | Peak GPU memory |
| --- | --- | --- | --- | --- | --- | ---: | ---: |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | off | 113869, 113036, 128761 | 120050 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | off | 113059, 122464, 126526 | 120610 (+0.47%) | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | on | 122355, 111723, 117532 | 117532 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | on | 116173, 105596, 117504 | 113715 (-3.25%) | 0.45 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `partial_dtensor` | regional | off | 69576 | 69576 | 3.29 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `spmd_types` | regional | off | 70268 | 70268 (+0.99%) | 3.29 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `partial_dtensor` | regional | off | 68334, 61409, 65488 | 65146 | 1.60 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `spmd_types` | regional | off | 56253, 70177, 56928 | 63973 (-1.80%) | 1.60 GiB |
Qwen backends ran concurrently on disjoint four-GPU sets and were then swapped.
The table reports GPUs 0-3. Results from GPUs 4-7 were excluded because GPU 4
reported sustained thermal throttling and produced severe throughput stalls.
The DeepSeek result has high run-to-run variance and should be treated as
provisional on this host.
The serialized precompile graphs are not node-for-node identical. Node targets
were normalized across generated callable addresses before comparison. CUDA
graph capture runs after artifact load, so the Llama CUDA-graph-on and -off
artifacts have the same pre-capture graph.
| Configuration | Nodes, partial / SPMD | AG | RS | AR | A2A | Compiled regions | Exact node sequence |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | --- |
| Llama3 FSDP4 + TP2, CUDA graph off | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Llama3 FSDP4 + TP2, CUDA graph on | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Qwen3 MoE FSDP4 + TP2 + EP4 | 5797 / 5603 | 222 / 206 | 44 / 44 | 12 / 12 | 40 / 40 | 16 / 16 | No |
| DeepSeek V3 FSDP4 + TP2 + EP4 | 4694 / 4468 | 225 / 215 | 116 / 116 | 54 / 54 | 25 / 25 | 12 / 12 | No |
| MuseGlimmer FSDP4 + TP2 | 4546 / 4453 | 254 / 254 | 52 / 52 | 12 / 12 | 0 / 0 | 16 / 16 | No |
DeepSeek graphs were compared with the bucketing pass removed from both sides
because the partial-DTensor precompile path hits the known topological-sort
failure. This comparison required analysis-only pass filtering: precompile does
not currently propagate `compile.disable_passes` to `apply_graph_passes`. No
workaround for that issue is included in this commit.
The SPMD graphs contain fewer process-group lookups and no additional
reduce-scatter, all-reduce, or all-to-all collectives. The main extra work is a
BF16 -> FP32 cast pair before FSDP gradient reduction for parameters replicated
on a non-DP axis:
| Model | Extra SPMD cast pairs | PG lookup delta | All-gather delta |
| --- | ---: | ---: | ---: |
| Llama3 | 13 | -39 | 0 |
| Qwen3 MoE | 49 | -75 | -16 |
| DeepSeek V3 | 35 | -66 | -10 |
| MuseGlimmer | 33 | -67 | 0 |
These casts are produced by composing the `spmd.redistribute(I -> R)` backward
dtype conversion with SimpleFSDP's FP32 gradient reduction. Under regional
Inductor they remain outside the compiled attention regions. The Kineto traces
have effectively identical profiled step times, and the healthy-device Qwen
control shows no measurable regression, so there is no evidence that these
casts materially affect runtime. DeepSeek's run medians range from 56.3K to
70.2K TPS, while its pooled steady-state median is only 1.8% below the baseline.
Artifact generation and distributed load/run used explicit mesh inputs and
mesh-coordinate registration.
| Model | Parallelism | CUDA graph | Artifact generation | 8-GPU load/run |
| --- | --- | --- | --- | --- |
| Llama3 | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
| Llama3 | FSDP4 + TP2 | on | Pass | Pass, 3 steps |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| MuseGlimmer | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
DeepSeek V3 and MuseGlimmer emitted non-fatal TritonBundler warnings for cached
FlexAttention cubins that were absent at load time; both jobs completed.
| Test | Result |
| --- | --- |
| MuseGlimmer FSDP4 + TP2, 3 steps | Pass |
| Llama3 FSDP4 + TP2, full Inductor | Pass |
| Llama3 FSDP4 + TP2, no optional graph passes | Pass |
| Llama3 FSDP4 + TP2, full recompute | Pass |
| Llama3 FSDP4 + TP2, SAC + CPU offload | Pass |
| Llama3 FSDP4 + TP2, FSDP AG/RS overlap | Pass |
| Llama3 FSDP4 + TP2, numerics-changing optimizations | Pass |
| Llama3 DCP save at step 2 and resume through step 4 | Pass |
| DeepSeek V3 FSDP4 + TP2 + EP4 DCP save/resume | Pass |
| Focused SimpleFSDP and precompile unit tests | 27 passed |
| Test | `partial_dtensor` | `spmd_types` | Classification |
| --- | --- | --- | --- |
| Llama3 FSDP2 + TP2 + CP2 | Rejected by configuration: CP requires `spmd_types` | FlexAttention trace fails with `FunctionalTensor on its own` | CP/FlexAttention limitation; only reachable with SPMD |
| DeepSeek V3 GraphPP Interleaved1F1B | Pass, 3 steps | Fails before partitioning on unresolved enum axes `(DP, CP)` | SPMD-specific integration gap; all schedules share this path |
| DeepSeek V3 EP-overlap eager chunking | Trace fails: block mask is larger than chunked query | Not reached in comparison | Backend-independent eager-chunk test failure |
| DeepSeek V3 graph EP overlap | CUDA device-side assert during expert-bias update | Same CUDA device-side assert | Backend-independent |
| DeepSeek V3 default FSDP bucketing | Stable-topological-sort assertion | Passes precompile/load/run | Existing `partial_dtensor` failure |
Run both commands concurrently, then swap the two `CUDA_VISIBLE_DEVICES`
assignments:
```bash
CUDA_VISIBLE_DEVICES=<four GPUs> NGPU=4 \
MODULE=graph_trainer.qwen3 CONFIG=graph_trainer_qwen3_debugmodel_moe \
./run_train.sh \
--training.steps=100 --training.disable_cuda_graphs --metrics.log_freq=10 \
--compile.mode=aot_fx_trace --compile.inductor_compilation=regional \
--compile.disable_passes=cudagraph_pass \
--parallelism.spmd_backend=<partial_dtensor|spmd_types> \
--parallelism.data_parallel_shard_degree=2 \
--parallelism.tensor_parallel_degree=2 \
--parallelism.expert_parallel_degree=2 \
--checkpoint.enable --checkpoint.load_only \
--checkpoint.initial_load_path=<seed-checkpoint> \
--debug.seed=42
```
```bash
python scripts/loss_compare.py main <spmd-commit> \
--baseline-module graph_trainer.<model> \
--baseline-config <config> \
--test-module graph_trainer.<model> \
--test-config <config> \
--baseline-options='<common options> --parallelism.spmd_backend partial_dtensor' \
--test-options='<common options> --parallelism.spmd_backend spmd_types' \
--steps 10 --metrics loss,grad_norm \
--baseline-ngpus 8 --test-ngpus 8
```
Common Llama options:
```text
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
```
Common Qwen3 MoE options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
Common DeepSeek V3 options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes joint_transformer_block_bucketing_reordering_pass,cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
```bash
python -m torchtitan.experiments.graph_trainer.precompile_main \
--module graph_trainer.<model> --config <config> \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
NGPU=8 MODULE=graph_trainer.<model> CONFIG=<config> \
./torchtitan/experiments/graph_trainer/run_train_precompile.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
```
```bash
NGPU=8 MODULE=graph_trainer.llama3 CONFIG=graph_trainer_llama3_debugmodel \
./run_train.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.disable_passes cudagraph_pass \
--parallelism.spmd_backend spmd_types \
--parallelism.data_parallel_shard_degree 4 \
--parallelism.tensor_parallel_degree 2 \
<one of:
--compile.inductor_compilation full
--compile.no-enable_passes
--compile.memory_policy full
--compile.memory_policy sac_and_offload
--compile.enable_fsdp_ag_rs_overlap
--compile.numerics_changing_optim>
```
```bash
pytest -q \
torchtitan/experiments/graph_trainer/tests/test_simple_fsdp.py \
torchtitan/experiments/graph_trainer/tests/test_precompile.py
```
Lint and GraphTrainer type checking were not run.
ghstack-source-id: ef08921
Pull Request resolved: #4325
- Reuse GraphTrainer's DTensor-backed SimpleFSDP implementation with an
`spmd_types` model-parallel backend.
- Preserve each parameter's `SpmdType` through FSDP wrapping and materialize
replicated non-DP axes with `spmd.redistribute`.
- Pass concrete mesh inputs through tracing and precompile so functional
collectives resolve runtime process groups.
| Item | Value |
| --- | --- |
| Test commit | This temporary commit |
| Baseline | `main` (`partial_dtensor`) |
| GPUs | 8x NVIDIA H100 80 GB |
| Numerics | `--debug.seed=42 --debug.deterministic` |
| Performance | 8-GPU sweep: 20 steps, discard 1-5, 3 repeats; Qwen control: 100 steps, discard 1-20 |
Both backends loaded the same seed checkpoint. Values were read from
TensorBoard rather than rounded stdout.
| Model | Parallelism | Steps | Max loss diff | Max grad-norm diff | Result |
| --- | --- | ---: | ---: | ---: | --- |
| Llama3 | FSDP4 + TP2 | 10 | 0 | 0 | Bitwise equal |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | 10 | 0 | 0 | Bitwise equal |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | 10 | `6.198883e-05` | `1.537800e-04` | Within expected EP all-to-all variation |
| Llama3 precompiled | FSDP4 + TP2 | 10 | 0 | 0 | `partial_dtensor` and `spmd_types` artifacts bitwise equal |
DeepSeek V3 required disabling
`joint_transformer_block_bucketing_reordering_pass` on both backends. The
baseline otherwise fails before step 1 with `stable topological sort of region
failed`, matching the disabled integration-test configuration.
The 8-GPU results use 20 steps, discard steps 1-5, and pool the 45 remaining
samples from three runs. The Qwen result uses concurrent 4-GPU jobs, 100 steps,
metrics every 10 steps, a shared seed checkpoint, and discards steps 1-20.
These are debug-model measurements.
| Model | Parallelism | Backend | Inductor | CUDA graph | Run median TPS | Median TPS | Peak GPU memory |
| --- | --- | --- | --- | --- | --- | ---: | ---: |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | off | 113869, 113036, 128761 | 120050 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | off | 113059, 122464, 126526 | 120610 (+0.47%) | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | on | 122355, 111723, 117532 | 117532 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | on | 116173, 105596, 117504 | 113715 (-3.25%) | 0.45 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `partial_dtensor` | regional | off | 69576 | 69576 | 3.29 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `spmd_types` | regional | off | 70268 | 70268 (+0.99%) | 3.29 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `partial_dtensor` | regional | off | 68334, 61409, 65488 | 65146 | 1.60 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `spmd_types` | regional | off | 56253, 70177, 56928 | 63973 (-1.80%) | 1.60 GiB |
Qwen backends ran concurrently on disjoint four-GPU sets and were then swapped.
The table reports GPUs 0-3. Results from GPUs 4-7 were excluded because GPU 4
reported sustained thermal throttling and produced severe throughput stalls.
The DeepSeek result has high run-to-run variance and should be treated as
provisional on this host.
The serialized precompile graphs are not node-for-node identical. Node targets
were normalized across generated callable addresses before comparison. CUDA
graph capture runs after artifact load, so the Llama CUDA-graph-on and -off
artifacts have the same pre-capture graph.
| Configuration | Nodes, partial / SPMD | AG | RS | AR | A2A | Compiled regions | Exact node sequence |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | --- |
| Llama3 FSDP4 + TP2, CUDA graph off | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Llama3 FSDP4 + TP2, CUDA graph on | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Qwen3 MoE FSDP4 + TP2 + EP4 | 5797 / 5603 | 222 / 206 | 44 / 44 | 12 / 12 | 40 / 40 | 16 / 16 | No |
| DeepSeek V3 FSDP4 + TP2 + EP4 | 4694 / 4468 | 225 / 215 | 116 / 116 | 54 / 54 | 25 / 25 | 12 / 12 | No |
| MuseGlimmer FSDP4 + TP2 | 4546 / 4453 | 254 / 254 | 52 / 52 | 12 / 12 | 0 / 0 | 16 / 16 | No |
DeepSeek graphs were compared with the bucketing pass removed from both sides
because the partial-DTensor precompile path hits the known topological-sort
failure. This comparison required analysis-only pass filtering: precompile does
not currently propagate `compile.disable_passes` to `apply_graph_passes`. No
workaround for that issue is included in this commit.
The SPMD graphs contain fewer process-group lookups and no additional
reduce-scatter, all-reduce, or all-to-all collectives. The main extra work is a
BF16 -> FP32 cast pair before FSDP gradient reduction for parameters replicated
on a non-DP axis:
| Model | Extra SPMD cast pairs | PG lookup delta | All-gather delta |
| --- | ---: | ---: | ---: |
| Llama3 | 13 | -39 | 0 |
| Qwen3 MoE | 49 | -75 | -16 |
| DeepSeek V3 | 35 | -66 | -10 |
| MuseGlimmer | 33 | -67 | 0 |
These casts are produced by composing the `spmd.redistribute(I -> R)` backward
dtype conversion with SimpleFSDP's FP32 gradient reduction. Under regional
Inductor they remain outside the compiled attention regions. The Kineto traces
have effectively identical profiled step times, and the healthy-device Qwen
control shows no measurable regression, so there is no evidence that these
casts materially affect runtime. DeepSeek's run medians range from 56.3K to
70.2K TPS, while its pooled steady-state median is only 1.8% below the baseline.
Artifact generation and distributed load/run used explicit mesh inputs and
mesh-coordinate registration.
| Model | Parallelism | CUDA graph | Artifact generation | 8-GPU load/run |
| --- | --- | --- | --- | --- |
| Llama3 | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
| Llama3 | FSDP4 + TP2 | on | Pass | Pass, 3 steps |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| MuseGlimmer | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
DeepSeek V3 and MuseGlimmer emitted non-fatal TritonBundler warnings for cached
FlexAttention cubins that were absent at load time; both jobs completed.
| Test | Result |
| --- | --- |
| MuseGlimmer FSDP4 + TP2, 3 steps | Pass |
| Llama3 FSDP4 + TP2, full Inductor | Pass |
| Llama3 FSDP4 + TP2, no optional graph passes | Pass |
| Llama3 FSDP4 + TP2, full recompute | Pass |
| Llama3 FSDP4 + TP2, SAC + CPU offload | Pass |
| Llama3 FSDP4 + TP2, FSDP AG/RS overlap | Pass |
| Llama3 FSDP4 + TP2, numerics-changing optimizations | Pass |
| Llama3 DCP save at step 2 and resume through step 4 | Pass |
| DeepSeek V3 FSDP4 + TP2 + EP4 DCP save/resume | Pass |
| Focused SimpleFSDP and precompile unit tests | 27 passed |
| Test | `partial_dtensor` | `spmd_types` | Classification |
| --- | --- | --- | --- |
| Llama3 FSDP2 + TP2 + CP2 | Rejected by configuration: CP requires `spmd_types` | FlexAttention trace fails with `FunctionalTensor on its own` | CP/FlexAttention limitation; only reachable with SPMD |
| DeepSeek V3 GraphPP Interleaved1F1B | Pass, 3 steps | Fails before partitioning on unresolved enum axes `(DP, CP)` | SPMD-specific integration gap; all schedules share this path |
| DeepSeek V3 EP-overlap eager chunking | Trace fails: block mask is larger than chunked query | Not reached in comparison | Backend-independent eager-chunk test failure |
| DeepSeek V3 graph EP overlap | CUDA device-side assert during expert-bias update | Same CUDA device-side assert | Backend-independent |
| DeepSeek V3 default FSDP bucketing | Stable-topological-sort assertion | Passes precompile/load/run | Existing `partial_dtensor` failure |
Run both commands concurrently, then swap the two `CUDA_VISIBLE_DEVICES`
assignments:
```bash
CUDA_VISIBLE_DEVICES=<four GPUs> NGPU=4 \
MODULE=graph_trainer.qwen3 CONFIG=graph_trainer_qwen3_debugmodel_moe \
./run_train.sh \
--training.steps=100 --training.disable_cuda_graphs --metrics.log_freq=10 \
--compile.mode=aot_fx_trace --compile.inductor_compilation=regional \
--compile.disable_passes=cudagraph_pass \
--parallelism.spmd_backend=<partial_dtensor|spmd_types> \
--parallelism.data_parallel_shard_degree=2 \
--parallelism.tensor_parallel_degree=2 \
--parallelism.expert_parallel_degree=2 \
--checkpoint.enable --checkpoint.load_only \
--checkpoint.initial_load_path=<seed-checkpoint> \
--debug.seed=42
```
```bash
python scripts/loss_compare.py main <spmd-commit> \
--baseline-module graph_trainer.<model> \
--baseline-config <config> \
--test-module graph_trainer.<model> \
--test-config <config> \
--baseline-options='<common options> --parallelism.spmd_backend partial_dtensor' \
--test-options='<common options> --parallelism.spmd_backend spmd_types' \
--steps 10 --metrics loss,grad_norm \
--baseline-ngpus 8 --test-ngpus 8
```
Common Llama options:
```text
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
```
Common Qwen3 MoE options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
Common DeepSeek V3 options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes joint_transformer_block_bucketing_reordering_pass,cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
```bash
python -m torchtitan.experiments.graph_trainer.precompile_main \
--module graph_trainer.<model> --config <config> \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
NGPU=8 MODULE=graph_trainer.<model> CONFIG=<config> \
./torchtitan/experiments/graph_trainer/run_train_precompile.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
```
```bash
NGPU=8 MODULE=graph_trainer.llama3 CONFIG=graph_trainer_llama3_debugmodel \
./run_train.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.disable_passes cudagraph_pass \
--parallelism.spmd_backend spmd_types \
--parallelism.data_parallel_shard_degree 4 \
--parallelism.tensor_parallel_degree 2 \
<one of:
--compile.inductor_compilation full
--compile.no-enable_passes
--compile.memory_policy full
--compile.memory_policy sac_and_offload
--compile.enable_fsdp_ag_rs_overlap
--compile.numerics_changing_optim>
```
```bash
pytest -q \
torchtitan/experiments/graph_trainer/tests/test_simple_fsdp.py \
torchtitan/experiments/graph_trainer/tests/test_precompile.py
```
Lint and GraphTrainer type checking were not run.
ghstack-source-id: cba1ac5
Pull Request resolved: #4325
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.12.0) (oldest at bottom): * #4325 * __->__ #4311
| module: nn.Module | None = None, | ||
| optimizer: "torch.optim.Optimizer | None" = None, | ||
| *, | ||
| precompile_meshes: list[DeviceMesh] | None = None, |
| mode: str = "replicate", | ||
| mp_policy: MixedPrecisionPolicy | None = None, | ||
| shard_dim: int = 0, | ||
| non_dp_mesh: DeviceMesh | None = None, |
There was a problem hiding this comment.
please add docstring, at least for this new field
There was a problem hiding this comment.
We didn't need this in FSDP2, why would we need it here?
https://github.com/pytorch/torchtitan/blob/main/torchtitan/distributed/fsdp.py#L168
The non-dp mesh should be obtainable from the TP/EP annotated spmd_types?
There was a problem hiding this comment.
The mesh we pass to fully_shard is the full one (FSDP + TP storage), but simplefsdp's device_mesh is just the FSDP axis, so this is stand-in for what's on the TP DTensors.
The MeshAxis objects on annotations are pretty lightweight, they don't have names/PGs so it's hard to reconstruct the DeviceMesh from the annotations. We could try to match against spmd dense/sparse meshes but this seems more general.
There was a problem hiding this comment.
I see. I feel we should unify them, some day. Maybe add a TODO
| ) | ||
| for axis_name in non_dp_mesh.mesh_dim_names | ||
| ) | ||
| return DTensor.from_local(tensor, non_dp_mesh, placements, run_check=False) |
There was a problem hiding this comment.
Does it matter if DTensor.from_local is differentiable?
There was a problem hiding this comment.
this call no, it's just DTensor wrapping, the param's also pre-sharded in module.parallelize. The differentiability only matters in ReplicateComputation redistribute (unshard) & convert I->R
| spmd.spmd_type_to_dtensor_placement( | ||
| non_dp_mesh_types[spmd.MeshAxis.of(non_dp_mesh.get_group(axis_name))] | ||
| ) |
There was a problem hiding this comment.
is there anything interesting here regarding spmd.I vs. spmd.R?
There was a problem hiding this comment.
Not really, both are Replicate at storage time, the I->R convert happens in pre-forward after unwrapping param
| TODO: In checkpoint saving/loading, avoid parametrization calls when calling | ||
| get_model_state_dict func in torchtitan/components/checkpointer/dcp.py. | ||
| """ | ||
| object.__setattr__(module, "_simple_fsdp_parametrization", parametrization) |
There was a problem hiding this comment.
I can try to redesign this, but on ReplicateComputation we're storing param_non_dp_mesh_types, which maps param name -> types, which we lookup in pre-forward to check if we need convert I->R for that param (ReplicateComputation now takes param name as argument). I guess because of closure, compiler wants this as attribute?
maybe creating one ReplicateComputation per param will work, I think with graph trainer we worry less about caching/reuse?
| self.device_mesh = device_mesh | ||
| self.param_sharding = param_sharding | ||
| self.mode = mode | ||
| self.param_non_dp_mesh_types = param_non_dp_mesh_types |
| # params replicated on non-FSDP-axes that require BWD all-reduce | ||
| # (e.g. TP RMSNorm w/ SP on) are annotated as spmd.R; | ||
| # FSDP2 is expected to handle the all-reduce in main trainer. | ||
| # mimic for SimpleFSDP with convert(I->R). |
There was a problem hiding this comment.
I couldn't internalize what's being done here.
How do you treat rmsnorm weight when SP is off?
There was a problem hiding this comment.
the sharding annotation would be I, so it doesn't go through this and doesn't all-reduce in BWD
I guess the "convert I->R if R" logic is a bit misleading, the R is "placement after FSDP", so we have to ensure that here instead
| ] | None = ({} if get_spmd_backend() == "spmd_types" else None) | ||
| for p_name, p in params_dict.items(): | ||
| if p is not None and p.numel() > 0: | ||
| non_dp_mesh_types = None |
There was a problem hiding this comment.
looks complicated
- could you extract the logic into a subfunction with proper name?
- a chart on the life cycle of a param during SimpleFSDP wrapping would be helpful
There was a problem hiding this comment.
added a note at top
[ghstack-poisoned]
- Reuse GraphTrainer's DTensor-backed SimpleFSDP implementation with an
`spmd_types` model-parallel backend.
- Preserve each parameter's `SpmdType` through FSDP wrapping and materialize
replicated non-DP axes with `spmd.redistribute`.
- Pass concrete mesh inputs through tracing and precompile so functional
collectives resolve runtime process groups.
| Item | Value |
| --- | --- |
| Test commit | This temporary commit |
| Baseline | `main` (`partial_dtensor`) |
| GPUs | 8x NVIDIA H100 80 GB |
| Numerics | `--debug.seed=42 --debug.deterministic` |
| Performance | 8-GPU sweep: 20 steps, discard 1-5, 3 repeats; Qwen control: 100 steps, discard 1-20 |
Both backends loaded the same seed checkpoint. Values were read from
TensorBoard rather than rounded stdout.
| Model | Parallelism | Steps | Max loss diff | Max grad-norm diff | Result |
| --- | --- | ---: | ---: | ---: | --- |
| Llama3 | FSDP4 + TP2 | 10 | 0 | 0 | Bitwise equal |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | 10 | 0 | 0 | Bitwise equal |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | 10 | `6.198883e-05` | `1.537800e-04` | Within expected EP all-to-all variation |
| Llama3 precompiled | FSDP4 + TP2 | 10 | 0 | 0 | `partial_dtensor` and `spmd_types` artifacts bitwise equal |
DeepSeek V3 required disabling
`joint_transformer_block_bucketing_reordering_pass` on both backends. The
baseline otherwise fails before step 1 with `stable topological sort of region
failed`, matching the disabled integration-test configuration.
The 8-GPU results use 20 steps, discard steps 1-5, and pool the 45 remaining
samples from three runs. The Qwen result uses concurrent 4-GPU jobs, 100 steps,
metrics every 10 steps, a shared seed checkpoint, and discards steps 1-20.
These are debug-model measurements.
| Model | Parallelism | Backend | Inductor | CUDA graph | Run median TPS | Median TPS | Peak GPU memory |
| --- | --- | --- | --- | --- | --- | ---: | ---: |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | off | 113869, 113036, 128761 | 120050 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | off | 113059, 122464, 126526 | 120610 (+0.47%) | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | on | 122355, 111723, 117532 | 117532 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | on | 116173, 105596, 117504 | 113715 (-3.25%) | 0.45 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `partial_dtensor` | regional | off | 69576 | 69576 | 3.29 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `spmd_types` | regional | off | 70268 | 70268 (+0.99%) | 3.29 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `partial_dtensor` | regional | off | 68334, 61409, 65488 | 65146 | 1.60 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `spmd_types` | regional | off | 56253, 70177, 56928 | 63973 (-1.80%) | 1.60 GiB |
Qwen backends ran concurrently on disjoint four-GPU sets and were then swapped.
The table reports GPUs 0-3. Results from GPUs 4-7 were excluded because GPU 4
reported sustained thermal throttling and produced severe throughput stalls.
The DeepSeek result has high run-to-run variance and should be treated as
provisional on this host.
The serialized precompile graphs are not node-for-node identical. Node targets
were normalized across generated callable addresses before comparison. CUDA
graph capture runs after artifact load, so the Llama CUDA-graph-on and -off
artifacts have the same pre-capture graph.
| Configuration | Nodes, partial / SPMD | AG | RS | AR | A2A | Compiled regions | Exact node sequence |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | --- |
| Llama3 FSDP4 + TP2, CUDA graph off | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Llama3 FSDP4 + TP2, CUDA graph on | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Qwen3 MoE FSDP4 + TP2 + EP4 | 5797 / 5603 | 222 / 206 | 44 / 44 | 12 / 12 | 40 / 40 | 16 / 16 | No |
| DeepSeek V3 FSDP4 + TP2 + EP4 | 4694 / 4468 | 225 / 215 | 116 / 116 | 54 / 54 | 25 / 25 | 12 / 12 | No |
| MuseGlimmer FSDP4 + TP2 | 4546 / 4453 | 254 / 254 | 52 / 52 | 12 / 12 | 0 / 0 | 16 / 16 | No |
DeepSeek graphs were compared with the bucketing pass removed from both sides
because the partial-DTensor precompile path hits the known topological-sort
failure. This comparison required analysis-only pass filtering: precompile does
not currently propagate `compile.disable_passes` to `apply_graph_passes`. No
workaround for that issue is included in this commit.
The SPMD graphs contain fewer process-group lookups and no additional
reduce-scatter, all-reduce, or all-to-all collectives. The main extra work is a
BF16 -> FP32 cast pair before FSDP gradient reduction for parameters replicated
on a non-DP axis:
| Model | Extra SPMD cast pairs | PG lookup delta | All-gather delta |
| --- | ---: | ---: | ---: |
| Llama3 | 13 | -39 | 0 |
| Qwen3 MoE | 49 | -75 | -16 |
| DeepSeek V3 | 35 | -66 | -10 |
| MuseGlimmer | 33 | -67 | 0 |
These casts are produced by composing the `spmd.redistribute(I -> R)` backward
dtype conversion with SimpleFSDP's FP32 gradient reduction. Under regional
Inductor they remain outside the compiled attention regions. The Kineto traces
have effectively identical profiled step times, and the healthy-device Qwen
control shows no measurable regression, so there is no evidence that these
casts materially affect runtime. DeepSeek's run medians range from 56.3K to
70.2K TPS, while its pooled steady-state median is only 1.8% below the baseline.
Artifact generation and distributed load/run used explicit mesh inputs and
mesh-coordinate registration.
| Model | Parallelism | CUDA graph | Artifact generation | 8-GPU load/run |
| --- | --- | --- | --- | --- |
| Llama3 | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
| Llama3 | FSDP4 + TP2 | on | Pass | Pass, 3 steps |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| MuseGlimmer | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
DeepSeek V3 and MuseGlimmer emitted non-fatal TritonBundler warnings for cached
FlexAttention cubins that were absent at load time; both jobs completed.
| Test | Result |
| --- | --- |
| MuseGlimmer FSDP4 + TP2, 3 steps | Pass |
| Llama3 FSDP4 + TP2, full Inductor | Pass |
| Llama3 FSDP4 + TP2, no optional graph passes | Pass |
| Llama3 FSDP4 + TP2, full recompute | Pass |
| Llama3 FSDP4 + TP2, SAC + CPU offload | Pass |
| Llama3 FSDP4 + TP2, FSDP AG/RS overlap | Pass |
| Llama3 FSDP4 + TP2, numerics-changing optimizations | Pass |
| Llama3 DCP save at step 2 and resume through step 4 | Pass |
| DeepSeek V3 FSDP4 + TP2 + EP4 DCP save/resume | Pass |
| Focused SimpleFSDP and precompile unit tests | 27 passed |
| Test | `partial_dtensor` | `spmd_types` | Classification |
| --- | --- | --- | --- |
| Llama3 FSDP2 + TP2 + CP2 | Rejected by configuration: CP requires `spmd_types` | FlexAttention trace fails with `FunctionalTensor on its own` | CP/FlexAttention limitation; only reachable with SPMD |
| DeepSeek V3 GraphPP Interleaved1F1B | Pass, 3 steps | Fails before partitioning on unresolved enum axes `(DP, CP)` | SPMD-specific integration gap; all schedules share this path |
| DeepSeek V3 EP-overlap eager chunking | Trace fails: block mask is larger than chunked query | Not reached in comparison | Backend-independent eager-chunk test failure |
| DeepSeek V3 graph EP overlap | CUDA device-side assert during expert-bias update | Same CUDA device-side assert | Backend-independent |
| DeepSeek V3 default FSDP bucketing | Stable-topological-sort assertion | Passes precompile/load/run | Existing `partial_dtensor` failure |
Run both commands concurrently, then swap the two `CUDA_VISIBLE_DEVICES`
assignments:
```bash
CUDA_VISIBLE_DEVICES=<four GPUs> NGPU=4 \
MODULE=graph_trainer.qwen3 CONFIG=graph_trainer_qwen3_debugmodel_moe \
./run_train.sh \
--training.steps=100 --training.disable_cuda_graphs --metrics.log_freq=10 \
--compile.mode=aot_fx_trace --compile.inductor_compilation=regional \
--compile.disable_passes=cudagraph_pass \
--parallelism.spmd_backend=<partial_dtensor|spmd_types> \
--parallelism.data_parallel_shard_degree=2 \
--parallelism.tensor_parallel_degree=2 \
--parallelism.expert_parallel_degree=2 \
--checkpoint.enable --checkpoint.load_only \
--checkpoint.initial_load_path=<seed-checkpoint> \
--debug.seed=42
```
```bash
python scripts/loss_compare.py main <spmd-commit> \
--baseline-module graph_trainer.<model> \
--baseline-config <config> \
--test-module graph_trainer.<model> \
--test-config <config> \
--baseline-options='<common options> --parallelism.spmd_backend partial_dtensor' \
--test-options='<common options> --parallelism.spmd_backend spmd_types' \
--steps 10 --metrics loss,grad_norm \
--baseline-ngpus 8 --test-ngpus 8
```
Common Llama options:
```text
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
```
Common Qwen3 MoE options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
Common DeepSeek V3 options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes joint_transformer_block_bucketing_reordering_pass,cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
```bash
python -m torchtitan.experiments.graph_trainer.precompile_main \
--module graph_trainer.<model> --config <config> \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
NGPU=8 MODULE=graph_trainer.<model> CONFIG=<config> \
./torchtitan/experiments/graph_trainer/run_train_precompile.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
```
```bash
NGPU=8 MODULE=graph_trainer.llama3 CONFIG=graph_trainer_llama3_debugmodel \
./run_train.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.disable_passes cudagraph_pass \
--parallelism.spmd_backend spmd_types \
--parallelism.data_parallel_shard_degree 4 \
--parallelism.tensor_parallel_degree 2 \
<one of:
--compile.inductor_compilation full
--compile.no-enable_passes
--compile.memory_policy full
--compile.memory_policy sac_and_offload
--compile.enable_fsdp_ag_rs_overlap
--compile.numerics_changing_optim>
```
```bash
pytest -q \
torchtitan/experiments/graph_trainer/tests/test_simple_fsdp.py \
torchtitan/experiments/graph_trainer/tests/test_precompile.py
```
Lint and GraphTrainer type checking were not run.
ghstack-source-id: e83e825
Pull Request resolved: #4325
- Reuse GraphTrainer's DTensor-backed SimpleFSDP implementation with an
`spmd_types` model-parallel backend.
- Preserve each parameter's `SpmdType` through FSDP wrapping and materialize
replicated non-DP axes with `spmd.redistribute`.
- Pass concrete mesh inputs through tracing and precompile so functional
collectives resolve runtime process groups.
| Item | Value |
| --- | --- |
| Test commit | This temporary commit |
| Baseline | `main` (`partial_dtensor`) |
| GPUs | 8x NVIDIA H100 80 GB |
| Numerics | `--debug.seed=42 --debug.deterministic` |
| Performance | 8-GPU sweep: 20 steps, discard 1-5, 3 repeats; Qwen control: 100 steps, discard 1-20 |
Both backends loaded the same seed checkpoint. Values were read from
TensorBoard rather than rounded stdout.
| Model | Parallelism | Steps | Max loss diff | Max grad-norm diff | Result |
| --- | --- | ---: | ---: | ---: | --- |
| Llama3 | FSDP4 + TP2 | 10 | 0 | 0 | Bitwise equal |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | 10 | 0 | 0 | Bitwise equal |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | 10 | `6.198883e-05` | `1.537800e-04` | Within expected EP all-to-all variation |
| Llama3 precompiled | FSDP4 + TP2 | 10 | 0 | 0 | `partial_dtensor` and `spmd_types` artifacts bitwise equal |
DeepSeek V3 required disabling
`joint_transformer_block_bucketing_reordering_pass` on both backends. The
baseline otherwise fails before step 1 with `stable topological sort of region
failed`, matching the disabled integration-test configuration.
The 8-GPU results use 20 steps, discard steps 1-5, and pool the 45 remaining
samples from three runs. The Qwen result uses concurrent 4-GPU jobs, 100 steps,
metrics every 10 steps, a shared seed checkpoint, and discards steps 1-20.
These are debug-model measurements.
| Model | Parallelism | Backend | Inductor | CUDA graph | Run median TPS | Median TPS | Peak GPU memory |
| --- | --- | --- | --- | --- | --- | ---: | ---: |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | off | 113869, 113036, 128761 | 120050 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | off | 113059, 122464, 126526 | 120610 (+0.47%) | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | on | 122355, 111723, 117532 | 117532 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | on | 116173, 105596, 117504 | 113715 (-3.25%) | 0.45 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `partial_dtensor` | regional | off | 69576 | 69576 | 3.29 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `spmd_types` | regional | off | 70268 | 70268 (+0.99%) | 3.29 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `partial_dtensor` | regional | off | 68334, 61409, 65488 | 65146 | 1.60 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `spmd_types` | regional | off | 56253, 70177, 56928 | 63973 (-1.80%) | 1.60 GiB |
Qwen backends ran concurrently on disjoint four-GPU sets and were then swapped.
The table reports GPUs 0-3. Results from GPUs 4-7 were excluded because GPU 4
reported sustained thermal throttling and produced severe throughput stalls.
The DeepSeek result has high run-to-run variance and should be treated as
provisional on this host.
The serialized precompile graphs are not node-for-node identical. Node targets
were normalized across generated callable addresses before comparison. CUDA
graph capture runs after artifact load, so the Llama CUDA-graph-on and -off
artifacts have the same pre-capture graph.
| Configuration | Nodes, partial / SPMD | AG | RS | AR | A2A | Compiled regions | Exact node sequence |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | --- |
| Llama3 FSDP4 + TP2, CUDA graph off | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Llama3 FSDP4 + TP2, CUDA graph on | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Qwen3 MoE FSDP4 + TP2 + EP4 | 5797 / 5603 | 222 / 206 | 44 / 44 | 12 / 12 | 40 / 40 | 16 / 16 | No |
| DeepSeek V3 FSDP4 + TP2 + EP4 | 4694 / 4468 | 225 / 215 | 116 / 116 | 54 / 54 | 25 / 25 | 12 / 12 | No |
| MuseGlimmer FSDP4 + TP2 | 4546 / 4453 | 254 / 254 | 52 / 52 | 12 / 12 | 0 / 0 | 16 / 16 | No |
DeepSeek graphs were compared with the bucketing pass removed from both sides
because the partial-DTensor precompile path hits the known topological-sort
failure. This comparison required analysis-only pass filtering: precompile does
not currently propagate `compile.disable_passes` to `apply_graph_passes`. No
workaround for that issue is included in this commit.
The SPMD graphs contain fewer process-group lookups and no additional
reduce-scatter, all-reduce, or all-to-all collectives. The main extra work is a
BF16 -> FP32 cast pair before FSDP gradient reduction for parameters replicated
on a non-DP axis:
| Model | Extra SPMD cast pairs | PG lookup delta | All-gather delta |
| --- | ---: | ---: | ---: |
| Llama3 | 13 | -39 | 0 |
| Qwen3 MoE | 49 | -75 | -16 |
| DeepSeek V3 | 35 | -66 | -10 |
| MuseGlimmer | 33 | -67 | 0 |
These casts are produced by composing the `spmd.redistribute(I -> R)` backward
dtype conversion with SimpleFSDP's FP32 gradient reduction. Under regional
Inductor they remain outside the compiled attention regions. The Kineto traces
have effectively identical profiled step times, and the healthy-device Qwen
control shows no measurable regression, so there is no evidence that these
casts materially affect runtime. DeepSeek's run medians range from 56.3K to
70.2K TPS, while its pooled steady-state median is only 1.8% below the baseline.
Artifact generation and distributed load/run used explicit mesh inputs and
mesh-coordinate registration.
| Model | Parallelism | CUDA graph | Artifact generation | 8-GPU load/run |
| --- | --- | --- | --- | --- |
| Llama3 | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
| Llama3 | FSDP4 + TP2 | on | Pass | Pass, 3 steps |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| MuseGlimmer | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
DeepSeek V3 and MuseGlimmer emitted non-fatal TritonBundler warnings for cached
FlexAttention cubins that were absent at load time; both jobs completed.
| Test | Result |
| --- | --- |
| MuseGlimmer FSDP4 + TP2, 3 steps | Pass |
| Llama3 FSDP4 + TP2, full Inductor | Pass |
| Llama3 FSDP4 + TP2, no optional graph passes | Pass |
| Llama3 FSDP4 + TP2, full recompute | Pass |
| Llama3 FSDP4 + TP2, SAC + CPU offload | Pass |
| Llama3 FSDP4 + TP2, FSDP AG/RS overlap | Pass |
| Llama3 FSDP4 + TP2, numerics-changing optimizations | Pass |
| Llama3 DCP save at step 2 and resume through step 4 | Pass |
| DeepSeek V3 FSDP4 + TP2 + EP4 DCP save/resume | Pass |
| Focused SimpleFSDP and precompile unit tests | 27 passed |
| Test | `partial_dtensor` | `spmd_types` | Classification |
| --- | --- | --- | --- |
| Llama3 FSDP2 + TP2 + CP2 | Rejected by configuration: CP requires `spmd_types` | FlexAttention trace fails with `FunctionalTensor on its own` | CP/FlexAttention limitation; only reachable with SPMD |
| DeepSeek V3 GraphPP Interleaved1F1B | Pass, 3 steps | Fails before partitioning on unresolved enum axes `(DP, CP)` | SPMD-specific integration gap; all schedules share this path |
| DeepSeek V3 EP-overlap eager chunking | Trace fails: block mask is larger than chunked query | Not reached in comparison | Backend-independent eager-chunk test failure |
| DeepSeek V3 graph EP overlap | CUDA device-side assert during expert-bias update | Same CUDA device-side assert | Backend-independent |
| DeepSeek V3 default FSDP bucketing | Stable-topological-sort assertion | Passes precompile/load/run | Existing `partial_dtensor` failure |
Run both commands concurrently, then swap the two `CUDA_VISIBLE_DEVICES`
assignments:
```bash
CUDA_VISIBLE_DEVICES=<four GPUs> NGPU=4 \
MODULE=graph_trainer.qwen3 CONFIG=graph_trainer_qwen3_debugmodel_moe \
./run_train.sh \
--training.steps=100 --training.disable_cuda_graphs --metrics.log_freq=10 \
--compile.mode=aot_fx_trace --compile.inductor_compilation=regional \
--compile.disable_passes=cudagraph_pass \
--parallelism.spmd_backend=<partial_dtensor|spmd_types> \
--parallelism.data_parallel_shard_degree=2 \
--parallelism.tensor_parallel_degree=2 \
--parallelism.expert_parallel_degree=2 \
--checkpoint.enable --checkpoint.load_only \
--checkpoint.initial_load_path=<seed-checkpoint> \
--debug.seed=42
```
```bash
python scripts/loss_compare.py main <spmd-commit> \
--baseline-module graph_trainer.<model> \
--baseline-config <config> \
--test-module graph_trainer.<model> \
--test-config <config> \
--baseline-options='<common options> --parallelism.spmd_backend partial_dtensor' \
--test-options='<common options> --parallelism.spmd_backend spmd_types' \
--steps 10 --metrics loss,grad_norm \
--baseline-ngpus 8 --test-ngpus 8
```
Common Llama options:
```text
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
```
Common Qwen3 MoE options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
Common DeepSeek V3 options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes joint_transformer_block_bucketing_reordering_pass,cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
```bash
python -m torchtitan.experiments.graph_trainer.precompile_main \
--module graph_trainer.<model> --config <config> \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
NGPU=8 MODULE=graph_trainer.<model> CONFIG=<config> \
./torchtitan/experiments/graph_trainer/run_train_precompile.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
```
```bash
NGPU=8 MODULE=graph_trainer.llama3 CONFIG=graph_trainer_llama3_debugmodel \
./run_train.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.disable_passes cudagraph_pass \
--parallelism.spmd_backend spmd_types \
--parallelism.data_parallel_shard_degree 4 \
--parallelism.tensor_parallel_degree 2 \
<one of:
--compile.inductor_compilation full
--compile.no-enable_passes
--compile.memory_policy full
--compile.memory_policy sac_and_offload
--compile.enable_fsdp_ag_rs_overlap
--compile.numerics_changing_optim>
```
```bash
pytest -q \
torchtitan/experiments/graph_trainer/tests/test_simple_fsdp.py \
torchtitan/experiments/graph_trainer/tests/test_precompile.py
```
Lint and GraphTrainer type checking were not run.
ghstack-source-id: e601f34
Pull Request resolved: #4325
| mode: str = "replicate", | ||
| mp_policy: MixedPrecisionPolicy | None = None, | ||
| shard_dim: int = 0, | ||
| non_dp_mesh: DeviceMesh | None = None, |
There was a problem hiding this comment.
We didn't need this in FSDP2, why would we need it here?
https://github.com/pytorch/torchtitan/blob/main/torchtitan/distributed/fsdp.py#L168
The non-dp mesh should be obtainable from the TP/EP annotated spmd_types?
| partition_spec_get_shard(partition_spec, axis) or local_type[axis] | ||
| ) | ||
| placements = tuple( | ||
| spmd.spmd_type_to_dtensor_placement( |
There was a problem hiding this comment.
For rmsnorm.weight with/without SP, is this converting it from Replicate to spmd.I so that you are inserting a convert(I -> R) below?
There was a problem hiding this comment.
The param should come annotated as spmd.R, this translates it to Replicate for storage, and the later hook handles the I->R convert
| from torch.distributed.tensor._redistribute import redistribute_local_tensor | ||
| from torch.distributed.tensor.placement_types import _StridedShard, Placement | ||
|
|
||
| from torchtitan.distributed.utils import get_spmd_backend |
There was a problem hiding this comment.
It looks like you are doing
- support spmd_types for eager trainer (done)
- support spmd_types for graph trainer (this PR)
- deprecate dtensor backend for both (next PR)
I wonder if we could do
- support spmd_types for eager trainer (done)
- change supported backend for graph trainer from dtensor only to spmd_types only (this PR)
- deprecate dtensor backend for eager trainer (next PR)
It will simplify the review work, but I don't feel that strong if you think there could be risk.
There was a problem hiding this comment.
Mostly worried about perf, was planning to post in group asking if anything is missed, having old backend would help if something is
[ghstack-poisoned]
This change enables GraphTrainer to use `spmd_types` annotations for TP and EP while retaining DTensor-backed SimpleFSDP storage. It preserves each parameter's non-DP SPMD type through FSDP wrapping and passes concrete mesh inputs through tracing and precompile so functional collectives can resolve their process groups. `non_dp_mesh` must remain explicit. A `MeshAxis` records a logical rank layout and an annotation records placement, but those values do not contain a `DeviceMesh`, its device type and mesh tensor, or its process-group objects. Any axis names are side-table metadata, not enough to reconstruct the original mesh. `spmd_types` itself only populates its axis-to-process-group map when given a concrete `DeviceMesh`. SimpleFSDP needs that concrete mesh immediately to create DTensor parameter storage with `DTensor.from_local`. Results below are from the current commit with PyTorch `2.15.0a0+gite337bdb`, CUDA 13.0, and 8x NVIDIA H100 GPUs. Unless stated otherwise, performance numbers are a single 20-step debug-model run and report the median over steps 6-20. They are useful smoke/performance indicators, not a stable benchmark. ## Backend parity Both backends loaded the same seed checkpoint and ran with `--debug.seed=42 --debug.deterministic`. Full-precision TensorBoard values were compared rather than rounded stdout. | Model | Parallelism | Steps | Max loss diff | Max grad-norm diff | Result | | --- | --- | ---: | ---: | ---: | --- | | Llama3 | FSDP4 + TP2 | 10 | 0 | 0 | Bitwise equal | | Qwen3 MoE | FSDP4 + TP2 + EP4 | 10 | 0 | 0 | Bitwise equal | | DeepSeek V3 | FSDP4 + TP2 + EP4 | 10 | `6.198883e-05` | `1.537800e-04` | Small EP all-to-all variation | DeepSeek parity disabled the bucketing and CUDA-graph passes on both backends. The focused deterministic suite also completed with 16 passed and 9 skipped. ## Activation checkpointing Configuration: Llama3 debug model, 8 GPUs, FSDP4 + TP2, `aot_fx_trace`, regional Inductor, CUDA graphs disabled, 20 steps, and one run per backend. Only `compile.memory_policy` changed between rows. The `partial_dtensor` and `spmd_types` graphs made identical save/recompute decisions for every tested policy and every one of the six Llama layers. | Policy | Forced boundary saves | Non-layer save/recompute | Per-layer save/recompute | Partial TPS | SPMD TPS | Delta | Peak memory | | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | | Default SAC | 6 | 2 / 21 | 13 / 79 | 138,625 | 136,919 | -1.23% | 0.45 GiB | | Eager-equivalent SAC | 6 | 2 / 21 | 11 / 81 | 137,665 | 134,516 | -2.29% | 0.39 GiB | | Full recompute | 7 | 1 / 22 | 1 / 91 | 134,015 | 125,254 | -6.54% | 0.24 GiB | | SAC + CPU offload | 6 | 2 / 21 | 13 / 79 | 122,406 | 128,597 | +5.06% | 0.33 GiB | CPU offload matched exactly as well: both backends tagged 35 activations (282.5 MB), offloaded 20 tensors (142.5 MB), replayed five views, and moved 20 reloads one layer earlier. ## Precompile | Model | Parallelism | Artifact generation | 8-GPU load/run | | --- | --- | --- | --- | | Llama3 SDPA | FSDP4 + TP2 | Pass | Pass, 10 steps | | Llama3 FlexAttention | FSDP4 + TP2 | Pass | Pass, 10 steps | | DeepSeek V3 | FSDP4 + TP2 + EP4 | Pass | Pass, 10 steps | DeepSeek used `--training.disable_cuda_graphs` because its default token dispatcher is rejected by CUDA-graph configuration validation. ## CUDA graphs CUDA graphs are not blocked for the `spmd_types` backend as a whole. They work on the precompiled Llama FlexAttention path: the artifact loaded, the pass logged `Applied cudagraph pass`, and training completed for 10 steps. Over steps 6-10, median throughput was 246,007 TPS with CUDA graphs versus 116,855 TPS from the same precompiled artifact with the pass disabled; peak memory was 0.46 versus 0.45 GiB. This is a single short run. The direct-trace Llama FSDP4 + TP2 path remains blocked from CUDA graph capture on both backends. The pass is invoked but logs `Skipping cudagraph: graph is not compatible`, so direct-trace runs with the pass enabled are not CUDA graph performance measurements. ## Inductor | Mode | Partial TPS | SPMD TPS | Delta | Partial memory | SPMD memory | | --- | ---: | ---: | ---: | ---: | ---: | | Regional | 138,625 | 136,919 | -1.23% | 0.45 GiB | 0.45 GiB | | Full | 181,628 | 187,040 | +2.98% | 0.48 GiB | 0.48 GiB | Both modes completed 20 steps. Full Inductor was the fastest tested direct trace configuration for both backends. ## FSDP SimpleFSDP unit coverage passed (`2 passed`). Llama FSDP4 + TP2 completed under both backends, and the optional AG/RS overlap pass found the same 22 overlap dependencies in each graph. | Configuration | Partial TPS | SPMD TPS | Delta | Peak memory | | --- | ---: | ---: | ---: | ---: | | Regional Inductor, no CUDA graph | 138,625 | 136,919 | -1.23% | 0.45 GiB | | Regional Inductor + FSDP AG/RS overlap | 131,768 | 136,092 | +3.28% | 0.45 GiB | For DeepSeek FSDP4 + TP2 + EP4 with the default bucketing pass, `partial_dtensor` fails with `stable topological sort of region failed`, while `spmd_types` completes. This is a baseline limitation rather than an `spmd_types` blocker. ## DCP Llama FSDP4 + TP2 with `spmd_types` trained for 10 steps, saved a full DCP checkpoint at step 10, then loaded it in a fresh process and resumed at step 11 through step 12. Model, optimizer, scheduler, dataloader, and trainer state were restored through the normal checkpoint path. ## GraphPP Configuration: DeepSeek V3 debug model, 8 GPUs, FSDP4 + PP2 + EP2, TP1, eight pipeline microbatches, 2,048 tokens per microbatch per DP rank, full Inductor, CUDA graphs disabled, `spmd_types`, and 10 training steps. All three schedules completed. | Schedule | Median rank-0 TPS, steps 6-10 | Max per-rank peak memory | | --- | ---: | ---: | | Interleaved1F1B | 41,991 | 0.69 GiB | | ZBVZeroBubble | 42,073 | 0.81 GiB | | DualPipeV | 44,192 | 0.87 GiB | ## Other coverage | Test | Result | | --- | --- | | MuseGlimmer FSDP4 + TP2 integration | Pass, 10 steps, 0.65 GiB peak | | Supported MoE-level graph EP chunking | Pass | | Supported MoE-level eager EP chunking | Pass | | `test_bitwise_deterministic.py` | 16 passed, 9 skipped | | `test_simple_fsdp.py` | 2 passed | | Formatter, pydoclint, codespell, CI Pyrefly | Pass | | Standard DeepSeek FSDP + TP + EP | Both 10-step parity runs passed; the integration test remains disabled for a recorded intermittent all-to-all failure | The formatter-only changes requested by lint are included in `simple_fsdp.py`. A local all-files Pyrefly invocation is not representative of CI in this dirty workspace because it scans unrelated untracked scripts and generated `torch_compile_debug` files; the clean CI result supplied for this commit passes. ## Unsupported GraphTrainer configurations | Area | `partial_dtensor` | `spmd_types` | Scope | | --- | --- | --- | --- | | CP + FlexAttention | Rejected by GraphTrainer configuration validation | Rejected by GraphTrainer configuration validation | Unsupported by GraphTrainer | | Runtime SPMD typechecking | Flag rejected as unsupported | Flag rejected as unsupported | Unsupported by GraphTrainer | | Direct-trace CUDA graphs, Llama FSDP4 + TP2 | Compatibility gate skips capture | Compatibility gate skips capture | Shared | | MoE EP overlap + dense-region FSDP scheduling | Fails on alias users of reduce-scatter wait sinks | Same failure | Shared (`#4052`) | | Transformer-level EP chunking | Graph mode hits a CUDA device assertion | Same failure; eager mode also produces an invalid attention mask | Shared, obsolete configuration (`#4342`) | ## Reproduction commands Backend parity used `scripts/loss_compare.py` with 10 steps, the same seed checkpoint, and backend-specific `--parallelism.spmd_backend` values. The common Llama options were FSDP4 + TP2; Qwen and DeepSeek additionally used EP4. DeepSeek disabled `joint_transformer_block_bucketing_reordering_pass`. Feature performance used: ```bash NGPU=8 MODULE=graph_trainer.llama3 CONFIG=graph_trainer_llama3_debugmodel \ ./run_train.sh --training.steps 20 --metrics.log_freq 1 \ --compile.mode aot_fx_trace --training.disable_cuda_graphs \ --compile.disable_passes cudagraph_pass \ --parallelism.spmd_backend <partial_dtensor|spmd_types> \ --parallelism.data_parallel_shard_degree 4 \ --parallelism.tensor_parallel_degree 2 \ <feature options> ``` `<feature options>` was one of `--compile.memory_policy eager`, `--compile.memory_policy full`, `--compile.memory_policy sac_and_offload`, `--compile.inductor_compilation full`, or `--compile.enable_fsdp_ag_rs_overlap`. GraphPP and precompile were run through their checked-in integration runners, except for the fresh DeepSeek and FlexAttention precompile probes noted above. ghstack-source-id: 7baf149 Pull Request resolved: #4325
[ghstack-poisoned]
- Reuse GraphTrainer's DTensor-backed SimpleFSDP implementation with an
`spmd_types` model-parallel backend.
- Preserve each parameter's `SpmdType` through FSDP wrapping and materialize
replicated non-DP axes with `spmd.redistribute`.
- Pass concrete mesh inputs through tracing and precompile so functional
collectives resolve runtime process groups.
| Item | Value |
| --- | --- |
| Test commit | This temporary commit |
| Baseline | `main` (`partial_dtensor`) |
| GPUs | 8x NVIDIA H100 80 GB |
| Numerics | `--debug.seed=42 --debug.deterministic` |
| Performance | 8-GPU sweep: 20 steps, discard 1-5, 3 repeats; Qwen control: 100 steps, discard 1-20 |
Both backends loaded the same seed checkpoint. Values were read from
TensorBoard rather than rounded stdout.
| Model | Parallelism | Steps | Max loss diff | Max grad-norm diff | Result |
| --- | --- | ---: | ---: | ---: | --- |
| Llama3 | FSDP4 + TP2 | 10 | 0 | 0 | Bitwise equal |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | 10 | 0 | 0 | Bitwise equal |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | 10 | `6.198883e-05` | `1.537800e-04` | Within expected EP all-to-all variation |
| Llama3 precompiled | FSDP4 + TP2 | 10 | 0 | 0 | `partial_dtensor` and `spmd_types` artifacts bitwise equal |
DeepSeek V3 required disabling
`joint_transformer_block_bucketing_reordering_pass` on both backends. The
baseline otherwise fails before step 1 with `stable topological sort of region
failed`, matching the disabled integration-test configuration.
The 8-GPU results use 20 steps, discard steps 1-5, and pool the 45 remaining
samples from three runs. The Qwen result uses concurrent 4-GPU jobs, 100 steps,
metrics every 10 steps, a shared seed checkpoint, and discards steps 1-20.
These are debug-model measurements.
| Model | Parallelism | Backend | Inductor | CUDA graph | Run median TPS | Median TPS | Peak GPU memory |
| --- | --- | --- | --- | --- | --- | ---: | ---: |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | off | 113869, 113036, 128761 | 120050 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | off | 113059, 122464, 126526 | 120610 (+0.47%) | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | on | 122355, 111723, 117532 | 117532 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | on | 116173, 105596, 117504 | 113715 (-3.25%) | 0.45 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `partial_dtensor` | regional | off | 69576 | 69576 | 3.29 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `spmd_types` | regional | off | 70268 | 70268 (+0.99%) | 3.29 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `partial_dtensor` | regional | off | 68334, 61409, 65488 | 65146 | 1.60 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `spmd_types` | regional | off | 56253, 70177, 56928 | 63973 (-1.80%) | 1.60 GiB |
Qwen backends ran concurrently on disjoint four-GPU sets and were then swapped.
The table reports GPUs 0-3. Results from GPUs 4-7 were excluded because GPU 4
reported sustained thermal throttling and produced severe throughput stalls.
The DeepSeek result has high run-to-run variance and should be treated as
provisional on this host.
The serialized precompile graphs are not node-for-node identical. Node targets
were normalized across generated callable addresses before comparison. CUDA
graph capture runs after artifact load, so the Llama CUDA-graph-on and -off
artifacts have the same pre-capture graph.
| Configuration | Nodes, partial / SPMD | AG | RS | AR | A2A | Compiled regions | Exact node sequence |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | --- |
| Llama3 FSDP4 + TP2, CUDA graph off | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Llama3 FSDP4 + TP2, CUDA graph on | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Qwen3 MoE FSDP4 + TP2 + EP4 | 5797 / 5603 | 222 / 206 | 44 / 44 | 12 / 12 | 40 / 40 | 16 / 16 | No |
| DeepSeek V3 FSDP4 + TP2 + EP4 | 4694 / 4468 | 225 / 215 | 116 / 116 | 54 / 54 | 25 / 25 | 12 / 12 | No |
| MuseGlimmer FSDP4 + TP2 | 4546 / 4453 | 254 / 254 | 52 / 52 | 12 / 12 | 0 / 0 | 16 / 16 | No |
DeepSeek graphs were compared with the bucketing pass removed from both sides
because the partial-DTensor precompile path hits the known topological-sort
failure. This comparison required analysis-only pass filtering: precompile does
not currently propagate `compile.disable_passes` to `apply_graph_passes`. No
workaround for that issue is included in this commit.
The SPMD graphs contain fewer process-group lookups and no additional
reduce-scatter, all-reduce, or all-to-all collectives. The main extra work is a
BF16 -> FP32 cast pair before FSDP gradient reduction for parameters replicated
on a non-DP axis:
| Model | Extra SPMD cast pairs | PG lookup delta | All-gather delta |
| --- | ---: | ---: | ---: |
| Llama3 | 13 | -39 | 0 |
| Qwen3 MoE | 49 | -75 | -16 |
| DeepSeek V3 | 35 | -66 | -10 |
| MuseGlimmer | 33 | -67 | 0 |
These casts are produced by composing the `spmd.redistribute(I -> R)` backward
dtype conversion with SimpleFSDP's FP32 gradient reduction. Under regional
Inductor they remain outside the compiled attention regions. The Kineto traces
have effectively identical profiled step times, and the healthy-device Qwen
control shows no measurable regression, so there is no evidence that these
casts materially affect runtime. DeepSeek's run medians range from 56.3K to
70.2K TPS, while its pooled steady-state median is only 1.8% below the baseline.
Artifact generation and distributed load/run used explicit mesh inputs and
mesh-coordinate registration.
| Model | Parallelism | CUDA graph | Artifact generation | 8-GPU load/run |
| --- | --- | --- | --- | --- |
| Llama3 | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
| Llama3 | FSDP4 + TP2 | on | Pass | Pass, 3 steps |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| MuseGlimmer | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
DeepSeek V3 and MuseGlimmer emitted non-fatal TritonBundler warnings for cached
FlexAttention cubins that were absent at load time; both jobs completed.
| Test | Result |
| --- | --- |
| MuseGlimmer FSDP4 + TP2, 3 steps | Pass |
| Llama3 FSDP4 + TP2, full Inductor | Pass |
| Llama3 FSDP4 + TP2, no optional graph passes | Pass |
| Llama3 FSDP4 + TP2, full recompute | Pass |
| Llama3 FSDP4 + TP2, SAC + CPU offload | Pass |
| Llama3 FSDP4 + TP2, FSDP AG/RS overlap | Pass |
| Llama3 FSDP4 + TP2, numerics-changing optimizations | Pass |
| Llama3 DCP save at step 2 and resume through step 4 | Pass |
| DeepSeek V3 FSDP4 + TP2 + EP4 DCP save/resume | Pass |
| Focused SimpleFSDP and precompile unit tests | 27 passed |
| Test | `partial_dtensor` | `spmd_types` | Classification |
| --- | --- | --- | --- |
| Llama3 FSDP2 + TP2 + CP2 | Rejected by configuration: CP requires `spmd_types` | FlexAttention trace fails with `FunctionalTensor on its own` | CP/FlexAttention limitation; only reachable with SPMD |
| DeepSeek V3 GraphPP Interleaved1F1B | Pass, 3 steps | Fails before partitioning on unresolved enum axes `(DP, CP)` | SPMD-specific integration gap; all schedules share this path |
| DeepSeek V3 EP-overlap eager chunking | Trace fails: block mask is larger than chunked query | Not reached in comparison | Backend-independent eager-chunk test failure |
| DeepSeek V3 graph EP overlap | CUDA device-side assert during expert-bias update | Same CUDA device-side assert | Backend-independent |
| DeepSeek V3 default FSDP bucketing | Stable-topological-sort assertion | Passes precompile/load/run | Existing `partial_dtensor` failure |
Run both commands concurrently, then swap the two `CUDA_VISIBLE_DEVICES`
assignments:
```bash
CUDA_VISIBLE_DEVICES=<four GPUs> NGPU=4 \
MODULE=graph_trainer.qwen3 CONFIG=graph_trainer_qwen3_debugmodel_moe \
./run_train.sh \
--training.steps=100 --training.disable_cuda_graphs --metrics.log_freq=10 \
--compile.mode=aot_fx_trace --compile.inductor_compilation=regional \
--compile.disable_passes=cudagraph_pass \
--parallelism.spmd_backend=<partial_dtensor|spmd_types> \
--parallelism.data_parallel_shard_degree=2 \
--parallelism.tensor_parallel_degree=2 \
--parallelism.expert_parallel_degree=2 \
--checkpoint.enable --checkpoint.load_only \
--checkpoint.initial_load_path=<seed-checkpoint> \
--debug.seed=42
```
```bash
python scripts/loss_compare.py main <spmd-commit> \
--baseline-module graph_trainer.<model> \
--baseline-config <config> \
--test-module graph_trainer.<model> \
--test-config <config> \
--baseline-options='<common options> --parallelism.spmd_backend partial_dtensor' \
--test-options='<common options> --parallelism.spmd_backend spmd_types' \
--steps 10 --metrics loss,grad_norm \
--baseline-ngpus 8 --test-ngpus 8
```
Common Llama options:
```text
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
```
Common Qwen3 MoE options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
Common DeepSeek V3 options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes joint_transformer_block_bucketing_reordering_pass,cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
```bash
python -m torchtitan.experiments.graph_trainer.precompile_main \
--module graph_trainer.<model> --config <config> \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
NGPU=8 MODULE=graph_trainer.<model> CONFIG=<config> \
./torchtitan/experiments/graph_trainer/run_train_precompile.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
```
```bash
NGPU=8 MODULE=graph_trainer.llama3 CONFIG=graph_trainer_llama3_debugmodel \
./run_train.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.disable_passes cudagraph_pass \
--parallelism.spmd_backend spmd_types \
--parallelism.data_parallel_shard_degree 4 \
--parallelism.tensor_parallel_degree 2 \
<one of:
--compile.inductor_compilation full
--compile.no-enable_passes
--compile.memory_policy full
--compile.memory_policy sac_and_offload
--compile.enable_fsdp_ag_rs_overlap
--compile.numerics_changing_optim>
```
```bash
pytest -q \
torchtitan/experiments/graph_trainer/tests/test_simple_fsdp.py \
torchtitan/experiments/graph_trainer/tests/test_precompile.py
```
Lint and GraphTrainer type checking were not run.
ghstack-source-id: 39e8fb2
Pull Request resolved: #4325
- Reuse GraphTrainer's DTensor-backed SimpleFSDP implementation with an
`spmd_types` model-parallel backend.
- Preserve each parameter's `SpmdType` through FSDP wrapping and materialize
replicated non-DP axes with `spmd.redistribute`.
- Pass concrete mesh inputs through tracing and precompile so functional
collectives resolve runtime process groups.
| Item | Value |
| --- | --- |
| Test commit | This temporary commit |
| Baseline | `main` (`partial_dtensor`) |
| GPUs | 8x NVIDIA H100 80 GB |
| Numerics | `--debug.seed=42 --debug.deterministic` |
| Performance | 8-GPU sweep: 20 steps, discard 1-5, 3 repeats; Qwen control: 100 steps, discard 1-20 |
Both backends loaded the same seed checkpoint. Values were read from
TensorBoard rather than rounded stdout.
| Model | Parallelism | Steps | Max loss diff | Max grad-norm diff | Result |
| --- | --- | ---: | ---: | ---: | --- |
| Llama3 | FSDP4 + TP2 | 10 | 0 | 0 | Bitwise equal |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | 10 | 0 | 0 | Bitwise equal |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | 10 | `6.198883e-05` | `1.537800e-04` | Within expected EP all-to-all variation |
| Llama3 precompiled | FSDP4 + TP2 | 10 | 0 | 0 | `partial_dtensor` and `spmd_types` artifacts bitwise equal |
DeepSeek V3 required disabling
`joint_transformer_block_bucketing_reordering_pass` on both backends. The
baseline otherwise fails before step 1 with `stable topological sort of region
failed`, matching the disabled integration-test configuration.
The 8-GPU results use 20 steps, discard steps 1-5, and pool the 45 remaining
samples from three runs. The Qwen result uses concurrent 4-GPU jobs, 100 steps,
metrics every 10 steps, a shared seed checkpoint, and discards steps 1-20.
These are debug-model measurements.
| Model | Parallelism | Backend | Inductor | CUDA graph | Run median TPS | Median TPS | Peak GPU memory |
| --- | --- | --- | --- | --- | --- | ---: | ---: |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | off | 113869, 113036, 128761 | 120050 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | off | 113059, 122464, 126526 | 120610 (+0.47%) | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | on | 122355, 111723, 117532 | 117532 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | on | 116173, 105596, 117504 | 113715 (-3.25%) | 0.45 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `partial_dtensor` | regional | off | 69576 | 69576 | 3.29 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `spmd_types` | regional | off | 70268 | 70268 (+0.99%) | 3.29 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `partial_dtensor` | regional | off | 68334, 61409, 65488 | 65146 | 1.60 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `spmd_types` | regional | off | 56253, 70177, 56928 | 63973 (-1.80%) | 1.60 GiB |
Qwen backends ran concurrently on disjoint four-GPU sets and were then swapped.
The table reports GPUs 0-3. Results from GPUs 4-7 were excluded because GPU 4
reported sustained thermal throttling and produced severe throughput stalls.
The DeepSeek result has high run-to-run variance and should be treated as
provisional on this host.
The serialized precompile graphs are not node-for-node identical. Node targets
were normalized across generated callable addresses before comparison. CUDA
graph capture runs after artifact load, so the Llama CUDA-graph-on and -off
artifacts have the same pre-capture graph.
| Configuration | Nodes, partial / SPMD | AG | RS | AR | A2A | Compiled regions | Exact node sequence |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | --- |
| Llama3 FSDP4 + TP2, CUDA graph off | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Llama3 FSDP4 + TP2, CUDA graph on | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Qwen3 MoE FSDP4 + TP2 + EP4 | 5797 / 5603 | 222 / 206 | 44 / 44 | 12 / 12 | 40 / 40 | 16 / 16 | No |
| DeepSeek V3 FSDP4 + TP2 + EP4 | 4694 / 4468 | 225 / 215 | 116 / 116 | 54 / 54 | 25 / 25 | 12 / 12 | No |
| MuseGlimmer FSDP4 + TP2 | 4546 / 4453 | 254 / 254 | 52 / 52 | 12 / 12 | 0 / 0 | 16 / 16 | No |
DeepSeek graphs were compared with the bucketing pass removed from both sides
because the partial-DTensor precompile path hits the known topological-sort
failure. This comparison required analysis-only pass filtering: precompile does
not currently propagate `compile.disable_passes` to `apply_graph_passes`. No
workaround for that issue is included in this commit.
The SPMD graphs contain fewer process-group lookups and no additional
reduce-scatter, all-reduce, or all-to-all collectives. The main extra work is a
BF16 -> FP32 cast pair before FSDP gradient reduction for parameters replicated
on a non-DP axis:
| Model | Extra SPMD cast pairs | PG lookup delta | All-gather delta |
| --- | ---: | ---: | ---: |
| Llama3 | 13 | -39 | 0 |
| Qwen3 MoE | 49 | -75 | -16 |
| DeepSeek V3 | 35 | -66 | -10 |
| MuseGlimmer | 33 | -67 | 0 |
These casts are produced by composing the `spmd.redistribute(I -> R)` backward
dtype conversion with SimpleFSDP's FP32 gradient reduction. Under regional
Inductor they remain outside the compiled attention regions. The Kineto traces
have effectively identical profiled step times, and the healthy-device Qwen
control shows no measurable regression, so there is no evidence that these
casts materially affect runtime. DeepSeek's run medians range from 56.3K to
70.2K TPS, while its pooled steady-state median is only 1.8% below the baseline.
Artifact generation and distributed load/run used explicit mesh inputs and
mesh-coordinate registration.
| Model | Parallelism | CUDA graph | Artifact generation | 8-GPU load/run |
| --- | --- | --- | --- | --- |
| Llama3 | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
| Llama3 | FSDP4 + TP2 | on | Pass | Pass, 3 steps |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| MuseGlimmer | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
DeepSeek V3 and MuseGlimmer emitted non-fatal TritonBundler warnings for cached
FlexAttention cubins that were absent at load time; both jobs completed.
| Test | Result |
| --- | --- |
| MuseGlimmer FSDP4 + TP2, 3 steps | Pass |
| Llama3 FSDP4 + TP2, full Inductor | Pass |
| Llama3 FSDP4 + TP2, no optional graph passes | Pass |
| Llama3 FSDP4 + TP2, full recompute | Pass |
| Llama3 FSDP4 + TP2, SAC + CPU offload | Pass |
| Llama3 FSDP4 + TP2, FSDP AG/RS overlap | Pass |
| Llama3 FSDP4 + TP2, numerics-changing optimizations | Pass |
| Llama3 DCP save at step 2 and resume through step 4 | Pass |
| DeepSeek V3 FSDP4 + TP2 + EP4 DCP save/resume | Pass |
| Focused SimpleFSDP and precompile unit tests | 27 passed |
| Test | `partial_dtensor` | `spmd_types` | Classification |
| --- | --- | --- | --- |
| Llama3 FSDP2 + TP2 + CP2 | Rejected by configuration: CP requires `spmd_types` | FlexAttention trace fails with `FunctionalTensor on its own` | CP/FlexAttention limitation; only reachable with SPMD |
| DeepSeek V3 GraphPP Interleaved1F1B | Pass, 3 steps | Fails before partitioning on unresolved enum axes `(DP, CP)` | SPMD-specific integration gap; all schedules share this path |
| DeepSeek V3 EP-overlap eager chunking | Trace fails: block mask is larger than chunked query | Not reached in comparison | Backend-independent eager-chunk test failure |
| DeepSeek V3 graph EP overlap | CUDA device-side assert during expert-bias update | Same CUDA device-side assert | Backend-independent |
| DeepSeek V3 default FSDP bucketing | Stable-topological-sort assertion | Passes precompile/load/run | Existing `partial_dtensor` failure |
Run both commands concurrently, then swap the two `CUDA_VISIBLE_DEVICES`
assignments:
```bash
CUDA_VISIBLE_DEVICES=<four GPUs> NGPU=4 \
MODULE=graph_trainer.qwen3 CONFIG=graph_trainer_qwen3_debugmodel_moe \
./run_train.sh \
--training.steps=100 --training.disable_cuda_graphs --metrics.log_freq=10 \
--compile.mode=aot_fx_trace --compile.inductor_compilation=regional \
--compile.disable_passes=cudagraph_pass \
--parallelism.spmd_backend=<partial_dtensor|spmd_types> \
--parallelism.data_parallel_shard_degree=2 \
--parallelism.tensor_parallel_degree=2 \
--parallelism.expert_parallel_degree=2 \
--checkpoint.enable --checkpoint.load_only \
--checkpoint.initial_load_path=<seed-checkpoint> \
--debug.seed=42
```
```bash
python scripts/loss_compare.py main <spmd-commit> \
--baseline-module graph_trainer.<model> \
--baseline-config <config> \
--test-module graph_trainer.<model> \
--test-config <config> \
--baseline-options='<common options> --parallelism.spmd_backend partial_dtensor' \
--test-options='<common options> --parallelism.spmd_backend spmd_types' \
--steps 10 --metrics loss,grad_norm \
--baseline-ngpus 8 --test-ngpus 8
```
Common Llama options:
```text
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
```
Common Qwen3 MoE options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
Common DeepSeek V3 options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes joint_transformer_block_bucketing_reordering_pass,cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
```bash
python -m torchtitan.experiments.graph_trainer.precompile_main \
--module graph_trainer.<model> --config <config> \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
NGPU=8 MODULE=graph_trainer.<model> CONFIG=<config> \
./torchtitan/experiments/graph_trainer/run_train_precompile.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
```
```bash
NGPU=8 MODULE=graph_trainer.llama3 CONFIG=graph_trainer_llama3_debugmodel \
./run_train.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.disable_passes cudagraph_pass \
--parallelism.spmd_backend spmd_types \
--parallelism.data_parallel_shard_degree 4 \
--parallelism.tensor_parallel_degree 2 \
<one of:
--compile.inductor_compilation full
--compile.no-enable_passes
--compile.memory_policy full
--compile.memory_policy sac_and_offload
--compile.enable_fsdp_ag_rs_overlap
--compile.numerics_changing_optim>
```
```bash
pytest -q \
torchtitan/experiments/graph_trainer/tests/test_simple_fsdp.py \
torchtitan/experiments/graph_trainer/tests/test_precompile.py
```
Lint and GraphTrainer type checking were not run.
ghstack-source-id: 680054a
Pull Request resolved: #4325
- Reuse GraphTrainer's DTensor-backed SimpleFSDP implementation with an
`spmd_types` model-parallel backend.
- Preserve each parameter's `SpmdType` through FSDP wrapping and materialize
replicated non-DP axes with `spmd.redistribute`.
- Pass concrete mesh inputs through tracing and precompile so functional
collectives resolve runtime process groups.
| Item | Value |
| --- | --- |
| Test commit | This temporary commit |
| Baseline | `main` (`partial_dtensor`) |
| GPUs | 8x NVIDIA H100 80 GB |
| Numerics | `--debug.seed=42 --debug.deterministic` |
| Performance | 8-GPU sweep: 20 steps, discard 1-5, 3 repeats; Qwen control: 100 steps, discard 1-20 |
Both backends loaded the same seed checkpoint. Values were read from
TensorBoard rather than rounded stdout.
| Model | Parallelism | Steps | Max loss diff | Max grad-norm diff | Result |
| --- | --- | ---: | ---: | ---: | --- |
| Llama3 | FSDP4 + TP2 | 10 | 0 | 0 | Bitwise equal |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | 10 | 0 | 0 | Bitwise equal |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | 10 | `6.198883e-05` | `1.537800e-04` | Within expected EP all-to-all variation |
| Llama3 precompiled | FSDP4 + TP2 | 10 | 0 | 0 | `partial_dtensor` and `spmd_types` artifacts bitwise equal |
DeepSeek V3 required disabling
`joint_transformer_block_bucketing_reordering_pass` on both backends. The
baseline otherwise fails before step 1 with `stable topological sort of region
failed`, matching the disabled integration-test configuration.
The 8-GPU results use 20 steps, discard steps 1-5, and pool the 45 remaining
samples from three runs. The Qwen result uses concurrent 4-GPU jobs, 100 steps,
metrics every 10 steps, a shared seed checkpoint, and discards steps 1-20.
These are debug-model measurements.
| Model | Parallelism | Backend | Inductor | CUDA graph | Run median TPS | Median TPS | Peak GPU memory |
| --- | --- | --- | --- | --- | --- | ---: | ---: |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | off | 113869, 113036, 128761 | 120050 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | off | 113059, 122464, 126526 | 120610 (+0.47%) | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | on | 122355, 111723, 117532 | 117532 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | on | 116173, 105596, 117504 | 113715 (-3.25%) | 0.45 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `partial_dtensor` | regional | off | 69576 | 69576 | 3.29 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `spmd_types` | regional | off | 70268 | 70268 (+0.99%) | 3.29 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `partial_dtensor` | regional | off | 68334, 61409, 65488 | 65146 | 1.60 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `spmd_types` | regional | off | 56253, 70177, 56928 | 63973 (-1.80%) | 1.60 GiB |
Qwen backends ran concurrently on disjoint four-GPU sets and were then swapped.
The table reports GPUs 0-3. Results from GPUs 4-7 were excluded because GPU 4
reported sustained thermal throttling and produced severe throughput stalls.
The DeepSeek result has high run-to-run variance and should be treated as
provisional on this host.
The serialized precompile graphs are not node-for-node identical. Node targets
were normalized across generated callable addresses before comparison. CUDA
graph capture runs after artifact load, so the Llama CUDA-graph-on and -off
artifacts have the same pre-capture graph.
| Configuration | Nodes, partial / SPMD | AG | RS | AR | A2A | Compiled regions | Exact node sequence |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | --- |
| Llama3 FSDP4 + TP2, CUDA graph off | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Llama3 FSDP4 + TP2, CUDA graph on | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Qwen3 MoE FSDP4 + TP2 + EP4 | 5797 / 5603 | 222 / 206 | 44 / 44 | 12 / 12 | 40 / 40 | 16 / 16 | No |
| DeepSeek V3 FSDP4 + TP2 + EP4 | 4694 / 4468 | 225 / 215 | 116 / 116 | 54 / 54 | 25 / 25 | 12 / 12 | No |
| MuseGlimmer FSDP4 + TP2 | 4546 / 4453 | 254 / 254 | 52 / 52 | 12 / 12 | 0 / 0 | 16 / 16 | No |
DeepSeek graphs were compared with the bucketing pass removed from both sides
because the partial-DTensor precompile path hits the known topological-sort
failure. This comparison required analysis-only pass filtering: precompile does
not currently propagate `compile.disable_passes` to `apply_graph_passes`. No
workaround for that issue is included in this commit.
The SPMD graphs contain fewer process-group lookups and no additional
reduce-scatter, all-reduce, or all-to-all collectives. The main extra work is a
BF16 -> FP32 cast pair before FSDP gradient reduction for parameters replicated
on a non-DP axis:
| Model | Extra SPMD cast pairs | PG lookup delta | All-gather delta |
| --- | ---: | ---: | ---: |
| Llama3 | 13 | -39 | 0 |
| Qwen3 MoE | 49 | -75 | -16 |
| DeepSeek V3 | 35 | -66 | -10 |
| MuseGlimmer | 33 | -67 | 0 |
These casts are produced by composing the `spmd.redistribute(I -> R)` backward
dtype conversion with SimpleFSDP's FP32 gradient reduction. Under regional
Inductor they remain outside the compiled attention regions. The Kineto traces
have effectively identical profiled step times, and the healthy-device Qwen
control shows no measurable regression, so there is no evidence that these
casts materially affect runtime. DeepSeek's run medians range from 56.3K to
70.2K TPS, while its pooled steady-state median is only 1.8% below the baseline.
Artifact generation and distributed load/run used explicit mesh inputs and
mesh-coordinate registration.
| Model | Parallelism | CUDA graph | Artifact generation | 8-GPU load/run |
| --- | --- | --- | --- | --- |
| Llama3 | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
| Llama3 | FSDP4 + TP2 | on | Pass | Pass, 3 steps |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| MuseGlimmer | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
DeepSeek V3 and MuseGlimmer emitted non-fatal TritonBundler warnings for cached
FlexAttention cubins that were absent at load time; both jobs completed.
| Test | Result |
| --- | --- |
| MuseGlimmer FSDP4 + TP2, 3 steps | Pass |
| Llama3 FSDP4 + TP2, full Inductor | Pass |
| Llama3 FSDP4 + TP2, no optional graph passes | Pass |
| Llama3 FSDP4 + TP2, full recompute | Pass |
| Llama3 FSDP4 + TP2, SAC + CPU offload | Pass |
| Llama3 FSDP4 + TP2, FSDP AG/RS overlap | Pass |
| Llama3 FSDP4 + TP2, numerics-changing optimizations | Pass |
| Llama3 DCP save at step 2 and resume through step 4 | Pass |
| DeepSeek V3 FSDP4 + TP2 + EP4 DCP save/resume | Pass |
| Focused SimpleFSDP and precompile unit tests | 27 passed |
| Test | `partial_dtensor` | `spmd_types` | Classification |
| --- | --- | --- | --- |
| Llama3 FSDP2 + TP2 + CP2 | Rejected by configuration: CP requires `spmd_types` | FlexAttention trace fails with `FunctionalTensor on its own` | CP/FlexAttention limitation; only reachable with SPMD |
| DeepSeek V3 GraphPP Interleaved1F1B | Pass, 3 steps | Fails before partitioning on unresolved enum axes `(DP, CP)` | SPMD-specific integration gap; all schedules share this path |
| DeepSeek V3 EP-overlap eager chunking | Trace fails: block mask is larger than chunked query | Not reached in comparison | Backend-independent eager-chunk test failure |
| DeepSeek V3 graph EP overlap | CUDA device-side assert during expert-bias update | Same CUDA device-side assert | Backend-independent |
| DeepSeek V3 default FSDP bucketing | Stable-topological-sort assertion | Passes precompile/load/run | Existing `partial_dtensor` failure |
Run both commands concurrently, then swap the two `CUDA_VISIBLE_DEVICES`
assignments:
```bash
CUDA_VISIBLE_DEVICES=<four GPUs> NGPU=4 \
MODULE=graph_trainer.qwen3 CONFIG=graph_trainer_qwen3_debugmodel_moe \
./run_train.sh \
--training.steps=100 --training.disable_cuda_graphs --metrics.log_freq=10 \
--compile.mode=aot_fx_trace --compile.inductor_compilation=regional \
--compile.disable_passes=cudagraph_pass \
--parallelism.spmd_backend=<partial_dtensor|spmd_types> \
--parallelism.data_parallel_shard_degree=2 \
--parallelism.tensor_parallel_degree=2 \
--parallelism.expert_parallel_degree=2 \
--checkpoint.enable --checkpoint.load_only \
--checkpoint.initial_load_path=<seed-checkpoint> \
--debug.seed=42
```
```bash
python scripts/loss_compare.py main <spmd-commit> \
--baseline-module graph_trainer.<model> \
--baseline-config <config> \
--test-module graph_trainer.<model> \
--test-config <config> \
--baseline-options='<common options> --parallelism.spmd_backend partial_dtensor' \
--test-options='<common options> --parallelism.spmd_backend spmd_types' \
--steps 10 --metrics loss,grad_norm \
--baseline-ngpus 8 --test-ngpus 8
```
Common Llama options:
```text
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
```
Common Qwen3 MoE options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
Common DeepSeek V3 options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes joint_transformer_block_bucketing_reordering_pass,cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
```bash
python -m torchtitan.experiments.graph_trainer.precompile_main \
--module graph_trainer.<model> --config <config> \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
NGPU=8 MODULE=graph_trainer.<model> CONFIG=<config> \
./torchtitan/experiments/graph_trainer/run_train_precompile.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
```
```bash
NGPU=8 MODULE=graph_trainer.llama3 CONFIG=graph_trainer_llama3_debugmodel \
./run_train.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.disable_passes cudagraph_pass \
--parallelism.spmd_backend spmd_types \
--parallelism.data_parallel_shard_degree 4 \
--parallelism.tensor_parallel_degree 2 \
<one of:
--compile.inductor_compilation full
--compile.no-enable_passes
--compile.memory_policy full
--compile.memory_policy sac_and_offload
--compile.enable_fsdp_ag_rs_overlap
--compile.numerics_changing_optim>
```
```bash
pytest -q \
torchtitan/experiments/graph_trainer/tests/test_simple_fsdp.py \
torchtitan/experiments/graph_trainer/tests/test_precompile.py
```
Lint and GraphTrainer type checking were not run.
ghstack-source-id: 81cf1b3
Pull Request resolved: #4325
- Reuse GraphTrainer's DTensor-backed SimpleFSDP implementation with an
`spmd_types` model-parallel backend.
- Preserve each parameter's `SpmdType` through FSDP wrapping and materialize
replicated non-DP axes with `spmd.redistribute`.
- Pass concrete mesh inputs through tracing and precompile so functional
collectives resolve runtime process groups.
| Item | Value |
| --- | --- |
| Test commit | This temporary commit |
| Baseline | `main` (`partial_dtensor`) |
| GPUs | 8x NVIDIA H100 80 GB |
| Numerics | `--debug.seed=42 --debug.deterministic` |
| Performance | 8-GPU sweep: 20 steps, discard 1-5, 3 repeats; Qwen control: 100 steps, discard 1-20 |
Both backends loaded the same seed checkpoint. Values were read from
TensorBoard rather than rounded stdout.
| Model | Parallelism | Steps | Max loss diff | Max grad-norm diff | Result |
| --- | --- | ---: | ---: | ---: | --- |
| Llama3 | FSDP4 + TP2 | 10 | 0 | 0 | Bitwise equal |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | 10 | 0 | 0 | Bitwise equal |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | 10 | `6.198883e-05` | `1.537800e-04` | Within expected EP all-to-all variation |
| Llama3 precompiled | FSDP4 + TP2 | 10 | 0 | 0 | `partial_dtensor` and `spmd_types` artifacts bitwise equal |
DeepSeek V3 required disabling
`joint_transformer_block_bucketing_reordering_pass` on both backends. The
baseline otherwise fails before step 1 with `stable topological sort of region
failed`, matching the disabled integration-test configuration.
The 8-GPU results use 20 steps, discard steps 1-5, and pool the 45 remaining
samples from three runs. The Qwen result uses concurrent 4-GPU jobs, 100 steps,
metrics every 10 steps, a shared seed checkpoint, and discards steps 1-20.
These are debug-model measurements.
| Model | Parallelism | Backend | Inductor | CUDA graph | Run median TPS | Median TPS | Peak GPU memory |
| --- | --- | --- | --- | --- | --- | ---: | ---: |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | off | 113869, 113036, 128761 | 120050 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | off | 113059, 122464, 126526 | 120610 (+0.47%) | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | on | 122355, 111723, 117532 | 117532 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | on | 116173, 105596, 117504 | 113715 (-3.25%) | 0.45 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `partial_dtensor` | regional | off | 69576 | 69576 | 3.29 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `spmd_types` | regional | off | 70268 | 70268 (+0.99%) | 3.29 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `partial_dtensor` | regional | off | 68334, 61409, 65488 | 65146 | 1.60 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `spmd_types` | regional | off | 56253, 70177, 56928 | 63973 (-1.80%) | 1.60 GiB |
Qwen backends ran concurrently on disjoint four-GPU sets and were then swapped.
The table reports GPUs 0-3. Results from GPUs 4-7 were excluded because GPU 4
reported sustained thermal throttling and produced severe throughput stalls.
The DeepSeek result has high run-to-run variance and should be treated as
provisional on this host.
The serialized precompile graphs are not node-for-node identical. Node targets
were normalized across generated callable addresses before comparison. CUDA
graph capture runs after artifact load, so the Llama CUDA-graph-on and -off
artifacts have the same pre-capture graph.
| Configuration | Nodes, partial / SPMD | AG | RS | AR | A2A | Compiled regions | Exact node sequence |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | --- |
| Llama3 FSDP4 + TP2, CUDA graph off | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Llama3 FSDP4 + TP2, CUDA graph on | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Qwen3 MoE FSDP4 + TP2 + EP4 | 5797 / 5603 | 222 / 206 | 44 / 44 | 12 / 12 | 40 / 40 | 16 / 16 | No |
| DeepSeek V3 FSDP4 + TP2 + EP4 | 4694 / 4468 | 225 / 215 | 116 / 116 | 54 / 54 | 25 / 25 | 12 / 12 | No |
| MuseGlimmer FSDP4 + TP2 | 4546 / 4453 | 254 / 254 | 52 / 52 | 12 / 12 | 0 / 0 | 16 / 16 | No |
DeepSeek graphs were compared with the bucketing pass removed from both sides
because the partial-DTensor precompile path hits the known topological-sort
failure. This comparison required analysis-only pass filtering: precompile does
not currently propagate `compile.disable_passes` to `apply_graph_passes`. No
workaround for that issue is included in this commit.
The SPMD graphs contain fewer process-group lookups and no additional
reduce-scatter, all-reduce, or all-to-all collectives. The main extra work is a
BF16 -> FP32 cast pair before FSDP gradient reduction for parameters replicated
on a non-DP axis:
| Model | Extra SPMD cast pairs | PG lookup delta | All-gather delta |
| --- | ---: | ---: | ---: |
| Llama3 | 13 | -39 | 0 |
| Qwen3 MoE | 49 | -75 | -16 |
| DeepSeek V3 | 35 | -66 | -10 |
| MuseGlimmer | 33 | -67 | 0 |
These casts are produced by composing the `spmd.redistribute(I -> R)` backward
dtype conversion with SimpleFSDP's FP32 gradient reduction. Under regional
Inductor they remain outside the compiled attention regions. The Kineto traces
have effectively identical profiled step times, and the healthy-device Qwen
control shows no measurable regression, so there is no evidence that these
casts materially affect runtime. DeepSeek's run medians range from 56.3K to
70.2K TPS, while its pooled steady-state median is only 1.8% below the baseline.
Artifact generation and distributed load/run used explicit mesh inputs and
mesh-coordinate registration.
| Model | Parallelism | CUDA graph | Artifact generation | 8-GPU load/run |
| --- | --- | --- | --- | --- |
| Llama3 | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
| Llama3 | FSDP4 + TP2 | on | Pass | Pass, 3 steps |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| MuseGlimmer | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
DeepSeek V3 and MuseGlimmer emitted non-fatal TritonBundler warnings for cached
FlexAttention cubins that were absent at load time; both jobs completed.
| Test | Result |
| --- | --- |
| MuseGlimmer FSDP4 + TP2, 3 steps | Pass |
| Llama3 FSDP4 + TP2, full Inductor | Pass |
| Llama3 FSDP4 + TP2, no optional graph passes | Pass |
| Llama3 FSDP4 + TP2, full recompute | Pass |
| Llama3 FSDP4 + TP2, SAC + CPU offload | Pass |
| Llama3 FSDP4 + TP2, FSDP AG/RS overlap | Pass |
| Llama3 FSDP4 + TP2, numerics-changing optimizations | Pass |
| Llama3 DCP save at step 2 and resume through step 4 | Pass |
| DeepSeek V3 FSDP4 + TP2 + EP4 DCP save/resume | Pass |
| Focused SimpleFSDP and precompile unit tests | 27 passed |
| Test | `partial_dtensor` | `spmd_types` | Classification |
| --- | --- | --- | --- |
| Llama3 FSDP2 + TP2 + CP2 | Rejected by configuration: CP requires `spmd_types` | FlexAttention trace fails with `FunctionalTensor on its own` | CP/FlexAttention limitation; only reachable with SPMD |
| DeepSeek V3 GraphPP Interleaved1F1B | Pass, 3 steps | Fails before partitioning on unresolved enum axes `(DP, CP)` | SPMD-specific integration gap; all schedules share this path |
| DeepSeek V3 EP-overlap eager chunking | Trace fails: block mask is larger than chunked query | Not reached in comparison | Backend-independent eager-chunk test failure |
| DeepSeek V3 graph EP overlap | CUDA device-side assert during expert-bias update | Same CUDA device-side assert | Backend-independent |
| DeepSeek V3 default FSDP bucketing | Stable-topological-sort assertion | Passes precompile/load/run | Existing `partial_dtensor` failure |
Run both commands concurrently, then swap the two `CUDA_VISIBLE_DEVICES`
assignments:
```bash
CUDA_VISIBLE_DEVICES=<four GPUs> NGPU=4 \
MODULE=graph_trainer.qwen3 CONFIG=graph_trainer_qwen3_debugmodel_moe \
./run_train.sh \
--training.steps=100 --training.disable_cuda_graphs --metrics.log_freq=10 \
--compile.mode=aot_fx_trace --compile.inductor_compilation=regional \
--compile.disable_passes=cudagraph_pass \
--parallelism.spmd_backend=<partial_dtensor|spmd_types> \
--parallelism.data_parallel_shard_degree=2 \
--parallelism.tensor_parallel_degree=2 \
--parallelism.expert_parallel_degree=2 \
--checkpoint.enable --checkpoint.load_only \
--checkpoint.initial_load_path=<seed-checkpoint> \
--debug.seed=42
```
```bash
python scripts/loss_compare.py main <spmd-commit> \
--baseline-module graph_trainer.<model> \
--baseline-config <config> \
--test-module graph_trainer.<model> \
--test-config <config> \
--baseline-options='<common options> --parallelism.spmd_backend partial_dtensor' \
--test-options='<common options> --parallelism.spmd_backend spmd_types' \
--steps 10 --metrics loss,grad_norm \
--baseline-ngpus 8 --test-ngpus 8
```
Common Llama options:
```text
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
```
Common Qwen3 MoE options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
Common DeepSeek V3 options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes joint_transformer_block_bucketing_reordering_pass,cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
```bash
python -m torchtitan.experiments.graph_trainer.precompile_main \
--module graph_trainer.<model> --config <config> \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
NGPU=8 MODULE=graph_trainer.<model> CONFIG=<config> \
./torchtitan/experiments/graph_trainer/run_train_precompile.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
```
```bash
NGPU=8 MODULE=graph_trainer.llama3 CONFIG=graph_trainer_llama3_debugmodel \
./run_train.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.disable_passes cudagraph_pass \
--parallelism.spmd_backend spmd_types \
--parallelism.data_parallel_shard_degree 4 \
--parallelism.tensor_parallel_degree 2 \
<one of:
--compile.inductor_compilation full
--compile.no-enable_passes
--compile.memory_policy full
--compile.memory_policy sac_and_offload
--compile.enable_fsdp_ag_rs_overlap
--compile.numerics_changing_optim>
```
```bash
pytest -q \
torchtitan/experiments/graph_trainer/tests/test_simple_fsdp.py \
torchtitan/experiments/graph_trainer/tests/test_precompile.py
```
Lint and GraphTrainer type checking were not run.
ghstack-source-id: 81cf1b3
Pull Request resolved: pytorch/torchtitan#4325
| # Cache of (original_class, param_names) -> wrapper class, so all instances | ||
| # of the same module type share one SimpleFSDP class for torch.compile reuse. | ||
| _wrap_class_cache: dict[tuple[type, frozenset[str]], type] = {} | ||
| _wrap_class_id = count() |
There was a problem hiding this comment.
I think because jit.compile, we wanted all frames to share a unified ReplicateComputation wrapper class to avoid recompile. Now we parametrize it with param name -> spmd type mapping so they won't match/cache hit, but this is fine because we're in graph trainer aot + passes instead.
The counter's for unique param names, but let me check if it's actually needed
| mode: str = "replicate", | ||
| mp_policy: MixedPrecisionPolicy | None = None, | ||
| shard_dim: int = 0, | ||
| non_dp_mesh: DeviceMesh | None = None, |
There was a problem hiding this comment.
I see. I feel we should unify them, some day. Maybe add a TODO
[ghstack-poisoned]
- Reuse GraphTrainer's DTensor-backed SimpleFSDP implementation with an
`spmd_types` model-parallel backend.
- Preserve each parameter's `SpmdType` through FSDP wrapping and materialize
replicated non-DP axes with `spmd.redistribute`.
- Pass concrete mesh inputs through tracing and precompile so functional
collectives resolve runtime process groups.
| Item | Value |
| --- | --- |
| Test commit | This temporary commit |
| Baseline | `main` (`partial_dtensor`) |
| GPUs | 8x NVIDIA H100 80 GB |
| Numerics | `--debug.seed=42 --debug.deterministic` |
| Performance | 8-GPU sweep: 20 steps, discard 1-5, 3 repeats; Qwen control: 100 steps, discard 1-20 |
Both backends loaded the same seed checkpoint. Values were read from
TensorBoard rather than rounded stdout.
| Model | Parallelism | Steps | Max loss diff | Max grad-norm diff | Result |
| --- | --- | ---: | ---: | ---: | --- |
| Llama3 | FSDP4 + TP2 | 10 | 0 | 0 | Bitwise equal |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | 10 | 0 | 0 | Bitwise equal |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | 10 | `6.198883e-05` | `1.537800e-04` | Within expected EP all-to-all variation |
| Llama3 precompiled | FSDP4 + TP2 | 10 | 0 | 0 | `partial_dtensor` and `spmd_types` artifacts bitwise equal |
DeepSeek V3 required disabling
`joint_transformer_block_bucketing_reordering_pass` on both backends. The
baseline otherwise fails before step 1 with `stable topological sort of region
failed`, matching the disabled integration-test configuration.
The 8-GPU results use 20 steps, discard steps 1-5, and pool the 45 remaining
samples from three runs. The Qwen result uses concurrent 4-GPU jobs, 100 steps,
metrics every 10 steps, a shared seed checkpoint, and discards steps 1-20.
These are debug-model measurements.
| Model | Parallelism | Backend | Inductor | CUDA graph | Run median TPS | Median TPS | Peak GPU memory |
| --- | --- | --- | --- | --- | --- | ---: | ---: |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | off | 113869, 113036, 128761 | 120050 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | off | 113059, 122464, 126526 | 120610 (+0.47%) | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `partial_dtensor` | regional | on | 122355, 111723, 117532 | 117532 | 0.45 GiB |
| Llama3 | FSDP4 + TP2 | `spmd_types` | regional | on | 116173, 105596, 117504 | 113715 (-3.25%) | 0.45 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `partial_dtensor` | regional | off | 69576 | 69576 | 3.29 GiB |
| Qwen3 MoE | FSDP2 + TP2 + EP2 | `spmd_types` | regional | off | 70268 | 70268 (+0.99%) | 3.29 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `partial_dtensor` | regional | off | 68334, 61409, 65488 | 65146 | 1.60 GiB |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | `spmd_types` | regional | off | 56253, 70177, 56928 | 63973 (-1.80%) | 1.60 GiB |
Qwen backends ran concurrently on disjoint four-GPU sets and were then swapped.
The table reports GPUs 0-3. Results from GPUs 4-7 were excluded because GPU 4
reported sustained thermal throttling and produced severe throughput stalls.
The DeepSeek result has high run-to-run variance and should be treated as
provisional on this host.
The serialized precompile graphs are not node-for-node identical. Node targets
were normalized across generated callable addresses before comparison. CUDA
graph capture runs after artifact load, so the Llama CUDA-graph-on and -off
artifacts have the same pre-capture graph.
| Configuration | Nodes, partial / SPMD | AG | RS | AR | A2A | Compiled regions | Exact node sequence |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | --- |
| Llama3 FSDP4 + TP2, CUDA graph off | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Llama3 FSDP4 + TP2, CUDA graph on | 2794 / 2723 | 134 / 134 | 42 / 42 | 10 / 10 | 0 / 0 | 12 / 12 | No |
| Qwen3 MoE FSDP4 + TP2 + EP4 | 5797 / 5603 | 222 / 206 | 44 / 44 | 12 / 12 | 40 / 40 | 16 / 16 | No |
| DeepSeek V3 FSDP4 + TP2 + EP4 | 4694 / 4468 | 225 / 215 | 116 / 116 | 54 / 54 | 25 / 25 | 12 / 12 | No |
| MuseGlimmer FSDP4 + TP2 | 4546 / 4453 | 254 / 254 | 52 / 52 | 12 / 12 | 0 / 0 | 16 / 16 | No |
DeepSeek graphs were compared with the bucketing pass removed from both sides
because the partial-DTensor precompile path hits the known topological-sort
failure. This comparison required analysis-only pass filtering: precompile does
not currently propagate `compile.disable_passes` to `apply_graph_passes`. No
workaround for that issue is included in this commit.
The SPMD graphs contain fewer process-group lookups and no additional
reduce-scatter, all-reduce, or all-to-all collectives. The main extra work is a
BF16 -> FP32 cast pair before FSDP gradient reduction for parameters replicated
on a non-DP axis:
| Model | Extra SPMD cast pairs | PG lookup delta | All-gather delta |
| --- | ---: | ---: | ---: |
| Llama3 | 13 | -39 | 0 |
| Qwen3 MoE | 49 | -75 | -16 |
| DeepSeek V3 | 35 | -66 | -10 |
| MuseGlimmer | 33 | -67 | 0 |
These casts are produced by composing the `spmd.redistribute(I -> R)` backward
dtype conversion with SimpleFSDP's FP32 gradient reduction. Under regional
Inductor they remain outside the compiled attention regions. The Kineto traces
have effectively identical profiled step times, and the healthy-device Qwen
control shows no measurable regression, so there is no evidence that these
casts materially affect runtime. DeepSeek's run medians range from 56.3K to
70.2K TPS, while its pooled steady-state median is only 1.8% below the baseline.
Artifact generation and distributed load/run used explicit mesh inputs and
mesh-coordinate registration.
| Model | Parallelism | CUDA graph | Artifact generation | 8-GPU load/run |
| --- | --- | --- | --- | --- |
| Llama3 | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
| Llama3 | FSDP4 + TP2 | on | Pass | Pass, 3 steps |
| Qwen3 MoE | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| DeepSeek V3 | FSDP4 + TP2 + EP4 | off | Pass | Pass, 3 steps |
| MuseGlimmer | FSDP4 + TP2 | off | Pass | Pass, 3 steps |
DeepSeek V3 and MuseGlimmer emitted non-fatal TritonBundler warnings for cached
FlexAttention cubins that were absent at load time; both jobs completed.
| Test | Result |
| --- | --- |
| MuseGlimmer FSDP4 + TP2, 3 steps | Pass |
| Llama3 FSDP4 + TP2, full Inductor | Pass |
| Llama3 FSDP4 + TP2, no optional graph passes | Pass |
| Llama3 FSDP4 + TP2, full recompute | Pass |
| Llama3 FSDP4 + TP2, SAC + CPU offload | Pass |
| Llama3 FSDP4 + TP2, FSDP AG/RS overlap | Pass |
| Llama3 FSDP4 + TP2, numerics-changing optimizations | Pass |
| Llama3 DCP save at step 2 and resume through step 4 | Pass |
| DeepSeek V3 FSDP4 + TP2 + EP4 DCP save/resume | Pass |
| Focused SimpleFSDP and precompile unit tests | 27 passed |
| Test | `partial_dtensor` | `spmd_types` | Classification |
| --- | --- | --- | --- |
| Llama3 FSDP2 + TP2 + CP2 | Rejected by configuration: CP requires `spmd_types` | FlexAttention trace fails with `FunctionalTensor on its own` | CP/FlexAttention limitation; only reachable with SPMD |
| DeepSeek V3 GraphPP Interleaved1F1B | Pass, 3 steps | Fails before partitioning on unresolved enum axes `(DP, CP)` | SPMD-specific integration gap; all schedules share this path |
| DeepSeek V3 EP-overlap eager chunking | Trace fails: block mask is larger than chunked query | Not reached in comparison | Backend-independent eager-chunk test failure |
| DeepSeek V3 graph EP overlap | CUDA device-side assert during expert-bias update | Same CUDA device-side assert | Backend-independent |
| DeepSeek V3 default FSDP bucketing | Stable-topological-sort assertion | Passes precompile/load/run | Existing `partial_dtensor` failure |
Run both commands concurrently, then swap the two `CUDA_VISIBLE_DEVICES`
assignments:
```bash
CUDA_VISIBLE_DEVICES=<four GPUs> NGPU=4 \
MODULE=graph_trainer.qwen3 CONFIG=graph_trainer_qwen3_debugmodel_moe \
./run_train.sh \
--training.steps=100 --training.disable_cuda_graphs --metrics.log_freq=10 \
--compile.mode=aot_fx_trace --compile.inductor_compilation=regional \
--compile.disable_passes=cudagraph_pass \
--parallelism.spmd_backend=<partial_dtensor|spmd_types> \
--parallelism.data_parallel_shard_degree=2 \
--parallelism.tensor_parallel_degree=2 \
--parallelism.expert_parallel_degree=2 \
--checkpoint.enable --checkpoint.load_only \
--checkpoint.initial_load_path=<seed-checkpoint> \
--debug.seed=42
```
```bash
python scripts/loss_compare.py main <spmd-commit> \
--baseline-module graph_trainer.<model> \
--baseline-config <config> \
--test-module graph_trainer.<model> \
--test-config <config> \
--baseline-options='<common options> --parallelism.spmd_backend partial_dtensor' \
--test-options='<common options> --parallelism.spmd_backend spmd_types' \
--steps 10 --metrics loss,grad_norm \
--baseline-ngpus 8 --test-ngpus 8
```
Common Llama options:
```text
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
```
Common Qwen3 MoE options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
Common DeepSeek V3 options:
```text
--training.disable_cuda_graphs
--compile.mode aot_fx_trace
--compile.disable_passes joint_transformer_block_bucketing_reordering_pass,cudagraph_pass
--parallelism.data_parallel_shard_degree 4
--parallelism.tensor_parallel_degree 2
--parallelism.expert_parallel_degree 4
```
```bash
python -m torchtitan.experiments.graph_trainer.precompile_main \
--module graph_trainer.<model> --config <config> \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
NGPU=8 MODULE=graph_trainer.<model> CONFIG=<config> \
./torchtitan/experiments/graph_trainer/run_train_precompile.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.precompile_artifact_dir "$ARTIFACT_DIR" \
--parallelism.spmd_backend spmd_types \
<parallelism options>
```
```bash
NGPU=8 MODULE=graph_trainer.llama3 CONFIG=graph_trainer_llama3_debugmodel \
./run_train.sh \
--training.steps 3 \
--compile.mode aot_fx_trace \
--compile.disable_passes cudagraph_pass \
--parallelism.spmd_backend spmd_types \
--parallelism.data_parallel_shard_degree 4 \
--parallelism.tensor_parallel_degree 2 \
<one of:
--compile.inductor_compilation full
--compile.no-enable_passes
--compile.memory_policy full
--compile.memory_policy sac_and_offload
--compile.enable_fsdp_ag_rs_overlap
--compile.numerics_changing_optim>
```
```bash
pytest -q \
torchtitan/experiments/graph_trainer/tests/test_simple_fsdp.py \
torchtitan/experiments/graph_trainer/tests/test_precompile.py
```
Lint and GraphTrainer type checking were not run.
ghstack-source-id: 3adfbfc
Pull Request resolved: #4325
Stack from ghstack (oldest at bottom):
spmd_typesbackend #4325human-written section
Enables graph trainer for spmd_types backend
Changes
spmd_typesmodel-parallel backend.SpmdTypethrough FSDP wrapping and materializereplicated non-DP axes with
spmd.redistribute.collectives resolve runtime process groups.
Test environment
main(partial_dtensor)--debug.seed=42 --debug.deterministicBackend parity
Both backends loaded the same seed checkpoint and ran with
--debug.seed=42 --debug.deterministic. Full-precision TensorBoard values werecompared rather than rounded stdout.
6.198883e-051.537800e-04DeepSeek parity disabled the bucketing and CUDA-graph passes on both backends.
The focused deterministic suite also completed with 16 passed and 9 skipped.
Activation checkpointing
Configuration: Llama3 debug model, 8 GPUs, FSDP4 + TP2,
aot_fx_trace, regional Inductor, CUDA graphs disabled, 20 steps, and one runper backend. TPS is the rank-0 median over steps 6-20, and memory is the
maximum reported peak across ranks. Only
compile.memory_policychangedbetween rows.
The
partial_dtensorandspmd_typesgraphs made identical save/recomputedecisions for every tested policy and every one of the six Llama layers.
CPU offload matched exactly as well: both backends tagged 35 activations
(282.5 MB), offloaded 20 tensors (142.5 MB), replayed five views, and moved 20
reloads one layer earlier.
Precompile
Artifacts were generated independently for each backend, then loaded by a
fresh 8-GPU process for a 20-step run. CUDA graphs were disabled so these
numbers isolate the precompiled regional-Inductor path. TPS is the rank-0
median over steps 6-20; memory is the maximum reported peak across ranks.
DeepSeek used
--training.disable_cuda_graphsbecause its default tokendispatcher is rejected by CUDA-graph configuration validation. Its
partial_dtensorartifact generation reaches the samestable topological sort of region failedlimitation as the direct-tracedefault-bucketing path;
spmd_typesgenerates, loads, and runs the artifact.CUDA graphs
CUDA graphs are not blocked for the
spmd_typesbackend as a whole. They workon the precompiled Llama FlexAttention path: the artifact loaded, the pass
logged
Applied cudagraph pass, and training completed for 10 steps. Oversteps 6-10, median throughput was 246,007 TPS with CUDA graphs versus 116,855
TPS from the same precompiled artifact with the pass disabled; peak memory was
0.46 versus 0.45 GiB. This is a single short run.
The direct-trace Llama FSDP4 + TP2 path remains blocked from CUDA graph capture
on both backends. The pass is invoked but logs
Skipping cudagraph: graph is not compatible, so direct-trace runs with the pass enabled are not CUDA graphperformance measurements.
Inductor
Both modes completed 20 steps. Full Inductor was the fastest tested direct
trace configuration for both backends.
FSDP
SimpleFSDP unit coverage passed (
2 passed). Llama FSDP4 + TP2 completed underboth backends, and the optional AG/RS overlap pass found the same 22 overlap
dependencies in each graph.
For DeepSeek FSDP4 + TP2 + EP4 with the default bucketing pass,
partial_dtensorfails withstable topological sort of region failed, whilespmd_typescompletes. This is a baseline limitation rather than anspmd_typesblocker.DCP
Llama FSDP4 + TP2 with
spmd_typestrained for 10 steps, saved a full DCPcheckpoint at step 10, then loaded it in a fresh process and resumed at step 11
through step 12. Model, optimizer, scheduler, dataloader, and trainer state were
restored through the normal checkpoint path.
GraphPP
Configuration: DeepSeek V3 debug model, 8 GPUs, FSDP4 + PP2 + EP2, TP1, eight
pipeline microbatches, 2,048 tokens per microbatch per DP rank, full Inductor,
CUDA graphs disabled, and 20 training steps. All three schedules completed
under both backends. TPS is the rank-0 median over steps 6-20; memory is the
maximum reported peak across ranks.
Other coverage
test_bitwise_deterministic.pytest_simple_fsdp.pyThe formatter-only changes requested by lint are included in
simple_fsdp.py. A local all-files Pyrefly invocation is not representative ofCI in this dirty workspace because it scans unrelated untracked scripts and
generated
torch_compile_debugfiles; the clean CI result supplied for thiscommit passes.
Unsupported GraphTrainer configurations
partial_dtensorspmd_types#4052)#4342)Reproduction commands
Backend parity used
scripts/loss_compare.pywith 10 steps, the same seedcheckpoint, and backend-specific
--parallelism.spmd_backendvalues. Thecommon Llama options were FSDP4 + TP2; Qwen and DeepSeek additionally used EP4.
DeepSeek disabled
joint_transformer_block_bucketing_reordering_pass.Feature performance used:
<feature options>was one of--compile.memory_policy eager,--compile.memory_policy full,--compile.memory_policy sac_and_offload,--compile.inductor_compilation full, or--compile.enable_fsdp_ag_rs_overlap. The paired GraphPP and precompileperformance runs used the same options as their checked-in integration cases,
with 20 steps and a separate launch or artifact for each backend.