Skip to content

[graph_trainer] Add EP overlap scheduling pass - #3328

Merged
sanketpurandare merged 1 commit into
mainfrom
sanketpurandare/stack/14
Jun 26, 2026
Merged

sanketpurandare merged 1 commit into
mainfrom
sanketpurandare/stack/14

Conversation

@sanketpurandare

@sanketpurandare sanketpurandare commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

Stacked PRs:


[graph_trainer] Add EP overlap scheduling pass

Add the EP overlap scheduler, process-group isolation, FSDP dense-region scheduling, and the scheduling metadata needed to pair EP token exchanges with chunked compute regions.

Split MoE token-dispatcher collectives into annotated helper methods so the graph scheduler can distinguish token-count sync, dispatch, and combine boundaries while preserving the existing non-blocking input split copy behavior.

Test Plan:

  • conda run -n pt-dev python -m pytest -q torchtitan/experiments/graph_trainer/tests/test_passes.py::TestFsdpDenseSchedulerPass torchtitan/experiments/graph_trainer/tests/test_passes.py::TestChunkPasses torchtitan/experiments/graph_trainer/tests/test_precompile.py::TestConfigFingerprint torchtitan/experiments/graph_trainer/tests/test_passes.py::TestEagerChunking
  • conda run -n pt-dev python -m pytest -q torchtitan/experiments/graph_trainer/tests/test_chunked_loss.py torchtitan/experiments/graph_trainer/tests/test_precompile.py::TestPrecompileLossSetup torchtitan/experiments/graph_trainer/tests/test_trace_module.py::TestTraceModule::test_chunked_ce_loss_train_step tests/unit_tests/test_loss.py::TestGradAccumulator tests/unit_tests/test_loss.py::TestGradAccumulatorDTensor tests/unit_tests/test_loss.py::TestChunkedCELoss tests/unit_tests/test_loss.py::TestChunkedCELossSPMD
  • conda run -n pt-dev python -m pytest -q torchtitan/experiments/graph_trainer/tests/test_bitwise_deterministic.py::TestDSv3FlexAttnBitwiseDeterministic::test_ep_chunk_matches_eager_chunking_bitwise
  • conda run -n pt-dev python -m pytest -q torchtitan/experiments/graph_trainer/tests/test_numerics.py::TestGraphTrainerNumerics::test_moe_dsv3_ep_overlap_aot_fx_trace_vs_eager_chunked torchtitan/experiments/graph_trainer/tests/test_numerics.py::TestGraphTrainerNumerics::test_moe_dsv3_ep_overlap_moe_seq_aot_fx_trace_vs_eager_chunked torchtitan/experiments/graph_trainer/tests/test_numerics.py::TestGraphTrainerNumerics::test_moe_dsv3_ep_overlap_moe_batch_aot_fx_trace_vs_eager_chunked
  • python torchtitan/experiments/graph_trainer/tests/integration_tests.py --test_suite graph_trainer_h100 --test_name --ngpu 8
  • SKIP=pyrefly-check conda run -n pt-dev pre-commit run --files
  • conda run -n pt-dev pyrefly check --project-excludes=agent_space --project-excludes=torchtitan/experiments --project-excludes='/tests/' --output-format omit-errors

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label May 12, 2026
sanketpurandare added a commit that referenced this pull request May 12, 2026
Expose EP overlap as the user-facing graph_trainer pass for chunked MoE communication scheduling. The pass is opt-in through --compile.passes ep_overlap, defaults to batch splitting transformer blocks, and keeps the lower-level chunk transform as an internal implementation detail used by the overlap scheduler.

The pass first applies chunking to the configured module regions, then classifies copied forward/backward nodes by chunk id and EP dispatch/combine annotations. It splits each EP phase at the last all-to-all launch so wait-suffix nodes can be delayed, then adds stable topological ordering constraints that launch peer chunk communication before waiting on the current chunk. Forward regions schedule dispatch before combine with chunk order 0 then 1; backward autograd regions schedule combine-gradient communication before dispatch-gradient communication with chunk order 1 then 0. Non-MoE transformer blocks keep the chunk transform's topological order, and configurations with no EP all-to-all regions fail fast.

Update MoE traceback annotation setup so the actual AllToAllTokenDispatcher dispatch/combine bodies are annotated, not only the local dispatcher fallback. The annotation helper is idempotent and shared by DeepSeek and Qwen graph trainer parallelization.

Replace the public chunk_modules/chunk_mode compile knobs with ep_overlap_modules/ep_overlap_mode. The trace input preparation hook now only runs when ep_overlap is present in compile.passes, and it marks every pytree tensor that shares the selected dynamic batch/sequence extent with the main input so labels and positional tensors carry the same dynamic annotation when they participate in tracing.

Harden the chunk planning path for whole-block and MoE-only overlap regions. Symbolic shape scalar helpers may be shared across adjacent planned regions, while real tensor compute remains disjoint. Region live-ins are filtered after the copied closure reaches a fixed point, scalar live-out materialization handles guarded even split dimensions explicitly, and FX renaming is used for copied/materialized nodes to avoid duplicate generated names in large multi-region transforms.

Test Plan:

- pytest torchtitan/experiments/graph_trainer/tests/test_passes.py -k 'ep_overlap or chunk' -q

- pre-commit run --files torchtitan/experiments/graph_trainer/chunk_passes.py torchtitan/experiments/graph_trainer/common_utils.py torchtitan/experiments/graph_trainer/configs.py torchtitan/experiments/graph_trainer/deepseek_v3/parallelize.py torchtitan/experiments/graph_trainer/passes.py torchtitan/experiments/graph_trainer/precompile.py torchtitan/experiments/graph_trainer/qwen3/parallelize.py torchtitan/experiments/graph_trainer/tests/test_passes.py torchtitan/experiments/graph_trainer/trainer.py

- pre-commit run --files torchtitan/experiments/graph_trainer/chunk_passes.py torchtitan/experiments/graph_trainer/tests/test_passes.py

- git diff --check

stack-info: PR: #3328, branch: sanketpurandare/stack/14
@sanketpurandare
sanketpurandare force-pushed the sanketpurandare/stack/14 branch from 6945c23 to 83081fc Compare May 12, 2026 08:41
@sanketpurandare

Copy link
Copy Markdown
Contributor Author

TL parse artifacts from the EP overlap graph-pass validation runs:

Verification notes:

  • Transformer-block default mode applied chunk_batch to 12 layer regions and ep_overlap to 10 EP chunked regions. That matches the debug model shape: dense/non-MoE layers can be chunked but do not have EP all-to-all scheduling phases.
  • MoE-only mode applied chunk_batch to 10 MoE regions and ep_overlap to 10 EP chunked regions.
  • The MoE-only graph diff shows the expected EP duplication from chunking: all_to_all_single.default: 25 -> 50, histc.default: 10 -> 20, and wait_tensor.default: 291 -> 366.
  • Generated rank0 code shows the intended launch/wait ordering for a MoE layer: chunk 0 dispatch launch, chunk 1 dispatch launch, then dispatch waits/compute, followed by chunk 0 combine launch, chunk 1 combine launch, then combine waits. The delayed wait-suffix nodes are tagged with EP_wait=True after the relevant all-to-all boundaries.

These artifacts validate the graph transformation and scheduling structure. They are not performance numbers; the performance/profile runs need to be collected separately on exclusively available GPUs.

@sanketpurandare
sanketpurandare marked this pull request as draft May 12, 2026 09:13
@sanketpurandare
sanketpurandare changed the base branch from sanketpurandare/stack/12 to main May 12, 2026 09:13
sanketpurandare added a commit that referenced this pull request May 12, 2026
Expose EP overlap as the user-facing graph_trainer pass for chunked MoE communication scheduling. The pass is opt-in through --compile.passes ep_overlap, defaults to batch splitting transformer blocks, and keeps the lower-level chunk transform as an internal implementation detail used by the overlap scheduler.

The pass first applies chunking to the configured module regions, then classifies copied forward/backward nodes by chunk id and EP dispatch/combine annotations. It splits each EP phase at the last all-to-all launch so wait-suffix nodes can be delayed, then adds stable topological ordering constraints that launch peer chunk communication before waiting on the current chunk. Forward regions schedule dispatch before combine with chunk order 0 then 1; backward autograd regions schedule combine-gradient communication before dispatch-gradient communication with chunk order 1 then 0. Non-MoE transformer blocks keep the chunk transform's topological order, and configurations with no EP all-to-all regions fail fast.

Update MoE traceback annotation setup so the actual AllToAllTokenDispatcher dispatch/combine bodies are annotated, not only the local dispatcher fallback. The annotation helper is idempotent and shared by DeepSeek and Qwen graph trainer parallelization.

Replace the public chunk_modules/chunk_mode compile knobs with ep_overlap_modules/ep_overlap_mode. The trace input preparation hook now only runs when ep_overlap is present in compile.passes, and it marks every pytree tensor that shares the selected dynamic batch/sequence extent with the main input so labels and positional tensors carry the same dynamic annotation when they participate in tracing.

Harden the chunk planning path for whole-block and MoE-only overlap regions. Symbolic shape scalar helpers may be shared across adjacent planned regions, while real tensor compute remains disjoint. Region live-ins are filtered after the copied closure reaches a fixed point, scalar live-out materialization handles guarded even split dimensions explicitly, and FX renaming is used for copied/materialized nodes to avoid duplicate generated names in large multi-region transforms.

Test Plan:

- pytest torchtitan/experiments/graph_trainer/tests/test_passes.py -k 'ep_overlap or chunk' -q

- pre-commit run --files torchtitan/experiments/graph_trainer/chunk_passes.py torchtitan/experiments/graph_trainer/common_utils.py torchtitan/experiments/graph_trainer/configs.py torchtitan/experiments/graph_trainer/deepseek_v3/parallelize.py torchtitan/experiments/graph_trainer/passes.py torchtitan/experiments/graph_trainer/precompile.py torchtitan/experiments/graph_trainer/qwen3/parallelize.py torchtitan/experiments/graph_trainer/tests/test_passes.py torchtitan/experiments/graph_trainer/trainer.py

- pre-commit run --files torchtitan/experiments/graph_trainer/chunk_passes.py torchtitan/experiments/graph_trainer/tests/test_passes.py

- git diff --check

stack-info: PR: #3328, branch: sanketpurandare/stack/14
@sanketpurandare
sanketpurandare force-pushed the sanketpurandare/stack/14 branch from 83081fc to 6783bda Compare May 12, 2026 09:13
@sanketpurandare
sanketpurandare changed the base branch from main to sanketpurandare/stack/12 May 12, 2026 09:13
@sanketpurandare
sanketpurandare marked this pull request as ready for review May 12, 2026 09:13

@xmfan xmfan left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please include both a tlparse and a perfetto trace of before vs after

@sanketpurandare
sanketpurandare marked this pull request as draft May 13, 2026 14:16
@sanketpurandare
sanketpurandare changed the base branch from sanketpurandare/stack/12 to main May 13, 2026 14:16
sanketpurandare added a commit that referenced this pull request May 13, 2026
Add the scheduling layer for graph_trainer's public ep_overlap pass. The previous commit creates the correctness-preserving chunked graph; this commit consumes that chunked graph after FSDP bucketing and reorders EP dispatch/combine phases so paired chunk all-to-all launches can run before their delayed wait suffixes.

The scheduling logic lives in ep_overlap_pass.py and is intentionally separate from chunking. Its input contract is an already chunked graph with exactly two chunks per selected region, chunk body nodes tagged with chunk_id and chunked_region metadata, and MoE dispatcher regions annotated with custom EP metadata for dispatch and combine. The scheduler validates canonical chunk order, extracts dispatch/combine phases, annotates delayed wait suffixes with EP_wait=True, and applies a priority topological sort. It does not duplicate nodes, delete nodes, split tensors, concatenate tensors, or otherwise change tensor values.

Wire the public ep_overlap pipeline as two stages: chunking runs after CPU offload and SAC/rematerialization, while scheduling runs after downstream FSDP bucketing/reordering. This keeps chunk planning aligned with the final recompute graph and lets bucketing place shared full waits before the overlap scheduler establishes the final EP launch/wait order.

The distributed DSV3 bitwise numerics tests introduced in the previous commit now cover this composed public ep_overlap path as well. Since this scheduling pass is value-preserving, those tests validate that adding the scheduler on top of graph chunking does not change the eager-chunk-equivalent loss/gradient behavior. Existing tlparse validation artifacts show the intended rank-code order: dispatch chunk0 launch, dispatch chunk1 launch, delayed dispatch waits, combine chunk0 launch, combine chunk1 launch, and delayed combine waits annotated with EP_wait=True.

This pass stack relies on pending PyTorch support for hinted unbacked symbolic dimensions in the tracing and distributed compiler paths:
- FakeTensor folded matmul: pytorch/pytorch#183397
- ProxyTensor SDPA tracing: pytorch/pytorch#183398
- Inductor bucketing trace isolation from ambient unbacked symbols: pytorch/pytorch#183495
- Inductor collective bucketing with hinted unbacked SymInts: pytorch/pytorch#183544
- DTensor sharding padding for hinted even unbacked shards: pytorch/pytorch#183545

Test Plan:
- pytest torchtitan/experiments/graph_trainer/tests/test_passes.py -k 'ep_overlap or chunk' -q
  - 8 passed, 73 deselected, 2 subtests passed
- pytest torchtitan/experiments/graph_trainer/tests/test_numerics.py -k ep_overlap -q
  - 3 passed, 20 deselected

stack-info: PR: #3328, branch: sanketpurandare/stack/14
@sanketpurandare
sanketpurandare force-pushed the sanketpurandare/stack/14 branch from 6783bda to 632a794 Compare May 13, 2026 14:16
@sanketpurandare sanketpurandare changed the title [graph_trainer] Add EP overlap pass [graph_trainer] Add EP overlap scheduling pass May 13, 2026
@sanketpurandare
sanketpurandare changed the base branch from main to sanketpurandare/stack/12 May 13, 2026 14:16
@sanketpurandare
sanketpurandare marked this pull request as ready for review May 13, 2026 14:16
@sanketpurandare
sanketpurandare marked this pull request as draft May 13, 2026 23:25
sanketpurandare added a commit that referenced this pull request May 26, 2026
Add the scheduling layer for graph_trainer's public ep_overlap pass. Graph and eager chunking producers create correctness-preserving chunked graphs; this commit consumes their shared chunk metadata after FSDP bucketing and reorders EP token-exchange regions to expose communication/compute overlap without changing tensor values.

The scheduling logic lives in ep_overlap_pass.py and is intentionally separate from chunking. Its input contract is an already chunked graph with exactly two chunks per selected region, chunk body nodes tagged with chunk_id and chunked_region metadata, and true EP token-exchange markers on _c10d_functional.all_to_all_single.default nodes via custom[EP_token_exchange]. Generic MoE dispatch/combine traceback annotations are sanitized and are not scheduling markers.

The scheduler validates that both chunks have the same token-exchange signature, annotates each token-exchange wait with EP_token_exchange_wait, and emits a wait-gated schedule. For each token-exchange pair it emits the launch dependency closure in chunk order, then emits ready non-wait filler work that can run while the previous token exchange is outstanding, and only then allows the required wait/tail work. Forward uses chunk order 0 then 1; backward uses chunk order 1 then 0. All nodes are emitted exactly once through a global topological emitter, and the pass does not duplicate, delete, split, concatenate, or otherwise compute tensor values.

Wire the public ep_overlap pipeline as graph/eager chunking, FSDP process-group isolation and bucketing, EP scheduling, chunk-symbol concretization, optional async TP fusion, and DTensor metadata cleanup. Add focused scheduler tests and H100 integration coverage for graph and eager chunking across SDPA and FlexAttention debug-model variants. The distributed bitwise numerics tests introduced with graph chunking cover this composed public ep_overlap path because scheduling is value-preserving.

This pass stack relies on PyTorch support for hinted unbacked symbolic dimensions in the tracing and distributed compiler paths:
- FakeTensor folded matmul: pytorch/pytorch#183397
- ProxyTensor SDPA tracing: pytorch/pytorch#183398
- Inductor bucketing trace isolation from ambient unbacked symbols: pytorch/pytorch#183495
- Inductor collective bucketing with hinted unbacked SymInts: pytorch/pytorch#183544
- DTensor sharding padding for hinted even unbacked shards: pytorch/pytorch#183545
- HOP fake traces with discarded unbacked symbols: pytorch/pytorch#183837
- FlexAttention chunked unbacked input extents: pytorch/pytorch#183838
- FakeTensor trace metadata for hinted symbolic storage: pytorch/pytorch#183839
- Inductor symbolic stride ordering with unbacked hints: pytorch/pytorch#183840
- Inductor TP slice/cat collective fusion: pytorch/pytorch#184833

Test Plan:
- pytest -q torchtitan/experiments/graph_trainer/tests/test_passes.py
- pytest -q torchtitan/experiments/graph_trainer/tests/test_numerics.py -k ep_overlap
- PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py <out_dir> --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_transformer_batch --ngpu 8
- PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py <out_dir> --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_moe_batch --ngpu 8
- PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py <out_dir> --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_moe_seq --ngpu 8
- PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py <out_dir> --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_transformer_batch --ngpu 8
- PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py <out_dir> --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_moe_batch --ngpu 8
- PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py <out_dir> --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_moe_seq --ngpu 8
- PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py <out_dir> --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_eager_transformer_batch --ngpu 8
- PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py <out_dir> --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_eager_transformer_batch --ngpu 8

stack-info: PR: #3328, branch: sanketpurandare/stack/14
@sanketpurandare
sanketpurandare changed the base branch from main to sanketpurandare/stack/12 May 26, 2026 05:29
@sanketpurandare
sanketpurandare marked this pull request as ready for review May 26, 2026 05:29
@sanketpurandare
sanketpurandare marked this pull request as draft May 26, 2026 05:31
@sanketpurandare
sanketpurandare changed the base branch from sanketpurandare/stack/12 to main May 26, 2026 05:31
@sanketpurandare
sanketpurandare changed the base branch from main to sanketpurandare/stack/12 May 26, 2026 05:31
@sanketpurandare
sanketpurandare marked this pull request as ready for review May 26, 2026 05:31
@sanketpurandare
sanketpurandare marked this pull request as draft May 27, 2026 03:51
@sanketpurandare
sanketpurandare changed the base branch from sanketpurandare/stack/12 to main May 27, 2026 03:51
@sanketpurandare
sanketpurandare force-pushed the sanketpurandare/stack/14 branch from 42d4319 to 414f3aa Compare May 27, 2026 03:51
sanketpurandare added a commit that referenced this pull request May 27, 2026
Add the scheduling layer for graph_trainer's public ep_overlap pass. Graph and eager chunking producers create correctness-preserving chunked graphs; this commit consumes their shared chunk metadata after FSDP bucketing and reorders EP token-exchange regions to expose communication/compute overlap without changing tensor values.

The scheduling logic lives in ep_overlap_pass.py and is intentionally separate from chunking. Its input contract is an already chunked graph with exactly two chunks per selected region, chunk body nodes tagged with chunk_id and chunked_region metadata, and true EP token-exchange markers on _c10d_functional.all_to_all_single.default nodes via custom[EP_token_exchange]. Generic MoE dispatch/combine traceback annotations are sanitized and are not scheduling markers.

The scheduler validates that both chunks have the same token-exchange signature, annotates each token-exchange wait with EP_token_exchange_wait, and emits a wait-gated schedule. For each token-exchange pair it emits the launch dependency closure in chunk order, then emits ready non-wait filler work that can run while the previous token exchange is outstanding, and only then allows the required wait/tail work. Forward uses chunk order 0 then 1; backward uses chunk order 1 then 0. All nodes are emitted exactly once through a global topological emitter, and the pass does not duplicate, delete, split, concatenate, or otherwise compute tensor values.

Wire the public ep_overlap pipeline as graph/eager chunking, FSDP process-group isolation and bucketing, EP scheduling, chunk-symbol concretization, optional async TP fusion, and DTensor metadata cleanup. Add focused scheduler tests and H100 integration coverage for graph and eager chunking across SDPA and FlexAttention debug-model variants. The distributed bitwise numerics tests introduced with graph chunking cover this composed public ep_overlap path because scheduling is value-preserving.

This pass stack relies on PyTorch support for hinted unbacked symbolic dimensions in the tracing and distributed compiler paths:
- FakeTensor folded matmul: pytorch/pytorch#183397
- ProxyTensor SDPA tracing: pytorch/pytorch#183398
- Inductor bucketing trace isolation from ambient unbacked symbols: pytorch/pytorch#183495
- Inductor collective bucketing with hinted unbacked SymInts: pytorch/pytorch#183544
- DTensor sharding padding for hinted even unbacked shards: pytorch/pytorch#183545
- HOP fake traces with discarded unbacked symbols: pytorch/pytorch#183837
- FlexAttention chunked unbacked input extents: pytorch/pytorch#183838
- FakeTensor trace metadata for hinted symbolic storage: pytorch/pytorch#183839
- Inductor symbolic stride ordering with unbacked hints: pytorch/pytorch#183840
- Inductor TP slice/cat collective fusion: pytorch/pytorch#184833

Test Plan:
- pytest -q torchtitan/experiments/graph_trainer/tests/test_passes.py
- pytest -q torchtitan/experiments/graph_trainer/tests/test_numerics.py -k ep_overlap
- PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py <out_dir> --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_transformer_batch --ngpu 8
- PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py <out_dir> --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_moe_batch --ngpu 8
- PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py <out_dir> --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_moe_seq --ngpu 8
- PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py <out_dir> --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_transformer_batch --ngpu 8
- PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py <out_dir> --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_moe_batch --ngpu 8
- PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py <out_dir> --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_moe_seq --ngpu 8
- PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py <out_dir> --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_sdpa_full_inductor_ep_overlap_eager_transformer_batch --ngpu 8
- PYTHONPATH=$PWD python torchtitan/experiments/graph_trainer/tests/integration_tests.py <out_dir> --test_suite graph_trainer_h100 --test_name aot_fx_trace_deepseek_v3_flexattn_full_inductor_ep_overlap_eager_transformer_batch --ngpu 8

stack-info: PR: #3328, branch: sanketpurandare/stack/14
@sanketpurandare
sanketpurandare changed the base branch from main to sanketpurandare/stack/12 May 27, 2026 03:52
@sanketpurandare
sanketpurandare marked this pull request as ready for review May 27, 2026 03:52
@sanketpurandare
sanketpurandare force-pushed the sanketpurandare/stack/12 branch from 629d28c to a0461e9 Compare May 27, 2026 04:41
Add the EP overlap scheduler, process-group isolation, FSDP dense-region scheduling, and the scheduling metadata needed to pair EP token exchanges with chunked compute regions.

Split MoE token-dispatcher collectives into annotated helper methods so the graph scheduler can distinguish token-count sync, dispatch, and combine boundaries while preserving the existing non-blocking input split copy behavior.

Test Plan:
- conda run -n pt-dev python -m pytest -q torchtitan/experiments/graph_trainer/tests/test_passes.py::TestFsdpDenseSchedulerPass torchtitan/experiments/graph_trainer/tests/test_passes.py::TestChunkPasses torchtitan/experiments/graph_trainer/tests/test_precompile.py::TestConfigFingerprint torchtitan/experiments/graph_trainer/tests/test_passes.py::TestEagerChunking
- conda run -n pt-dev python -m pytest -q torchtitan/experiments/graph_trainer/tests/test_chunked_loss.py torchtitan/experiments/graph_trainer/tests/test_precompile.py::TestPrecompileLossSetup torchtitan/experiments/graph_trainer/tests/test_trace_module.py::TestTraceModule::test_chunked_ce_loss_train_step tests/unit_tests/test_loss.py::TestGradAccumulator tests/unit_tests/test_loss.py::TestGradAccumulatorDTensor tests/unit_tests/test_loss.py::TestChunkedCELoss tests/unit_tests/test_loss.py::TestChunkedCELossSPMD
- conda run -n pt-dev python -m pytest -q torchtitan/experiments/graph_trainer/tests/test_bitwise_deterministic.py::TestDSv3FlexAttnBitwiseDeterministic::test_ep_chunk_matches_eager_chunking_bitwise
- conda run -n pt-dev python -m pytest -q torchtitan/experiments/graph_trainer/tests/test_numerics.py::TestGraphTrainerNumerics::test_moe_dsv3_ep_overlap_aot_fx_trace_vs_eager_chunked torchtitan/experiments/graph_trainer/tests/test_numerics.py::TestGraphTrainerNumerics::test_moe_dsv3_ep_overlap_moe_seq_aot_fx_trace_vs_eager_chunked torchtitan/experiments/graph_trainer/tests/test_numerics.py::TestGraphTrainerNumerics::test_moe_dsv3_ep_overlap_moe_batch_aot_fx_trace_vs_eager_chunked
- python torchtitan/experiments/graph_trainer/tests/integration_tests.py <out> --test_suite graph_trainer_h100 --test_name <each ep_overlap entry> --ngpu 8
- SKIP=pyrefly-check conda run -n pt-dev pre-commit run --files <stack files>
- conda run -n pt-dev pyrefly check --project-excludes=agent_space --project-excludes=torchtitan/experiments --project-excludes='**/tests/**' --output-format omit-errors

stack-info: PR: #3328, branch: sanketpurandare/stack/14
Comment on lines -384 to -386
# pyrefly: ignore [missing-attribute]
ep_size = self.ep_mesh.size()
e = num_global_tokens_per_local_expert_E.shape[0] // ep_size

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why removing these and putting into args?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The original motivation was:

  • dispatch() had already proven self.ep_mesh is not None and computed ep_size.
  • _permute() and TorchAOTokenDispatcher._permute() both needed ep_size and local expert count.
  • Passing them in avoided another self.ep_mesh.size() inside _permute() and removed the old pyrefly missing-attribute ignore caused by self.ep_mesh being typed as optional.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can revert back the original behavior of recomputing it, all I want are separate functions for token count sync, dispatch and combine.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sounds fine

@tianyu-l tianyu-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

unblock, but please answer my question

@wwwjn wwwjn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stamp to unblock

pg,
metadata.input_splits,
metadata.output_splits,
)

@pianpwk pianpwk Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this looks like a plain refactor , but in case you're testing spmd_types breakage , it should be reasonable to run this test + spmd backend + typechecking (it's gated in integration_tests/features.py) :

OverrideDefinitions(
[
[
"--module deepseek_v3 --config deepseek_v3_debugmodel",
"--override.imports torchtitan.overrides.fused_swiglu",
"--parallelism.tensor_parallel_degree 2",
"--parallelism.expert_parallel_degree 4",
],
],
"Override: fuse grouped experts + FFNs on deepseek_v3 "
"(FSDP2 + TP2 dense, EP4 sparse)",
"override_fused_grouped_experts",
ngpu=4,
),

maybe for qwen3 as well to be safe

after #3673 landed

cc @tianyu-l

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@pianpwk why were unit tests not added when making changes to token dispatcher? @tianyu-l when committing code changes we should add at-least one test that exercises new path. Adding tests in upward stack for a downward PR is only okay when you plan to land the stack all at once.

@tianyu-l tianyu-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sg

scheduling markers.
"""
if (
torch.compiler.is_compiling() or torch.compiler._is_non_strict_tracing()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just curious, does the two flag ever overlap -- can they both be true under any circumstance?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes during nested compile, for example using flex attention under non-strict tracing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/h100.8 Trigger H100.8 CI ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RFC: Graph-Based EP Overlap For GraphTrainer

8 participants