[Qwen-MOE] Fix memory duplication issues in case layers weights are re-assigned during weight loading (#18255)
This commit is contained in:
@@ -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 (
|
||||
|
||||
@@ -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.")
|
||||
|
||||
@@ -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.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user