怎样在Linux系统中安装Llama3

AI技术
小华
2025-07-19

在Linux系统中安装Llama3模型可以通过多种方法实现,以下是详细的步骤指南:

使用Ollama工具部署Llama3

  1. 安装Ollama
  • 安装依赖项:
sudo apt update && sudo apt install -y curl
  • 一键安装Ollama:
curl -fsSL https://ollama.com/install.sh | sh

或者,您可以先下载脚本查看内容,确认无误后再执行:

curl -fsSL https://ollama.com/install.sh -o install_ollama.sh
cat install_ollama.sh
bash install_ollama.sh
  1. 下载并运行Llama3模型
  • 下载Llama3模型:
ollama run llama3:8b

这将下载并运行8亿参数的Llama3模型。您也可以使用ollama run llama3来运行默认的8B模型。

  1. 使用OpenWebUI进行交互(可选):
  • 安装Docker(如果尚未安装):
sudo apt-get install -y apt-transport-https ca-certificates curl python-software-properties software-properties-common
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/debian/gpg | sudo apt-key add -
# 根据您的Deepin Linux版本添加相应的Docker CE仓库
deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/debian buster stable
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker
  • 安装OpenWebUI:
docker run -d -p 3000:8080 --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main

或者使用国内下载源:

docker run -d -p 3000:8080 --network=host -v open-webui:/app/backend/data -e OLLAMA_BASE_URL=http://127.0.0.1:11434 --name open-webui --restart always ghcr.io/open-webui/open-webui:main
  1. 验证安装
  • 启动Ollama服务:
sudo systemctl start ollama
sudo systemctl status ollama

确认状态为“active (running)”。

  • 运行模型:
ollama run llama3:8b

这将启动与模型的交互界面,您可以在浏览器中访问http://localhost:3000来使用OpenWebUI。

从GitHub部署Llama3

  1. 克隆Llama3仓库
git clone https://github.com/meta-llama/llama3.git
cd llama3
  1. 创建并激活Python虚拟环境
python3 -m venv venv
source venv/bin/activate
  1. 安装依赖
pip install -e .
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
  1. 配置运行环境
  • 修改llama3/code/utils/init_process_group.py文件中的ncclgloo
  • 设置环境变量:
export MASTER_ADDR=localhost
export MASTER_PORT=12355
export RANK=0
export WORLD_SIZE=1
  1. 运行Llama3聊天项目
  • 创建一个名为chat.py的文件,并粘贴必要的代码。
  • 运行项目:
python chat.py --ckpt_dir Meta-Llama-3-8B-Instruct/ --tokenizer_path Meta-Llama-3-8B-Instruct/tokenizer.model --max_seq_len 512 --max_batch_size 6

以上步骤应该能帮助您在Linux系统上成功配置并运行Llama3模型。如果在安装过程中遇到问题,可以参考官方文档或相关社区支持。

亿速云提供售前/售后服务

售前业务咨询

售后技术保障

400-100-2938

7*24小时售后电话

官方微信小程序