vllm.v1.attention.backends.pallas
TPU_STR_DTYPE_TO_TORCH_DTYPE module-attribute
¶
TPU_STR_DTYPE_TO_TORCH_DTYPE = {
"half": half,
"bfloat16": bfloat16,
"float": float,
"fp8": float8_e4m3fn,
"fp8_e4m3": float8_e4m3fn,
"fp8_e5m2": float8_e5m2,
"int8": int8,
"uint8": uint8,
}
PallasAttentionBackend ¶
Bases: AttentionBackend
Source code in vllm/v1/attention/backends/pallas.py
get_impl_cls staticmethod
¶
get_impl_cls() -> type[PallasAttentionBackendImpl]
get_kv_cache_shape staticmethod
¶
get_kv_cache_shape(
num_blocks: int,
block_size: int,
num_kv_heads: int,
head_size: int,
) -> tuple[int, ...]
Source code in vllm/v1/attention/backends/pallas.py
get_max_num_seqs staticmethod
¶
get_metadata_cls staticmethod
¶
get_metadata_cls() -> type[PallasMetadata]
get_min_page_size staticmethod
¶
get_min_page_size(vllm_config: VllmConfig) -> int
Source code in vllm/v1/attention/backends/pallas.py
get_page_size staticmethod
¶
get_page_size(vllm_config: VllmConfig) -> int
Source code in vllm/v1/attention/backends/pallas.py
get_state_cls staticmethod
¶
get_state_cls() -> type[CommonAttentionState]
swap_blocks staticmethod
¶
PallasAttentionBackendImpl ¶
Bases: AttentionImpl
Source code in vllm/v1/attention/backends/pallas.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
kv_sharing_target_layer_name instance-attribute
¶
__init__ ¶
__init__(
num_heads: int,
head_size: int,
scale: float,
num_kv_heads: int,
alibi_slopes: Optional[list[float]],
sliding_window: Optional[int],
kv_cache_dtype: str,
logits_soft_cap: Optional[float] = None,
attn_type: str = DECODER,
kv_sharing_target_layer_name: Optional[int] = None,
) -> None
Source code in vllm/v1/attention/backends/pallas.py
forward ¶
forward(
layer: AttentionLayer,
query: Tensor,
key: Tensor,
value: Tensor,
kv_cache: Tensor,
attn_metadata: PallasMetadata,
output: Optional[Tensor] = None,
output_scale: Optional[Tensor] = None,
) -> Tensor
Forward pass with Pallas attention.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query | Tensor | shape = [num_tokens, num_heads * head_size] | required |
key | Tensor | shape = [num_tokens, num_kv_heads * head_size] | required |
value | Tensor | shape = [num_tokens, num_kv_heads * head_size] | required |
attn_metadata | PallasMetadata | Metadata for attention. | required |
Returns: shape = [num_tokens, num_heads * head_size]
Source code in vllm/v1/attention/backends/pallas.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
PallasMetadata dataclass
¶
Source code in vllm/v1/attention/backends/pallas.py
dtype_bits ¶
dtype_bits(dtype: dtype)
Source code in vllm/v1/attention/backends/pallas.py
get_dtype_packing ¶
get_page_size_bytes ¶
get_page_size_bytes(
block_size: int,
num_kv_heads: int,
head_size: int,
kv_cache_dtype: dtype,
) -> int
Returns the size in bytes of one page of the KV cache.
Source code in vllm/v1/attention/backends/pallas.py
kv_cache_update_op_impl ¶
kv_cache_update_op_impl(
kv: Tensor,
slot_mapping: Tensor,
kv_cache: Tensor,
num_kv_update_slices: Tensor,
page_size: int,
num_slices_per_block: int,
)
Source code in vllm/v1/attention/backends/pallas.py
kv_cache_update_op_non_xla ¶
kv_cache_update_op_non_xla(
kv: Tensor,
slot_mapping: Tensor,
kv_cache: Tensor,
num_kv_update_slices: Tensor,
page_size: int,
num_slices_per_block: int,
) -> Tensor
Source code in vllm/v1/attention/backends/pallas.py
kv_cache_update_op_xla ¶
kv_cache_update_op_xla(
kv: Tensor,
slot_mapping: Tensor,
kv_cache: Tensor,
num_kv_update_slices: Tensor,
page_size: int,
num_slices_per_block: int,
) -> Tensor
Source code in vllm/v1/attention/backends/pallas.py
write_to_kv_cache ¶
write_to_kv_cache(
key: Tensor,
value: Tensor,
kv_cache: Tensor,
slot_mapping: Tensor,
num_slices_per_kv_cache_update_block: int,
num_kv_update_slices: Tensor,
kv_cache_quantized_dtype: Optional[dtype] = None,
k_scale: float = 1.0,
v_scale: float = 1.0,
) -> None
Write the key and values to the KV cache.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key | Tensor | shape = [num_tokens, num_kv_heads, head_size] | required |
value | Tensor | shape = [num_tokens, num_kv_heads, head_size] | required |
num_slices_per_kv_cache_update_block | int | int | required |