TRF007
self.post_init() in __init__ should remain at the end of initialization for PreTrainedModel classes.
| Default | Enabled |
| Scope | All models |
| Source | mlinter/trf007.py |
| Show in terminal | mlinter --rule TRF007 |
What it does
Checks for self attribute assignments after self.post_init() in __init__.
Why is this bad?
Mutating model structure after post_init can bypass intended initialization/finalization logic.
Example
def __init__(self, config):
...
- self.post_init()
- self.proj = nn.Linear(...)
+ self.proj = nn.Linear(...)
+ self.post_init()
Suppressing this rule
Add a # trf-ignore: TRF007 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
7 models are exempt from TRF007 in mlinter/rules.toml, because they predate the convention and cannot be changed without breaking backward compatibility.
Show the 7 allowlisted models
distilbertlxmertmt5pix2structpop2pianoswitch_transformerst5
