Skip to content

Removing call to init_weights in model's __init__ - #1711

Merged
tianyu-l merged 1 commit into
pytorch:mainfrom
lkhphuc:init
Sep 15, 2025
Merged

tianyu-l merged 1 commit into
pytorch:mainfrom
lkhphuc:init

Conversation

@lkhphuc

@lkhphuc lkhphuc commented Sep 15, 2025

Copy link
Copy Markdown
Contributor

As discussed here and here, I create this PR to limit the scope of the other PR #1615 .

When subclassing a torchtitan's model for training, the call to self.init_weights() inside model __init__ could have side effect.
Solution is to delete this line because in practice it currently has no effect, we explicitly called m.init_weights(buffer_device) in train.py already.
Flux model already doesn't do it.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 15, 2025

@tianyu-l tianyu-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tianyu-l
tianyu-l merged commit 40a8725 into pytorch:main Sep 15, 2025
@lkhphuc
lkhphuc deleted the init branch October 14, 2025 10:58
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 13, 2026
As discussed
[here](pytorch#1615 (comment))
and
[here](pytorch#1615 (comment)),
I create this PR to limit the scope of the other PR pytorch#1615 .

When subclassing a torchtitan's model for training, the call to
`self.init_weights()` inside model `__init__` could have side effect.
Solution is to delete this line because in practice it currently has no
effect, we explicitly called `m.init_weights(buffer_device)` in
`train.py` already.
Flux model already doesn't do it.
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 25, 2026
As discussed
[here](pytorch#1615 (comment))
and
[here](pytorch#1615 (comment)),
I create this PR to limit the scope of the other PR pytorch#1615 .

When subclassing a torchtitan's model for training, the call to
`self.init_weights()` inside model `__init__` could have side effect.
Solution is to delete this line because in practice it currently has no
effect, we explicitly called `m.init_weights(buffer_device)` in
`train.py` already.
Flux model already doesn't do it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants