https://github.com/meta-llama/llama3/issues/80
讀模型沒問題,推理時出現:
RuntimeError: “triu_tril_cuda_template” not implemented for ‘BFloat16’
————————————————
事發原因
我嘗試了解transformers的AutoProcessor時,它提示我:
RuntimeError: Failed to import transformers.models.auto.processing_auto because of the following error (look up to see its traceback):
Detected that PyTorch and torchvision were compiled with different CUDA versions. PyTorch has CUDA Version=11.8 and torchvision has CUDA Version=11.7. Please reinstall the torchvision that matches your PyTorch install.
說我torch和torchvision的cuda版本對不上?我當初是按Pytorch安裝的啊。。。
我的torch 版本如下:
torch 2.0.0+cu118
torchaudio 2.0.1
torchvision 0.15.1
很怪,倆后面確實沒跟cu118字樣。所以我找pytorch官方網站又下了一次:
pip install torch2.0.0 torchvision0.15.1 torchaudio==2.0.1 --index-url https://download.pytorch.org/whl/cu118
這回對了。我只卸載了torchvision,所以torchaudio沒有更新。
torch 2.0.0+cu118
torchaudio 2.0.1
torchvision 0.15.1+cu118
此時就出現了最前面的錯誤。
————————
暫時的補救方法
我讀的是qwen1.5 7B,設置torch_dtype=torch.bfloat16。把bfloat16改成torch_dtype=torch.float16后, 就能推理了。或者把torchvision退回普通版本。
但是torch.float16和torch.bfloat16是完全不同的兩個東西,就這么換了,不對勁啊。。。
——————————————
最好的補救方法
使用torch_dtype=“auto”,transformers會自動使用bfloat16.
我還做了一些觀察,在不同條件下打印model.config:
- 我用Autoconfig使用qwen自帶的config文件送到AutoModelForCausalLM.from_pertrained里,顯示用bfloat16,實際耗了float32的空間。
- 設置torch_dtype=torch.float16,耗費16的空間,顯示用的float16.
- 設置torch_dtype=“auto”,耗費16的空間,顯示bfloat16.
唉,太啥比了。