省流:python(3.12.7) 和 pytorch(2.4.0)版本不配套
问题
起因是看到了这本书《Build a Large Language Model (From Scratch) 》,是2024年9月新出的, 作者 Sebastian Raschka,想要按照作者给出的步骤来手搓一个大语言模型,以便后面拿出来吹牛。
作者在书中写道:
Therefore, when installing PyTorch, it’s advisable to use a version of Python that is one or two releases older. For instance, if the latest version of Python is 3.13, using Python 3.11 or 3.12 is recommended.
。。。。
I use PyTorch 2.4.0 for the examples, so I recommend that you use the following command to install the exact version to guarantee compatibility with this book:
pip install torch==2.4.0
为了防止和作者环境不一致,遇到一堆奇怪的问题,需要安装pytorch的2.4.0版本,但作者坑就坑在这里,没说自己用的哪个python版本,只是推荐3.11和3.12。
秉着[装新不装旧]的原则,上python官网找了个 3.12.7版本(win10 64位)来安装。然后用pip安装pytorch 2.4.0。看起来很顺利,但用起来就出问题了:
【OSError: [WinError 126] 找不到指定的模块。 Error loading "D:\Python3127\Lib\site-packages\torch\lib\torch_python.dll" or one of its dependencies.】
C:\>python
Python 3.12.7 (tags/v3.12.7:0b05ead, Oct 1 2024, 03:06:41) [MSC v.1941 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceba