Skip to content

Commit ba3df56

Browse files
committed
brin in meaningful changes from child PR
Signed-off-by: Felix Marty <Felix.Marty@amd.com>
1 parent 4edcc73 commit ba3df56

9 files changed

Lines changed: 44 additions & 31 deletions

File tree

tests/quantization/test_online_mxfp4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def make_layer(prefix: str) -> RoutedExperts:
350350
input_config={"dtype": "fp4", "is_dynamic": True},
351351
moe=checkpoint_layer.moe_config,
352352
)
353-
online_method = Mxfp4OnlineMoEMethod(layer=online_layer)
353+
online_method = Mxfp4OnlineMoEMethod(moe=online_layer.moe_config)
354354

355355
# `RoutedExperts.__init__` applies this round-up in production; these
356356
# layers are built without a quant config, so it is applied explicitly.

vllm/model_executor/layers/quantization/experts_int8.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ def get_quant_method(
5656
if isinstance(layer, LinearBase):
5757
return UnquantizedLinearMethod()
5858
elif isinstance(layer, RoutedExperts):
59-
return Int8OnlineMoEMethod(layer=layer)
59+
return Int8OnlineMoEMethod(moe=layer.moe_config)
6060
return None

vllm/model_executor/layers/quantization/fp8.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def get_quant_method(
216216
Fp8PerTensorOnlineMoEMethod,
217217
)
218218

219-
return Fp8PerTensorOnlineMoEMethod(layer=layer)
219+
return Fp8PerTensorOnlineMoEMethod(moe=layer.moe_config)
220220
elif isinstance(layer, Attention):
221221
return Fp8KVCacheMethod(self)
222222
return None

vllm/model_executor/layers/quantization/online/base.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
33

4-
from typing import Any
4+
from typing import Any, cast
55

66
import torch
77

88
from vllm.config.quantization import QuantizationConfigArgs, QuantSpec
99
from vllm.logger import init_logger
1010
from vllm.model_executor.layers.fused_moe import (
11+
FusedMoEMethodBase,
1112
RoutedExperts,
1213
)
1314
from vllm.model_executor.layers.fused_moe.unquantized_fused_moe_method import (
@@ -32,6 +33,7 @@
3233
Fp8PerTensorOnlineMoEMethod,
3334
Fp8PtpcOnlineLinearMethod,
3435
Fp8PtpcOnlineMoEMethod,
36+
OnlineLinearBase,
3537
)
3638
from vllm.model_executor.layers.quantization.online.int8 import (
3739
Int8OnlineMoEMethod,
@@ -223,8 +225,11 @@ def get_quant_method(
223225
self.quantized_layers[prefix] = (source, str(spec), None)
224226
cls = target[2]
225227
if isinstance(layer, RoutedExperts):
226-
return cls(layer=layer)
227-
return cls()
228+
assert issubclass(cls, FusedMoEMethodBase)
229+
return cls(moe=layer.moe_config)
230+
assert issubclass(cls, OnlineLinearBase)
231+
linear_method_cls = cast(type[OnlineLinearBase], cls)
232+
return linear_method_cls()
228233

229234
if isinstance(layer, LinearBase):
230235
return UnquantizedLinearMethod()

vllm/model_executor/layers/quantization/online/fp8.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
MarlinFP8ScaledMMLinearKernel,
2424
)
2525
from vllm.model_executor.layers.fused_moe import RoutedExperts
26+
from vllm.model_executor.layers.fused_moe.config import FusedMoEConfig
2627
from vllm.model_executor.layers.fused_moe.oracle.fp8 import (
2728
select_fp8_moe_backend,
2829
)
@@ -111,7 +112,7 @@ def _is_tp_sharded(layer: Module, *, reduces_output_dim: bool = True) -> bool:
111112
return is_row_parallel or (reduces_output_dim and is_column_parallel)
112113

113114

114-
class _Fp8OnlineLinearBase(LinearMethodBase):
115+
class OnlineLinearBase(LinearMethodBase):
115116
"""Shared base for online FP8 linear methods. Loads fp16/bf16 checkpoint
116117
weights onto meta device and materializes them just-in-time."""
117118

@@ -155,7 +156,7 @@ def create_weights(
155156
initialize_online_processing(layer)
156157

157158

158-
class Fp8PerTensorOnlineLinearMethod(_Fp8OnlineLinearBase):
159+
class Fp8PerTensorOnlineLinearMethod(OnlineLinearBase):
159160
"""Online tensorwise FP8 linear quantization.
160161
Loads fp16/bf16 weights and quantizes them per-tensor during loading."""
161162

@@ -256,7 +257,7 @@ def apply(
256257
return self.fp8_linear.apply_weights(layer, x, bias)
257258

258259

259-
class Fp8PerBlockOnlineLinearMethod(_Fp8OnlineLinearBase):
260+
class Fp8PerBlockOnlineLinearMethod(OnlineLinearBase):
260261
"""Online blockwise FP8 linear quantization.
261262
Loads fp16/bf16 weights and quantizes them per-block during loading."""
262263

@@ -336,7 +337,7 @@ def apply(
336337
)
337338

338339

339-
class Fp8PtpcOnlineLinearMethod(_Fp8OnlineLinearBase):
340+
class Fp8PtpcOnlineLinearMethod(OnlineLinearBase):
340341
"""Online PTPC FP8 linear quantization.
341342
342343
Per-output-channel weight scale + dynamic per-token activation scale. The
@@ -443,12 +444,12 @@ def __init__(
443444
self,
444445
*,
445446
weight_block_size: list[int] | None,
446-
layer: torch.nn.Module,
447+
moe: FusedMoEConfig,
447448
weight_key: "QuantKey | None" = None,
448449
activation_key: "QuantKey | None" = None,
449450
allow_vllm_cutlass: bool = False,
450451
):
451-
super().__init__(layer.moe_config)
452+
super().__init__(moe)
452453
self.weight_block_size = weight_block_size
453454
self.block_quant: bool = self.weight_block_size is not None
454455
self.weight_scale_name = (
@@ -555,11 +556,11 @@ class Fp8PerTensorOnlineMoEMethod(_Fp8OnlineMoEBase):
555556
def __init__(
556557
self,
557558
*,
558-
layer: torch.nn.Module,
559+
moe: FusedMoEConfig,
559560
):
560561
super().__init__(
561562
weight_block_size=None,
562-
layer=layer,
563+
moe=moe,
563564
)
564565

565566
def process_weights_after_loading(self, layer: Module) -> None:
@@ -612,11 +613,11 @@ class Fp8PerBlockOnlineMoEMethod(_Fp8OnlineMoEBase):
612613
def __init__(
613614
self,
614615
*,
615-
layer: torch.nn.Module,
616+
moe: FusedMoEConfig,
616617
):
617618
super().__init__(
618619
weight_block_size=[128, 128],
619-
layer=layer,
620+
moe=moe,
620621
)
621622

622623
def maybe_roundup_sizes(
@@ -716,13 +717,13 @@ class Fp8PtpcOnlineMoEMethod(_Fp8OnlineMoEBase):
716717
def __init__(
717718
self,
718719
*,
719-
layer: torch.nn.Module,
720+
moe: FusedMoEConfig,
720721
):
721722
from vllm.model_executor.layers.fused_moe.oracle.fp8 import Fp8MoeBackend
722723

723724
super().__init__(
724725
weight_block_size=None,
725-
layer=layer,
726+
moe=moe,
726727
weight_key=kFp8StaticChannelSym,
727728
activation_key=kFp8DynamicTokenSym,
728729
allow_vllm_cutlass=True,

vllm/model_executor/layers/quantization/online/int8.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
)
1313

1414
from vllm.model_executor.layers.fused_moe import RoutedExperts
15+
from vllm.model_executor.layers.fused_moe.config import FusedMoEConfig
1516
from vllm.model_executor.layers.fused_moe.oracle.int8 import (
1617
convert_to_int8_moe_kernel_format,
1718
make_int8_moe_kernel,
@@ -38,9 +39,9 @@ class Int8OnlineMoEMethod(OnlineMoEMethodBase):
3839
def __init__(
3940
self,
4041
*,
41-
layer: torch.nn.Module,
42+
moe: FusedMoEConfig,
4243
):
43-
super().__init__(layer.moe_config)
44+
super().__init__(moe)
4445
self.int8_backend, self.experts_cls = select_int8_moe_backend(
4546
config=self.moe,
4647
weight_key=kInt8StaticChannelSym,

vllm/model_executor/layers/quantization/online/mxfp4.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
)
1818

1919
from vllm.model_executor.kernels.linear import init_mxfp4_linear_kernel
20+
from vllm.model_executor.layers.fused_moe.config import FusedMoEConfig
2021
from vllm.model_executor.layers.fused_moe.oracle.mxfp4 import (
2122
TRITON_BACKENDS,
2223
Mxfp4MoeBackend,
@@ -27,7 +28,7 @@
2728
select_mxfp4_moe_backend,
2829
)
2930
from vllm.model_executor.layers.quantization.online.fp8 import (
30-
_Fp8OnlineLinearBase,
31+
OnlineLinearBase,
3132
)
3233
from vllm.model_executor.layers.quantization.online.moe_base import (
3334
OnlineMoEMethodBase,
@@ -73,7 +74,7 @@ def _quantize_mxfp4_moe_weight(
7374
return w_quant, w_scales
7475

7576

76-
class Mxfp4OnlineLinearMethod(_Fp8OnlineLinearBase):
77+
class Mxfp4OnlineLinearMethod(OnlineLinearBase):
7778
"""Online MXFP4 linear method.
7879
Loads bf16/fp16 checkpoints and quantizes weights to MXFP4 (microscaling
7980
FP4 with block-32 scales) during weight loading.
@@ -144,8 +145,8 @@ class Mxfp4OnlineMoEMethod(OnlineMoEMethodBase):
144145
experts_cls: "type[mk.FusedMoEExperts] | None"
145146
activation_quant_key = kMxfp4Dynamic
146147

147-
def __init__(self, *, layer: torch.nn.Module):
148-
super().__init__(layer.moe_config)
148+
def __init__(self, *, moe: FusedMoEConfig):
149+
super().__init__(moe)
149150
self.weight_block_size: list[int] = [1, MXFP4_BLOCK_SIZE]
150151
self.weight_scale_name = "weight_scale"
151152

vllm/model_executor/layers/quantization/online/mxfp8.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import torch
99
from torch.nn import Module
1010

11+
from vllm.model_executor.layers.fused_moe.config import FusedMoEConfig
12+
1113
if TYPE_CHECKING:
1214
import vllm.model_executor.layers.fused_moe.modular_kernel as mk
1315
from vllm.model_executor.layers.fused_moe import (
@@ -21,7 +23,7 @@
2123
select_mxfp8_moe_backend,
2224
)
2325
from vllm.model_executor.layers.quantization.online.fp8 import (
24-
_Fp8OnlineLinearBase,
26+
OnlineLinearBase,
2527
)
2628
from vllm.model_executor.layers.quantization.online.moe_base import (
2729
OnlineMoEMethodBase,
@@ -34,7 +36,7 @@
3436
from vllm.platforms import current_platform
3537

3638

37-
class Mxfp8OnlineLinearMethod(_Fp8OnlineLinearBase):
39+
class Mxfp8OnlineLinearMethod(OnlineLinearBase):
3840
"""Online MXFP8 linear method.
3941
Loads bf16/fp16 checkpoints and quantizes weights to MXFP8 (microscaling
4042
FP8 with block-32 scales) during weight loading.
@@ -100,8 +102,8 @@ class Mxfp8OnlineMoEMethod(OnlineMoEMethodBase):
100102
fp8_backend: "Fp8MoeBackend"
101103
experts_cls: "type[mk.FusedMoEExperts] | None"
102104

103-
def __init__(self, *, layer: torch.nn.Module):
104-
super().__init__(layer.moe_config)
105+
def __init__(self, *, moe: FusedMoEConfig):
106+
super().__init__(moe)
105107
self.weight_block_size: list[int] = [1, MXFP8_BLOCK_SIZE]
106108
self.weight_scale_name = "weight_scale"
107109

vllm/model_executor/layers/quantization/online/nvfp4.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
from vllm._custom_ops import scaled_fp4_quant
88
from vllm.model_executor.layers.fused_moe import RoutedExperts
9-
from vllm.model_executor.layers.fused_moe.config import FusedMoEQuantConfig
9+
from vllm.model_executor.layers.fused_moe.config import (
10+
FusedMoEConfig,
11+
FusedMoEQuantConfig,
12+
)
1013
from vllm.model_executor.layers.fused_moe.oracle.nvfp4 import (
1114
convert_to_nvfp4_moe_kernel_format,
1215
make_nvfp4_moe_kernel,
@@ -87,13 +90,13 @@ class Nvfp4OnlineMoEMethod(OnlineMoEMethodBase):
8790
def __init__(
8891
self,
8992
*,
90-
layer: torch.nn.Module,
93+
moe: FusedMoEConfig,
9194
):
9295
if not current_platform.is_device_capability_family(100):
9396
raise ValueError(
9497
"nvfp4_per_token online quantization requires a Blackwell (SM100) GPU."
9598
)
96-
super().__init__(layer.moe_config)
99+
super().__init__(moe)
97100
self.nvfp4_backend, self.experts_cls = select_nvfp4_moe_backend(
98101
config=self.moe,
99102
weight_key=kNvfp4Static,

0 commit comments

Comments
 (0)