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()与self交换之前,other是如何重新映射的。注意
此方法应始终返回一个新对象,该对象不是
self或other。例如,默认实现会在assign为False时返回self.copy_(other).detach(),或者在assign为True时返回other.detach()。- 参数
other (Tensor) – 状态字典中与
self对应的键的值assign (bool) – 传递给
nn.Module.load_state_dict()的 assign 参数