TRF033

Hyperparameters must be set on the config, not mutated through a set_* method.

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

What it does

In modeling_*.py and modular_*.py, flags methods whose name starts with set_, except the PreTrainedModel contract methods set_input_embeddings, set_output_embeddings, set_decoder, set_encoder, set_attn_implementation and set_default_language.

Why is this bad?

A setter makes the model’s behaviour depend on call order: the value is not in the config, so it is not saved, not restored by from_pretrained, and not visible to anything planning device maps or parallelism. Users then have to know to call it, and forgetting is silent.

Example

 class AcmeTriangleAttention(nn.Module):
-    def set_chunk_size(self, chunk_size):
-        self.chunk_size = chunk_size
+    def __init__(self, config):
+        super().__init__()
+        self.chunk_size = config.chunk_size

Suppressing this rule

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