[Bugfix]Fix transformer backend failed: AttributeError: 'Parameter' object has no attribute 'weight_loader' (#48699)

Signed-off-by: Lai, Yejing <yejing.lai@intel.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>

Yejing Lai committed Jul 17, 2026 at 19:43 UTC 7b3192523e194e20077017ed104caff37c1ad691
1 file changed +13 -12
vllm/model_executor/models/transformers/base.py
+13 -12
@@ -587,22 +587,23 @@ class Base(
587 self.model: "PreTrainedModel" = AutoModel.from_config(...)
588 ```
589 """
590 + dtype = dtype or self.model_config.dtype
591 + device = self.device_config.device
592
591 - def _init_parameters(module: nn.Module, dtype: torch.dtype | None):
593 + def _init_parameters(module: nn.Module):
594 for name, param in module.named_parameters(recurse=False):
593 - if param.device == torch.device("meta"):
594 - new_param = nn.Parameter(
595 - torch.empty_like(
596 - param.data,
597 - dtype=dtype or self.model_config.dtype,
598 - device=self.device_config.device,
599 - )
600 - )
601 - setattr(module, name, new_param)
595 + # Already on device, nothing to do
596 + if param.device != torch.device("meta"):
597 + continue
598 + # Already a vLLM parameter, nothing to do
599 + if hasattr(param, "weight_loader"):
600 + continue
601 + data = torch.empty_like(param.data, dtype=dtype, device=device)
602 + setattr(module, name, nn.Parameter(data=data))
603 for child in module.children():
603 - _init_parameters(child, dtype)
604 + _init_parameters(child)
605
605 - _init_parameters(module, dtype)
606 + _init_parameters(module)
607
608 def embed_input_ids(self, input_ids: torch.Tensor) -> torch.Tensor:
609 return self.model.get_input_embeddings()(input_ids)