
GTN代码torch-sparse,gpu改cpu
跑GTN死活安装不上torch-sparse-old
我们在 pip 上以 torch-sparse-old 的名义上传了带有 backward() 的旧版本的 torch-sparse。
D:\Users\STREAM\anaconda3\Lib\site-packages\torch\utils\cpp_extension.py:381: UserWarning: Error checking compiler version for cl: [WinError 2] 系统找不到指定的文件。
warnings.warn(f'Error checking compiler version for {compiler}: {error}')
building 'torch_sparse._convert_cpu' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for torch_sparse
Running setup.py clean for torch_sparse
Failed to build torch_sparse
ERROR: Could not build wheels for torch_sparse, which is required to install pyproject.toml-based projects
发现是无法生成wheel,安装Microsoft C++ Build Tools也没什么用,本身就安装了VS写过C#软件,但是安装文件里也没有cl.exe。
查找教程发现安装cl.exe需要在Visual Studio Installer 里安装(修改)添加C++生成工具MSVC。
可以看到最终cl.exe就在MSVC文件夹里,这里是VS2022,可能具体情况不完全相同,在安装文件里查找cl.exe即可。
复制路径,添加到系统变量Path里,设置找不到可以直接在开始处全局搜索。
环境变量->系统变量->Path编辑->添加cl.exe所在的目录(文件夹)
torch-sparse和torch-sparse-old就都能安装了。
然后安装PyG (PyTorch Geometric), 配置把torch版本改成自己的版本。
PyG安装命令生成:Installation — pytorch_geometric documentation (pytorch-geometric.readthedocs.io)
比如我的是torch2.2.0,仅cpu
pip install torch_geometric
# Optional dependencies:
pip install torch_scatter torch_sparse torch_cluster torch_spline_conv -f https://data.pyg.org/whl/torch-2.2.0+cpu.html
安装成功,开始跑代码。
根据github里的命令,这里跑的DBLP,用的快速GTN模型。
报错:
(base) G:\Graph_Transformer_Networks-master> python main.py --dataset DBLP --model FastGTN --num_layers 4 --epoch 100 --lr 0.02 --channel_agg mean --num_channels 2
Traceback (most recent call last):
File "G:\Graph_Transformer_Networks-master\main.py", line 8, in <module>
from torch_geometric.utils import f1_score, add_self_loops
ImportError: cannot import name 'f1_score' from 'torch_geometric.utils' (D:\Users\STREAM\anaconda3\Lib\site-packages\torch_geometric\utils\__init__.py)
torch_geometric中的f1_score 已经被弃用,改一下引用,把第八行的f1_score 改到第十行。
官方文档CPU和GPU转换:torch.Tensor — PyTorch 2.2 documentation
main.py替换:
torch.cuda.LongTensor>>>torch.LongTensor
torch.cuda.FloatTensor>>>torch.FloatTensor
model.cuda()>>>model.cpu()
跑通了就是挺慢
环境:
参考:
UserWarning: Error checking compiler version for cl: [WinError 2] 系统找不到指定的文件。-CSDN博客
文章讲述了在Windows环境下安装GTN库及其依赖torch-sparse时遇到的问题,涉及编译器错误、MicrosoftC++BuildTools的安装、添加cl.exe到系统路径以及处理torch_geometric库中被弃用的f1_score函数。
755

被折叠的 条评论
为什么被折叠?



