Compare commits

..
Author SHA1 Message Date
Matej SirovatkaandGitHub 7a7dd80291 feat(inference): add online quantization config (#3031)
Docker Push / Push CUDA image to Docker (push) Canceled after 0s
* feat(inference): add online quantization config

* fix(config): report missing torch for mxfp8
2026-07-15 01:12:49 +02:00
2 changed files with 51 additions and 0 deletions
@@ -366,6 +366,9 @@ class InferenceConfig(BaseConfig):
gpu_memory_utilization: float = 0.9
"""GPU memory utilization. Forwarded as ``--gpu-memory-utilization``."""
quantization: Literal["mxfp8", "fp8_per_block"] | None = None
"""Online inference quantization method. Forwarded as ``--quantization``."""
api_server_count: int = Field(1, ge=0)
"""API servers to run. Forwarded as ``--api-server-count``. Set to 0 for headless mode."""
@@ -432,6 +435,24 @@ class InferenceConfig(BaseConfig):
raise ValueError("Must use SLURM for multi-node / disaggregated deployment.")
return self
@model_validator(mode="after")
def validate_mxfp8_requires_sm100(self):
"""Reject MXFP8 when validation runs on a non-SM100 CUDA host."""
if self.quantization != "mxfp8":
return self
try:
import torch
except ModuleNotFoundError as exc:
raise ValueError("inference.quantization='mxfp8' requires torch to validate SM100 support.") from exc
if torch.cuda.is_available():
capability = torch.cuda.get_device_capability()
if capability != (10, 0):
detected = f"SM{capability[0]}{capability[1]}"
raise ValueError(f"inference.quantization='mxfp8' requires SM100, detected {detected}.")
return self
@model_validator(mode="after")
def validate_llmd_no_routed_experts(self):
"""Reject routed-expert return with the llm-d router (breaks P/D, unverified for multi-node)."""
@@ -576,6 +597,7 @@ class InferenceConfig(BaseConfig):
"max_lora_rank": "max_lora_rank",
"lora_target_modules": "lora_target_modules",
"gpu_memory_utilization": "gpu_memory_utilization",
"quantization": "quantization",
"api_server_count": "api_server_count",
"enable_return_routed_experts": "enable_return_routed_experts",
"enable_expert_parallel": "enable_expert_parallel",
@@ -625,6 +647,10 @@ class InferenceConfig(BaseConfig):
if hasattr(namespace, "lora_target_modules") and namespace.lora_target_modules is None:
delattr(namespace, "lora_target_modules")
# Remove quantization if not set so vLLM can infer it from the checkpoint.
if namespace.quantization is None:
delattr(namespace, "quantization")
# Remove rope_scaling if not set (vLLM doesn't accept None)
if hasattr(namespace, "rope_scaling"):
if namespace.rope_scaling is None:
+25
View File
@@ -19,6 +19,31 @@ def apply_shared_vllm_patches():
monkey_patch_vllm_padded_input_scrub()
monkey_patch_return_routed_experts_with_nixl_connector()
monkey_patch_kv_xfer_finished_tolerate_freed()
monkey_patch_online_fp8_parameter_cast()
def monkey_patch_online_fp8_parameter_cast():
"""Pass plain tensors to vLLM's compiled block-FP8 caster.
Layerwise reload restores ``ModelWeightParameter`` objects before online
quantization. TorchDynamo recursively dispatches that tensor subclass while
tracing ``per_block_cast_to_fp8``. ``Parameter.data`` shares storage but is
a plain tensor, matching the input accepted during the initial model load.
"""
from torch.nn import Parameter
from vllm.model_executor.layers.quantization.online import fp8
original_cast = fp8.per_block_cast_to_fp8
if getattr(original_cast, "_prime_rl_unwraps_parameters", False):
return
def _per_block_cast_to_fp8(x, *args, **kwargs):
if isinstance(x, Parameter):
x = x.data
return original_cast(x, *args, **kwargs)
_per_block_cast_to_fp8._prime_rl_unwraps_parameters = True
fp8.per_block_cast_to_fp8 = _per_block_cast_to_fp8
def monkey_patch_kv_xfer_finished_tolerate_freed():