Skip to content

vllm.v1.attention.backends.zentorch_sdpa

Encoder attention through the zentorch SDPA kernel on Zen CPUs.

Functions:

should_use_zentorch_sdpa(attn_type, dtype)

True when encoder attention should dispatch to zentorch_sdpa.

Full, sliding-window, and ALiBi encoder layers all dispatch. A window is a single-head [1, 1, S, S] additive mask; ALiBi is a per-query-head [1, H, S, S] bias. The zentorch_sdpa_attn op builds both.

dtype must match the op's ISA gate (bf16: AVX512-BF16, fp32: AVX512); fp16 needs AVX512-FP16, which torch exposes no query for, so it stays native.

zentorch_sdpa_attn(query, key, value, output, attn_metadata, scale, sliding_window=-1, alibi_slopes=None)

Run encoder / encoder-only attention with zentorch_sdpa.

Encoder attention reads no KV cache, so the packed [num_tokens, num_heads, head_size] query/key/value are attended in place and written straight into output.

Parameters:

  • query

    (Tensor) –

    Query of shape [num_tokens, num_heads, head_size].

  • key

    (Tensor) –

    Key of shape [num_tokens, num_kv_heads, head_size].

  • value

    (Tensor) –

    Value of shape [num_tokens, num_kv_heads, head_size].

  • output

    (Tensor) –

    Pre-allocated output, same shape as query.

  • attn_metadata

    (CPUAttentionMetadata) –

    Metadata carrying the per-sequence token offsets and whether attention is causal.

  • scale

    (float) –

    Softmax scale.

  • sliding_window

    (int, default: -1 ) –

    Encoder window size, or -1 for full bidirectional attention. Handed to the op, which masks token i to [i-(W-1), i+(W-1)].

  • alibi_slopes

    (Tensor | None, default: None ) –

    Per-query-head ALiBi slopes, or None. Handed to the op, which applies them as an additive per-head bias.

Returns:

  • Tensor –

    output, filled in place.