Repository navigation
[HybridEP] Enable HybridEP with graph_trainer - #3007
Conversation
|
|
tianyu-l
left a comment
There was a problem hiding this comment.
sounds OK to me, would like @shuhuayu @yiming0416 @xmfan to take a look
|
|
||
| torch.compile Compatibility: | ||
| Decorated with @torch.compiler.disable() to always run in eager mode. | ||
| This avoids issues with CUDA event operations not being traceable. |
There was a problem hiding this comment.
Needs to update the docstring to reflect the changes.
There was a problem hiding this comment.
Thanks! Will do.
| hidden_dim=hidden_states.shape[1], | ||
| num_tokens=hidden_states.shape[0], | ||
| num_local_experts=num_local_experts, | ||
| ) |
There was a problem hiding this comment.
Do we also need this condition in
There was a problem hiding this comment.
This PR is only targeting CUDAGraph + HybridEP composability (through graph trainer). I believe DeepEP fundamentally won't work with CUDAGraph because of CPU syncs. Should we rather just document that DeepEP is not composable with CUDAGraphs?
There was a problem hiding this comment.
Agreed. DeepEP has d2h sync for both handle_id and and dispatch metadata num_recv_token. The former can be unified as the same as hybridep but the latter is fundamental. I think we can skip this.
yiming0416
left a comment
There was a problem hiding this comment.
For aot_fx_trace mode, you need to run the command with --compile.mode aot_fx_trace
dee0cf4 to
9e9f813
Compare
|
9e9f813 to
12db973
Compare
|
@yiming0416 could you help review? |
|
It looks like the latest TorchTitan/PyTorch broke the
|
yiming0416
left a comment
There was a problem hiding this comment.
LGTM. Changes to graph trainer are guarded under comm_backend.
It's expected that aot doesn't work given some recent regression. Let's try to add a test for aot_fx_trace
|
Thanks! Will add a test for aot_fx_trace. |
| return config | ||
|
|
||
|
|
||
| def graph_trainer_deepseek_v3_debugmodel_hybridep() -> GraphTrainer.Config: |
There was a problem hiding this comment.
let's add a test case for this model in integration test?
There was a problem hiding this comment.
Added an integration test exercising this config. See note below.
| "Applied Data Parallel (simple_fsdp) (dp mode=%s) to the model", dp_mode | ||
| ) | ||
|
|
||
| if comm_backend == "hybridep" and parallel_dims.ep_enabled: |
There was a problem hiding this comment.
is HybridEP also applicable to other Sparse model, e.g Qwen3?
Please leave a todo here to refactor the common part out into util?
Non blocking comment tho
There was a problem hiding this comment.
Yes, HybridEP is also applicable to models like Qwen3. Left a TODO.
3260299 to
5798c4e
Compare
5798c4e to
f9e679b
Compare
|
@SherlockNoMad Address your review comments - added the TODO and the integration test.
|
|
Ah I see why #2868 blocks grouped_mm from cuda graph. The sync is there for pre-blackwell architecture. |
f9e679b to
d2c17be
Compare
|
@SherlockNoMad Made the grouped mm exclusion in the cudagraph pass architecture dependent (if that's ok). |
d2c17be to
535f00a
Compare
Enable HybridEP to work with graph_trainer's aot and aot_fx_trace compilation paths. 1. Wire comm_backend through graph_trainer's parallelize_deepseekv3 to apply_moe_ep_tp. Pre-initialize HybridEP buffer before apply_compile so it's available at trace time. 2. Replace @torch.compiler.disable() on sync_combine with an is_compiling() guard — the decorator breaks fullgraph tracing under Dynamo. Under make_fx (aot_fx_trace), is_compiling() is False but the function is still safe since _pending_combine_event is None during tracing. 3. Fix fake dispatch scores shape from (0,) to (out_tokens,). 4. Guard _disable_current_modes() with _buffer is None instead of is_compiling() — is_compiling() returns False under make_fx. 5. Add FunctionalTensor/FakeTensor fallback in dispatch/combine backward for aot and aot_fx_trace tracing respectively. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
33f438d to
cf16bd9
Compare
|
@SherlockNoMad Here's the integration test to be added later after figuring out how to run DeepEP in the CI: syed-ahmed@857c500 And here's what I tried so far to upgrade the CI, but need to think about it a little more: syed-ahmed@4f8beed. The current base container is 12.4, doesn't have cuda toolkit, nvshmem, ibverbs, and installs pytorch with cuda 13 - because of which DeepEP can't be installed. Also since we don't have blackwell in the CI, cudagraph pass disables torch._grouped_mm, so the integration test can't really exercise the cudagraph pass with hybridep in the CI, until we have blackwell runners for torchtitan. |
| def _671b( | ||
| attn_backend: str, | ||
| moe_comm_backend: str, | ||
| non_blocking_capacity_factor: float | None = None, |
There was a problem hiding this comment.
nit: since model_registry has default value for this field, we don't need default values for concrete model flavors
There was a problem hiding this comment.
Some tests actually call the concrete model flavors directly. So rejecting this nit in the fix-up PR: #3177
4094c6d to
cf16bd9
Compare
Add non_blocking_capacity_factor parameter to DeepSeek-v3 config factories (_debugmodel, _16b, _236b, _671b) and both model_registry functions (core and graph_trainer) so HybridEP non-blocking mode can be configured at model construction time. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
- Mark MoE custom ops (hybridep dispatch/combine, grouped_mm) as cudagraph-safe so the cudagraph pass doesn't bail out. - Log HybridEP application in parallelize_deepseekv3. - Add debug logging for pass application in passes.py. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
cf16bd9 to
8c21fea
Compare
|
Thanks for all the approvals! Landed. |
…Config (#3177) `expert_parallel_comm_backend` was removed from #3167. #3007 didn't take it into account and broke graph trainer CI. - This PR reads comm backend from the model config to initialize hybridep buffers. - Also restores non_blocking_capacity_factor default value for the concrete model flavors, since some tests call the concrete flavors directly. Tested locally: ``` + NGPU=4 + export LOG_RANK=0 + LOG_RANK=0 + MODULE=graph_trainer.deepseek_v3 + CONFIG=graph_trainer_deepseek_v3_debugmodel_hybridep + COMM_MODE= + TORCHFT_LIGHTHOUSE=http://localhost:29510 + '[' -n '' ']' + PYTORCH_ALLOC_CONF=expandable_segments:True + TORCHFT_LIGHTHOUSE=http://localhost:29510 + torchrun --nproc_per_node=4 --rdzv_backend c10d --rdzv_endpoint=localhost:0 --local-ranks-filter 0 --role rank --tee 3 -m torchtitan.train --module graph_trainer.deepseek_v3 --config graph_trainer_deepseek_v3_debugmodel_hybridep --compile.mode aot_fx_trace --parallelism.data_parallel_shard_degree=2 --parallelism.tensor_parallel_degree=2 --parallelism.expert_parallel_degree=2 --training.steps=3 [rank0]:[titan] 2026-04-30 09:24:36,606 - root - INFO - torchtitan version: 0.2.2 [rank0]:[titan] 2026-04-30 09:24:37,184 - root - INFO - Building device mesh with parallelism: pp=1, dp_replicate=1, dp_shard=2, cp=1, tp=2, ep=2 [rank0]:[titan] 2026-04-30 09:24:37,204 - root - INFO - Successfully created meshes with active dimensions: ['batch', 'loss', 'fsdp', 'tp', 'ep', 'efsdp'] [rank0]:[titan] 2026-04-30 09:24:38,881 - root - INFO - Building graph_trainer/deepseek_v3 debugmodel [rank0]:[titan] 2026-04-30 09:24:38,924 - root - INFO - CUDA capacity: NVIDIA GB200 with 184.00GiB memory [rank0]:[titan] 2026-04-30 09:24:38,942 - root - INFO - Total parameter count: dense 23,173,376, sparse 9,840,640, active 28,098,816 [rank0]:[titan] 2026-04-30 09:24:38,942 - root - INFO - Model graph_trainer/deepseek_v3 debugmodel size: 33,014,016 total parameters [rank0]:[titan] 2026-04-30 09:24:39,022 - root - INFO - Applied Data Parallel (simple_fsdp) (dp mode=fully_shard) to the model [rank0]:[titan] 2026-04-30 09:24:39,817 - root - INFO - Pre-initialized HybridEP buffer (hidden_dim=256, num_tokens=16384, num_local_experts=4) [rank0]:[titan] 2026-04-30 09:24:39,817 - root - INFO - aot_fx_trace compile mode: graph capture will happen at training time [rank0]:[titan] 2026-04-30 09:24:40,725 - root - INFO - Peak FLOPS used for computing MFU: 2.500e+15 [rank0]:[titan] 2026-04-30 09:24:40,725 - root - INFO - CUDA memory usage for model: 0.04GiB(0.02%) [rank0]:[titan] 2026-04-30 09:24:42,931 - root - INFO - Trainer is initialized with local batch size 8, global batch size 16, gradient accumulation steps 1, sequence length 2048, total steps 3 (warmup 2) [rank0]:[titan] 2026-04-30 09:24:42,931 - root - INFO - Training starts at step 1 [rank0]:[titan] 2026-04-30 09:24:47,646 - root - INFO - Removed 62 aten.detach.default node(s) from the graph [rank0]:[titan] 2026-04-30 09:24:47,708 - root - INFO - Removed 669 identity view/reshape node(s) from the graph [rank0]:[titan] 2026-04-30 09:24:47,709 - root - INFO - Removed 66 identity slice node(s) [rank0]:[titan] 2026-04-30 09:24:47,880 - root - INFO - Applied selective activation checkpointing (SAC) graph pass. [rank0]:[titan] 2026-04-30 09:24:47,880 - root - INFO - Forced 5 nodes to MUST_SAVE at layer boundaries [rank0]:[titan] 2026-04-30 09:24:47,880 - root - INFO - Layer non-layer: 2 MUST_SAVE, 62 PREFER_RECOMPUTE [rank0]:[titan] 2026-04-30 09:24:47,880 - root - INFO - Layer 0: 10 MUST_SAVE, 90 PREFER_RECOMPUTE [rank0]:[titan] 2026-04-30 09:24:47,880 - root - INFO - Layer 1: 13 MUST_SAVE, 120 PREFER_RECOMPUTE [rank0]:[titan] 2026-04-30 09:24:47,880 - root - INFO - Layer 2: 13 MUST_SAVE, 120 PREFER_RECOMPUTE [rank0]:[titan] 2026-04-30 09:24:47,880 - root - INFO - Layer 3: 13 MUST_SAVE, 120 PREFER_RECOMPUTE [rank0]:[titan] 2026-04-30 09:24:47,880 - root - INFO - Layer 4: 13 MUST_SAVE, 120 PREFER_RECOMPUTE [rank0]:[titan] 2026-04-30 09:24:47,880 - root - INFO - Layer 5: 13 MUST_SAVE, 120 PREFER_RECOMPUTE [rank0]:[titan] 2026-04-30 09:24:50,157 - root - INFO - Applied cudagraph pass. [rank0]:[titan] 2026-04-30 09:25:00,187 - root - INFO - step: 1 loss: 4.03640 grad_norm: 3.3902 memory: 1.93GiB(1.05%) tps: 386 tflops: 0.21 mfu: 0.01% [rank0]:[titan] 2026-04-30 09:25:00,345 - root - INFO - step: 2 loss: 3.05691 grad_norm: 4.5189 memory: 1.93GiB(1.05%) tps: 52,168 tflops: 28.32 mfu: 1.13% [rank0]:[titan] 2026-04-30 09:25:00,389 - root - INFO - step: 3 loss: 2.46308 grad_norm: 2.7644 memory: 1.93GiB(1.05%) tps: 186,611 tflops: 101.32 mfu: 4.05% [rank0]:[titan] 2026-04-30 09:25:02,389 - root - INFO - Training completed [rank0]:[titan] 2026-04-30 09:25:03,816 - root - INFO - Process group destroyed ``` Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Enables HybridEP to work with graph_trainer's
aot_fx_tracecompilation path, including full composability with SAC (selective activation checkpointing) and CUDA graph capture.Fixes
Wire HybridEP config through graph_trainer's
parallelize_deepseekv3— Passcomm_backendtoapply_moe_ep_tp()and threadnon_blocking_capacity_factorthrough all DeepSeekV3 config factories. Pre-initialize HybridEP buffer inparallelize_deepseekv3before tracing.Guard
_disable_current_modes()with_buffer is None— Instead of unconditionally callingget_bufferinside_disable_current_modes(), only call it when the buffer hasn't been initialized yet. This prevents re-initialization during make_fx tracing.Fix fake dispatch scores shape — Change from
(0,)to(out_tokens,)to prevent shape mismatch during tracing.Replace
@torch.compiler.disable()onsync_combine— The decorator breaks make_fx tracing. Use anis_compiling()guard inside the function body instead.Add
FunctionalTensor/FakeTensorfallback in dispatch/combine backward — During tracing,DispatchHandle.valueisNonebecause the opaque handle doesn't survive fake tensor execution. Detect this and return zero gradients (the traced backward graph will use real handles at runtime). Preserves theRuntimeErrorraise on the eager path.Remove
_grouped_mmcudagraph incompatibility check — Theis_cudagraph_compatiblefunction conservatively blocked CUDA graph capture for graphs containingaten._grouped_mm. This is overly conservative —_grouped_mmis CUDA graph compatible (verified empirically). Removing this allows cudagraph to be applied automatically for MoE models in theaot_fx_tracedefault pass pipeline.Add cudagraph pass logging — Add
"Applied cudagraph pass."log message for parity with SAC logging.Add HybridEP integration test — Add
aot_fx_trace_deepseek_v3_hybridepintegration test entry using thegraph_trainer_deepseek_v3_debugmodel_hybridepconfig with FSDP+TP+EP. DeepEP is installed (pinned to commit1b8f467) in the H100 CI workflow before running the test suite.Add TODO for HybridEP refactoring — HybridEP applies to other sparse models (e.g. Qwen3). Added TODO to refactor the common HybridEP buffer init into a shared utility.
Note: the
aotcompile mode path has a known upstream regression (DispatchHandleasFakeScriptObjectin graph output) and is not supported in this PR.Setup
Requires DeepEP with the
hybrid-epbranch:Test plan
aot_fx_tracewith HybridEP (3 steps, 4×GB200). SAC and cudagraph are applied automatically by the default pass pipeline — no--compile.passesor--compile.joint_passesflags needed:Smoke test output (4×GB200):
Integration test output (4×GB200):