From 53fc16640281a939e01c98be80fa67179ba9a088 Mon Sep 17 00:00:00 2001 From: Ilya Markov Date: Thu, 29 Jan 2026 09:52:11 +0100 Subject: [PATCH] [BugFix] Fix EPLB fail for MoeFP4 model with Marlin backend (#33262) Signed-off-by: ilmarkov --- vllm/model_executor/utils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/vllm/model_executor/utils.py b/vllm/model_executor/utils.py index d4e87707c8..0b844d1493 100644 --- a/vllm/model_executor/utils.py +++ b/vllm/model_executor/utils.py @@ -44,7 +44,9 @@ def set_weight_attrs( setattr(weight, key, value) -def replace_parameter(layer: torch.nn.Module, param_name: str, new_data: torch.Tensor): +def replace_parameter( + layer: torch.nn.Module, param_name: str, new_data: torch.Tensor | None +): """ Replace a parameter of a layer while maintaining the ability to reload the weight. Called within implementations of the `process_weights_after_loading` method. @@ -54,9 +56,15 @@ def replace_parameter(layer: torch.nn.Module, param_name: str, new_data: torch.T Args: layer: Layer containing parameter to replace param_name: Name of parameter to replace - new_data: New data of the new parameter + new_data: New data of the new parameter, or None to set the parameter to None """ # should not be used on a tied/shared param + + # If new_data is None, set the parameter to None + if new_data is None: + setattr(layer, param_name, None) + return + if isinstance(new_data, torch.nn.Parameter): new_data = new_data.data new_param = torch.nn.Parameter(new_data, requires_grad=False)