Construct a module while skipping its parameter initialisation.
Instantiates module_cls(*args, **kwargs) with every
lucid.nn.init initialiser turned into a no-op, so each
parameter keeps whatever its allocation left. The intended pattern
is "construct, then load_state_dict": skipping the
lucid.nn.init.xavier_uniform_ /
lucid.nn.init.kaiming_normal_ work that is about to be
overwritten saves measurable time on large models with many layers.
Parameters
module_clstypelucid.nn.Module subclass to instantiate.*argsobject= ()module_cls.__init__.**kwargsobject= {}module_cls.__init__.Returns
ModuleFully constructed module whose parameter data is undefined. Buffers (running statistics, attention masks, etc.) are left intact because they are typically not refreshed from a checkpoint.
Notes
The initialisers are skipped, not run and discarded: no random draw
and no fill happens while the module is built, and the global random
state is left where it was. A module that fills its parameters some
other way — by assigning a freshly drawn tensor in __init__ —
still pays for that.
Callers must not inspect parameter values before loading a
checkpoint; the contents are unspecified and may contain nan
or inf.
Examples
>>> import lucid.nn as nn
>>> from lucid.nn.utils import skip_init
>>> model = skip_init(nn.Linear, 1024, 1024)
>>> # ... immediately load a checkpoint ...