meta¶
meta
¶
MetaMixin
¶
MetaMixin(*args, dispatch: bool = False, meta_buffers: bool = True, rename: Optional[Dict[str, str]] = None, **kwargs)
Bases: LoadableMixin
Mixin that adds lazy loading with meta tensors and deferred dispatch.
When dispatch=False (the default), the model is initialized with
meta tensors (no memory allocation) using :meth:_load_meta. Real
weights are loaded later when :meth:dispatch is called, or
automatically on the first :meth:trace / :meth:generate call.
When dispatch=True or a pre-loaded torch.nn.Module is passed,
the model is loaded immediately via :meth:_load.
| PARAMETER | DESCRIPTION |
|---|---|
*args
|
Forwarded to :meth:
DEFAULT:
|
dispatch
|
If
TYPE:
|
meta_buffers
|
If
TYPE:
|
rename
|
Module path aliases.
TYPE:
|
**kwargs
|
Forwarded to :meth:
DEFAULT:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
dispatched |
Whether real weights have been loaded.
TYPE:
|
args |
Saved positional arguments for deferred :meth:
|
kwargs |
Saved keyword arguments for deferred :meth:
|
dispatch
¶
Load real weights into the model, replacing meta tensors.
Calls :meth:_load with the saved constructor arguments and
updates the Envoy tree to reflect the newly loaded module.
After this call, :attr:dispatched is True.
interleave
¶
Run fn with interleaved interventions, auto-dispatching if needed.
If the model has not been dispatched yet and this is not a scan,
:meth:dispatch is called first and fn is rebound to the
newly loaded module.