Skip to content

Speed up model load by skipping init on strict load - #12

Merged
mrzzmrzz merged 1 commit into
aurekaresearch:mainfrom
rizsp:feat/skip-init
Jul 23, 2026
Merged

Speed up model load by skipping init on strict load#12
mrzzmrzz merged 1 commit into
aurekaresearch:mainfrom
rizsp:feat/skip-init

Conversation

@rizsp

@rizsp rizsp commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Model load spends significant time on initializing layers with a slow truncnorm plus an implicit kaiminig_uniform_ of torch.nn.Linear. But this work is discarded at construction when the parameters are overwritten by the actual model weights with load_state_dict.

Changes
This commit monkey patches trunc_normal_init_ and nn.Linear's reset_parameters to noops during inference via a skip_random_init context manager.

On my machine, this leads to a reduction of ~1 minute. A similar patch has already been merged into openfold-3 (PR 220).

Model load spends significant time on initializing layers with a slow
truncnorm plus an implicit kaiminig_uniform_ of torch.nn.Linear. But this
work is discarded at construction when the parameters are overwritten by
the actual model weights with load_state_dict.

This commit monkey patches trunc_normal_init_ and nn.Linear's
reset_parameters to noops during inference via a skip_random_init
context manager.
@mrzzmrzz

Copy link
Copy Markdown
Collaborator

Hi rizsp, thank you for the contribution! We validated the change with a real checkpoint. It significantly reduces the unnecessary parameter-initialization overhead before loading the checkpoint. The change fits our inference use case well.

This should be ready to merge. Thanks again!

@mrzzmrzz
mrzzmrzz merged commit f607bb3 into aurekaresearch:main Jul 23, 2026
4 checks passed
@rizsp
rizsp deleted the feat/skip-init branch July 23, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants