MCPcopy Index your code
hub / github.com/huggingface/diffusers / no_init_weights

Function no_init_weights

src/diffusers/models/modeling_utils.py:213–229  ·  view source on GitHub ↗

Context manager to globally disable weight initialization to speed up loading large models. To do that, all the torch.nn.init function are all replaced with skip.

()

Source from the content-addressed store, hash-verified

211
212@contextmanager
213def no_init_weights():
214 """
215 Context manager to globally disable weight initialization to speed up loading large models. To do that, all the
216 torch.nn.init function are all replaced with skip.
217 """
218
219 def _skip_init(*args, **kwargs):
220 pass
221
222 for name, init_func in TORCH_INIT_FUNCTIONS.items():
223 setattr(torch.nn.init, name, _skip_init)
224 try:
225 yield
226 finally:
227 # Restore the original initialization functions
228 for name, init_func in TORCH_INIT_FUNCTIONS.items():
229 setattr(torch.nn.init, name, init_func)
230
231
232class ModelMixin(torch.nn.Module, PushToHubMixin):

Callers 1

from_pretrainedMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…