1. 问题描述
在部署大模型LLaMA/Qwen-7B的过程中,需要安装量化工具包bitsandbytes,环境如下:
操作系统:Ubuntu 22.04
GPU:4xA100 80G
CUDA:11.7
cuDNN:8.0
bitsandbytes: 0.41.0
在conda python环境下,通过pip install bitsandbytes直接安装,或是按源码编译安装,在python -m bitsandbytes检测时均出现异常。,主要异常内容如下:
============================ERROR=====================
CUDA SETUP: CUDA detection failed! Possible reasons:
1. You need to manually override the PyTorch CUDA version. Please see: "https://github.com/TimDettmers/bitsandbytes/blob/main/how_to_use_nonpytorch_cuda.md
2. CUDA driver not installed
3. CUDA not installed
4. You have multiple conflicting CUDA libraries
5. Required library not pre-compiled for this bitsandbytes release!
CUDA SETUP: If you compiled from source, try again with `make CUDA_VERSION=DETECTED_CUDA_VERSION` for example, `make CUDA_VERSION=113`.
CUDA SETUP: The CUDA version for the compile might depend on your conda install. Inspect CUDA version via `conda list | grep cuda`.
=======================================================
2. 问题解决
在环境变量LD_LIBRARY_PATH中增加CUDA的lib路径:
export PATH=/usr/local/cuda-11.7/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.7/lib64:$LD_LIBRARY_PATH
然后重新安装bitsandbytes即可:
pip uninstall bitsandbytes
pip install bitsandbytes
最后正常加载模型并训练: