Skip to content

vllm.v1.attention.ops.segmented_attention

ROCm token-major segmented attention kernels and dispatch.

Functions:

_launch_segmented_attention(q, out, kc, vc, table, starts, lengths, k_scale, v_scale, sinks, scale, cfg, partial, lse, qcap, sliding_window, causal, *, compile_only)

Launch or compile the exact stage and reduction specializations.

can_use_segmented_attention(q, k, v, out, kc, vc, table, starts, lengths, k_scale, v_scale)

Check tensor metadata; unsupported feature checks live in the caller.

compile_segmented_attention(q, out, kc, vc, table, starts, lengths, max_query_len, k_scale, v_scale, scale, config, workspace, *, sliding_window=-1, causal=True, sinks=None)

Compile one segmented attention configuration without launching it.

get_segmented_attention_workspace(device, sizes)

Keep scratch storage stable and separate for each runtime lane/ubatch.

get_segmented_config(*args, **kwargs)

Load the tuner on demand to avoid a kernel/tuner import cycle.

run_segmented_attention(q, out, kc, vc, table, starts, lengths, max_query_len, max_seq_len, k_scale, v_scale, scale, *, sliding_window=-1, causal=True, sinks=None, config=None, workspace=None)

Write eligible unified-cache attention rows; leave other requests untouched.

segmented_attention(query, key, value, output, kv_cache_dtype, key_cache, value_cache, block_table, query_start_loc, seq_lens, max_seq_len, max_query_len, k_scale, v_scale, sm_scale, *, sliding_window=-1, output_scale=None, sinks=None, causal=True, softcap=0.0, workspace=None, use_tuned_config=True)

Run segmented attention when eligible, otherwise use unified Triton.

segmented_attention_workspace_size(max_batch, hq, hk, dim, max_seq_len, *, max_tokens=None, fp8=False, autotune=False) cached

Size the largest selected attention workspace before graph capture.

max_tokens bounds reachable (batch, query_len) pairs using one longest query and one token for each remaining sequence. Omitting it keeps the legacy reservation behavior for callers without scheduler limits. autotune reserves additional splits for tuned D64 candidates.

supports_segmented_native_fp8(dtype, kv_dtype)

Native OCP conversion is available for BF16 queries on gfx12.