Torch未使用CUDA编译,需要在我的本地PC上使用CUDA。

huangapple go评论64阅读模式
英文:

Torch not compiled with CUDA enabled, need to use CUDA on my local PC

问题

I'm here to provide the translated code and relevant information:

我正在尝试使用我的视频卡来分析一些机器学习任务

我正在使用以下代码

```python
import torch
from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained("cointegrated/rubert-tiny2")
model = AutoModel.from_pretrained("cointegrated/rubert-tiny2")
model.cuda()  # 如果您有GPU,请取消注释此行

def embed_bert_cls(text, model, tokenizer):
    t = tokenizer(text, padding=True, truncation=True, return_tensors='pt')
    with torch.no_grad():
        model_output = model(**{k: v.to(model.device) for k, v in t.items()})
    embeddings = model_output.last_hidden_state[:, 0, :]
    embeddings = torch.nn.functional.normalize(embeddings)
    return embeddings[0].cpu().numpy()

并且得到以下错误:

AssertionError: Torch not compiled with CUDA enabled

我检查了我的系统和驱动程序,并得到了以下信息:

torch.cuda.is_available()

返回值是 false

然后我查看了Torch的版本:

torch.__version__

返回值是 2.0.1+cpu

nvcc --version

返回信息如下:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Mon_Apr__3_17:36:15_Pacific_Daylight_Time_2023
Cuda compilation tools, release 12.1, V12.1.105
Build cuda_12.1.r12.1/compiler.32688072_0
nvidia-smi

返回信息如下:

+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 531.68                 Driver Version: 531.68       CUDA Version: 12.1     |
|-----------------------------------------+----------------------+----------------------+

我尝试了使用以下命令从pip获取最新的安装:

pip install torch torchvision torchaudio -f https://download.pytorch.org/whl/cu121/torch_stable.html

但仍然得到了2.0.1+cpu版本的Torch和不可用的CUDA。

我的操作系统是Windows 10 x64。

我希望不使用conda,只使用pip。我想要使用我的视频卡进行机器学习分析。


<details>
<summary>英文:</summary>

I&#39;m trying to use my video card to analise some ML task.

I&#39;m using this code:

import torch
from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained("cointegrated/rubert-tiny2")
model = AutoModel.from_pretrained("cointegrated/rubert-tiny2")
model.cuda() # uncomment it if you have a GPU

def embed_bert_cls(text, model, tokenizer):
t = tokenizer(text, padding=True, truncation=True, return_tensors='pt')
with torch.no_grad():
model_output = model(**{k: v.to(model.device) for k, v in t.items()})
embeddings = model_output.last_hidden_state[:, 0, :]
embeddings = torch.nn.functional.normalize(embeddings)
return embeddings[0].cpu().numpy()

and get this error:

`AssertionError: Torch not compiled with CUDA enabled`

I check my system and drivers and get this:

torch.cuda.is_available()

`false`

so i look in to version of torch:

torch.version

`2.0.1+cpu`

nvcc --version

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Mon_Apr__3_17:36:15_Pacific_Daylight_Time_2023
Cuda compilation tools, release 12.1, V12.1.105
Build cuda_12.1.r12.1/compiler.32688072_0


nvidia-smi

+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 531.68 Driver Version: 531.68 CUDA Version: 12.1 |
|-----------------------------------------+----------------------+----------------------+


I wipe all my libs on pip and get fresh install from:

pip install torch torchvision torchaudio -f https://download.pytorch.org/whl/cu121/torch_stable.html

but still get `2.0.1+cpu` version fo torch and cuda `not available`.

My OS is Windows 10 x64.
I prefer not to use `conda`, only `pip`. I want to use my video card for ML analyse.


</details>


# 答案1
**得分**: 0

你在安装中使用了错误的链接,你可以在浏览器中打开以检查其是否可访问,[安装指南](https://pytorch.org/get-started/locally/)为 `3.8-3.11` 提供了正确的安装命令(除了 `pip`)。

[稳定版] https://download.pytorch.org/whl/cu118
[夜间版] https://download.pytorch.org/whl/nightly/cu121 (使用 --pre)

如果你要使用 `pip`,你应该已经在使用 `virtualenv`,如果还没有使用的话。

<details>
<summary>英文:</summary>

You are using a wrong link in the install, you can open it in the browser to check if it is accesible, the [install](https://pytorch.org/get-started/locally/) guide gives you the correct install command (except with `pip`) for `3.8-3.11`.

[Stable] https://download.pytorch.org/whl/cu118
[Nightly] https://download.pytorch.org/whl/nightly/cu121 (with --pre)


If you are going to use `pip` you should be using `virtualenv` too if you aren&#39;t already using it.


</details>



# 答案2
**得分**: 0

我确实犯了同样的错误,当然,当安装正确版本时,一切都更快更正常...

pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu121

<details>
<summary>英文:</summary>

I did indeed the same mistake and of course, when installing the right version, everything goes faster and properly ...

    pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu121



</details>



huangapple
  • 本文由 发表于 2023年5月14日 20:05:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76247391.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定