TRF036

nn.Sequential hides the forward flow; declare the submodules explicitly.

   
Default Enabled
Scope Models added on or after 2026-06-20
Source mlinter/trf036.py
Show in terminal mlinter --rule TRF036

What it does

In modeling_*.py and modular_*.py, flags any nn.Sequential(...) construction.

Why is this bad?

Sequential names its children by position, so weights land at mlp.0.weight and mlp.2.weight; the conversion mapping, _tied_weights_keys and every parallelism plan then have to reference indices, and inserting a layer renames everything after it. It also hides the forward, so the dtype casts and residuals between the steps are not visible where they happen.

Example

-        self.mlp = nn.Sequential(
-            nn.Linear(config.hidden_size, config.intermediate_size),
-            nn.GELU(),
-            nn.Linear(config.intermediate_size, config.hidden_size),
-        )
+        self.fc1 = nn.Linear(config.hidden_size, config.intermediate_size)
+        self.act = ACT2FN[config.hidden_act]
+        self.fc2 = nn.Linear(config.intermediate_size, config.hidden_size)

Suppressing this rule

Add a # trf-ignore: TRF036 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

1 model are exempt from TRF036 in mlinter/rules.toml, because they predate the convention and cannot be changed without breaking backward compatibility.

Show the 1 allowlisted model
  • x_clip