vllm.v1.attention.backends.hybrid_attn ¶
HybridAttentionBackend ¶
Bases: AttentionBackend
Backend that combines Triton sliding-window attention with an SSM branch.
KV cache layout and metadata are identical to the Triton attention backend; the only difference is that the implementation fuses in an additional SSM contribution computed by a HybridSSMAdapter owned by the layer.
Source code in vllm/v1/attention/backends/hybrid_attn.py
supported_dtypes class-attribute instance-attribute ¶
supported_kv_cache_dtypes class-attribute instance-attribute ¶
supported_kv_cache_dtypes: list[CacheDType] = [
"auto",
"fp8",
"fp8_e4m3",
"fp8_e5m2",
]
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/hybrid_attn.py
get_supported_kernel_block_sizes staticmethod ¶
get_supported_kernel_block_sizes() -> list[
int | MultipleOf
]
supports_compute_capability classmethod ¶
supports_compute_capability(
capability: DeviceCapability,
) -> bool
supports_head_size classmethod ¶
HybridAttentionImpl ¶
Bases: AttentionImpl
Implementation that wraps TritonAttentionImpl and adds an SSM branch.
Source code in vllm/v1/attention/backends/hybrid_attn.py
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 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 | |
_triton_impl instance-attribute ¶
_triton_impl = TritonAttentionImpl(
num_heads=num_heads,
head_size=head_size,
scale=scale,
num_kv_heads=num_kv_heads,
alibi_slopes=tolist()
if isinstance(alibi_slopes, Tensor)
else alibi_slopes,
sliding_window=sliding_window,
kv_cache_dtype=kv_cache_dtype,
logits_soft_cap=logits_soft_cap,
attn_type=attn_type,
kv_sharing_target_layer_name=kv_sharing_target_layer_name,
sinks=sinks,
)
kv_sharing_target_layer_name instance-attribute ¶
__init__ ¶
__init__(
num_heads: int,
head_size: int,
scale: float,
num_kv_heads: int,
alibi_slopes: list[float] | None,
sliding_window: int | None,
kv_cache_dtype: str,
logits_soft_cap: float | None = None,
attn_type: AttentionType = DECODER,
kv_sharing_target_layer_name: int | None = None,
sinks: Tensor | None = None,
) -> None
Source code in vllm/v1/attention/backends/hybrid_attn.py
forward ¶
forward(
layer: Module,
query: Tensor,
key: Tensor,
value: Tensor,
kv_cache: Tensor,
attn_metadata: HybridAttentionMetadata,
output: Tensor | None = None,
output_scale: Tensor | None = None,
output_block_scale: Tensor | None = None,
) -> Tensor
Forward pass combining Triton attention with an SSM history branch.
- Run standard Triton attention to populate the output tensor.
- If the layer exposes an
ssm_adapterattribute, call itsforward_history_branch_decodemethod to obtain an SSM contribution and fuse it into the firstnum_actual_tokenspositions of the output.
Source code in vllm/v1/attention/backends/hybrid_attn.py
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 | |
fused_output_quant_supported ¶
HybridAttentionMetadata dataclass ¶
Source code in vllm/v1/attention/backends/hybrid_attn.py
__init__ ¶
__init__(
triton_metadata: TritonAttentionMetadata,
mamba_metadata: Mamba1AttentionMetadata,
) -> None
HybridAttentionMetadataBuilder ¶
Bases: AttentionMetadataBuilder[HybridAttentionMetadata]
Reuse TritonAttentionMetadataBuilder for hybrid attention.
Source code in vllm/v1/attention/backends/hybrid_attn.py
_cudagraph_support class-attribute instance-attribute ¶
_cudagraph_support: AttentionCGSupport = ALWAYS
_mamba_builder instance-attribute ¶
_mamba_builder = Mamba1AttentionMetadataBuilder(
mamba_spec, layer_names, vllm_config, device
)
_triton_builder instance-attribute ¶
_triton_builder = TritonAttentionMetadataBuilder(
kv_cache_spec, layer_names, vllm_config, device
)
__init__ ¶
__init__(
kv_cache_spec: AttentionSpec,
layer_names: list[str],
vllm_config: VllmConfig,
device: device,
)
Source code in vllm/v1/attention/backends/hybrid_attn.py
build ¶
build(
common_prefix_len: int,
common_attn_metadata: CommonAttentionMetadata,
fast_build: bool = False,
) -> HybridAttentionMetadata
Source code in vllm/v1/attention/backends/hybrid_attn.py
build_for_cudagraph_capture ¶
build_for_cudagraph_capture(
common_attn_metadata: CommonAttentionMetadata,
) -> HybridAttentionMetadata