TRF004
Models must never override tie_weights. Use _tied_weights_keys instead.
| Default | Enabled |
| Scope | All models |
| Source | mlinter/trf004.py |
| Show in terminal | mlinter --rule TRF004 |
What it does
Checks that no model class defines a tie_weights method.
Why is this bad?
Overriding tie_weights leads to bad consequences for loading, device_map computation, and saving. Use _tied_weights_keys class attribute to declare tied weights instead.
Example
-def tie_weights(self):
- self.lm_head.weight = self.emb.weight
+class AcmeForCausalLM(AcmePreTrainedModel):
+ _tied_weights_keys = ["lm_head.weight"]
Suppressing this rule
Add a # trf-ignore: TRF004 comment on the flagged line or the line directly above it. See Suppressing rules for whole-file directives and when a suppression is the wrong answer.
Allowlisted models
9 models are exempt from TRF004 in mlinter/rules.toml, because they predate the convention and cannot be changed without breaking backward compatibility.
Show the 9 allowlisted models
data2vechubertsewsew_dunispeechunispeech_satwav2vec2wav2vec2_conformerwavlm
