TRF055

PreTrainedModel classes declare their config with a config: SomeConfig annotation, matched by __init__(config: SomeConfig); never config_class.

   
Default Enabled
Scope All models
Source mlinter/trf055.py
Show in terminal mlinter --rule TRF055

What it does

Flags config_class, a config = SomeConfig assignment, a <Model>PreTrainedModel without a config annotation, and an __init__ whose config argument is unannotated or names another config. A class built from a sub-config (AcmeTextModel(config.text_config)) must declare that sub-config. A modular_*.py file is checked through the files it generates.

Why is this bad?

PreTrainedModel derives config_class from the config annotation. An assignment or a hand-written config_class keeps or drifts from the parent’s, and a mismatched __init__ builds the model from one config while it 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.