TingsongYu / PyTorch-Tutorial-2nd

《Pytorch实用教程》(第二版)无论是零基础入门,还是CV、NLP、LLM项目应用,或是进阶工程化部署落地,在这里都有。相信在本书的帮助下,读者将能够轻松掌握 PyTorch 的使用,成为一名优秀的深度学习工程师。
https://tingsongyu.github.io/PyTorch-Tutorial-2nd/
2.37k stars 263 forks source link

9.4 机器翻译Transformer, 推理代码有错误 #25

Open justinge opened 3 days ago

justinge commented 3 days ago

Traceback (most recent call last): File "/home/justin/Desktop/code/python_project/pytorch-Tutorial-2nd/chapter-9/c_transformer/inference_transformer.py", line 115, in main() File "/home/justin/Desktop/code/python_project/pytorch-Tutorial-2nd/chapter-9/c_transformer/inference_transformer.py", line 62, in main transformer.load_state_dict(checkpoint['model']) File "/home/justin/miniconda3/envs/pytorchbook/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1497, in load_state_dict raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( RuntimeError: Error(s) in loading state_dict for Transformer: size mismatch for encoder.src_word_emb.weight: copying a param with shape torch.Size([2556, 512]) from checkpoint, the shape in current model is torch.Size([3000, 512]).

justinge commented 3 days ago

修改这里后,后面的transformer模型的前馈计算的方法传参数量也不对