Skip to content

vllm.model_executor.kernels.linear

This module re-exports linear kernel implementations to provide a stable import interface during an ongoing reorganization. Upcoming PRs will remove the scaled_mm and mixed_precision subdirectories and reorganize kernels by provider (aiter, cutlass, flashinfer, etc.) rather than by precision type. By centralizing exports here, we minimize the need to update imports across other modules when the internal structure changes. If you are adding a new kernel selector or kernel implementation, add it to this init.py to maintain import stability.

Modules:

Classes:

Functions:

AiterInt8ScaledMMLinearKernel

Bases: CutlassInt8ScaledMMLinearKernel

Methods:

  • apply_weights –

    AiterInt8ScaledMMLinearKernel implements a fused version of

apply_weights(layer, x, bias=None)

AiterInt8ScaledMMLinearKernel implements a fused version of output = torch.mm((scale_a * a), (scale_b * b)).to(out_dtype) where scale_a * a and scale_b * b are implemented using numpy-style broadcasting. Currently only supports per-token-per-channel GEMM through AITER w8a8 scaled gemm. AiterInt8ScaledMMLinearKernel also does not support AITER block scaled GEMM and mix-precision GEMM.

AiterMxfp4LinearKernel

Bases: MxFp4LinearKernel

AITER-based native MXFP4 GEMM kernel for ROCm.

B12xFp8BlockScaledMMKernel

Bases: Fp8BlockScaledMMLinearKernel

K128 block-FP8 linear through the native B12X SM120 dense GEMM.

B12xMxFp4LinearKernel

Bases: MxFp4LinearKernel

MXFP4 linear through the native B12X SM120 dense GEMM.

B12xMxfp8LinearKernel

Bases: Mxfp8LinearKernel

ModelOpt MXFP8 linear through the native b12x SM120 dense GEMM path.

B12xNvFp4LinearKernel

Bases: NvFp4LinearKernel

ModelOpt NVFP4 linear through the native B12X SM120 dense GEMM.

B12xNvFp4W4A16LinearKernel

Bases: B12xNvFp4LinearKernel

BF16 x NVFP4 GEMM without activation quantization.

B12xTensorFP8ScaledMMLinearKernel

Bases: FP8ScaledMMLinearKernel

Static per-tensor FP8 linear through the B12X SM12x dense GEMM.

CutlassFP8ScaledMMLinearKernel

Bases: FP8ScaledMMLinearKernel

Methods:

  • input_quant_key –

    Static per-tensor and dynamic per-token activations can be quantized

_pad_to_alignment(x, dim, alignment, value=0.0) staticmethod

Pad tensor x along dim to the next multiple of alignment.

input_quant_key()

Static per-tensor and dynamic per-token activations can be quantized outside the kernel: neither is padded, and cutlass_scaled_mm takes the (M, 1) token scales as is.

CutlassNvFp4LinearKernel

Bases: NvFp4LinearKernel

NVFP4 GEMM via the vLLM CUTLASS kernel.

EmulationMxfp4LinearKernel

Bases: MxFp4LinearKernel

Software emulation fallback for OCP MXFP4/MXFP6 (dequant + F.linear).

EmulationMxfp6LinearKernel

Bases: MxFp6LinearKernel

Software emulation fallback for OCP MXFP4/MXFP6 (dequant + F.linear).

EmulationMxfp8LinearKernel

Bases: Mxfp8LinearKernel

Software emulation fallback for MXFP8 (dequant to BF16).

EmulationNvFp4LinearKernel

Bases: NvFp4LinearKernel

Software emulation fallback for NVFP4 (dequant → BF16 matmul).

FbgemmNvFp4LinearKernel

Bases: NvFp4LinearKernel

NVFP4 GEMM via FBGEMM.

FlashInferB12xNvFp4LinearKernel

Bases: NvFp4LinearKernel

NVFP4 GEMM via FlashInfer's b12x CuTe DSL warp-level MMA kernel (SM12x).

FlashInferCudnnNvFp4LinearKernel

Bases: NvFp4LinearKernel

NVFP4 GEMM via FlashInfer's cuDNN wrapper.

FlashInferCuteDslNvFp4LinearKernel

Bases: NvFp4LinearKernel

NVFP4 GEMM via FlashInfer's cutedsl backend.

FlashInferCuteDslNvFp4W4A16LinearKernel

Bases: NvFp4LinearKernel

BF16 x NVFP4 GEMM via FlashInfer's CuTe-DSL backend.

FlashInferCutedslMxfp8LinearKernel

Bases: Mxfp8LinearKernel

MXFP8 W8A8 GEMM via FlashInfer CuTe-DSL (SM100/SM103).

FlashInferCutlassMxfp8LinearKernel

Bases: Mxfp8LinearKernel

MXFP8 W8A8 GEMM via FlashInfer CUTLASS (SM100+).

FlashInferCutlassNvFp4LinearKernel

Bases: NvFp4LinearKernel

NVFP4 GEMM via FlashInfer's CUTLASS wrapper.

Methods:

  • input_quant_key –

    This kernel supports dynamic quantization of the input. By

input_quant_key()

This kernel supports dynamic quantization of the input. By convention, pre-quantized blockscales must use the swizzled layout.

FlashInferFp8DeepGEMMDynamicBlockScaledKernel

Bases: Fp8BlockScaledDynamicMMLinearKernel

Conditional FlashInfer / DeepGEMM FP8 block-scaled GEMM.

Dispatches between two kernels based on input batch size: - Small batches (M < 32): FlashInfer's swapAB trick for better utilisation. - Large batches (M >= 32): DeepGEMM for peak throughput.

apply_input_quant is False because FlashInfer accepts BF16 input and handles FP8 conversion internally. The DeepGEMM branch therefore quantises BF16→FP8 inside apply_mm via a closure before dispatching to the DeepGEMM kernel — keeping both branches compatible with the single BF16 tensor operand list passed by torch.cond.

FlashInferMxFp4LinearKernel

Bases: MxFp4LinearKernel

MXFP4 W4A4 GEMM via FlashInfer CUTLASS (SM100+).

FlashInferTrtllmMxfp8LinearKernel

Bases: Mxfp8LinearKernel

MXFP8 W8A8 GEMM via FlashInfer's TensorRT-LLM wrapper.

FlashInferTrtllmNvFp4LinearKernel

Bases: NvFp4LinearKernel

NVFP4 GEMM via FlashInfer's TensorRT-LLM wrapper.

HummingHadamardNvFp4LinearKernel

Bases: HummingNvFp4LinearKernel

Humming W4A4 NVFP4 with a Sylvester Hadamard fused into input quantization.

Runs the activation dtype the checkpoint declares, without A16 fallback.

HummingMxFp6LinearKernel

Bases: MxFp6LinearKernel

Humming GEMM for packed MXFP6 E2M3 and E3M2 weights.

LinearKernel

Bases: ABC, Generic[_LinearConfigT]

Base class of every quantized linear kernel.

Methods:

apply_weights(layer, x, bias=None) abstractmethod

Run the quantized GEMM.

can_implement(config) abstractmethod classmethod

Whether the kernel handles config, and if not, why.

executed_activation_key(activation_quant_key) classmethod

The activation quantization the kernel runs for a layer requesting activation_quant_key. Weight-only kernels return None; kernel selection then warns about, or under VLLM_STRICT_QUANT_SCHEME forbids, the fallback.

input_quant_key()

The activation quant key the kernel accepts pre-quantized (via as_quantized_activation), or None if it quantizes its own input.

is_supported(compute_capability=None) abstractmethod classmethod

Whether the kernel runs on this device (the current one if compute_capability is None), and if not, why.

process_weights_after_loading(layer) abstractmethod

Convert the loaded weights on layer in place to the kernel's format.

supports_batch_invariance() classmethod

Whether a row's output is independent of the other rows in the batch.

MarlinMxfp8LinearKernel

Bases: Mxfp8LinearKernel

MXFP8 W8A16 GEMM via Marlin (SM80+).

MarlinNvFp4LinearKernel

Bases: NvFp4LinearKernel

NVFP4 weight-only GEMM via Marlin (W4A16).

MxFp4LinearKernel

Bases: LinearKernel[MxFp4LinearLayerConfig]

Base class for MXFP4 quantized linear kernels.

Each subclass implements a specific GEMM backend (CUTLASS, Marlin, etc). The kernel selection mechanism iterates over registered subclasses in priority order, calling is_supported, _supports_quant_scheme and can_implement to find the best match for the current hardware.

Methods:

_supports_quant_scheme(weight_key, activation_key) classmethod

Return whether this kernel implements weight_key x activation_key.

Selection uses this to dispatch on the requested activation format (from the checkpoint or --quantization-config.linear.activation). The default covers MXFP4 weights with MXFP4 or unquantized activations; kernels for other activation formats override it.

fuse_input_hadamard(size)

Rotate the input by the size-size block Hadamard matrix inside apply_weights from now on, if supported (see InputHadamardFusable). Call after process_weights_after_loading.

MxFp4LinearLayerConfig dataclass

Configuration for an MXFP4 linear layer.

All MXFP4 layers share the same structure: packed uint8 weights (2 FP4 values per byte) and per-block weight scales (group size 32).

Attributes:

  • activation_quant_key (QuantKey | None) –

    Identifies the activation quantization format, or None when activations must not be quantized.

MxFp6LinearKernel

Bases: LinearKernel[MxFp6LinearLayerConfig]

Base class for MXFP6 quantized linear kernels.

Each subclass implements a specific GEMM backend (CUTLASS, Marlin, etc). The kernel selection mechanism iterates over registered subclasses in priority order,calling is_supported and can_implement to find the best match for the current hardware.

MxFp6LinearLayerConfig dataclass

Configuration for an MXFP6 linear layer.

All MXFP6 layers share the same structure: packed uint8 weights (4 FP6 values per 3 bytes) and per-block weight scales (group size 32).

Attributes:

  • weight_quant_key (QuantKey) –

    Identifies the weight quantization format. Can be kMxfp6E2M3Static or kMxfp6E3M2Static.

  • activation_quant_key (QuantKey | None) –

    Identifies the activation quantization format, or None when activations must not be quantized.

Mxfp8LinearLayerConfig dataclass

Configuration for an MXFP8 linear layer.

All MXFP8 layers share the same structure: FP8-E4M3 weights with uint8 (E8M0) per-block scales at block size 32.

Attributes:

  • weight_shape (tuple[int, int]) –

    The layer's (out_features, in_features), i.e. (N, K).

  • activation_quant_key (QuantKey | None) –

    Requested activation format; None means weight-only.

NvFp4LinearKernel

Bases: LinearKernel[NvFp4LinearLayerConfig]

Base class for NVFP4 quantized linear kernels.

Each subclass implements a specific GEMM backend (CUTLASS, Marlin, etc). The kernel selection mechanism iterates over registered subclasses in priority order,calling is_supported and can_implement to find the best match for the current hardware.

Methods:

  • prepare_input –

    Return 2D packed NVFP4 data with swizzled 128x4 block scales.

prepare_input(layer, x)

Return 2D packed NVFP4 data with swizzled 128x4 block scales.

K is zero-padded to match the padded weight. Prequantized inputs are validated and padded without modifying the caller's activation.

NvFp4LinearLayerConfig dataclass

Configuration for an NVFP4 linear layer.

All NVFP4 layers share the same structure: packed uint8 weights (2 FP4 values per byte), FP8-E4M3 per-block weight scales (group size 16), and scalar global scales for both weights and activations. act_dtype is the activation dtype of weight-only layers, when the caller knows it.

RDNAHybridW4A16LinearKernel

Bases: MPLinearKernel

Hybrid W4A16 kernel: HIP skinny for decode, Triton for prefill.

Stores the weights once as int8 [N, K//2] (ExLlama shuffle packed). The HIP skinny kernel reads it directly; the triton kernel reinterprets the same buffer as int32 [N, K//8] via a view, so there is no dual weight storage unless rdna_hybrid_w4a16_prefill_dequant caches a dense prefill copy.

Rdna3W4A8MxFp4LinearKernel

Bases: MxFp4LinearKernel

MXFP4 GEMM for RDNA3/RDNA3.5: W4A8 int8-dot GEMV for M <= 8, dequant + high-precision GEMM above.

TorchMxFp8LinearKernel

Bases: Mxfp8LinearKernel

MXFP8 W8A8 GEMM using the native torch._scaled_mm dispatch.

Supported on XPU (oneDNN) and CUDA (cuBLASLt, SM90+).

TorchNvFp4LinearKernel

Bases: NvFp4LinearKernel

NVFP4 GEMM implemented with PyTorch's native torch._scaled_mm.

Eager execution uses PyTorch's native scaled-matmul implementation. Under torch.compile, TorchInductor may select any enabled scaled-GEMM backend, including NVGEMM on supported Blackwell systems.

TritonW4A16LinearKernel

Bases: MPLinearKernel

Triton-based W4A16 GEMM kernel for ROCm (MI300 and newer).

Supports GPTQ-format int4 weights (uint4b8 symmetric, uint4 asymmetric) and, on ROCm, symmetric int8 weights (uint8b128) with grouped quantization. Weight tensors are transposed from the compressed-tensors checkpoint layout to the kernel's [K, N//pack] layout.

Methods:

process_weights_after_loading(layer)

Convert compressed-tensors checkpoint layout to kernel layout.

Checkpoint (from compressed_tensors_wNa16.create_weights): weight_packed: [N, K//8] int32 input_dim=1, output_dim=0, packed_dim=1 weight_scale: [N, K//G] fp16 input_dim=1, output_dim=0 weight_zero_point: [N//8, K//G] int32 output_dim=0, packed_dim=0

Kernel needs

qweight: [K, N//8] int32 (transpose weight_packed) scales: [K//G, N] fp16 (transpose weight_scale) qzeros: [K//G, N//8] int32 (transpose weight_zero_point)

XPUMxFp8LinearKernel

Bases: Mxfp8LinearKernel

MXFP8 W8A8 GEMM on XPU.

_prepare_bmm_params(layer, scale_kn)

Precompute batched weight and scale for grouped fp8_bmm (e.g. wo_a).

Splits scale [K//32, N_total] into [G, K//32, N_per_group] and weight [N_total, K] into contiguous [G, K, N_per_group] for batch GEMM.

XPUW4A8IntLinearKernel

Bases: MPLinearKernel

XPU kernel for W4A8 integer quantization using oneDNN int4_gemm_w4a8.

Weights are symmetric group-quantized int4 packed as uint4. Activations are dynamically quantized per-token to symmetric int8.

ZentorchInt8ScaledMMLinearKernel

Bases: Int8ScaledMMLinearKernel

Methods:

process_weights_after_loading(layer)

Prepare weights for zentorch_dynamic_qlinear.

Keeps weight in [N, K] layout (int8, contiguous) and converts the per-channel weight scale to bf16 with shape (N,).

ZentorchWNA16LinearKernel

Bases: CPUWNA16LinearKernel

Int4 kernel backed by zentorch_dynamic_qlinear (DA8W4) or zentorch_woq_linear (W4A16).

Methods:

_maybe_process_da8w4_weights(layer)

Repack layer into the DA8W4 layout, or leave it untouched.

Returns False without mutating the layer when it is not eligible, so the caller falls through to the W4A16 paths.

_zentorch_woq_eligible(layer)

Eligibility predicate for the zentorch W4A16 GPTQ fast path.

Constraints (any failure -> cpu_gemm_wna16 path via super() with layer untouched).

process_weights_after_loading(layer)

Repack CT GPTQ weights into the zentorch DA8W4 or WOQ layout.

Falls back to CPUWNA16LinearKernel.process_weights_after_loading via super() when the layer doesn't satisfy _zentorch_woq_eligible.

On success, layer._zentorch_processed_weights is set to True

_filter_kernels_by_backend(backend, kernels)

Prefer matching kernels, falling back to auto by layer type.

_first_usable_kernel(kernels, config, activation_quant_key, extra_check=None)

The first kernel in priority order that is enabled, supported, implements config and may run activation_quant_key, plus why earlier ones were skipped.

_get_linear_backend(*, quantization)

Get the linear_backend setting from the current vllm config.

_resolve_backend_kernels(kernels, layer_desc, *, quantization, compute_capability=None)

Apply device priorities and --linear-backend filtering to a kernel list.

When the requested backend has no kernel for this layer type, fall back to the unfiltered list (with a WARNING log) instead of failing engine startup: an explicitly requested backend usually provides kernels for a single quantization scheme, while a model can contain several linear layer types (e.g. NVFP4 MoE projections next to FP8 attention projections).

_resolve_linear_activation_key(model_activation_key)

Apply --quantization-config.linear.activation to the checkpoint's activation key. The override wins: it may replace a checkpoint's MXFP4 activations with a format a kernel computes directly (e.g. int8), or with null to run the layer weight-only.

_user_linear_activation_override()

User's linear activation override from quantization_config, or None.

_user_linear_activation_override_is_set()

Whether the user set the linear activation, explicit null included.

choose_mp_linear_kernel(config, compute_capability=None)

Choose an MPLinearKernel that can implement the given config for the given compute capability. Attempts to choose the best kernel in terms of performance.

Parameters:

  • config

    (MPLinearLayerConfig) –

    Description of the linear layer to be implemented.

  • compute_capability

    (Optional[int], default: None ) –

    The compute capability of the target device, if None uses current_platform to get the compute capability. Defaults to None.

Raises:

  • ValueError –

    If no kernel can implement the given config.

Returns:

choose_scaled_mm_linear_kernel(config, possible_kernels, compute_capability=None, force_kernel=None, *, quantization, activation_quant_key=None)

Choose a _KernelT that can implement the given config for the given compute capability. Attempts to choose the best kernel in terms of performance.

Parameters:

  • config

    (_KernelConfigT) –

    Description of the linear layer to be implemented.

  • possible_kernels

    (dict[PlatformEnum, list[_KernelT]]) –

    A dictionary of platforms and their list of possible kernels.

  • compute_capability

    (Optional[int], default: None ) –

    The compute capability of the target device, if None uses current_platform to get the compute capability. Defaults to None.

  • force_kernel

    (Optional[type[_KernelT]], default: None ) –

    An Optional forced kernel to override the possible_kernels if it can be implemented. If None, it will only try the possible kernels.

  • quantization

    (str) –

    Quantization scheme used to select a backend override.

  • activation_quant_key

    (QuantKey | None, default: None ) –

    Activation quantization the layer requests.

Raises:

  • ValueError –

    If no kernel can implement the given config.

Returns:

  • _KernelT ( type[_KernelT] ) –

    Chosen kernel.

fp8_scaled_mm_is_batch_invariant(kernel)

Whether a row's output from the kernel is independent of the other rows.

init_mxfp4_linear_kernel(activation_quant_key=None)

Select and instantiate the best MXFP4 linear kernel for the current platform.

Returns a placeholder for requantization sources, which have no kernel.

init_mxfp6_linear_kernel(weight_quant_key, activation_quant_key=None)

Select and instantiate the best MXFP6 linear kernel for the current platform.

Returns a placeholder for requantization sources, which have no kernel.

init_mxfp8_linear_kernel(*, weight_shape, bmm_batch_size=None, activation_quant_key=kMxfp8Dynamic)

Select and instantiate the best MXFP8 linear kernel for the current platform and (N, K) weight shape.

Omitted activation keys preserve the existing W8A8 selection and A16 fallback. Explicit None requests weight-only execution. Returns a placeholder for requantization sources, which have no kernel.

init_nvfp4_linear_kernel(use_a16=False, act_dtype=None)

Select and instantiate the best NVFP4 linear kernel for the current platform.

Parameters:

  • use_a16

    (bool, default: False ) –

    Weight-only (W4A16) instead of W4A4.

  • act_dtype

    (dtype | None, default: None ) –

    Activation dtype of a W4A16 layer, so that BF16-only kernels are skipped for FP16 models. None if unknown.

Returns:

register_linear_kernel(kernel_class, platform, kernel_type='mp')

Register a new linear kernel class to be considered in kernel selection.

Parameters:

  • kernel_class

    (type) –

    The kernel class to register.

  • platform

    (PlatformEnum) –

    The platform for which this kernel is applicable.

  • kernel_type

    (str, default: 'mp' ) –

    The type of the kernel, either "mp", "int8", "fp8", "fp8_block", "mxfp8", "nvfp4", "mxfp4" or "mxfp6". Defaults to "mp".

Raises:

  • ValueError –

    If the kernel_type is not recognized.