[Bugfix] Fix HSDP compatibility with the new online FP8 linear method (#5677)

Signed-off-by: roG0d <baonudesifeizhai@gmail.com>
This commit is contained in:
baonudesifeizhai authored and GitHub committed 2026-08-14 15:45:55 +08:00
1 parent bc73546c06
commit b300f66656
3 files changed
+79 -6

No files matched your search

+32 -2
View File
@@ -36,15 +36,23 @@ class _ToyKernel:
# --- helper to build a toy module simulating online-FP8 post-load state ---
def _make_fp8_toy_module(out_features: int = 16, in_features: int = 32):
def _make_fp8_toy_module(
out_features: int = 16,
in_features: int = 32,
*,
quant_method_cls=None,
):
"""Return a module whose weight is ``qweight.t()`` (non-contiguous) and whose
``quant_method`` is an ``Fp8LinearMethod`` with a ``_ToyKernel``.
"""
from vllm.model_executor.layers.quantization.fp8 import Fp8LinearMethod
if quant_method_cls is None:
quant_method_cls = Fp8LinearMethod
# Create the quant-method instance without calling __init__ (avoids
# heavyweight upstream config dependencies). isinstance() still works.
qm = object.__new__(Fp8LinearMethod)
qm = object.__new__(quant_method_cls)
qm.fp8_linear = _ToyKernel()
# randn does not support float8 on CPU; zeros does and the test only
@@ -104,6 +112,28 @@ def test_rewrites_non_contiguous_weight():
assert module.weight.shape == (16, 32)
def test_rewrites_per_tensor_online_fp8_weight():
"""Regression test for vLLM's new online FP8 frontend (#45463)."""
from vllm.model_executor.layers.quantization.online.fp8 import (
Fp8PerTensorOnlineLinearMethod,
)
module = _make_fp8_toy_module(
16,
32,
quant_method_cls=Fp8PerTensorOnlineLinearMethod,
)
n_rewritten_layers = prepare_fp8_layers_for_fsdp(module)
assert n_rewritten_layers == 1
assert module.weight.is_contiguous()
assert module.weight.shape == (16, 32)
w, *_ = module.quant_method.fp8_linear._get_layer_params(module)
assert w.shape == (32, 16)
assert w.stride() == (1, 32)
def test_patched_get_layer_params_returns_transposed_view():
module = _make_fp8_toy_module(16, 32)
prepare_fp8_layers_for_fsdp(module)