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:
-
MPLinearKernel– -
Mxfp8LinearKernel– -
ScaledMMLinearKernel– -
base– -
cute_dsl– -
mixed_precision– -
mxfp4– -
mxfp6– -
mxfp8– -
nvfp4– -
requantization_source–Placeholder linear kernels for online requantization sources.
-
scaled_mm– -
zentorch_utils–Gates zentorch CPU linear dispatch on platform/op availability.
Classes:
-
AiterInt8ScaledMMLinearKernel– -
AiterMxfp4LinearKernel–AITER-based native MXFP4 GEMM kernel for ROCm.
-
B12xFp8BlockScaledMMKernel–K128 block-FP8 linear through the native B12X SM120 dense GEMM.
-
B12xMxFp4LinearKernel–MXFP4 linear through the native B12X SM120 dense GEMM.
-
B12xMxfp8LinearKernel–ModelOpt MXFP8 linear through the native b12x SM120 dense GEMM path.
-
B12xNvFp4LinearKernel–ModelOpt NVFP4 linear through the native B12X SM120 dense GEMM.
-
B12xNvFp4W4A16LinearKernel–BF16 x NVFP4 GEMM without activation quantization.
-
B12xTensorFP8ScaledMMLinearKernel–Static per-tensor FP8 linear through the B12X SM12x dense GEMM.
-
CutlassFP8ScaledMMLinearKernel– -
CutlassNvFp4LinearKernel–NVFP4 GEMM via the vLLM CUTLASS kernel.
-
EmulationMxfp4LinearKernel–Software emulation fallback for OCP MXFP4/MXFP6 (dequant + F.linear).
-
EmulationMxfp6LinearKernel–Software emulation fallback for OCP MXFP4/MXFP6 (dequant + F.linear).
-
EmulationMxfp8LinearKernel–Software emulation fallback for MXFP8 (dequant to BF16).
-
EmulationNvFp4LinearKernel–Software emulation fallback for NVFP4 (dequant → BF16 matmul).
-
FbgemmNvFp4LinearKernel–NVFP4 GEMM via FBGEMM.
-
FlashInferB12xNvFp4LinearKernel–NVFP4 GEMM via FlashInfer's b12x CuTe DSL warp-level MMA kernel (SM12x).
-
FlashInferCudnnNvFp4LinearKernel–NVFP4 GEMM via FlashInfer's cuDNN wrapper.
-
FlashInferCuteDslNvFp4LinearKernel–NVFP4 GEMM via FlashInfer's cutedsl backend.
-
FlashInferCuteDslNvFp4W4A16LinearKernel–BF16 x NVFP4 GEMM via FlashInfer's CuTe-DSL backend.
-
FlashInferCutedslMxfp8LinearKernel–MXFP8 W8A8 GEMM via FlashInfer CuTe-DSL (SM100/SM103).
-
FlashInferCutlassMxfp8LinearKernel–MXFP8 W8A8 GEMM via FlashInfer CUTLASS (SM100+).
-
FlashInferCutlassNvFp4LinearKernel–NVFP4 GEMM via FlashInfer's CUTLASS wrapper.
-
FlashInferFp8DeepGEMMDynamicBlockScaledKernel–Conditional FlashInfer / DeepGEMM FP8 block-scaled GEMM.
-
FlashInferMxFp4LinearKernel–MXFP4 W4A4 GEMM via FlashInfer CUTLASS (SM100+).
-
FlashInferTrtllmMxfp8LinearKernel–MXFP8 W8A8 GEMM via FlashInfer's TensorRT-LLM wrapper.
-
FlashInferTrtllmNvFp4LinearKernel–NVFP4 GEMM via FlashInfer's TensorRT-LLM wrapper.
-
HummingHadamardNvFp4LinearKernel–Humming W4A4 NVFP4 with a Sylvester Hadamard fused into input quantization.
-
HummingMxFp6LinearKernel–Humming GEMM for packed MXFP6 E2M3 and E3M2 weights.
-
MarlinMxfp8LinearKernel–MXFP8 W8A16 GEMM via Marlin (SM80+).
-
MarlinNvFp4LinearKernel–NVFP4 weight-only GEMM via Marlin (W4A16).
-
MxFp4LinearKernel–Base class for MXFP4 quantized linear kernels.
-
MxFp4LinearLayerConfig–Configuration for an MXFP4 linear layer.
-
MxFp6LinearKernel–Base class for MXFP6 quantized linear kernels.
-
MxFp6LinearLayerConfig–Configuration for an MXFP6 linear layer.
-
Mxfp8LinearLayerConfig–Configuration for an MXFP8 linear layer.
-
NvFp4LinearKernel–Base class for NVFP4 quantized linear kernels.
-
NvFp4LinearLayerConfig–Configuration for an NVFP4 linear layer.
-
RDNAHybridW4A16LinearKernel–Hybrid W4A16 kernel: HIP skinny for decode, Triton for prefill.
-
Rdna3W4A8MxFp4LinearKernel–MXFP4 GEMM for RDNA3/RDNA3.5: W4A8 int8-dot GEMV for M <= 8, dequant +
-
TorchMxFp8LinearKernel–MXFP8 W8A8 GEMM using the native
torch._scaled_mmdispatch. -
TorchNvFp4LinearKernel–NVFP4 GEMM implemented with PyTorch's native
torch._scaled_mm. -
TritonW4A16LinearKernel–Triton-based W4A16 GEMM kernel for ROCm (MI300 and newer).
-
XPUMxFp8LinearKernel–MXFP8 W8A8 GEMM on XPU.
-
XPUW4A8IntLinearKernel–XPU kernel for W4A8 integer quantization using oneDNN int4_gemm_w4a8.
-
ZentorchInt8ScaledMMLinearKernel– -
ZentorchWNA16LinearKernel–Int4 kernel backed by
zentorch_dynamic_qlinear(DA8W4) or
Functions:
-
choose_mp_linear_kernel–Choose an MPLinearKernel that can implement the given config for the given
-
fp8_scaled_mm_is_batch_invariant–Whether a row's output from the kernel is independent of the other rows.
-
init_mxfp4_linear_kernel–Select and instantiate the best MXFP4 linear kernel for the
-
init_mxfp6_linear_kernel–Select and instantiate the best MXFP6 linear kernel for the
-
init_mxfp8_linear_kernel–Select and instantiate the best MXFP8 linear kernel for the
-
init_nvfp4_linear_kernel–Select and instantiate the best NVFP4 linear kernel for the
-
register_linear_kernel–Register a new linear kernel class to be considered in kernel selection.
AiterInt8ScaledMMLinearKernel
¶
Bases: CutlassInt8ScaledMMLinearKernel
Methods:
-
apply_weights–AiterInt8ScaledMMLinearKernelimplements a fused version of
Source code in vllm/model_executor/kernels/linear/scaled_mm/aiter.py
39 40 41 42 43 44 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 | |
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.
Source code in vllm/model_executor/kernels/linear/scaled_mm/aiter.py
AiterMxfp4LinearKernel
¶
Bases: MxFp4LinearKernel
AITER-based native MXFP4 GEMM kernel for ROCm.
Source code in vllm/model_executor/kernels/linear/mxfp4/aiter.py
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 268 269 270 | |
B12xFp8BlockScaledMMKernel
¶
Bases: Fp8BlockScaledMMLinearKernel
K128 block-FP8 linear through the native B12X SM120 dense GEMM.
Source code in vllm/model_executor/kernels/linear/scaled_mm/b12x.py
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 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 | |
B12xMxFp4LinearKernel
¶
Bases: MxFp4LinearKernel
MXFP4 linear through the native B12X SM120 dense GEMM.
Source code in vllm/model_executor/kernels/linear/mxfp4/b12x.py
B12xMxfp8LinearKernel
¶
Bases: Mxfp8LinearKernel
ModelOpt MXFP8 linear through the native b12x SM120 dense GEMM path.
Source code in vllm/model_executor/kernels/linear/mxfp8/b12x.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 149 150 151 | |
B12xNvFp4LinearKernel
¶
Bases: NvFp4LinearKernel
ModelOpt NVFP4 linear through the native B12X SM120 dense GEMM.
Source code in vllm/model_executor/kernels/linear/nvfp4/b12x.py
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 | |
B12xNvFp4W4A16LinearKernel
¶
Bases: B12xNvFp4LinearKernel
BF16 x NVFP4 GEMM without activation quantization.
Source code in vllm/model_executor/kernels/linear/nvfp4/b12x.py
B12xTensorFP8ScaledMMLinearKernel
¶
Bases: FP8ScaledMMLinearKernel
Static per-tensor FP8 linear through the B12X SM12x dense GEMM.
Source code in vllm/model_executor/kernels/linear/scaled_mm/b12x.py
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 | |
CutlassFP8ScaledMMLinearKernel
¶
Bases: FP8ScaledMMLinearKernel
Methods:
-
input_quant_key–Static per-tensor and dynamic per-token activations can be quantized
Source code in vllm/model_executor/kernels/linear/scaled_mm/cutlass.py
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 | |
_pad_to_alignment(x, dim, alignment, value=0.0)
staticmethod
¶
Pad tensor x along dim to the next multiple of
alignment.
Source code in vllm/model_executor/kernels/linear/scaled_mm/cutlass.py
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.
Source code in vllm/model_executor/kernels/linear/scaled_mm/cutlass.py
CutlassNvFp4LinearKernel
¶
Bases: NvFp4LinearKernel
NVFP4 GEMM via the vLLM CUTLASS kernel.
Source code in vllm/model_executor/kernels/linear/nvfp4/cutlass.py
EmulationMxfp4LinearKernel
¶
Bases: MxFp4LinearKernel
Software emulation fallback for OCP MXFP4/MXFP6 (dequant + F.linear).
Source code in vllm/model_executor/kernels/linear/mxfp4/emulation.py
43 44 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 | |
EmulationMxfp6LinearKernel
¶
Bases: MxFp6LinearKernel
Software emulation fallback for OCP MXFP4/MXFP6 (dequant + F.linear).
Source code in vllm/model_executor/kernels/linear/mxfp6/emulation.py
EmulationMxfp8LinearKernel
¶
Bases: Mxfp8LinearKernel
Software emulation fallback for MXFP8 (dequant to BF16).
Source code in vllm/model_executor/kernels/linear/mxfp8/emulation.py
EmulationNvFp4LinearKernel
¶
Bases: NvFp4LinearKernel
Software emulation fallback for NVFP4 (dequant → BF16 matmul).
Source code in vllm/model_executor/kernels/linear/nvfp4/emulation.py
FbgemmNvFp4LinearKernel
¶
Bases: NvFp4LinearKernel
NVFP4 GEMM via FBGEMM.
Source code in vllm/model_executor/kernels/linear/nvfp4/fbgemm.py
FlashInferB12xNvFp4LinearKernel
¶
Bases: NvFp4LinearKernel
NVFP4 GEMM via FlashInfer's b12x CuTe DSL warp-level MMA kernel (SM12x).
Source code in vllm/model_executor/kernels/linear/nvfp4/flashinfer.py
FlashInferCudnnNvFp4LinearKernel
¶
Bases: NvFp4LinearKernel
NVFP4 GEMM via FlashInfer's cuDNN wrapper.
Source code in vllm/model_executor/kernels/linear/nvfp4/flashinfer.py
FlashInferCuteDslNvFp4LinearKernel
¶
Bases: NvFp4LinearKernel
NVFP4 GEMM via FlashInfer's cutedsl backend.
Source code in vllm/model_executor/kernels/linear/nvfp4/flashinfer.py
FlashInferCuteDslNvFp4W4A16LinearKernel
¶
Bases: NvFp4LinearKernel
BF16 x NVFP4 GEMM via FlashInfer's CuTe-DSL backend.
Source code in vllm/model_executor/kernels/linear/nvfp4/flashinfer.py
FlashInferCutedslMxfp8LinearKernel
¶
Bases: Mxfp8LinearKernel
MXFP8 W8A8 GEMM via FlashInfer CuTe-DSL (SM100/SM103).
Source code in vllm/model_executor/kernels/linear/mxfp8/flashinfer.py
FlashInferCutlassMxfp8LinearKernel
¶
Bases: Mxfp8LinearKernel
MXFP8 W8A8 GEMM via FlashInfer CUTLASS (SM100+).
Source code in vllm/model_executor/kernels/linear/mxfp8/flashinfer.py
FlashInferCutlassNvFp4LinearKernel
¶
Bases: NvFp4LinearKernel
NVFP4 GEMM via FlashInfer's CUTLASS wrapper.
Methods:
-
input_quant_key–This kernel supports dynamic quantization of the input. By
Source code in vllm/model_executor/kernels/linear/nvfp4/flashinfer.py
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.
Source code in vllm/model_executor/kernels/linear/scaled_mm/flashinfer.py
FlashInferMxFp4LinearKernel
¶
Bases: MxFp4LinearKernel
MXFP4 W4A4 GEMM via FlashInfer CUTLASS (SM100+).
Source code in vllm/model_executor/kernels/linear/mxfp4/flashinfer.py
FlashInferTrtllmMxfp8LinearKernel
¶
Bases: Mxfp8LinearKernel
MXFP8 W8A8 GEMM via FlashInfer's TensorRT-LLM wrapper.
Source code in vllm/model_executor/kernels/linear/mxfp8/flashinfer.py
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 | |
FlashInferTrtllmNvFp4LinearKernel
¶
Bases: NvFp4LinearKernel
NVFP4 GEMM via FlashInfer's TensorRT-LLM wrapper.
Source code in vllm/model_executor/kernels/linear/nvfp4/flashinfer.py
HummingHadamardNvFp4LinearKernel
¶
Bases: HummingNvFp4LinearKernel
Humming W4A4 NVFP4 with a Sylvester Hadamard fused into input quantization.
Runs the activation dtype the checkpoint declares, without A16 fallback.
Source code in vllm/model_executor/kernels/linear/nvfp4/humming.py
HummingMxFp6LinearKernel
¶
Bases: MxFp6LinearKernel
Humming GEMM for packed MXFP6 E2M3 and E3M2 weights.
Source code in vllm/model_executor/kernels/linear/mxfp6/humming.py
MarlinMxfp8LinearKernel
¶
Bases: Mxfp8LinearKernel
MXFP8 W8A16 GEMM via Marlin (SM80+).
Source code in vllm/model_executor/kernels/linear/mxfp8/marlin.py
MarlinNvFp4LinearKernel
¶
Bases: NvFp4LinearKernel
NVFP4 weight-only GEMM via Marlin (W4A16).
Source code in vllm/model_executor/kernels/linear/nvfp4/marlin.py
MxFp4LinearKernel
¶
Bases: ABC
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:
-
apply_weights–Run the quantized GEMM.
-
can_implement–Return whether this kernel can handle config.
-
executed_activation_key–The activation quantization the kernel runs for a layer requesting
-
fuse_input_hadamard–Rotate the input by the size-
sizeblock Hadamard matrix inside -
is_supported–Return whether this kernel can run on the current platform.
-
process_weights_after_loading–Transform weights into the format required by this kernel.
Source code in vllm/model_executor/kernels/linear/mxfp4/base.py
_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.
Source code in vllm/model_executor/kernels/linear/mxfp4/base.py
apply_weights(layer, x, bias=None)
abstractmethod
¶
Run the quantized GEMM.
can_implement(config)
abstractmethod
classmethod
¶
Return whether this kernel can handle config.
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.
Source code in vllm/model_executor/kernels/linear/mxfp4/base.py
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.
Source code in vllm/model_executor/kernels/linear/mxfp4/base.py
is_supported(compute_capability=None)
abstractmethod
classmethod
¶
Return whether this kernel can run on the current platform.
process_weights_after_loading(layer)
abstractmethod
¶
Transform weights into the format required by this kernel.
Called once after checkpoint weights have been loaded onto the device. Implementations should repack / swizzle / pad weights and scales in-place on layer.
Source code in vllm/model_executor/kernels/linear/mxfp4/base.py
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
Nonewhen activations must not be quantized.
Source code in vllm/model_executor/kernels/linear/mxfp4/base.py
MxFp6LinearKernel
¶
Bases: ABC
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.
Methods:
-
apply_weights–Run the quantized GEMM.
-
can_implement–Return whether this kernel can handle config.
-
executed_activation_key–The activation quantization the kernel runs for a layer requesting
-
is_supported–Return whether this kernel can run on the current platform.
-
process_weights_after_loading–Transform weights into the format required by this kernel.
Source code in vllm/model_executor/kernels/linear/mxfp6/base.py
apply_weights(layer, x, bias=None)
abstractmethod
¶
Run the quantized GEMM.
can_implement(config)
abstractmethod
classmethod
¶
Return whether this kernel can handle config.
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.
Source code in vllm/model_executor/kernels/linear/mxfp6/base.py
is_supported(compute_capability=None)
abstractmethod
classmethod
¶
Return whether this kernel can run on the current platform.
process_weights_after_loading(layer)
abstractmethod
¶
Transform weights into the format required by this kernel.
Called once after checkpoint weights have been loaded onto the device. Implementations should repack / swizzle / pad weights and scales in-place on layer.
Source code in vllm/model_executor/kernels/linear/mxfp6/base.py
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
Nonewhen activations must not be quantized.
Source code in vllm/model_executor/kernels/linear/mxfp6/base.py
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:
Source code in vllm/model_executor/kernels/linear/mxfp8/Mxfp8LinearKernel.py
NvFp4LinearKernel
¶
Bases: ABC
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:
-
apply_weights–Run the quantized GEMM.
-
can_implement–Return whether this kernel can handle config.
-
executed_activation_key–The activation quantization the kernel runs for a layer requesting
-
input_quant_key–Return the input quantization key supported by this kernel. If the kernel
-
is_supported–Return whether this kernel can run on the current platform.
-
prepare_input–Return 2D packed NVFP4 data with swizzled 128x4 block scales.
-
process_weights_after_loading–Transform weights into the format required by this kernel.
Source code in vllm/model_executor/kernels/linear/nvfp4/base.py
37 38 39 40 41 42 43 44 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 | |
apply_weights(layer, x, bias=None)
abstractmethod
¶
Run the quantized GEMM.
can_implement(config)
abstractmethod
classmethod
¶
Return whether this kernel can handle config.
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.
Source code in vllm/model_executor/kernels/linear/nvfp4/base.py
input_quant_key()
¶
Return the input quantization key supported by this kernel. If the kernel does not support input quantization outside of the kernel, return None.
is_supported(compute_capability=None)
abstractmethod
classmethod
¶
Return whether this kernel can run on the current platform.
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.
Source code in vllm/model_executor/kernels/linear/nvfp4/base.py
process_weights_after_loading(layer)
abstractmethod
¶
Transform weights into the format required by this kernel.
Called once after checkpoint weights have been loaded onto the device. Implementations should repack / swizzle / pad weights and scales in-place on layer.
Source code in vllm/model_executor/kernels/linear/nvfp4/base.py
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.
Source code in vllm/model_executor/kernels/linear/nvfp4/base.py
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.
Source code in vllm/model_executor/kernels/linear/mixed_precision/rdna_hybrid_w4a16.py
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 | |
Rdna3W4A8MxFp4LinearKernel
¶
Bases: MxFp4LinearKernel
MXFP4 GEMM for RDNA3/RDNA3.5: W4A8 int8-dot GEMV for M <= 8, dequant + high-precision GEMM above.
Source code in vllm/model_executor/kernels/linear/mxfp4/rdna3_hip.py
TorchMxFp8LinearKernel
¶
Bases: Mxfp8LinearKernel
MXFP8 W8A8 GEMM using the native torch._scaled_mm dispatch.
Supported on XPU (oneDNN) and CUDA (cuBLASLt, SM90+).
Source code in vllm/model_executor/kernels/linear/mxfp8/pytorch.py
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.
Source code in vllm/model_executor/kernels/linear/nvfp4/pytorch.py
TritonW4A16LinearKernel
¶
Bases: MPLinearKernel
Triton-based W4A16 GEMM kernel for ROCm (MI300 and newer).
Supports GPTQ-format int4 weights (uint4b8 symmetric, uint4 asymmetric) with grouped quantization. Weight tensors are transposed from the compressed-tensors checkpoint layout to the kernel's [K, N//8] layout.
Methods:
-
process_weights_after_loading–Convert compressed-tensors checkpoint layout to kernel layout.
Source code in vllm/model_executor/kernels/linear/mixed_precision/triton_w4a16.py
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 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
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)
Source code in vllm/model_executor/kernels/linear/mixed_precision/triton_w4a16.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | |
XPUMxFp8LinearKernel
¶
Bases: Mxfp8LinearKernel
MXFP8 W8A8 GEMM on XPU.
Source code in vllm/model_executor/kernels/linear/mxfp8/xpu.py
_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.
Source code in vllm/model_executor/kernels/linear/mxfp8/xpu.py
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.
Source code in vllm/model_executor/kernels/linear/mixed_precision/xpu.py
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 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 | |
ZentorchInt8ScaledMMLinearKernel
¶
Bases: Int8ScaledMMLinearKernel
Methods:
-
process_weights_after_loading–Prepare weights for
zentorch_dynamic_qlinear.
Source code in vllm/model_executor/kernels/linear/scaled_mm/zentorch.py
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,).
Source code in vllm/model_executor/kernels/linear/scaled_mm/zentorch.py
ZentorchWNA16LinearKernel
¶
Bases: CPUWNA16LinearKernel
Int4 kernel backed by zentorch_dynamic_qlinear (DA8W4) or
zentorch_woq_linear (W4A16).
Methods:
-
process_weights_after_loading–Repack CT GPTQ weights into the zentorch DA8W4 or WOQ layout.
Source code in vllm/model_executor/kernels/linear/mixed_precision/zentorch.py
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 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 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 | |
_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.
Source code in vllm/model_executor/kernels/linear/mixed_precision/zentorch.py
_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).
Source code in vllm/model_executor/kernels/linear/mixed_precision/zentorch.py
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
Source code in vllm/model_executor/kernels/linear/mixed_precision/zentorch.py
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 | |
_filter_kernels_by_backend(backend, kernels)
¶
Prefer matching kernels, falling back to auto by layer type.
Source code in vllm/model_executor/kernels/linear/__init__.py
_get_linear_backend(*, quantization)
¶
Get the linear_backend setting from the current vllm config.
Source code in vllm/model_executor/kernels/linear/__init__.py
_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).
Source code in vllm/model_executor/kernels/linear/__init__.py
_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.
Source code in vllm/model_executor/kernels/linear/__init__.py
_user_linear_activation_override()
¶
User's linear activation override from quantization_config, or None.
Source code in vllm/model_executor/kernels/linear/__init__.py
_user_linear_activation_override_is_set()
¶
Whether the user set the linear activation, explicit null included.
Source code in vllm/model_executor/kernels/linear/__init__.py
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_platformto get the compute capability. Defaults to None.
Raises:
-
ValueError–If no kernel can implement the given config.
Returns:
-
type[MPLinearKernel]–type[MPLinearKernel]: Chosen kernel.
Source code in vllm/model_executor/kernels/linear/__init__.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 | |
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_platformto 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.
Source code in vllm/model_executor/kernels/linear/__init__.py
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 | |
fp8_scaled_mm_is_batch_invariant(kernel)
¶
Whether a row's output from the kernel is independent of the other rows.
Source code in vllm/model_executor/kernels/linear/__init__.py
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.
Source code in vllm/model_executor/kernels/linear/__init__.py
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 | |
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.
Source code in vllm/model_executor/kernels/linear/__init__.py
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 | |
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.
Returns a placeholder for requantization sources, which have no kernel.
Source code in vllm/model_executor/kernels/linear/__init__.py
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 | |
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:
-
NvFp4LinearKernel–The kernel, or a placeholder for requantization sources, which have
-
NvFp4LinearKernel–no kernel.
Source code in vllm/model_executor/kernels/linear/__init__.py
1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 | |
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.