Llama 3官网|llama3 本地部署|llama3下载

在家用电脑上部署Llama 3 ,不需要联网来运行自己的私有AI模型。

nidongde2024-04-24 21:10:1337
Meta 推出其最新一代开源大型语言模型 Llama 3,它再一次成为开源模型界的领头羊驼。我前面的文章已经介绍过Llama 3 了,今天主要讲怎么在家用电脑上部署Llama 3 ,不需要联网来运行自己的私有AI模型。
Meta的新一代开源模型Llama3惊艳登场!划重点比Gemini Pro 1.5都强
Llama 3目前提供 8B 和 70B 两种大小参数,经过预训练或微调的多种配置模型。预训练是基础模型,方便开发者后续开发自己的微调模型。我们本地部署主要下载8B参数的微调模型,只要8G以上显卡就可以了,70B参数一般需要专业显卡,例如A100,40G显卡。
下面是如何在本地运行模型的详细指南。
选项1:Python部署
这个适合电脑已经部署有Python的Conda环境下的直接安装 Llama 3。
在github.com/meta-llama/llama3 下载Llama 3压缩包

解压到C盘
然后到llama.meta.com/llama-downloads 申请许可和模型下载链接。填一下姓名,生日,国籍,公司,邮箱。不需要实名,随便填一下,勾选Meta Llama 3,点击下方continue,确认许可,会返回一个下载链接,这个链接并不能直接下载,只能在终端命令行下载。

进入刚刚解压的\llama3-main文件夹里,文件夹栏输入“CMD”,在命令行输入“pip install -e”安装环境。如果报错,可能需要在pip install -e 后面加上你的llama3的文件夹地址,例如“pip install -e :\llama3-main”。

等它自动下载安装好环境后,右键选择“bash here”进入conda命令行,输入“bash download.sh”,出现“Enter the URL from email:”后粘贴刚才获得的下载链接,然后会让你选择要下载的模型,有4个模型,分别是8B(预训练模型),8B-instruct(微调模型),70B,70B-instruct,我们选第二个,输入“8B-instruct”后回车,会自动下载模型。
(有可能会报错缺失weget命令,在eternallybored.org/misc/wget/ 下载weget.exe文件放到C:\Windows\System32 里就好了)

下载好模型后,在命令行运行示例脚步,执行以下命令:
torchrun --nproc_per_node 1 example_chat_completion.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
创建对话脚本,在根目录下创建以下chat.py脚本
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This software may be used and distributed in accordance with the terms of the Llama 3 Community License Agreement.
from typing import List, Optional
import fire
from llama import Dialog, Llama
def main(
ckpt_dir: str,
tokenizer_path: str,
temperature: float = 0.6,
top_p: float = 0.9,
max_seq_len: int = 512,
max_batch_size: int = 4,
max_gen_len: Optional[int] = None,
):
"""
Examples to run with the models finetuned for chat. Prompts correspond of chat
turns between the user and assistant with the final one always being the user.
An optional system prompt at the beginning to control how the model should respond
is also supported.
The context window of llama3 models is 8192 tokens, so `max_seq_len` needs to be <= 8192.="">
`max_gen_len` is optional because finetuned models are able to stop generations naturally.
"""
generator = Llama.build(
ckpt_dir=ckpt_dir,
tokenizer_path=tokenizer_path,
max_seq_len=max_seq_len,
max_batch_size=max_batch_size,
)
# Modify the dialogs list to only include user inputs
dialogs: List[Dialog] = [
[{"role": "user", "content": ""}],  # Initialize with an empty user input
]
# Start the conversation loop
while True:
# Get user input
user_input = input("You: ")
# Exit loop if user inputs 'exit'
if user_input.lower() == 'exit':
break
# Append user input to the dialogs list
dialogs[0][0]["content"] = user_input
# Use the generator to get model response
result = generator.chat_completion(
dialogs,
max_gen_len=max_gen_len,
temperature=temperature,
top_p=top_p,
)[0]
# Print model response
print(f"Model: {result['generation']['content']}")
if __name__ == "__main__":
fire.Fire(main)
运行以下命令就可以开始对话了:

torchrun --nproc_per_node 1 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

选项 2:使用 Ollama + Open Webui
支持的平台: MacOS、Ubuntu、Windows(预览版)

Ollama 是目前在本地部署AI大语言模型最常用的方法之一。只需在此处下载应用程序,点击文件自动安装,然后在命令行中运行以下命令。
ollama run llama3
这将下载 Llama 3 8B 指令(微调)模型。
您可以选择提供标签,但如果不这样做,它将默认为最新的。该标签用于标识特定版本。例如你可以运行:
ollama run llama3:70b-text
ollama run llama3:70b-instruct
下载好模型后,再次在命令行运行 ollama runllama3 ,就可以直接跟 llama3 对话了,当然这种方式很不直观,也不能保存历史对话。

如果您想要一个类似于OpenAI的ChatGPT那样的对话窗口,就需要安装Open WebUI项目了。而安装Open Webui 需要先安装docker。
在github.com/open-webui/open-webui 或者 www.docker.com/products/docker-desktop/ 下载docker。下载安装后在命令行输入以下命令安装Open Webui。
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
完成后打开浏览器,您可以通过http://localhost:3000访问 Open WebUI ,并进行AI对话了。

选项 3:使用 LM Studio
前面我已讲过LM Studio的安装使用。

使用LM Studio一键部署本地AI大语言模型

需要更新到0.2.20版

然后搜索“lmstudio llama 3”,下载好模型就可以使用了。注意8B-instruct 有14个模型选择,推荐选择 Meta-Llama-3-8B-Instruct.Q5_K_M.gguf,电脑较好的也可以选择最大8G多的那个模型。

选项 4:Jan.ai
这是我目前使用过的最简单,最方便的,本地部署AI大模型的开源软件。
只需要在Jan.ai下载相应版本软件,点击文件会自动安装。

然后去抱抱脸下载 llama 3 模型。没有魔法网络的推荐国内镜像网站下载 hf-mirror.com/QuantFactory/Meta-Llama-3-8B-Instruct-GGUF/tree/main。
模型越大需要的电脑配置越高,根据自己电脑情况酌情下载。将下载好的模型放到C:\Users\xxx\jan\models 目录下(xxx是你自己电脑的用户名)。然后点开Jan就可以直接跟AI聊天了。
选项 5:GPT4All
GPT4ALL也是一个很方便本地部署AI模型的一个工具,只有安装文件,然后下载模型就可以运行了,唯一的缺点是全英文界面。
只需在此处下载模型,就可以对话了。或者选择右上角的设置,改变模型地址,将前面下载的模型放到设置的文件夹中。

Llama特别喜欢用表情符号。

以上就是目前比较常用的几种本地部署AI大语言模型的方法了,新手建议选择最后两种,简单快捷。以上所有文件我都放在网盘,需要的朋友后台回复“llama3”免费领取。


本文链接:https://www.hzby.vip/Llama3/36.html

llama模型开源协议llama模型羊驼llama模型与达芬奇模型llama开源模型llama 65b模型部署llama模型是干什么的如何部署llama2大模型llama 模型结构llama65b大模型llama模型是什么架构

相关文章

网友评论