vllm.v1.attention.backends.triton_attn ¶
High-Performance Triton-only Attention layer.
TritonAttentionBackend ¶
Bases: AttentionBackend
Source code in vllm/v1/attention/backends/triton_attn.py
get_builder_cls staticmethod
¶
get_builder_cls() -> type[TritonAttentionMetadataBuilder]
get_impl_cls staticmethod
¶
get_impl_cls() -> type[TritonAttentionImpl]
get_kv_cache_shape staticmethod
¶
get_kv_cache_shape(
num_blocks: int,
block_size: int,
num_kv_heads: int,
head_size: int,
cache_dtype_str: str = "auto",
) -> tuple[int, ...]
Source code in vllm/v1/attention/backends/triton_attn.py
get_metadata_cls staticmethod
¶
get_metadata_cls() -> type[AttentionMetadata]
get_supported_dtypes classmethod
¶
validate_head_size classmethod
¶
validate_head_size(head_size: int) -> None
Source code in vllm/v1/attention/backends/triton_attn.py
TritonAttentionImpl ¶
Bases: AttentionImpl
Source code in vllm/v1/attention/backends/triton_attn.py
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 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
|
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: AttentionType = DECODER,
kv_sharing_target_layer_name: Optional[int] = None,
sinks: Optional[Tensor] = None,
) -> None
Source code in vllm/v1/attention/backends/triton_attn.py
forward ¶
forward(
layer: Module,
query: Tensor,
key: Tensor,
value: Tensor,
kv_cache: Tensor,
attn_metadata: TritonAttentionMetadata,
output: Optional[Tensor] = None,
output_scale: Optional[Tensor] = None,
output_block_scale: Optional[Tensor] = None,
) -> Tensor
Forward pass with Paged Attention impl. in Triton.
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 |
kv_cache | Tensor | shape = [num_blocks, 2, block_size, num_kv_heads, head_size] | required |
attn_metadata | TritonAttentionMetadata | Metadata for attention. | required |
Returns: shape = [num_tokens, num_heads * head_size]
Source code in vllm/v1/attention/backends/triton_attn.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
|
TritonAttentionMetadata dataclass
¶
Source code in vllm/v1/attention/backends/triton_attn.py
prefix_scheduler_metadata class-attribute
instance-attribute
¶
__init__ ¶
__init__(
num_actual_tokens: int,
max_query_len: int,
query_start_loc: Tensor,
max_seq_len: int,
seq_lens: Tensor,
block_table: Tensor,
slot_mapping: Tensor,
use_cascade: bool,
common_prefix_len: int,
cu_prefix_query_lens: Optional[Tensor],
prefix_kv_lens: Optional[Tensor],
suffix_kv_lens: Optional[Tensor],
scheduler_metadata: Optional[Tensor] = None,
prefix_scheduler_metadata: Optional[Tensor] = None,
) -> None
TritonAttentionMetadataBuilder ¶
Bases: AttentionMetadataBuilder[TritonAttentionMetadata]
Source code in vllm/v1/attention/backends/triton_attn.py
__init__ ¶
__init__(
kv_cache_spec: AttentionSpec,
layer_names: list[str],
vllm_config: VllmConfig,
device: device,
)
Source code in vllm/v1/attention/backends/triton_attn.py
build ¶
build(
common_prefix_len: int,
common_attn_metadata: CommonAttentionMetadata,
fast_build: bool = False,
) -> TritonAttentionMetadata
Source code in vllm/v1/attention/backends/triton_attn.py
build_for_cudagraph_capture ¶
build_for_cudagraph_capture(
common_attn_metadata: CommonAttentionMetadata,
) -> TritonAttentionMetadata