torch.Tensor.module_load — PyTorch 2.7 documentation (original) (raw)
Tensor.module_load(other, assign=False)[source][source]¶
Defines how to transform other
when loading it into self
in load_state_dict().
Used when get_swap_module_params_on_conversion() is True
.
It is expected that self
is a parameter or buffer in an nn.Module
and other
is the value in the state dictionary with the corresponding key, this method defines how other
is remapped before being swapped with self
viaswap_tensors() in load_state_dict().
Note
This method should always return a new object that is not self
or other
. For example, the default implementation returns self.copy_(other).detach()
if assign
is False
or other.detach()
if assign
is True
.
Parameters
- other (Tensor) – value in state dict with key corresponding to
self
- assign (bool) – the assign argument passed to nn.Module.load_state_dict()