在安装Llama3所需的Python依赖(如torch
、tiktoken
、sentencepiece
)时,常因版本不兼容导致安装失败(如ERROR: Could not find a version that satisfies the requirement...
)。
解决方法:使用指定版本的依赖包,避免自动安装最新版的不兼容问题。例如:
pip install torch==2.0.1 tiktoken==0.5.1 sentencepiece==0.1.99
建议参考Llama3官方文档或项目requirements.txt
文件中的版本要求。
Llama3需要GPU加速(支持CUDA),若CUDA版本与GPU驱动、PyTorch版本不匹配,会出现CUDA error: no kernel image is available for execution on the device
或RuntimeError: CUDA out of memory
等错误。
解决方法:
pip install torch --extra-index-url https://download.pytorch.org/whl/cu112
)。加载模型时,若指定的模型路径不存在或文件不完整(如缺少consolidated.00.pth
、params.json
等关键文件),会出现FileNotFoundError
或Failed to load model weights
错误。
解决方法:
ls
命令检查路径下的文件);model_path = "/home/user/llama3/Meta-Llama-3-8B"
);Llama3模型(尤其是70B参数版本)对显存要求极高(如8B模型需至少16GB显存,70B模型需24GB+显存),若显存不足,会出现CUDA out of memory
错误。
解决方法:
max_batch_size
参数,如从32调整为16);--tensor_model_parallel_size 2
启动参数,将模型分配到多个GPU);gradient_checkpointing=True
)减少显存占用。若Ollama服务默认端口(11434)已被其他程序占用,会出现Error: listen tcp 127.0.0.1:11434: bind: address already in use
错误。
解决方法:
netstat -tulpn | grep 11434
);~/.ollama/config.json
中的OLLAMA_HOST
字段,如改为0.0.0.0:11435
);kill -9
,其中
为netstat
命令输出的进程ID)。若CUDA或Python环境变量(如PATH
、LD_LIBRARY_PATH
)未正确设置,会导致torch
无法找到CUDA库(RuntimeError: CUDA runtime error: invalid device ordinal
)或命令无法识别(如ollama: command not found
)。
解决方法:
PATH
(如export PATH=/usr/local/cuda/bin:$PATH
);LD_LIBRARY_PATH
(如export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
);PATH
(如export PATH=/usr/local/src/ollama/bin:$PATH
);source ~/.bashrc
或source ~/.zshrc
使配置生效。Llama3模型需要params.json
(模型参数)或config.json
(Hugging Face配置)文件,若文件缺失或格式错误,会出现JSONDecodeError
或KeyError
。
解决方法:
Meta-Llama-3-8B/params.json
);FileNotFoundError
并设置默认参数)。