torch.Tensor.module_load
- Tensor.module_load(other, assign=False)[源代码]
-
定义了在调用
load_state_dict()
将other
加载到self
时,如何转换other
。当
get_swap_module_params_on_conversion()
为True
时使用。预期
self
是nn.Module
中的一个参数或缓冲区,而other
是在状态字典中与之对应的值。此方法定义了在load_state_dict()
调用swap_tensors()
之前,如何重新映射other
并与self
进行交换。注意
此方法应始终返回一个新的对象,该对象既不是
self
也不是other
。例如,默认实现当assign
为False
时返回self.copy_(other).detach()
,而当assign
为True
时则返回other.detach()
。