Repository navigation
[rl] remove duplicated transpose around VllmAttention in generator - #2709
Merged
Merged
Conversation
tianyu-l
requested changes
Mar 25, 2026
| layer.attention.inner_attention = vllm_attn | ||
|
|
||
| # Swap GQAttention to VLLMGQAttention for zero-copy forward path | ||
| layer.attention.__class__ = VLLMGQAttention |
Contributor
There was a problem hiding this comment.
changing __class__ sounds suspicious -- is it replacing attention with a newly created module?
tianyu-l
reviewed
Mar 26, 2026
wwwjn
force-pushed
the
rl-attention-transpose
branch
from
March 26, 2026 02:35
2876e15 to
769efb0
Compare
tianyu-l
approved these changes
Mar 26, 2026
tianyu-l
left a comment
Contributor
There was a problem hiding this comment.
please address remaining comments
Replace post-build class swapping (replace_with_vllm_attention) with config-time VLLMGQAttention.Config so the model builds with vLLM-compatible attention directly. - VLLMGQAttention gets a proper Config subclass of GQAttention.Config that creates VLLMInnerAttention during __init__ using vLLM's runtime config for tp_degree - vllm_wrapper replaces GQAttention.Config with VLLMGQAttention.Config before model.build(), removing the post-hoc __class__ swap - Remove replace_with_vllm_attention function - Remove duplicated __call__ from VLLMInnerAttention, relying on LocalMapAttention's base __call__ with relaxed Shard dim assertion - LocalMapAttention now accepts any Shard placement (not just Shard(1)) with a guard that all placements use the same shard dim
- Use attn_backend="varlen" instead of "vllm" to correctly describe the attention mechanism (vLLM is KV cache management, not a backend) - Remove hacky __post_init__ override and dataclasses.replace workaround that bypassed parent config validation - Move _layer_counter from VLLMGQAttention to VLLMInnerAttention where it's actually needed for vLLM prefix generation - Remove layer_name parameter, use counter-based layer_id directly - Add TODO noting counter breaks with pipeline parallelism
wwwjn
force-pushed
the
rl-attention-transpose
branch
from
March 30, 2026 15:29
a518908 to
d5c6e99
Compare
acisseJZhong
pushed a commit
that referenced
this pull request
Mar 31, 2026
…2709) As titled - Previous Standard GQAttention + VLLMInnerAttention flow: (bs,seq,heads,dim) → transpose → (bs,heads,seq,dim) → VLLMInnerAttention transpose back → clone → (bs*seq,heads,dim) → vllm_attn → reshape → transpose → contiguous (4 layout ops) <img width="1480" height="363" alt="Screenshot 2026-03-30 at 1 53 29 PM" src="https://github.com/user-attachments/assets/c5566510-48e2-4f68-bb3f-456ba17b001b" /> - New VLLMGQAttention subclass: (bs,seq,heads,dim) → reshape → (bs*seq,heads,dim) (1 zero-copy op)→ vllm_attn → view → (bs,seq,hidden) <img width="1480" height="363" alt="Screenshot 2026-03-30 at 1 14 26 PM" src="https://github.com/user-attachments/assets/97ad664b-e965-4f85-b4ae-7da6d02572c0" /> From Claude's summary of trace before vs. after: - aten::transpose: 28,090 → 15,486 (-12,604 calls), the redundant transpose round-trip is gone - aten::view: 54,508 → 51,707 (-2,801 calls), fewer intermediate views
tianyu-l
added a commit
that referenced
this pull request
Mar 31, 2026
for several things: - Save a pair of transpose for varlen attention, by moving the transpose for sdpa / flex inside their own module. I had to change `_ContextParallel(seq_dim=2, ...)` to `seq_dim=1` -> I also had to change flux model impl to adapt. - The above change follows #2709 which is only for the generator. With this PR I'm able to remove `VLLMGQAttention` module added in that PR. - Make `inner_attention` a python config, instead of string `attn_backend` which is now used in qwen3 `model_registry` as a convenient way to switch config. - Thanks to that, we can support FlexAttention with configurable options, including `block_size` and `kernel_options` to enable Flash attention backend #2171. Added a config `qwen3_debugmodel_flex_flash` to the registry. - Move `annotate_flex_attention_for_regional_inductor` from general attention file to `graph_trainer` where it's used. - remove outdated artificial restrictions on CP / CP + TP - some naming improvement NOTE: - GraphTrainer tests fail on main as well - Model test on Llama4+PP+compile fails on main as well
TXacs
pushed a commit
to McmillanTAC/torchtitan
that referenced
this pull request
Apr 13, 2026
…ytorch#2709) As titled - Previous Standard GQAttention + VLLMInnerAttention flow: (bs,seq,heads,dim) → transpose → (bs,heads,seq,dim) → VLLMInnerAttention transpose back → clone → (bs*seq,heads,dim) → vllm_attn → reshape → transpose → contiguous (4 layout ops) <img width="1480" height="363" alt="Screenshot 2026-03-30 at 1 53 29 PM" src="https://github.com/user-attachments/assets/c5566510-48e2-4f68-bb3f-456ba17b001b" /> - New VLLMGQAttention subclass: (bs,seq,heads,dim) → reshape → (bs*seq,heads,dim) (1 zero-copy op)→ vllm_attn → view → (bs,seq,hidden) <img width="1480" height="363" alt="Screenshot 2026-03-30 at 1 14 26 PM" src="https://github.com/user-attachments/assets/97ad664b-e965-4f85-b4ae-7da6d02572c0" /> From Claude's summary of trace before vs. after: - aten::transpose: 28,090 → 15,486 (-12,604 calls), the redundant transpose round-trip is gone - aten::view: 54,508 → 51,707 (-2,801 calls), fewer intermediate views
TXacs
pushed a commit
to McmillanTAC/torchtitan
that referenced
this pull request
Apr 13, 2026
for several things: - Save a pair of transpose for varlen attention, by moving the transpose for sdpa / flex inside their own module. I had to change `_ContextParallel(seq_dim=2, ...)` to `seq_dim=1` -> I also had to change flux model impl to adapt. - The above change follows pytorch#2709 which is only for the generator. With this PR I'm able to remove `VLLMGQAttention` module added in that PR. - Make `inner_attention` a python config, instead of string `attn_backend` which is now used in qwen3 `model_registry` as a convenient way to switch config. - Thanks to that, we can support FlexAttention with configurable options, including `block_size` and `kernel_options` to enable Flash attention backend pytorch#2171. Added a config `qwen3_debugmodel_flex_flash` to the registry. - Move `annotate_flex_attention_for_regional_inductor` from general attention file to `graph_trainer` where it's used. - remove outdated artificial restrictions on CP / CP + TP - some naming improvement NOTE: - GraphTrainer tests fail on main as well - Model test on Llama4+PP+compile fails on main as well
ACharacterInASimulation
pushed a commit
to ACharacterInASimulation/torchtitan
that referenced
this pull request
Apr 21, 2026
…ytorch#2709) As titled - Previous Standard GQAttention + VLLMInnerAttention flow: (bs,seq,heads,dim) → transpose → (bs,heads,seq,dim) → VLLMInnerAttention transpose back → clone → (bs*seq,heads,dim) → vllm_attn → reshape → transpose → contiguous (4 layout ops) <img width="1480" height="363" alt="Screenshot 2026-03-30 at 1 53 29 PM" src="https://github.com/user-attachments/assets/c5566510-48e2-4f68-bb3f-456ba17b001b" /> - New VLLMGQAttention subclass: (bs,seq,heads,dim) → reshape → (bs*seq,heads,dim) (1 zero-copy op)→ vllm_attn → view → (bs,seq,hidden) <img width="1480" height="363" alt="Screenshot 2026-03-30 at 1 14 26 PM" src="https://github.com/user-attachments/assets/97ad664b-e965-4f85-b4ae-7da6d02572c0" /> From Claude's summary of trace before vs. after: - aten::transpose: 28,090 → 15,486 (-12,604 calls), the redundant transpose round-trip is gone - aten::view: 54,508 → 51,707 (-2,801 calls), fewer intermediate views
ACharacterInASimulation
pushed a commit
to ACharacterInASimulation/torchtitan
that referenced
this pull request
Apr 21, 2026
for several things: - Save a pair of transpose for varlen attention, by moving the transpose for sdpa / flex inside their own module. I had to change `_ContextParallel(seq_dim=2, ...)` to `seq_dim=1` -> I also had to change flux model impl to adapt. - The above change follows pytorch#2709 which is only for the generator. With this PR I'm able to remove `VLLMGQAttention` module added in that PR. - Make `inner_attention` a python config, instead of string `attn_backend` which is now used in qwen3 `model_registry` as a convenient way to switch config. - Thanks to that, we can support FlexAttention with configurable options, including `block_size` and `kernel_options` to enable Flash attention backend pytorch#2171. Added a config `qwen3_debugmodel_flex_flash` to the registry. - Move `annotate_flex_attention_for_regional_inductor` from general attention file to `graph_trainer` where it's used. - remove outdated artificial restrictions on CP / CP + TP - some naming improvement NOTE: - GraphTrainer tests fail on main as well - Model test on Llama4+PP+compile fails on main as well
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As titled
From Claude's summary of trace before vs. after: