pytorch常见问题

1 Gather function not implemented for CPU tensors

多卡训练时候,net的forward里面存在Tensor变成其它类型的操作,比如变成numpy,list

解决:改成Tensor操作

2 RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn

https://blog.csdn.net/weixin_41990278/article/details/90311313

https://blog.csdn.net/wu_xin1/article/details/116502378

pytorch常见操作

1 pytorch中对tensor操作

https://blog.csdn.net/HailinPan/article/details/109818774

2 模型加载

1 model.load_state_dict(torch.load(path))

2 model=BertModel.from_pretrained

后者的底层为前者

用法不同,前者model为一个对象,然后用load_state_dict加载权重;后者BertModel为一个类,然后用from_pretrained创建对象并加载权重


:D 一言句子获取中...