TRF045
forward must not declare output_attentions/output_hidden_states/return_dict; decorators own them.
| Default | Enabled |
| Scope | Models added on or after 2026-06-20 |
| Source | mlinter/trf045.py |
| Show in terminal | mlinter --rule TRF045 |
What it does
Checks forward signatures in modeling_*.py and modular_*.py for the legacy output_attentions, output_hidden_states, and return_dict parameters. Models contributed before the cutoff date are exempt.
Why is this bad?
The decorator stack owns output control: @capture_outputs resolves output_* flags against the config and records the tensors via _can_record_outputs, and @can_return_tuple handles return_dict. Declaring them in the signature reintroduces manual flag threading that drifts from the decorator behavior.
Example
+@capture_outputs
def forward(
self,
input_ids,
- output_attentions=None,
- output_hidden_states=None,
- return_dict=None,
**kwargs: Unpack[TransformersKwargs],
):
Suppressing this rule
Add a # trf-ignore: TRF045 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
4 models are exempt from TRF045 in mlinter/rules.toml, because they predate the convention and cannot be changed without breaking backward compatibility.
Show the 4 allowlisted models
kosmos2openaitimm_backbonetimm_wrapper
