TRF044
cache_position must not appear as a parameter in modeling code; it is removed framework surface.
| Default | Enabled |
| Scope | All models |
| Source | mlinter/trf044.py |
| Show in terminal | mlinter --rule TRF044 |
What it does
Checks every function in modeling_*.py and modular_*.py for a parameter named cache_position.
Why is this bad?
cache_position was removed from all models in v5. Code that reintroduces it (usually copied from pre-v5 sources) threads a dead argument through every layer; the cache update call is past_key_values.update(key_states, value_states, self.layer_idx) with no position threading.
Example
def forward(
self,
hidden_states,
past_key_values=None,
- cache_position=None,
**kwargs,
):
- key_states, value_states = past_key_values.update(key_states, value_states, self.layer_idx, cache_position)
+ key_states, value_states = past_key_values.update(key_states, value_states, self.layer_idx)
Suppressing this rule
Add a # trf-ignore: TRF044 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.
