torch.Tensor.module_load

Tensor.module_load(other, assign=False)[源代码]

定义了在调用load_state_dict()other加载到self时,如何转换other

get_swap_module_params_on_conversion()True 时使用。

预期selfnn.Module中的一个参数或缓冲区,而other是在状态字典中与之对应的值。此方法定义了在load_state_dict()调用swap_tensors()之前,如何重新映射other并与self进行交换。

注意

此方法应始终返回一个新的对象,该对象既不是 self 也不是 other。例如,默认实现当 assignFalse 时返回 self.copy_(other).detach(),而当 assignTrue 时则返回 other.detach()

参数
  • other (Tensor) – 状态字典中与 self 对应的键的值

  • assign (bool) – 传递给 nn.Module.load_state_dict() 的 assign 参数

本页目录