TRF055
PreTrainedModel config must be an annotation (config: SomeConfig) matched by __init__(config: SomeConfig); config_class is never used.
| Default | Enabled |
| Scope | All models |
| Source | mlinter/trf055.py |
| Show in terminal | mlinter --rule TRF055 |
What it does
In modeling_*.py, flags on PreTrainedModel classes: any config_class; config = SomeConfig as a class attribute; a <Model>PreTrainedModel with no config: SomeConfig annotation; and an __init__ whose config argument is unannotated or names a different config than the class declares or inherits. A class the model builds from a sub-config (AcmeTextModel(config.text_config), or ._from_config(...)) must declare that sub-config, as listed in the composite config’s sub_configs; otherwise it inherits the composite config unnoticed, for example a modular class AcmeTextModel(LlamaModel): pass. A modular_*.py file is checked through the modeling_*.py files generated from it, since the class hierarchy is only complete there; each problem is reported on the class in the modular file, and classes the converter copied from another model are left to that model’s files.
Why is this bad?
PreTrainedModel.__init_subclass__ derives config_class from a config **annotation**, via inspect.get_annotations(cls). An assignment creates a stray class attribute that call does not report, so the subclass silently keeps the parent’s config_class; a hand-written config_class is redundant and can drift from the annotation. A bare annotation has no runtime value, creates no attribute, and is picked up correctly. The __init__ annotation must agree with the class’s config, otherwise the model is built from one config type but advertises another.
Example
class Gemma4VisionModel(Gemma4PreTrainedModel):
"""The Gemma 4 Vision Encoder."""
- config = Gemma4VisionConfig
+ config: Gemma4VisionConfig
- def __init__(self, config):
+ def __init__(self, config: Gemma4VisionConfig):
Suppressing this rule
Add a # trf-ignore: TRF055 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.
