Repository navigation
Fused MLA override - #4134
Fused MLA override#4134
Conversation
|
|
||
| Activate with:: | ||
|
|
||
| --override.imports torchtitan.overrides.fused_mla.fused_mla |
There was a problem hiding this comment.
could you add this to the existing deepseek CI
https://github.com/pytorch/torchtitan/blob/main/tests/integration_tests/models.py#L100
or if you want to guard it on cudagraph, need to create a new one without EP
There was a problem hiding this comment.
added test with override. I am not too worry about the cudagraph.
4e72be0 to
e9bf3e3
Compare
| "--override.imports torchtitan.overrides.fused_mla.fused_mla," | ||
| "torchtitan.overrides.fused_swiglu.fused_swiglu", | ||
| "--parallelism.data_parallel_shard_degree 4", | ||
| "--parallelism.expert_parallel_degree 2", |
There was a problem hiding this comment.
default EP backend won't work with cudagraph which is by default turned on
There was a problem hiding this comment.
changed to MinimalAsyncEP so it's cudagraphable.
There was a problem hiding this comment.
ah... A100 Ci machine doesn't support MinimalAsyncEP, so I am reverting back and disable cudagraph.
sanketpurandare
left a comment
There was a problem hiding this comment.
- Add cudagraphable integration test with minimal async ep instead of default ep backend
- tuned configs are great but you can pull all the kernel configs in a dataclass with defaults set to the tuned ones that would be great, would help others using MLA. Also ask the agent to insert a one line comment explaining the config.
The stock DeepSeek-V3 attention assembles q and k with eager cats (and their split-backward cats), which run as non-vectorized CatArrayBatchedCopy kernels. The opt-in fused_mla override (pytorch#4134) replaces that glue with Triton kernels and is bitwise equal to the stock module. Add deepseek_v3_16b_perf and deepseek_v3_671b_perf recipes that request it, as the RL _perf recipes do for fused_swiglu, so the base recipes keep the stock path (overrides stay opt-in, OVERRIDE.md). Document the new recipes in the DeepSeek-V3 README and the override's docstring, and test that the perf recipes fuse every attention while the base recipes do not.
Fused DeepSeek-V3 MLA
Summary
Adds an opt-in fused MLA implementation for TorchTitan's DeepSeek-V3 attention.
The override:
torch.librarycustom operators so they remain visibleto GraphTrainer and
make_fx.The core fusion strategy is inspired by Megatron Core's fused MLA design. This
is an independent TorchTitan implementation using BSHD layouts,
ComplexRoPE,explicit position IDs, and GraphTrainer-compatible custom operators; no
Megatron Core or Transformer Engine kernel code is copied.
Performance
Measured on one NVIDIA GB300 with BF16 tensors,
B=16,L=4096,H=128.MLA assembly microbenchmark
The activation-checkpointing workload is two forwards plus one backward
(
2F + 1B).2F + 1BThe latest head-tiling tuning also makes the fused boundary 3.82x faster
than the initial fused implementation.
DeepSeek-V3 671B GraphTrainer
Configuration:
Both graphs retain the same 361 FSDP overlap dependencies.
In the profiled window, the targeted 4-D MLA
CatArrayBatchedCopykernelaccounts for 309 launches and 2.601 seconds in the stock run. The fused run
removes all of those launches; its three MLA kernels consume approximately
273 ms in total.
Overall CUDA kernel time falls from 29.954 seconds to 26.906 seconds.
Validation
Result: 10 passed.
Coverage includes:
make_fxThe full trainer's step-1 loss and gradient norm match the stock implementation.
Formatting, lint, spelling, documentation, type, and Python compilation checks
also pass.
Scope and limitations
ComplexRoPE.CosSinRoPE,MRoPE, and non-MLA attention modules are not supported.It measures full local graph execution and scheduling, but not real multi-node
networking or communication contention.