torch.Tensor.module_load¶
- Tensor.module_load(other, assign=False)[源代码]¶
定义在
load_state_dict()中将other加载到self时如何对其进行转换。当
get_swap_module_params_on_conversion()为True时使用。预计
self是nn.Module中的参数或缓冲区,而other是状态字典中具有相应键的值,此方法定义了在通过swap_tensors()在load_state_dict()中与self交换之前,如何重新映射other。注意
此方法应始终返回一个新的对象,而不是
self或other。例如,默认实现返回self.copy_(other).detach()(如果assign为False)或other.detach()(如果assign为True)。- 参数
other (张量) – 状态字典中与
self对应的键的值assign (布尔值) – 传递给
nn.Module.load_state_dict()的 assign 参数