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
是 state dictionary 中对应键的值,此方法定义了在通过swap_tensors()
在load_state_dict()
中与self
交换之前如何重新映射other
。注意
此方法应始终返回一个新对象,该对象不是
self
或other
。例如,如果assign
为False
,默认实现返回self.copy_(other).detach()
;如果assign
为True
,则返回other.detach()
。- 参数
other (Tensor) – state dict 中与
self
对应的键所对应的值assign (bool) – 传递给
nn.Module.load_state_dict()
的 assign 参数