Repository navigation
MLA support for titanRL w/ vllm - #5556
Conversation
|
2 things needs to be fixed in this PR when I tried to run it
|
65154c9 to
baf20e8
Compare
| self.v_head_dim = config.v_head_dim | ||
|
|
||
| layer_id = next(VLLMInnerAttention._layer_counter) | ||
| self.vllm_mla = _VLLMNativeMLAAttention( |
There was a problem hiding this comment.
Why we use vLLM native MLA attention here? Why not torchtitan MLA
There was a problem hiding this comment.
torchtitan mla can't cache the latent it runs wkv_b before calling inner attention so vllm's cache layer will receive the decompressed per-head kv
There was a problem hiding this comment.
There was a problem hiding this comment.
torchtitan mla can't cache the latent it runs wkv_b before calling inner attention
I'm confused other attention like varlen we are using pytorch kernel for attention calculation, but there, the attention kernel is vllm native (I see FlashInfer/TRT in my test running), similar to Flex. What's your consideration on using vllm native MLA or having a MLA in attention-gym?
Does it support bitwise identical mode between trainer (torchtitan MLA https://github.com/pytorch/torchtitan/blob/refs/heads/main/torchtitan/models/deepseek_v3/attention.py#L30) vs vllm native MLA?
There was a problem hiding this comment.
no for bitwise we fallback to uncompressed kv and use materialized K/V through VLLMInnerAttention (the same path as trainer). we can def explore potentially adding mla support in attention gym (maybe as a followup so we can first unblock?)
There was a problem hiding this comment.
I don't think we should use vllm's native MLA, can we not use torchtitan's?
I don't see how it relates to attention-gym yet -- torchtitan has its own MLA. Having torchtitan depending on atten-gym for MLA is a separate work.
There was a problem hiding this comment.
we can't use torchtitan's mla because it doesn't have a latent space decode kernel (which is what we can add to attention gym).
we are already using torchtitan mla for the batch invariant path where we don't compress.
There was a problem hiding this comment.
yeah I think we should have one! just like varlen for GQA
14d0b3d to
9106ca3
Compare
|
|
||
| # vLLM sets is_mla based on specific model types, and we pass in | ||
| # model_type="torchtitan", so is_mla would be False. | ||
| # TODO: Wait until the vLLM PR adding register_model_arch_config_convertor |
There was a problem hiding this comment.
There was a problem hiding this comment.
can we ping reviewers to review?
dd4ac7e to
1e4164a
Compare
33ee528 to
fe536a5
Compare
|
@claude review my latest comments, give suggestions |
|
Claude finished @tianyu-l's task in 2m 1s —— View job Suggestions on @tianyu-l's latest review comments
I couldn't open vLLM's own 1.
|
3743251 to
e56ad19
Compare
| raise ValueError("No full attention layer found in the model spec.") | ||
| kernel_config = attention.inner_attention | ||
| if uses_compressed_mla_cache(kernel_config): | ||
| return None |
There was a problem hiding this comment.
None lets vLLM select a native MLA backend for compressed MLA caches
is this what we defines in titan? what if we add more attn backends in the future?
There was a problem hiding this comment.
no this is for vllm we want to let vllm auto select mla backend
|
|
||
| class TorchTitanModelArchConfigConvertor(ModelArchConfigConvertorBase): | ||
| def is_deepseek_mla(self) -> bool: | ||
| return getattr(self.hf_text_config, "kv_lora_rank", None) is not None |
There was a problem hiding this comment.
what about kimik3 mla?
There was a problem hiding this comment.
yes this works for both this is just overriding the vllm function that decides is_mla
There was a problem hiding this comment.
give it a more general name then?
|
|
||
| # vLLM sets is_mla based on specific model types, and we pass in | ||
| # model_type="torchtitan", so is_mla would be False. | ||
| # TODO: Wait until the vLLM PR adding register_model_arch_config_convertor |
There was a problem hiding this comment.
can we ping reviewers to review?
| return getattr(self.hf_text_config, "kv_lora_rank", None) is not None | ||
|
|
||
| # vLLM sets is_mla based on specific model types, and we pass in | ||
| # model_type="torchtitan", so is_mla would be False. |
There was a problem hiding this comment.
I thought this makes is_mla = True?
| linear applies. | ||
| """ | ||
|
|
||
| quant_method = None |
There was a problem hiding this comment.
yea we want to select unquantized branch
| scale: float | ||
|
|
||
| @property | ||
| def is_full_attention(self) -> bool: |
There was a problem hiding this comment.
shouldn't be always true?
There was a problem hiding this comment.
it is always true but InnerAttention.Config.is_full_attention defaults to false
| attention_metadata: None = None, | ||
| **kwargs, | ||
| ) -> torch.Tensor: | ||
| """Run vLLM MLA attention on local (non-DTensor) tensors. |
There was a problem hiding this comment.
we don't have Dtensor anymore during runtime?
| "converter's FQNs." | ||
| ) | ||
| self.wkv_b = config.wkv_b.build() | ||
| self.inner_attention = config.inner_attention.build(kv_b_proj=self.wkv_b) |
There was a problem hiding this comment.
qq: why do we need to pass in kv_b_proj=self.wkv_b?
There was a problem hiding this comment.
compressed cache needs wkv_b inside the attention kernel cus the cache holds the latent from before wkv_b is applied so the kernel has to apply it itself
tianyu-l
left a comment
There was a problem hiding this comment.
lgtm!
please merge after @acisseJZhong approves
| trainer's. For a bf16 ``Linear`` they are views of ``wkv_b.weight``, so weight | ||
| sync's in-place copy updates them without re-deriving. |
There was a problem hiding this comment.
Interesting ... the name w_uk and w_uv suggest to me that they are for k and v, respectively. But it looks like it's not the case, at least for bf16.
e56ad19 to
f73d5b2
Compare
| ).view(num_tokens, -1, self.v_head_dim) | ||
|
|
||
|
|
||
| class VLLMMLAAttention(MLAAttention): |
There was a problem hiding this comment.
will generator CP work under this design(right now we don't support generator CP)? do we replace VLLMMLAAttention with CP variant?
There was a problem hiding this comment.
no need to replace rn vllm will handle but also after i land this pr i plan to implement a solution in attention-gym/flash attn so that kernel will need to handle cp
acisseJZhong
left a comment
There was a problem hiding this comment.
need to address #5556 (comment)
) ## Summary (human-written) Merge conflicts from the previous PRs cause CI failing. `disable_cuda_graph`->`disable_accelerator_graphs` ## Why CPU Unit Test fails on main: https://github.com/pytorch/torchtitan/actions/runs/40973844709/job/123796998693 #5353 renamed `training.disable_cuda_graphs` to `training.disable_accelerator_graphs`. #4920 and #5556 landed after it and still use the old name. `TestShippedCpRecipes::test_every_cp_recipe_passes_the_gate` builds `deepseek_v4_debugmodel_fsdp4_ep4` and fails: AttributeError: 'TrainingConfig' object has no attribute 'disable_cuda_graphs' `rl_grpo_deepseek_v3_debug_varlen` in `alphabet_sort.py` has the same stale keyword. No CPU test builds it, but it raises `TypeError` when run. ## What changed - Mechanical rename in two places: `tests/integration_tests/models.py` and `torchtitan_recipes/tests/rl/alphabet_sort.py`. ## Testing - `git grep disable_cuda_graphs` returns nothing. - Expect the CPU Unit Test job on this PR to pass `test_every_cp_recipe_passes_the_gate`.
The Model support table in torchtitan/rl/README.md lags behind main and the
image RL stack:
- DeepSeek V3 ("Not supported") and Kimi K3 ("Support coming soon") have run
RL end to end in CI since #5556 and #4680: `rl_grpo_deepseek_v3_debug` and
`rl_grpo_kimi_k3_debug_batch_invariant` in the RL H100 Integration Tests
(3 steps, debug model, trainer FSDP=2, two generators at TP=1, no EP). Their
MLA decode and KDA kernels need SM90+, so both rows say "SM90+", and the
intro says how they were tested.
- Muse Spark and Qwen 3.5/3.6/3.8 ("text only") run image prompts end to end:
`rl_grpo_qwen3_5_0_8b_geometry3k` (Qwen3.5-0.8B, Geometry3K, #5825) and
`rl_muse_spark_816b_a42b_slake_lora_gb300` (Muse Spark 816B-A42B, SLAKE).
Qwen 3.6 and 3.8 build `Qwen35Model` and share Qwen3.5's vision processor
config, so they take the same image path.
- The CI table gets the RL H100 Integration Tests badge, the workflow that
runs the DeepSeek V3 and Kimi K3 tests.
Unchanged: GPT-OSS (supported), DeepSeek V4 (no RL code yet), FLUX (diffusion,
no generator path), Kimi K2.7 (no RL recipe or test).
The Model support table in torchtitan/rl/README.md lags behind main and the
image RL stack:
- DeepSeek V3 ("Not supported") and Kimi K3 ("Support coming soon") have run
RL end to end in CI since #5556 and #4680: `rl_grpo_deepseek_v3_debug` and
`rl_grpo_kimi_k3_debug_batch_invariant` in the RL H100 Integration Tests
(3 steps, debug model, trainer FSDP=2, two generators at TP=1, no EP). Their
MLA decode and KDA kernels need SM90+, so both rows say "SM90+", and the
intro says how they were tested.
- Muse Spark and Qwen 3.5/3.6/3.8 ("text only") run image prompts end to end:
`rl_grpo_qwen3_5_0_8b_geometry3k` (Qwen3.5-0.8B, Geometry3K, #5825) and
`rl_muse_spark_816b_a42b_slake_lora_gb300` (Muse Spark 816B-A42B, SLAKE).
Qwen 3.6 and 3.8 build `Qwen35Model` and share Qwen3.5's vision processor
config, so they take the same image path.
- The CI table gets the RL H100 Integration Tests badge, the workflow that
runs the DeepSeek V3 and Kimi K3 tests.
Unchanged: GPT-OSS (supported), DeepSeek V4 (no RL code yet), FLUX (diffusion,
no generator path), Kimi K2.7 (no RL recipe or test).
The Model support table in torchtitan/rl/README.md lags behind main and the
image RL stack:
- DeepSeek V3 ("Not supported") and Kimi K3 ("Support coming soon") have run
RL end to end in CI since #5556 and #4680: `rl_grpo_deepseek_v3_debug` and
`rl_grpo_kimi_k3_debug_batch_invariant` in the RL H100 Integration Tests
(3 steps, debug model, trainer FSDP=2, two generators at TP=1, no EP). Their
MLA decode and KDA kernels need SM90+, so both rows say "SM90+", and the
intro says how they were tested.
- Muse Spark and Qwen 3.5/3.6/3.8 ("text only") run image prompts end to end:
`rl_grpo_qwen3_5_0_8b_geometry3k` (Qwen3.5-0.8B, Geometry3K, #5825) and
`rl_muse_spark_816b_a42b_slake_lora_gb300` (Muse Spark 816B-A42B, SLAKE).
Qwen 3.6 and 3.8 build `Qwen35Model` and share Qwen3.5's vision processor
config, so they take the same image path.
- The CI table gets the RL H100 Integration Tests badge, the workflow that
runs the DeepSeek V3 and Kimi K3 tests.
Unchanged: GPT-OSS (supported), DeepSeek V4 (no RL code yet), FLUX (diffusion,
no generator path), Kimi K2.7 (no RL recipe or test).
The Model support table in torchtitan/rl/README.md lags behind main and the
image RL stack:
- DeepSeek V3 ("Not supported") and Kimi K3 ("Support coming soon") have run
RL end to end in CI since #5556 and #4680: `rl_grpo_deepseek_v3_debug` and
`rl_grpo_kimi_k3_debug_batch_invariant` in the RL H100 Integration Tests
(3 steps, debug model, trainer FSDP=2, two generators at TP=1, no EP). Their
MLA decode and KDA kernels need SM90+, so both rows say "SM90+", and the
intro says how they were tested.
- Muse Spark and Qwen 3.5/3.6/3.8 ("text only") run image prompts end to end:
`rl_grpo_qwen3_5_0_8b_geometry3k` (Qwen3.5-0.8B, Geometry3K, #5825) and
`rl_muse_spark_816b_a42b_slake_lora_gb300` (Muse Spark 816B-A42B, SLAKE).
Qwen 3.6 and 3.8 build `Qwen35Model` and share Qwen3.5's vision processor
config, so they take the same image path.
- The CI table gets the RL H100 Integration Tests badge, the workflow that
runs the DeepSeek V3 and Kimi K3 tests.
Unchanged: GPT-OSS (supported), DeepSeek V4 (no RL code yet), FLUX (diffusion,
no generator path), Kimi K2.7 (no RL recipe or test).
The Model support table in torchtitan/rl/README.md lags behind main and the
image RL stack:
- DeepSeek V3 ("Not supported") and Kimi K3 ("Support coming soon") have run
RL end to end in CI since #5556 and #4680: `rl_grpo_deepseek_v3_debug` and
`rl_grpo_kimi_k3_debug_batch_invariant` in the RL H100 Integration Tests
(3 steps, debug model, trainer FSDP=2, two generators at TP=1, no EP). Their
MLA decode and KDA kernels need SM90+, so both rows say "SM90+", and the
intro says how they were tested.
- Muse Spark and Qwen 3.5/3.6/3.8 ("text only") run image prompts end to end:
`rl_grpo_qwen3_5_0_8b_geometry3k` (Qwen3.5-0.8B, Geometry3K, #5825) and
`rl_muse_spark_816b_a42b_slake_lora_gb300` (Muse Spark 816B-A42B, SLAKE).
Qwen 3.6 and 3.8 build `Qwen35Model` and share Qwen3.5's vision processor
config, so they take the same image path.
- The CI table gets the RL H100 Integration Tests badge, the workflow that
runs the DeepSeek V3 and Kimi K3 tests.
Unchanged: GPT-OSS (supported), DeepSeek V4 (no RL code yet), FLUX (diffusion,
no generator path), Kimi K2.7 (no RL recipe or test).
The Model support table in torchtitan/rl/README.md lags behind main and the
image RL stack:
- DeepSeek V3 ("Not supported") and Kimi K3 ("Support coming soon") have run
RL end to end in CI since #5556 and #4680: `rl_grpo_deepseek_v3_debug` and
`rl_grpo_kimi_k3_debug_batch_invariant` in the RL H100 Integration Tests
(3 steps, debug model, trainer FSDP=2, two generators at TP=1, no EP). Their
MLA decode and KDA kernels need SM90+, so both rows say "SM90+", and the
intro says how they were tested.
- Muse Spark and Qwen 3.5/3.6/3.8 ("text only") run image prompts end to end:
`rl_grpo_qwen3_5_0_8b_geometry3k` (Qwen3.5-0.8B, Geometry3K, #5825) and
`rl_muse_spark_816b_a42b_slake_lora_gb300` (Muse Spark 816B-A42B, SLAKE).
Qwen 3.6 and 3.8 build `Qwen35Model` and share Qwen3.5's vision processor
config, so they take the same image path.
- The CI table gets the RL H100 Integration Tests badge, the workflow that
runs the DeepSeek V3 and Kimi K3 tests.
Unchanged: GPT-OSS (supported), DeepSeek V4 (no RL code yet), FLUX (diffusion,
no generator path), Kimi K2.7 (no RL recipe or test).
The Model support table in torchtitan/rl/README.md lags behind main and the
image RL stack:
- DeepSeek V3 ("Not supported") and Kimi K3 ("Support coming soon") have run
RL end to end in CI since #5556 and #4680: `rl_grpo_deepseek_v3_debug` and
`rl_grpo_kimi_k3_debug_batch_invariant` in the RL H100 Integration Tests
(3 steps, debug model, trainer FSDP=2, two generators at TP=1, no EP). Their
MLA decode and KDA kernels need SM90+, so both rows say "SM90+", and the
intro says how they were tested.
- Muse Spark and Qwen 3.5/3.6/3.8 ("text only") run image prompts end to end:
`rl_grpo_qwen3_5_0_8b_geometry3k` (Qwen3.5-0.8B, Geometry3K, #5825) and
`rl_muse_spark_816b_a42b_slake_lora_gb300` (Muse Spark 816B-A42B, SLAKE).
Qwen 3.6 and 3.8 build `Qwen35Model` and share Qwen3.5's vision processor
config, so they take the same image path.
- The CI table gets the RL H100 Integration Tests badge, the workflow that
runs the DeepSeek V3 and Kimi K3 tests.
Unchanged: GPT-OSS (supported), DeepSeek V4 (no RL code yet), FLUX (diffusion,
no generator path), Kimi K2.7 (no RL recipe or test).
The Model support table in torchtitan/rl/README.md lags behind main and the
image RL stack:
- DeepSeek V3 ("Not supported") and Kimi K3 ("Support coming soon") have run
RL end to end in CI since #5556 and #4680: `rl_grpo_deepseek_v3_debug` and
`rl_grpo_kimi_k3_debug_batch_invariant` in the RL H100 Integration Tests
(3 steps, debug model, trainer FSDP=2, two generators at TP=1, no EP). Their
MLA decode and KDA kernels need SM90+, so both rows say "SM90+", and the
intro says how they were tested.
- Muse Spark and Qwen 3.5/3.6/3.8 ("text only") run image prompts end to end:
`rl_grpo_qwen3_5_0_8b_geometry3k` (Qwen3.5-0.8B, Geometry3K, #5825) and
`rl_muse_spark_816b_a42b_slake_lora_gb300` (Muse Spark 816B-A42B, SLAKE).
Qwen 3.6 and 3.8 build `Qwen35Model` and share Qwen3.5's vision processor
config, so they take the same image path.
- The CI table gets the RL H100 Integration Tests badge, the workflow that
runs the DeepSeek V3 and Kimi K3 tests.
Unchanged: GPT-OSS (supported), DeepSeek V4 (no RL code yet), FLUX (diffusion,
no generator path), Kimi K2.7 (no RL recipe or test).
The Model support table in torchtitan/rl/README.md lags behind main and the
image RL stack:
- DeepSeek V3 ("Not supported") and Kimi K3 ("Support coming soon") have run
RL end to end in CI since #5556 and #4680: `rl_grpo_deepseek_v3_debug` and
`rl_grpo_kimi_k3_debug_batch_invariant` in the RL H100 Integration Tests
(3 steps, debug model, trainer FSDP=2, two generators at TP=1, no EP). Their
MLA decode and KDA kernels need SM90+, so both rows say "SM90+", and the
intro says how they were tested.
- Muse Spark and Qwen 3.5/3.6/3.8 ("text only") run image prompts end to end:
`rl_grpo_qwen3_5_0_8b_geometry3k` (Qwen3.5-0.8B, Geometry3K, #5825) and
`rl_muse_spark_816b_a42b_slake_lora_gb300` (Muse Spark 816B-A42B, SLAKE).
Qwen 3.6 and 3.8 build `Qwen35Model` and share Qwen3.5's vision processor
config, so they take the same image path.
- The CI table gets the RL H100 Integration Tests badge, the workflow that
runs the DeepSeek V3 and Kimi K3 tests.
Unchanged: GPT-OSS (supported), DeepSeek V4 (no RL code yet), FLUX (diffusion,
no generator path), Kimi K2.7 (no RL recipe or test).
Based on main, outside the image RL stack. The image rows name recipes from #5825 and #6025, so merge it after those. ## Summary (human-written) <!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why this approach, and what you checked yourself. --> ## Why The Model support table in `torchtitan/rl/README.md` lags behind main and the image RL stack: - DeepSeek V3 and Kimi K3 have run RL end to end in CI since #5556 (2026-10-29) and #4680 (2026-10-02), but are listed as "Not supported" and "Support coming soon". Their tests, `rl_grpo_deepseek_v3_debug` and `rl_grpo_kimi_k3_debug_batch_invariant`, run in the RL H100 Integration Tests on every push to main and every 12 hours. - Muse Spark and Qwen 3.5/3.6/3.8 are listed as "text only", but both run image prompts end to end with the image RL stack: `rl_grpo_qwen3_5_0_8b_geometry3k` (Qwen3.5-0.8B on Geometry3K, #5825) and `rl_muse_spark_816b_a42b_slake_lora_gb300` (Muse Spark 816B-A42B on SLAKE, 32 GB300 GPUs, #6025). **Example.** | Model | Before | After | |---|---|---| | Muse Spark | ✅ Supported (text only) | ✅ Supported (text and image) | | Qwen 3.5/3.6/3.8 | ✅ Supported (text only) | ✅ Supported (text and image) | | DeepSeek V3 | Not supported | ✅ Supported (SM90+) | | Kimi K3 | Support coming soon | ✅ Supported (SM90+) | ## What changed - The four rows above. - The intro says how DeepSeek V3 and Kimi K3 were tested, since it differs from the other entries (generator DP and TP at degree 2, EP at degree 4): 3 steps with a debug model on H100, trainer FSDP=2, two generators at TP=1, no EP. Their MLA decode and KDA kernels need SM90+. It also names the two image recipes. - Qwen 3.6 and 3.8 build `Qwen35Model` and share Qwen3.5's vision processor config, so they take the same image path; the image recipe runs Qwen3.5. - The CI table gets the RL H100 Integration Tests badge, the workflow that runs the DeepSeek V3 and Kimi K3 tests. - Unchanged: GPT-OSS (supported; debug RL recipe and bitwise parity test), DeepSeek V4 (no RL code yet), FLUX (diffusion model, no generator path), Kimi K2.7 (no RL recipe or test). ## Testing Docs only. `pre-commit run --files torchtitan/rl/README.md` passes locally without the lychee link check, which needs GitHub access; CI runs it. The new badge points at the existing `integration_test_rl_h100.yaml` workflow.
adds mla support in titanrl's vllm generator. on compressed path VLLMCompressedMLAAttention wraps vllm's native mla layer and on materialized it decompresses k/v and runs the same ops as the trainer
for batch invariance we can't use the vllm native latent-space kernel so we fall back to the old path of decompressing - we use vllminnerattention and we wrap w/ mlaattention class but this actually just uses full attention. uncommented k3 batch invariant test does not test the new mla behaviour
adding deepseek v3 h100 run to test the mla path