TRF013
PreTrainedModel __init__ must call self.post_init().
| Default | Enabled |
| Scope | All models |
| Source | mlinter/trf013.py |
| Show in terminal | mlinter --rule TRF013 |
What it does
Checks that every PreTrainedModel subclass with an __init__ method calls self.post_init(). In modular files, calling super().__init__() is also accepted since it propagates post_init from the parent.
Why is this bad?
post_init performs essential finalization (weight initialization, gradient checkpointing setup, etc.). Omitting it causes subtle runtime bugs.
Example
class AcmeModel(AcmePreTrainedModel):
def __init__(self, config):
super().__init__(config)
self.layers = nn.ModuleList(...)
+ self.post_init()
Suppressing this rule
Add a # trf-ignore: TRF013 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.
