TRF059

Routed Experts modules tagged with moe_tp_experts must take hidden states, top-k indices and top-k weights in that order.

   
Default Enabled
Scope All models
Source mlinter/trf059.py
Show in terminal mlinter --rule TRF059

What it does

For model directories whose tensor-parallel plan assigns moe_tp_experts, checks that routed *Experts classes take hidden states, top-k indices and top-k routing weights as the first three positional forward arguments. Aliases such as selected_experts and routing_weights are accepted.

Why is this bad?

MoeExpertsParallel applies a gradient transform to positional argument 3. A different signature silently applies it to the wrong tensor or skips it.

Example

 class AcmeExperts(nn.Module):
-    def forward(self, hidden_states):
+    def forward(self, hidden_states, top_k_index, top_k_weights):
         ...

Suppressing this rule

Add a # trf-ignore: TRF059 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 TRF059 in mlinter/rules.toml, because they predate the convention and cannot be changed without breaking backward compatibility.

Show the 1 allowlisted model
  • llama4