vllm.v1.attention.backends.zentorch_sdpa
¶
Encoder attention through the zentorch SDPA kernel on Zen CPUs.
Functions:
-
should_use_zentorch_sdpa–True when encoder attention should dispatch to zentorch_sdpa.
-
zentorch_sdpa_attn–Run encoder / encoder-only attention with zentorch_sdpa.
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.
Source code in vllm/v1/attention/backends/zentorch_sdpa.py
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.
Source code in vllm/v1/attention/backends/zentorch_sdpa.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |