ctranslate2-4you commited on
Commit
a5f6029
·
verified ·
1 Parent(s): 3c6073d

Update modeling_qwen3_pseudo_moe.py

Browse files

Fix loading under Transformers 5 (_tied_weights_keys)
Loading fails on Transformers 5.x in post_init() with AttributeError: 'list' object has no attribute 'keys'. The cause is that _tied_weights_keys = [] uses the old list format while config.json sets tie_word_embeddings: true. This sets it to None, the PreTrainedModel default; nothing is tied, since the model has no LM head. It also replaces the deprecated config.use_return_dict with an equivalent expression. Tested with Transformers 4.51.3, 4.57.1 and 5.18.0: all 475 weights load and the embeddings are identical to the original code's.

Files changed (1) hide show
  1. modeling_qwen3_pseudo_moe.py +8 -3
modeling_qwen3_pseudo_moe.py CHANGED
@@ -92,7 +92,9 @@ class MultiLoRALinear(nn.Module):
92
  class Qwen3PseudoMoEModelModel(Qwen3PreTrainedModel):
93
  config_class = Qwen3PseudoMoEConfig
94
  _no_split_modules = ["Qwen3DecoderLayer"]
95
- _tied_weights_keys = []
 
 
96
 
97
  def __init__(self, config: Qwen3PseudoMoEConfig):
98
  super().__init__(config)
@@ -169,7 +171,10 @@ class Qwen3PseudoMoEModelModel(Qwen3PreTrainedModel):
169
  if domain is not None:
170
  self.set_domain(domain)
171
 
172
- return_dict = return_dict if return_dict is not None else self.config.use_return_dict
 
 
 
173
 
174
  outputs = self.model(
175
  input_ids=input_ids,
@@ -222,4 +227,4 @@ class Qwen3PseudoMoEModelModel(Qwen3PreTrainedModel):
222
 
223
 
224
  AutoConfig.register("qwen3_pseudo_moe", Qwen3PseudoMoEConfig)
225
- AutoModel.register(Qwen3PseudoMoEConfig, Qwen3PseudoMoEModelModel)
 
92
  class Qwen3PseudoMoEModelModel(Qwen3PreTrainedModel):
93
  config_class = Qwen3PseudoMoEConfig
94
  _no_split_modules = ["Qwen3DecoderLayer"]
95
+ # Nothing is tied (the model has no LM head). None is the PreTrainedModel default in every Transformers
96
+ # version; the former [] crashes Transformers 5, which expects a dict here when tie_word_embeddings is true.
97
+ _tied_weights_keys = None
98
 
99
  def __init__(self, config: Qwen3PseudoMoEConfig):
100
  super().__init__(config)
 
171
  if domain is not None:
172
  self.set_domain(domain)
173
 
174
+ # Same result as config.use_return_dict, which Transformers 5 deprecates (5.x also drops torchscript).
175
+ return_dict = return_dict if return_dict is not None else (
176
+ getattr(self.config, "return_dict", True) and not getattr(self.config, "torchscript", False)
177
+ )
178
 
179
  outputs = self.model(
180
  input_ids=input_ids,
 
227
 
228
 
229
  AutoConfig.register("qwen3_pseudo_moe", Qwen3PseudoMoEConfig)
230
+ AutoModel.register(Qwen3PseudoMoEConfig, Qwen3PseudoMoEModelModel)