TRF056
forward() must not materialize tensors with .item() or .tolist().
| Default | Enabled |
| Scope | Models added on or after 2026-06-20 |
| Source | mlinter/trf056.py |
| Show in terminal | mlinter --rule TRF056 |
What it does
In modeling_*.py and modular_*.py, flags .item() and .tolist() calls inside any forward. A .tolist() whose result is the split-size argument of split(...), is exempt as torch.split needs Python ints.
Why is this bad?
Both calls read a tensor back to the host, so dynamo cannot trace them resulting in a graph break.
Example
- for grid, item in zip(grid_thw.tolist(), split_items):
- _, height, width = grid
- merged.append(self.patch_merger(item, size=(height, width)))
+ for grid, item in zip(grid_thw, split_items):
+ merged.append(self.patch_merger(item, size=(grid[1], grid[2])))
Suppressing this rule
Add a # trf-ignore: TRF056 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
2 models are exempt from TRF056 in mlinter/rules.toml, because they predate the convention and cannot be changed without breaking backward compatibility.
Show the 2 allowlisted models
hunyuan_vlkimi_k25
