报错问题:UserWarning: /usr/local/lib:/usr/local/cuda-12.3/lib64:/usr/local/gcc-9.3.0/lib64/: did not contain ['libcudart.so', 'libcudart.so.11.0', 'libcudart.so.12.0'] as expected! Searching further paths... & CUDA SETUP: CUDA detection failed. Either CUDA driver not installed
在使用hugging_face库的from_pretrained函数的过程中,因为传入参数有量化的需求:
tokenizer = AutoTokenizer.from_pretrained("eachadea/vicuna-13b")
base_model = AutoModelForCausalLM.from_pretrained(
"eachadea/vicuna-13b",
torch_dtype=torch.float16,
load_in_8bit=True,
device_map='auto',
)
这里加入了8-bit量化,然后bitsandbytes库报了如下的错误,此时将cuda的库目录加入LD_LIBRARY_PATH也不生效。
===================================BUG REPORT===================================
Welcome to bitsandbytes. For bug reports, please submit your error trace to: https://github.com/TimDettmers/bitsandbytes/issues
For effortless bug reporting copy-paste your error into this form: https://docs.google.com/forms/d/e/1FAIpQLScPB8emS3Thkp66nvqwmjTEgxp8Y9ufuWTzFyr9kJ5AoI47dQ/viewform?usp=sf_link
================================================================================
/home/zhangpan/.conda/envs/archetype/lib/python3.9/site-packages/bitsandbytes/cuda_setup/paths.py:93: UserWarning: /home/***/.conda/envs/archetype did not contain libcudart.so as expected! Searching further paths...
warn(
CUDA SETUP: CUDA runtime path found: /usr/local/cuda-12.3/lib64/libcudart.so
CUDA SETUP: Highest compute capability among GPUs detected: 8.9
CUDA SETUP: Detected CUDA version 123
CUDA SETUP: TODO: compile library for specific version: libbitsandbytes_cuda123_nocublaslt.so
CUDA SETUP: Defaulting to libbitsandbytes.so...
CUDA SETUP: CUDA detection failed. Either CUDA driver not installed, CUDA not installed, or you have multiple conflicting CUDA libraries!
CUDA SETUP: If you compiled from source, try again with `make CUDA_VERSION=DETECTED_CUDA_VERSION` for example, `make CUDA_VERSION=113`.
解决方案
1. 将原先的bitsandbytes库uninstall掉
pip uninstall bitsandbytes
2. 将cuda的环境添加至PATH和LD_LIBRARY_PATH中
export LD_LIBRARY_PATH=/path/to/your/CUDA/lib64:$LD_LIBRARY_PATH
export PATH=$PATH:/path/to/your/CUDA/bin
export BNB_CUDA_VERSION=123 //如果你的CUDA是12.3就是123,其他版本同理
3. 重新安装bitsandbytes库,注意,步骤2一定要在步骤3前面
pip install bitsandbytes
亲测有效,解决完毕!