TRF034
Layer classes held in an nn.ModuleList must subclass GradientCheckpointingLayer.
| Default | Enabled |
| Scope | Models added on or after 2026-06-20 |
| Source | mlinter/trf034.py |
| Show in terminal | mlinter --rule TRF034 |
What it does
In modeling_*.py and modular_*.py, flags a locally-defined class whose name ends in Layer or Block, instantiated inside an nn.ModuleList(...), that does not reach GradientCheckpointingLayer through its local base chain. One violation per layer class. ModuleLists of projections, heads or experts are out of scope because they are not checkpointing boundaries.
Why is this bad?
gradient_checkpointing_enable() wraps layers by asking each one whether it is a GradientCheckpointingLayer. A plain nn.Module in the stack is skipped silently, so training appears to use checkpointing and still allocates full activations for those layers, and the OOM shows up far from the cause.
Example
-class AcmeDecoderLayer(nn.Module):
+class AcmeDecoderLayer(GradientCheckpointingLayer):
def __init__(self, config, layer_idx):
super().__init__()
Suppressing this rule
Add a # trf-ignore: TRF034 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
10 models are exempt from TRF034 in mlinter/rules.toml, because they predate the convention and cannot be changed without breaking backward compatibility.
Show the 10 allowlisted models
cosmos3_edgedinov3_convnexthunyuan_vlkimi_k25openairadiotipsv2tipsv2_dptx_clipxcodec2
