Skip to content

[rl] Restore the get_cuda_flash_attention_impl import in the vLLM attention backend - #5908

Merged
felipemello1 merged 1 commit into
pytorch:mainfrom
felipemello1:fix-get-cuda-fa-impl-import
Nov 6, 2026
Merged

felipemello1 merged 1 commit into
pytorch:mainfrom
felipemello1:fix-get-cuda-fa-impl-import

Conversation

@felipemello1

Copy link
Copy Markdown
Contributor

Summary (human-written)

Agent details

Written with Claude Code.

TLDR: On main, every RL test that starts a vLLM generator with TorchTitan's varlen attention fails with NameError. c50b0aeae (use attn-gym mla decode kernel) removed get_cuda_flash_attention_impl from an import, but _FA4PageSize.get_supported_kernel_block_sizes still calls it. This PR restores the import.

torchtitan/rl/generator/vllm/attention/attention.py:65, in get_supported_kernel_block_sizes
    get_cuda_flash_attention_impl() == "FA4"
NameError: name 'get_cuda_flash_attention_impl' is not defined. Did you mean: 'activate_cuda_flash_attention_impl'?

Problem

  1. bcab6e87d (128-token KV pages when FA4 runs attention) added the call in _FA4PageSize.get_supported_kernel_block_sizes.
  2. c50b0aeae moved the file's only other call into activate_cuda_flash_attention_impl. On its branch the import looked unused, so it was removed.
  3. That branch did not have the call from step 1, so its CI could not see the break. Git merged both changes without a conflict.
  4. Cost: since c50b0aeae, four RL workflows fail on every main commit because of the missing import:
    • RL GPU Unit Tests, RL Integration Tests (A10G), RL H100 Integration Tests: this NameError.
    • RL CPU Unit Tests: the 11 tests in test_vllm_attention.py fail with AttributeError: they patch a name the module no longer has.

Solution: restore the import. Nothing else changes.

NOTE: RL Integration Tests (A10G) stays red for a second reason. The 2026-11-06 PyTorch nightly changed the losses that its loss check expects. The PR stacked on this one updates the saved losses (tests/assets/losses/rl_grpo_cuda.txt).

Test plan

  • pytest tests/rl/unit_tests/cpu/test_vllm_attention.py: 11 failed on main (AttributeError: no get_cuda_flash_attention_impl to patch). 11 passed with this PR.
  • pytest tests/rl/unit_tests/cpu --ignore=tests/rl/unit_tests/cpu/test_vllm_wrapper.py: 546 passed, 8 skipped. The ignored file needs attn_gym.mla, which my attention-gym does not have.
  • One GB300, no mocks: TorchTitanVarlenInnerAttentionBackend.get_supported_kernel_block_sizes() returns [128] (FA4).
  • CI on this PR is the first RL GPU run on current main since c50b0aeae. Expected: RL CPU Unit, RL GPU Unit and RL H100 Integration pass. RL Integration Tests (A10G) stays red until the stacked PR lands.

…ention backend

The attn-gym MLA decode change removed get_cuda_flash_attention_impl from the
torchtitan.tools.utils import, but _FA4PageSize.get_supported_kernel_block_sizes
still calls it. Every vLLM generator then fails at engine init with
NameError: name 'get_cuda_flash_attention_impl' is not defined.
@pytorch-bot pytorch-bot Bot added the ciflow/rl label Nov 6, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 6, 2026
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude review

@claude

claude Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 52s —— View job


Approve: the PR restores an import that attention.py:69 still calls; the only remaining item is to fill in the human-written summary. 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 item below before merging -- the PR restores an import that _FA4PageSize.get_supported_kernel_block_sizes still needs. Without it, every varlen vLLM generator fails with NameError.

What this PR does. It adds get_cuda_flash_attention_impl back to the torchtitan.tools.utils import in torchtitan/rl/generator/vllm/attention/attention.py. The function is defined at torchtitan/tools/utils.py:40. Its only use in this module is attention.py:69. The CPU tests in tests/rl/unit_tests/cpu/test_vllm_attention.py (lines 39, 60, 80) patch it as vllm_attention.get_cuda_flash_attention_impl, so they need it as a module-level name.

Must fix

  1. PR description -- the "Summary (human-written)" section is empty. The author fills this in before merge (CONTRIBUTING.md, "AI-assisted contributions").
Details
  • Gate: the problem exists on main. The name is called at attention.py:69 but not imported, so vLLM raises a NameError when it asks the backend for KV page sizes. The fix is in the right layer and is as small as it can be. mla.py:49 imports only activate_cuda_flash_attention_impl and does not call the getter, so it is fine.
  • No new test needed: test_vllm_attention.py already patches this name, so it fails if the import is removed again. The break got through because the branch that removed the import did not yet have the call.
  • Overlapping work: the only other open PR in this area is #4866 (ROCm paged KV gather). It does not cover this fix.

Not verified: GPU behavior (FA4 returning [128] on SM100). That comes from the author's GB300 run and RL GPU CI.

@felipemello1
felipemello1 marked this pull request as ready for review November 6, 2026 20:00
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Nov 6, 2026
@felipemello1
felipemello1 merged commit 6250ba5 into pytorch:main Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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