[Qwen-MOE] Fix memory duplication issues in case layers weights are re-assigned during weight loading (#18255)

This commit is contained in:
fxmarty-amd
2026-03-10 18:34:56 +01:00
committed by GitHub
parent 11d9c36c2f
commit 031d0a2aad
3 changed files with 8 additions and 12 deletions

View File

@@ -1043,10 +1043,9 @@ class Qwen3MoeForCausalLM(nn.Module):
num_experts=self.config.num_experts,
)
# Cache params_dict to avoid repeated expensive traversal of model parameters
if not hasattr(self, "_cached_params_dict"):
self._cached_params_dict = dict(self.named_parameters())
params_dict = self._cached_params_dict
# Pre-define `params_dict` to avoid repeated expensive traversal of model parameters.
params_dict = dict(self.named_parameters())
for name, loaded_weight in weights:
layer_id = get_layer_id(name)
if (

View File

@@ -524,10 +524,8 @@ class Qwen3OmniMoeForConditionalGeneration(PreTrainedModel):
num_experts = self.config.num_experts
# Cache params_dict to avoid repeated expensive traversal of model parameters
if not hasattr(self, "_cached_params_dict"):
self._cached_params_dict = dict(self.named_parameters())
params_dict = self._cached_params_dict
# Pre-define `params_dict` to avoid repeated expensive traversal of model parameters.
params_dict = dict(self.named_parameters())
for name, loaded_weight in weights:
name = name.replace(r"model.language_model.", r"model.")

View File

@@ -226,10 +226,9 @@ class Qwen3VLMoeForConditionalGeneration(Qwen3VLForConditionalGeneration):
num_experts = self.config.num_experts
# Cache params_dict to avoid repeated expensive traversal of model parameters
if not hasattr(self, "_cached_params_dict"):
self._cached_params_dict = dict(self.named_parameters())
params_dict = self._cached_params_dict
# Pre-define `params_dict` to avoid repeated expensive traversal of model parameters.
params_dict = dict(self.named_parameters())
for name, loaded_weight in weights:
name = name.replace(r"model.language_model.", r"model.")