TRF032
Masked positions must be filled with torch.finfo(dtype).min, not a magic negative number.
| Default | Enabled |
| Scope | Models added on or after 2026-06-20 |
| Source | mlinter/trf032.py |
| Show in terminal | mlinter --rule TRF032 |
What it does
In modeling_*.py and modular_*.py, flags masked_fill, masked_fill_, full, full_like and new_full called with a negated numeric literal of magnitude 1e3 or more.
Why is this bad?
A hardcoded -1e9 overflows to -inf in float16 and is not nearly the smallest value in float32, so the same mask behaves differently per dtype and can produce NaNs after softmax. torch.finfo(dtype).min is the smallest representable value in whatever dtype is actually running.
Example
-attention_scores = attention_scores.masked_fill(~mask, -1e9)
+attention_scores = attention_scores.masked_fill(~mask, torch.finfo(attention_scores.dtype).min)
Suppressing this rule
Add a # trf-ignore: TRF032 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.
