diff --git a/vllm/model_executor/layers/fused_moe/oracle/mxfp4.py b/vllm/model_executor/layers/fused_moe/oracle/mxfp4.py index cd4b30b772..e6e9d17925 100644 --- a/vllm/model_executor/layers/fused_moe/oracle/mxfp4.py +++ b/vllm/model_executor/layers/fused_moe/oracle/mxfp4.py @@ -1146,8 +1146,13 @@ def convert_gpt_oss_weight_to_mxfp4_moe_kernel_format( weight_scale=w2_scale, flex_ctx=FlexCtx(rhs_data=w2_flex) ) + # The original mxfp4 block scales have been swizzled into the + # precision configs above and are no longer read by the kernel, so + # drop the now-dead weight/scale Parameters to free their memory. del layer.w13_weight del layer.w2_weight + del layer.w13_weight_scale + del layer.w2_weight_scale return ( w13_weight, @@ -1508,8 +1513,13 @@ def convert_weight_to_mxfp4_moe_kernel_format( weight_scale=w2_scale, flex_ctx=FlexCtx(rhs_data=w2_flex) ) + # The original mxfp4 block scales have been swizzled into the + # precision configs above and are no longer read by the kernel, so + # drop the now-dead weight/scale Parameters to free their memory. del layer.w13_weight del layer.w2_weight + del layer.w13_weight_scale + del layer.w2_weight_scale return ( w13_weight, diff --git a/vllm/model_executor/layers/quantization/mxfp4.py b/vllm/model_executor/layers/quantization/mxfp4.py index 1b2a8a74bd..5ef5fd40d5 100644 --- a/vllm/model_executor/layers/quantization/mxfp4.py +++ b/vllm/model_executor/layers/quantization/mxfp4.py @@ -393,16 +393,19 @@ class GptOssMxfp4MoEMethod(FusedMoEMethodBase): def get_fused_moe_quant_config( self, layer: RoutedExperts ) -> FusedMoEQuantConfig | None: - w1_scale = layer.w13_weight_scale - w2_scale = layer.w2_weight_scale w1_bias = getattr(layer, "w13_bias", None) w2_bias = getattr(layer, "w2_bias", None) if self.mxfp4_backend in TRITON_BACKENDS: + # TRITON backends free w13/w2_weight_scale after swizzling; the + # swizzled scales live inside the precision configs instead. assert self.w13_precision_config is not None assert self.w2_precision_config is not None w1_scale = self.w13_precision_config w2_scale = self.w2_precision_config + else: + w1_scale = layer.w13_weight_scale + w2_scale = layer.w2_weight_scale return make_mxfp4_moe_quant_config( mxfp4_backend=self.mxfp4_backend, @@ -738,17 +741,20 @@ class Mxfp4MoEMethod(FusedMoEMethodBase): self, layer: RoutedExperts, ) -> FusedMoEQuantConfig | None: - w1_scale = layer.w13_weight_scale - w2_scale = layer.w2_weight_scale w1_bias = getattr(layer, "w13_bias", None) w2_bias = getattr(layer, "w2_bias", None) swiglu_limit = getattr(layer, "swiglu_limit", None) if self.mxfp4_backend in TRITON_BACKENDS: + # TRITON backends free w13/w2_weight_scale after swizzling; the + # swizzled scales live inside the precision configs instead. assert self.w13_precision_config is not None assert self.w2_precision_config is not None w1_scale = self.w13_precision_config w2_scale = self.w2_precision_config + else: + w1_scale = layer.w13_weight_scale + w2_scale = layer.w2_weight_scale return make_mxfp4_moe_quant_config( mxfp4_backend=self.mxfp4_backend,