前言
我在运行魔塔社区(modelscope)的ZhipuAI/chatglm3-6b模型(智谱)的实例程序的时候,碰到了一个奇怪的错误(torch.empty),我尝试解决了一下。
(当前采用的Python版本是3.11,程序在PyCharm中调试,torch采用的是cpu版本)
一、错误提示
File "D:\PycharmProjects\ChatGLM3_py311_cpu_test\venv\Lib\site-packages\torch\nn\modules\sparse.py", line 167, in __init__
torch.empty((num_embeddings, embedding_dim), **factory_kwargs),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: empty() received an invalid combination of arguments - got (tuple, dtype=str, device=str), but expected one of:
* (tuple of ints size, *, tuple of names names, torch.memory_format memory_format = None, torch.dtype dtype = None, torch.layout layout = None, torch.device device = None, bool pin_memory = False, bool requires_grad = False)
二、初步判断
初步判断是torch的版本和transformers的版本没有对应上。
目前版本的对应关系如下:
直接运行
pip install torch==2.0.0 transformers==4.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
出现了“can't find Rust compilier”的错误。
三、can't find Rust compiler
这个错误怎么如何解决?
参考这个链接:
但是似乎又有所不同,直接运行命令easy_install -U pip 似乎不行,如下图:
可能是pycharm的版本比较新,改为如下命令:
pip install --upgrade pip
得到提示后,重新运行了命令:
再安装cryptography
没有什么用,错误依旧
四、跳过问题3
将安装命令修改为:
pip install torch==2.3.0 transformers==4.40.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
想不到后续安装顺利,实例程序可以正常运行了,如下图:
以下是各个包的版本情况,如下2个图:
五、源程序的链接