Skip to content

use attn-gym mla decode kernel - #5712

Merged
liangel-02 merged 1 commit into
mainfrom
vllm-mla-latent-decode
Nov 6, 2026
Merged

liangel-02 merged 1 commit into
mainfrom
vllm-mla-latent-decode

Conversation

@liangel-02

@liangel-02 liangel-02 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

use the attention gym mla kernels inst of vllm native so that we can own attention kernels ourselves
call fa3's mla kernel for hopper and fa4's mla kernel for blackwell
working on meta-pytorch/attention-gym#690 to autotun kernels ourselves for better perf

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 30, 2026
@liangel-02
liangel-02 force-pushed the vllm-mla-latent-decode branch 6 times, most recently from a1e9a7a to 92922a7 Compare November 4, 2026 21:31
@liangel-02

Copy link
Copy Markdown
Contributor Author

@claude review this pr ignore the problems with attention gym or fa4 version pins

@claude

claude Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @liangel-02's task in 4m 13s —— View job


Request changes: see the review and its inline comments. I ignored the attn-gym/FA4 version pins as you asked.

@claude claude Bot 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.

Verdict: Request changes -- the kimi_k3 debugmodel architecture change alters trainer numerics without regenerating kimi_k3_b200.txt, and the PR gives no perf or numerics evidence for replacing vLLM's native MLA kernels. (attn-gym/FA4 version pins ignored as requested.)

What this PR does. For the non-batch-invariant RL generator with a compressed MLA cache, each VLLMMLAInnerAttention now passes its own vLLM backends instead of letting vLLM pick one. Decode runs attn-gym's paged_mla_decode (FA3 on SM90, FA4 on SM100/103) on [kv_c_normed | k_pe]. Prefill runs torch's varlen_attn on expanded K/V. vllm_attention_backend now raises unless kv_lora_rank=512, rope=64, SM90/SM100/SM103, and a supported dtype.

Example.

deepseek_v3 debugmodel, RL generator, batch_invariant=False
Before: vLLM auto-selects FlashMLA / CUTLASS MLA / Triton MLA for the GPU;
        A100 or kv_lora_rank=64 still work.
After:  decode   -> attn_gym.paged_mla_decode (requests with <=512 new tokens)
        prefill  -> torch varlen_attn over expanded K/V
        A100, kv_lora_rank != 512, or float16 on SM100 -> ValueError at engine build
        kimi_k3 debugmodel: kv_lora_rank 64 -> 512 (trainer too)

Must fix

  1. PR description -- it doesn't say why vLLM's native MLA is being replaced. There are no throughput numbers against vLLM's FlashMLA/CUTLASS MLA (the description says autotuning for "better perf" is still in progress, so is this currently slower?), no generator-vs-trainer logprob/KL comparison, and no testing section. It also omits the user-facing changes in the example above: hardware, shape, and dtype combinations that used to work now raise, and the trainer debug flavor changes. Please follow the pr-description skill and include a before/after table.
  2. torchtitan/models/kimi_k3/flavors.py:707 -- trainer debugmodel architecture change; golden kimi_k3_b200.txt not regenerated (inline).

Should consider

  • torchtitan/rl/generator/vllm/registry.py:106-128 -- duplicates attn-gym's support matrix and threads model_dtype through three files. Move the checks into TorchTitanMLAImpl.__init__ or leave them to the kernel (inline).
  • torchtitan/rl/generator/vllm/attention/mla.py:84 -- reorder_batch_threshold = 512 is unexplained and routes short prefills through ~3.4x-FLOP latent attention (inline).
  • tests/rl/unit_tests/gpu/test_vllm_mla_backends.py:100 -- the prefill test mostly re-tests torch varlen_attn (inline).

Questions

  • mla.py:119 and mla.py:179 -- both new backends return get_name() == "CUSTOM", and AttentionBackendEnum.CUSTOM is already registered to TorchTitanVarlenInnerAttentionBackend. Does any vLLM path map a backend name back to a class (cudagraph support checks, KV-cache spec, logging) and pick up the varlen backend for MLA layers?
  • mla.py run_prefill_new_tokens/run_prefill_context_chunk assert out is None. Does vLLM's MLA prefill never pass a preallocated out in the paths you enable (chunked context, CUDA graphs)?
Details
  • Coverage: build_b200_rl_test_list includes the H100 list, so rl_grpo_deepseek_v3_debug exercises both the FA3 and FA4 decode paths end to end. The new decode unit test adds an output-correctness check that the e2e run doesn't have.
  • kimi_k3: in-repo, only rl_grpo_kimi_k3_debug_varlen (not in CI) and the CPU registry test use the non-BI compressed MLA path. The CI jobs rl_grpo_kimi_k3_debug_batch_invariant and TestBitwiseParityKimiK3DebugVarlen use materialized K/V. The flavor change therefore costs trainer golden churn for no CI-covered generator path.
  • _build_decode calls .item() on query_start_loc_cpu, a host tensor, so there is no D2H sync.

Not verified: vLLM API details (MLAPrefillBackend, ContextChunk field names, _build_decode signature, get_name lookups). vLLM isn't installed in this environment, and the GPU tests weren't run.

A maintainer still needs to review.

Comment thread torchtitan/models/kimi_k3/flavors.py Resolved
@liangel-02
liangel-02 force-pushed the vllm-mla-latent-decode branch from 92922a7 to 216c104 Compare November 4, 2026 21:59
@liangel-02 liangel-02 added the ciflow/b200 Trigger B200 CI label Nov 4, 2026
@liangel-02
liangel-02 marked this pull request as ready for review November 4, 2026 21:59
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Nov 4, 2026
@github-actions
github-actions Bot requested a review from pzhan9 November 4, 2026 21:59
@liangel-02
liangel-02 force-pushed the vllm-mla-latent-decode branch from 216c104 to e275ca6 Compare November 4, 2026 22:23
@liangel-02

Copy link
Copy Markdown
Contributor Author

@claude review again, ignore problems about version pins, also ignore why we are switching to attention-gym perf results are here meta-pytorch/attention-gym#690

@claude

claude Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @liangel-02's task in 2m 9s —— View job


Approve (please address the items before merging): see the review.

@claude claude Bot 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.

Verdict: Approve -- please address the items below before merging. Every code finding from the last review is fixed at HEAD. What's left is the PR description and a TODO link. (As you asked, I ignored the version pins and the reasons for switching kernels; perf is tracked in meta-pytorch/attention-gym#690.)

What this PR does. In the non-batch-invariant RL generator, each compressed-cache MLA layer now passes its own vLLM backends. Decode runs attn-gym's paged_mla_decode on [kv_c_normed | k_pe] for requests with up to 512 new tokens. Prefill runs torch's varlen_attn on expanded K/V. The kimi_k3 debugmodel moves to kv_lora_rank=512, and its B200 golden is regenerated.

Example.

deepseek_v3 debugmodel, RL generator, batch_invariant=False
Before: vLLM auto-selects FlashMLA / CUTLASS MLA / Triton MLA for the GPU
After:  decode  -> attn_gym.paged_mla_decode (FA3 on SM90, FA4 on SM100)
        prefill -> torch varlen_attn over expanded K/V
        GPUs or shapes attn-gym doesn't support -> the kernel raises (no torchtitan-side table)
kimi_k3 debugmodel (trainer too): kv_lora_rank 64 -> 512; step-10 loss 6.417 -> 5.946

Resolved since the last review

  • kimi_k3 golden: kimi_k3_b200.txt is regenerated, and it's the only kimi_k3 golden (no fake-PG file exists).
  • registry support matrix: removed. vllm_attention_backend, generate.py, engine.py, and uses_compressed_mla_cache are back to unchanged.
  • reorder_batch_threshold = 512: now has a comment saying it matches vLLM's FlashAttnMLA, plus a TODO to tune it.
  • Prefill unit test: dropped. The decode test (cache slicing, block table, causal offset) stays.

Must fix

  1. PR description: please add a testing section and explain the expected numerics change. The kimi_k3 debug trainer flavor changes architecture, and the golden loss and grad_norm move a lot (grad_norm at step 10 goes 7.1 -> 12.3). Also state the user-facing change: compressed-MLA generation used to run on any GPU and with any kv_lora_rank that vLLM supports, and now needs what paged_mla_decode supports (SM90/SM100, kv_lora_rank=512, rope 64). Users on other GPUs or shapes need batch-invariant mode.
  2. torchtitan/rl/generator/vllm/attention/mla.py:95 -- the TODO for the protected _build_decode override has no upstream issue link (inline).

Should consider

  • tests/rl/unit_tests/cpu/test_vllm_registry.py:234 -- test_compressed_mla_configures_vllm_native_mla is now misnamed, since this path no longer runs vLLM's native MLA kernels. Rename it in this PR.

Questions (still open from the last review)

  • Both new backends return get_name() == "CUSTOM", and AttentionBackendEnum.CUSTOM is registered to TorchTitanVarlenInnerAttentionBackend. Does any vLLM path look up a backend class by name and get the varlen backend for MLA layers? The pending rl_grpo_deepseek_v3_debug H100/B200 runs should show this.
  • run_prefill_new_tokens and run_prefill_context_chunk assert out is None. Does vLLM ever pass a preallocated out in chunked-context or CUDA-graph prefill?

Not verified: vLLM API details (attn_backend/prefill_backend_cls kwargs, the _build_decode signature, and whether varlen_attn handles QK dim 192 vs V dim 128 on every FA build). vLLM isn't installed here. The GPU tests weren't run and CI is still pending.

A maintainer still needs to review.

Comment on lines +95 to +97
# TODO: _build_decode is a protected vLLM hook; switch once vLLM's MLA
# decode metadata carries query_start_loc/max_query_len or exposes a public
# hook for custom decode kernels.

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 TODO marks an override of a protected vLLM hook, but there's no upstream issue link. CLAUDE.md principle 3 asks for one so the workaround can be found and removed when vLLM changes _build_decode. Please file a vLLM issue (or link an existing one) that asks for query_start_loc/max_query_len on MLACommonDecodeMetadata or a public hook, and add the link here.

@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.

please address remaining comments

@liangel-02
liangel-02 force-pushed the vllm-mla-latent-decode branch 2 times, most recently from ec004c5 to 0d88d55 Compare November 5, 2026 19:38
@liangel-02
liangel-02 force-pushed the vllm-mla-latent-decode branch from 0d88d55 to 1b482a3 Compare November 5, 2026 21:18

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 this change?

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 changed the debug model's kv_lora_rank from 64 to 512 cus the fa4 mla kernel doesnt support 64

@liangel-02
liangel-02 force-pushed the vllm-mla-latent-decode branch from 1b482a3 to 5f6478e Compare November 6, 2026 16:26
@liangel-02
liangel-02 merged commit c50b0ae into main Nov 6, 2026
tianyu-l added a commit that referenced this pull request Nov 26, 2026
…er override; agent self-review; rl/transport (#6407)

## 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

Since #5667, `@claude review` has reviewed 459 PRs. Of the 380 PRs it
approved,
30 then got a formal "request changes" from a maintainer, and about 20
more got
substantive inline asks. In nearly all of them the bot either saw the
problem
and approved anyway, or never asked the questions maintainers ask most
("does
the repo already do this?", "who should own this?"). The opposite
failure, the
bot blocking something a maintainer was fine with, is rare: in the PRs
we
sampled, 2 of its 81 must-fix items were wrong and about a third were
minor
(the empty human-written summary was the biggest source).

**Example** (#6112, controller sizes the rollout worker pool):

```
before: bot approved 10 times; tianyu-l then blocked: "the controller reads
        rollouter.rollouts_per_worker to compute a count it hands back to the
        Rollouter -- violates encapsulation"
after:  same commit, new skill -> Request changes, must-fix #1:
        "controller.py:589 -- wrong owner for the worker count ..."
```

There was also no way for a code owner to overrule the bot except
dismissing
its review in the GitHub UI, and a later `@claude review again` would
block
again.

## What changed

**Review skill** (`.claude/skills/pr-review/`, `review-checklist.md`):
- Verdict rules: Approve only when every remaining item is an edit the
bot
could write itself. Anything the author still owes (a design change, an
unexplained golden change, evidence the PR rests on) is Request changes;
anything only a maintainer can decide is Needs discussion. A hedge like
"a
  maintainer should decide" can't come with Approve.
- Always must-fix: a violated written rule, a silent wrong result, a
second
  definition of an existing concept, a gate finding.
- Design gate: new questions for the existing counterpart, in-repo
ownership,
and the design behind a bug; "ban only what doesn't work on main"; read
the
numbers behind a claim. The overlapping-PR search is mandatory and
reported.
- Re-review covers every commit since the last full review, including
code
taken from the bot's own suggestions. A scoped question gets a
`COMMENT`, not
  a whole-PR verdict.
- The bot fact-checks its own proposed fixes, and cites a source for
claims
  about external tools or marks them unverified (never must-fix).
- An empty "Summary (human-written)" is a one-line "Before merge" note
that
  never affects the verdict.
- Checklist: config ownership direction, general shared wrappers, dead
code the
PR creates, model variants as flavors, a mechanical pass over every new
or
  changed function.

**Code owner override** (`SKILL.md`, `claude-code.yml`,
`CONTRIBUTING.md`): a
code owner comments `@claude override` (optionally `@claude override
2,3:
<reason>`); the bot approves if nothing else is open and doesn't
re-raise the
overridden items. A code owner's GitHub approval or "LGTM" is not an
override,
so a teammate can approve without the bot dropping its findings.
Dismissing the
bot's review still unblocks the PR, but isn't an override: the bot can't
tell
who dismissed it.

**Agent self-review** (`CLAUDE.md`, `pr-description`): an agent
preparing a PR
runs `pr-review` in branch mode first and records unaddressed items in
an
optional "Self-review" section. PRs written without an agent are
unaffected; a
missing section is never a finding.

Where each new rule comes from (maintainer asks the bot missed):

| Change | PRs |
| --- | --- |
| No Approve with open design/evidence items or a "maintainer should
decide" hedge | #6007, #5837, #5997, #5712, #5511, #5996 |
| Author waiver can't clear a must-fix | #6201, #6202, #6203 |
| Existing counterpart; one source of truth | #5228, #6169, #5881,
#5823, #5824, #6059, #5812 |
| Responsibility owner; config ownership direction | #6112, #6332,
#5802, #5803, #6325 |
| Fix the design behind the bug; a TODO doesn't justify a workaround |
#5572, #5689, #5657 |
| Fact-check the bot's own suggested fixes | #5740, #5802, #5511, #4819,
#5543 |
| Re-review covers all new commits; scoped asks don't approve | #5824,
#5842 |
| Mandatory overlap search | #5885, #6248 |
| Ban only what doesn't work on main | #5543 |
| Summary placeholder no longer a must-fix | #6119, #6174, #6112, #5868
|

**Rules**: `design.md` gets the one-general-wrapper rule (moved from
`models.md`, whose glob skipped `torchtitan/rl`), thin adapters, and the
consumer owning its values; `config.md` gets ownership direction and "a
Config
doesn't read runtime state"; `direction.md` calls all-to-all the MoE
reference
implementation, so a new vendor-specific dispatch path (e.g. #6242)
needs a
reason the existing backends can't serve.

**Area reviewers**: `.ci/` -> huydhn, wwwjn; `torchtitan/rl/transport/`
-> d4l3k.

**Mechanical, skim**: `torchtitan/rl/transport/` holds data movement
between RL
actors.
- `rl/model_state_dict_transport.py` ->
`rl/transport/model_state_dict.py`
- `rl/MODEL_STATE_DICT_TRANSPORT.md` ->
`rl/transport/MODEL_STATE_DICT_TRANSPORT.md`
- `rl/trainer/rdma_microbatch.py` -> `rl/transport/rdma_microbatch.py`
- tests:
`tests/rl/unit_tests/cpu/test_{model_state_dict_transport,rdma_microbatch}.py`
->
`tests/rl/unit_tests/cpu/transport/test_{model_state_dict,rdma_microbatch}.py`
- imports, READMEs and `scripts/install_rl_env.sh` updated; no code
changes.

## User-facing changes

| Before | After |
| --- | --- |
| Overrule the bot: dismiss its review in the UI, and it blocks again on
the next run | `@claude override [items]: <reason>`; the bot approves
and doesn't re-raise them |
| Empty human-written summary: bot must-fix | One "Before merge" line,
no effect on the verdict |
| `from torchtitan.rl.model_state_dict_transport import ...` | `from
torchtitan.rl.transport.model_state_dict import ...` |
| `from torchtitan.rl.trainer.rdma_microbatch import ...` | `from
torchtitan.rl.transport.rdma_microbatch import ...` |

## Testing

Backtest: the new skill run locally (nothing posted) on each PR at the
commit
and thread state the bot originally saw.

| PR | Bot then | New skill | What the maintainer asked |
| --- | --- | --- | --- |
| #6112 | Approve | Request changes | worker-count ownership (caught) |
| #5837 | Approve | Request changes | apply to `dp_shard` too (caught) |
| #5572 | Approve | Request changes | delete the injection design
(caught) |
| #6201 | Approve after author waived pins | Request changes, waiver
ignored | pins broke GPU tests after merge (caught) |
| #6007 | Approve | Request changes | fold K3.1 into K3 (caught) |
| #5543 | Request changes: "ban it" | Request changes: keep main's path
| don't break gpt-oss + DeepEP (fixed) |
| #6144, #5905 (controls) | Approve | Approve | -- |
| #6137 (control) | Approve | Needs discussion | -- (merge gate on an
upstream API) |

Code owner override, simulated on #6201: override by a code owner lifts
the
named item; `@claude override` from the author changes nothing; a code
owner's
"LGTM" approval followed by "review again" keeps Request changes.

Transport move: 83 RL CPU unit tests pass locally
(`transport/test_model_state_dict.py`, `test_trainer.py`,
`test_engine_loop.py`). `transport/test_rdma_microbatch.py`,
`test_generator.py` and
`test_batcher_actor.py` fail to collect in my env on `origin/main` too
(stale
attention-gym / Monarch), so CI is the check for those.

## Known issues / follow-ups
- Open PRs that edit the moved files rebase cleanly (git follows the
renames),
but new imports of the old module paths will break: #6309 (adds a delta
transport that should live in `rl/transport/`), #6237, #6176, #6177,
#5862,
  and drafts #6127, #6393, #6163, #5764.
- The Actions bot can't read dependency source (e.g. SGLang); follow-up
for the
  workflow.

## Self-review
pr-review (branch mode) at ad905a5: Needs discussion. Fixed: branch
mode diffs
against `origin/main` and skips description findings before a
description
exists; the "Config doesn't read runtime state" rule no longer
contradicts
hardware validation; dismissal dropped as an override form (the bot
can't tell
who dismissed); `test_rdma_microbatch.py` added to the transport area.
Not
addressed:
- One concern per PR -- the five changes ship together at the
maintainer's
  request.
- Open PRs touching the moved files -- listed above; the maintainer will
  coordinate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/b200 Trigger B200 CI ciflow/docker ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl 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.

2 participants