需要加速和bitsandbytes来安装,但我做到了

use*_*230 17 python huggingface-transformers

我正在尝试加载量化

from transformers import LlamaForCausalLM
from transformers import BitsAndBytesConfig

model = '/model/'
model = LlamaForCausalLM.from_pretrained(model, quantization_config=BitsAndBytesConfig(load_in_8bit=True))
Run Code Online (Sandbox Code Playgroud)

但我得到了错误

ImportError: Using `load_in_8bit=True` requires Accelerate: `pip install accelerate` and the latest version of bitsandbytes `pip install -i https://test.pypi.org/simple/ bitsandbytes` or pip install bitsandbytes` 
Run Code Online (Sandbox Code Playgroud)

但我都安装了,但出现同样的错误。我关闭并重新启动了我正在使用的 jupyter 内核。

小智 25

transformers使用以下命令将库降级到版本 4.30:

pip install transformers==4.30
Run Code Online (Sandbox Code Playgroud)

  • 大家好,来自 Transformers 团队的 Niels - 降级 Transformers 版本实际上并不是正确的解决方案,该错误通常发生在您在 CPU 上运行 `load_in_4bit=True` 或 `load_in_8bit=True` 时。我们现在返回一条更好的错误消息,指出未找到 GPU。 (2认同)

Pet*_*org 6

我使用的是 M1 Mac,也有类似的问题。安装后acceleratebitsandbytes仍然得到

ImportError: 使用load_in_8bit=True需要 Accelerate:pip install accelerate和最新版本的 bitsandbytespip install -i https://test.pypi.org/simple/ bitsandbytes或 pip install bitsandbytes

我在 Transformers 源代码中查看了一下,发现一个名为 的函数is_bitsandbytes_available(),只有在安装了 BitsandBytes且 且 torch.cuda.is_available()时才返回 true ,而在 Apple Silicon 机器上则不是这种情况。另外,https://github.com/TimDettmers/bitsandbytes/issues/252确认 Bitsandbytes 不支持 MPS(金属)。我不知道为什么 Huggingface 的文档没有提到(除非我在某个地方错过了)他们的示例不适用于 Apple Silicon。