自学内容网 自学内容网

RuntimeError: CUDA is required but not available for bitsandbytes.

今天想配置大模型的环境,需要用到 bitsandbytes这个包,但是遇到报错:

RuntimeError: CUDA is required but not available for bitsandbytes. Please consider installing the multi-platform enabled version of bitsandbytes, which is currently a work in progress. Please check currently supported platforms and installation instructions at https://huggingface.co/docs/bitsandbytes/main/en/installation#multi-backend

我想说的是,不要按照这个报错去安装 cpu的包,否则还是跑不了。因为就是需要 cuda的环境,把cuda配出来就可以了。
于是我按照一些博客所说配置了 LD_LIBRARY_PATH,但是事实上早就有这个环境变量了,引用博客如下:点我
于是我打开了对应的报错文件:
/home/***/anaconda3/envs/***/lib/python3.8/site-packages/transformers/integrations/bitsandbytes.py
查看原因,报错在536行,代码显示如下:

523 def _validate_bnb_cuda_backend_availability(raise_exception):
524     if not is_torch_available():
525         return False
526 
527     import torch
528 
529     if not torch.cuda.is_available():
530         log_msg = (
531             "CUDA is required but not available for bitsandbytes. Please consider installing the multi-platform enabled version of bitsandbytes, whi    ch is currently a work in progress. "
532             "Please check currently supported platforms and installation instructions at https://huggingface.co/docs/bitsandbytes/main/en/installati    on#multi-backend"
533         )
534         if raise_exception:
535             logger.error(log_msg)
536             raise RuntimeError(log_msg)
537 
538         logger.warning(log_msg)
539         return False

可以看到,他检查cuda的有效性是根据torch来看的,于是我新开了一个文件:

import torch

print(torch.__version__)
print(torch.cuda.is_available())
print(torch.version.cuda)

发现这个available确实不行,于是反应过来torch的版本是不能随便安装的,可以去这个网址找:
https://pytorch.org/get-started/previous-versions/
查看具体torch安装命令,我的是:
pip install torch==1.12.0+cu116 torchvision==0.13.0+cu116 torchaudio==0.12.0 --extra-index-url https://download.pytorch.org/whl/cu116
选择时,需要根据平台和cuda版本筛选
然后安装torch就可以运行了
还有一点注意是,安装bitsandbytes时,必须根据这个网站(https://huggingface.co/docs/bitsandbytes/main/en/installation)的指示安装,不要直接 pip install
但还是可能遇到nn的问题,如下:
AttributeError: module 'bitsandbytes' has no attribute 'nn'
这个问题,可以参考这个网址:
https://github.com/bitsandbytes-foundation/bitsandbytes/issues/462

使用pip install bitsandbytes==0.39.0即可

希望可以对你有所帮助~

这是我今天遇到的所有问题,需要自取:

链接: https://pan.baidu.com/s/1PNbDp6mhB__L7MdGbPI18w?pwd=1234提取码: 1234 复制这段内容后打开百度网盘手机App,操作更方便哦


原文地址:https://blog.csdn.net/weixin_52205764/article/details/143821537

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!