[Bugfix][Quantization] Fix MXFP8 startup crash on layers below mm_mxfp8 shape limits (#54223)

Signed-off-by: samuelkim7 <samuelmwkim@gmail.com>
Signed-off-by: mgoin <mgoin64@gmail.com>
Co-authored-by: mgoin <mgoin64@gmail.com>
This commit is contained in:
Samuel Kim
2026-09-25 02:54:11 +00:00
committed by GitHub
co-authored by mgoin
parent 6936e77ba4
commit f55419c43c
16 changed files with 221 additions and 57 deletions
@@ -880,10 +880,15 @@ def choose_mp_linear_kernel(
)
def init_mxfp8_linear_kernel(*, bmm_batch_size: int | None = None) -> Mxfp8LinearKernel:
def init_mxfp8_linear_kernel(
*, weight_shape: tuple[int, int], bmm_batch_size: int | None = None
) -> Mxfp8LinearKernel:
"""Select and instantiate the best MXFP8 linear kernel for the
current platform."""
config = Mxfp8LinearLayerConfig(bmm_batch_size=bmm_batch_size)
current platform and `(N, K)` weight shape."""
config = Mxfp8LinearLayerConfig(
weight_shape=weight_shape,
bmm_batch_size=bmm_batch_size,
)
platform = current_platform._enum
possible: list[type[Mxfp8LinearKernel]]
@@ -15,8 +15,13 @@ class Mxfp8LinearLayerConfig:
All MXFP8 layers share the same structure: FP8-E4M3 weights with
uint8 (E8M0) per-block scales at block size 32.
Attributes:
weight_shape: The layer's `(out_features, in_features)`, i.e. `(N, K)`.
"""
weight_shape: tuple[int, int]
bmm_batch_size: int | None = None
@@ -24,6 +24,20 @@ from vllm.utils.flashinfer import has_flashinfer, has_flashinfer_cutedsl
from .Mxfp8LinearKernel import Mxfp8LinearKernel, Mxfp8LinearLayerConfig
def _check_mm_mxfp8_shape(weight_shape: tuple[int, int]) -> tuple[bool, str | None]:
N, K = weight_shape
if K < 128:
return False, f"mm_mxfp8 requires K >= 128, got K={K}."
if K % MXFP8_BLOCK_SIZE != 0:
return (
False,
f"mm_mxfp8 requires K to be divisible by {MXFP8_BLOCK_SIZE}, got K={K}.",
)
if N < 128:
return False, f"mm_mxfp8 requires N >= 128, got N={N}."
return True, None
class FlashInferCutlassMxfp8LinearKernel(Mxfp8LinearKernel):
"""MXFP8 W8A8 GEMM via FlashInfer CUTLASS (SM100+)."""
@@ -43,6 +57,15 @@ class FlashInferCutlassMxfp8LinearKernel(Mxfp8LinearKernel):
@classmethod
def can_implement(cls, c: Mxfp8LinearLayerConfig) -> tuple[bool, str | None]:
can_implement, reason = _check_mm_mxfp8_shape(c.weight_shape)
if not can_implement:
return False, reason
N, _ = c.weight_shape
if current_platform.is_device_capability_family(120) and N % 32 != 0:
return (
False,
f"mm_mxfp8 on SM12x requires N to be divisible by 32, got N={N}.",
)
return True, None
def input_quant_key(self) -> QuantKey:
@@ -72,20 +95,6 @@ class FlashInferCutlassMxfp8LinearKernel(Mxfp8LinearKernel):
weight_scale = layer.weight_scale
N, K = weight.shape
min_dim = 128
assert min_dim <= K, (
f"mm_mxfp8 requires K >= {min_dim}, got K={K}. "
f"in_features is too small for mm_mxfp8."
)
assert K % MXFP8_BLOCK_SIZE == 0, (
f"mm_mxfp8 requires K to be divisible by {MXFP8_BLOCK_SIZE}, got K={K}."
)
assert min_dim <= N, (
f"mm_mxfp8 requires N >= {min_dim}, got N={N}. "
f"out_features is too small for mm_mxfp8."
)
qa = as_quantized_activation(x, self.input_quant_key())
if qa is not None:
input_mxfp8, input_scale = qa.data, qa.scale
@@ -136,7 +145,7 @@ class FlashInferCutedslMxfp8LinearKernel(Mxfp8LinearKernel):
@classmethod
def can_implement(cls, c: Mxfp8LinearLayerConfig) -> tuple[bool, str | None]:
return True, None
return _check_mm_mxfp8_shape(c.weight_shape)
def input_quant_key(self) -> QuantKey:
# Activations use FlashInfer's F8_128x4 swizzled scale layout.
@@ -166,20 +175,6 @@ class FlashInferCutedslMxfp8LinearKernel(Mxfp8LinearKernel):
weight_scale = layer.weight_scale
K, N = weight.shape
min_dim = 128
assert min_dim <= K, (
f"mm_mxfp8 requires K >= {min_dim}, got K={K}. "
f"in_features is too small for mm_mxfp8."
)
assert K % MXFP8_BLOCK_SIZE == 0, (
f"mm_mxfp8 requires K to be divisible by {MXFP8_BLOCK_SIZE}, got K={K}."
)
assert min_dim <= N, (
f"mm_mxfp8 requires N >= {min_dim}, got N={N}. "
f"out_features is too small for mm_mxfp8."
)
qa = as_quantized_activation(x, self.input_quant_key())
if qa is not None:
input_mxfp8, input_scale = qa.data, qa.scale
@@ -3,6 +3,10 @@
import torch
from vllm.model_executor.layers.quantization.utils.mxfp8_utils import (
MXFP8_BLOCK_SIZE,
)
from .Mxfp8LinearKernel import Mxfp8LinearKernel, Mxfp8LinearLayerConfig
@@ -23,6 +27,16 @@ class MarlinMxfp8LinearKernel(Mxfp8LinearKernel):
@classmethod
def can_implement(cls, c: Mxfp8LinearLayerConfig) -> tuple[bool, str | None]:
N, K = c.weight_shape
if N <= 0 or K <= 0:
return False, f"Marlin MXFP8 requires positive N and K, got N={N}, K={K}."
if K % MXFP8_BLOCK_SIZE != 0:
return (
False,
f"Marlin MXFP8 requires K to be divisible by {MXFP8_BLOCK_SIZE}, "
f"got K={K}.",
)
# Tile misalignment is fixed by zero-padding at weight prep.
return True, None
def process_weights_after_loading(self, layer: torch.nn.Module) -> None: