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– -
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 (SM120+).
-
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.
-
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
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
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 | |
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 | |
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
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
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 | |
CutlassFP8ScaledMMLinearKernel
¶
Bases: FP8ScaledMMLinearKernel
Methods:
-
input_quant_key–Only static per-tensor activation quantization is supported for external
Source code in vllm/model_executor/kernels/linear/scaled_mm/cutlass.py
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 | |
_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()
¶
Only static per-tensor activation quantization is supported for external quantization.
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 (SM120+).
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
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 | |
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
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.
-
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.
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.
-
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.
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.
-
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.
-
process_weights_after_loading–Transform weights into the format required by this kernel.
Source code in vllm/model_executor/kernels/linear/nvfp4/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.
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.
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.
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
711 712 713 714 715 716 717 718 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 798 799 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 | |
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
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 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 | |
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
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 | |
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
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 | |
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
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 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 | |
_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
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 | |
_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).
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
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
choose_scaled_mm_linear_kernel(config, possible_kernels, compute_capability=None, force_kernel=None, *, quantization)
¶
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.
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
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.
Source code in vllm/model_executor/kernels/linear/__init__.py
init_mxfp6_linear_kernel(weight_quant_key, activation_quant_key=None)
¶
Select and instantiate the best MXFP6 linear kernel for the current platform.
Source code in vllm/model_executor/kernels/linear/__init__.py
init_mxfp8_linear_kernel(*, weight_shape, bmm_batch_size=None)
¶
Select and instantiate the best MXFP8 linear kernel for the
current platform and (N, K) weight shape.
Source code in vllm/model_executor/kernels/linear/__init__.py
init_nvfp4_linear_kernel(use_a16=False)
¶
Select and instantiate the best NVFP4 linear kernel for the current platform.
Source code in vllm/model_executor/kernels/linear/__init__.py
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 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 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 | |
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.