Skip to content

[profiler] Emit non-contiguous V operand stride in ViT attention profiler scope - #1071

Open
parthash0804 wants to merge 1 commit into
gfx11from
parthash/vit-attn-profile-vstride
Open

[profiler] Emit non-contiguous V operand stride in ViT attention profiler scope#1071
parthash0804 wants to merge 1 commit into
gfx11from
parthash/vit-attn-profile-vstride

Conversation

@parthash0804

@parthash0804 parthash0804 commented Jul 30, 2026

Copy link
Copy Markdown

Summary

The ViT encoder attention is fed a non-contiguous V — a slice of the fused QKV projection with token stride mult*H*D (e.g. 3*H*D), vs H*D for a contiguous V. This operand layout has a measurable latency impact on some GPUs (notably Strix Point / gfx1150 when the cache is cold), but it was previously invisible in profiles and could only be confirmed by monkeypatching
context_attention_fwd at runtime. This PR surfaces the V operand's token stride directly in the attention profiler scope label, for every selectable ViT-encoder backend, so the layout can be read straight from a profile (and from the vllm-bench.py attention
table) without any instrumentation.

Changes

  • create_attention_profiler_scope (vllm/v1/utils.py) gains an optional v_token_stride argument.
  • The scope label appends Vstride=<n> only when the stride is not the natural contiguous value (num_kv_heads * head_size). Natural/contiguous strides are omitted to keep the label short, so the tag only appears for the fused-QKV ViT layout that actually matters.
  • Wired at all ViT encoder attention sites, across every --mm-encoder-attn-backend:
    • TRITON_ATTNMMEncoderAttention._forward_triton, triton_attn_wrapper
    • FLASH_ATTN / ROCM_AITER_FAMMEncoderAttention._forward_fa, flash_attn_maxseqlen_wrapper
    • TORCH_SDPAMMEncoderAttention._forward_sdpa
  • Decoder / KV-cache attention paths (triton_attn, rocm_attn, rocm_aiter_unified_attn, rocm_aiter_fa) and all other callers are unchanged — the new arg defaults to None, and their V (paged value_cache) has the natural stride anyway.

Result

image

…pe text

Add an optional v_token_stride argument to create_attention_profiler_scope
and wire it at all ViT encoder attention sites, for every selectable
mm-encoder backend:
  - TRITON_ATTN  (MMEncoderAttention._forward_triton, triton_attn_wrapper)
  - FLASH_ATTN / ROCM_AITER_FA (MMEncoderAttention._forward_fa,
    flash_attn_maxseqlen_wrapper)
  - TORCH_SDPA   (MMEncoderAttention._forward_sdpa)

The stride is appended to the profiler scope label as "Vstride=<n>" only
when it is *not* the natural contiguous value (num_kv_heads * head_size) --
i.e. the real ViT layout where V is a non-contiguous slice of the fused QKV
projection (token stride mult*H*D, e.g. 3*H*D). Natural strides are omitted
to keep the label short.

This surfaces the V operand memory layout directly in profiles regardless of
which ViT backend is selected, which carries a measurable latency impact on
some GPUs (e.g. Strix Point cold cache). Decoder / KV-cache attention paths
and all other callers are unchanged since the new arg defaults to None.

Co-authored-by: Cursor <cursoragent@cursor.com>

Signed-off-by: Parth Ashwin Jain <parthash@amd.com>
@parthash0804
parthash0804 requested a review from mgehre-amd July 30, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant