TRF012

_init_weights must use init primitives, not in-place operations on module weights.

   
Default Enabled
Scope All models
Source mlinter/trf012.py
Show in terminal mlinter --rule TRF012

What it does

Flags in-place ops (.normal_(), .zero_(), …) on module weights inside _init_weights.

Why is this bad?

Parameters carry internal flags tracking whether they still need re-initialization; in-place ops bypass them. Use the init primitives.

Example

+from transformers import initialization as init
+
 def _init_weights(self, module):
-    module.weight.normal_(mean=0.0, std=0.02)
+    init.normal_(module.weight, mean=0.0, std=0.02)

Suppressing this rule

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