Skip to content

enable varlen full cudagraph#3893

Draft
liangel-02 wants to merge 1 commit into
mainfrom
fix_varlen_cudagraph
Draft

enable varlen full cudagraph#3893
liangel-02 wants to merge 1 commit into
mainfrom
fix_varlen_cudagraph

Conversation

@liangel-02

Copy link
Copy Markdown
Contributor

No description provided.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 9, 2026
@liangel-02 liangel-02 force-pushed the fix_varlen_cudagraph branch from e967c82 to 4e61e94 Compare July 9, 2026 21:09
@tianyu-l tianyu-l requested a review from wwwjn July 9, 2026 23:02
# (vLLM refreshes them before each replay) BEFORE the None check, else replay
# short-circuits to output.fill_(0) (zeroed attention). No-op outside capture.
attn_metadata, _, kv_cache, _ = get_attention_context(layer.layer_name)

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.

could you help explain what's the difference between attn_metadata.num_actual_tokens and attn_metadata.max_query_len

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.

yeah attn_metadata.max_query_len is set to 1 at cuda graph capture time by vllm, so if you then replay this, your runtime max_query_len > 1 so you will get nans. but if you set it to essentially worst worst case and then run the fwd, this will be prevented. this would normally come at a perf cost but i copied vllm's flash attention linearized combine kernel in Dao-AILab/flash-attention#2692

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.

attn_metadata.max_query_len is set to 1 at cuda graph capture time by vllm

This sounds a bit suspicious -- naively reading max_query_len set to 1 means it's decoding only. Why would cuda graph capture (for prefill / decode / mixed prefill-decode) only run on decode-only tasks?

class PyTorchVarlenAttentionMetadataBuilder(FlashAttentionMetadataBuilder):
_cudagraph_support = AttentionCGSupport.UNIFORM_SINGLE_TOKEN_DECODE
_cudagraph_support = AttentionCGSupport.ALWAYS

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.

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.

yes

@@ -180,23 +154,18 @@ def forward(

cu_seqlens_q = attn_metadata.query_start_loc
seqused_k = attn_metadata.seq_lens
max_seqlen_q = attn_metadata.max_query_len
# Pin max_seqlen_q to the total token count for safe cudagraph capture and use
# the linearize FA3 combine kernel to preserve performance.

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.

Suggested change
# the linearize FA3 combine kernel to preserve performance.
# the linearized FA3 combine kernel to preserve performance.

# (vLLM refreshes them before each replay) BEFORE the None check, else replay
# short-circuits to output.fill_(0) (zeroed attention). No-op outside capture.
attn_metadata, _, kv_cache, _ = get_attention_context(layer.layer_name)

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.

attn_metadata.max_query_len is set to 1 at cuda graph capture time by vllm

This sounds a bit suspicious -- naively reading max_query_len set to 1 means it's decoding only. Why would cuda graph capture (for prefill / decode / mixed prefill-decode) only run on decode-only tasks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl ciflow/8gpu 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