微信扫码
添加专属顾问
我要投稿
北京时间4月19日凌晨,Meta公司通过其官方网站宣布了Llama系列的最新开源大模型:Llama-3。
继Llama-1、Llama-2以及Code-Llama之后,Llama-3作为该系列的第三代模型,在众多关键的基准测试中取得了全面的进步,其性能在当前业界的同类模型中处于领先地位。
Llama大模型家族概述
Llama3技术特性
模型架构
预训练数据
扩展预训练
指令微调
Llama3大模型微调
注:请申请一个免费 T4 GPU 来运行该脚本
%cd /content/%rm -rf LLaMA-Factory!git clone https://github.com/hiyouga/LLaMA-Factory.git%cd LLaMA-Factory%ls!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"!pip install --no-deps xformers==0.0.25!pip install .[bitsandbytes]
检查 GPU 环境
import torchtry:assert torch.cuda.is_available() is Trueexcept AssertionError: print("ERROR,需要 GPU 环境")更新自我认知数据集
import json%cd /content/LLaMA-Factory/NAME = "Llama-Chinese"AUTHOR = "LLaMA Factory"with open("data/identity.json", "r", encoding="utf-8") as f:dataset = json.load(f)for sample in dataset:sample["output"] = sample["output"].replace("NAME", NAME).replace("AUTHOR", AUTHOR)with open("data/identity.json", "w", encoding="utf-8") as f:json.dump(dataset, f, indent=2, ensure_ascii=False)
from llmtuner import run_expfrom llmtuner.extras.misc import torch_gc%cd /content/LLaMA-Factory/run_exp(dict(stage="sft",# 进行指令监督微调do_train=True,model_name_or_path="unsloth/llama-3-8b-Instruct-bnb-4bit", # 使用 4 比特量化版 Llama-3-8b-Instruct 模型dataset="identity,alpaca_gpt4_en,alpaca_gpt4_zh",# 使用 alpaca 和自我认知数据集template="llama3", # 使用 llama3 提示词模板finetuning_type="lora", # 使用 LoRA 适配器来节省显存lora_target="all", # 添加 LoRA 适配器至全部线性层output_dir="llama3_lora",# 保存 LoRA 适配器的路径per_device_train_batch_size=2, # 批处理大小gradient_accumulation_steps=4, # 梯度累积步数lr_scheduler_type="cosine", # 使用余弦学习率退火算法logging_steps=10,# 每 10 步输出一个记录warmup_ratio=0.1,# 使用预热学习率save_steps=1000,# 每 1000 步保存一个检查点learning_rate=5e-5, # 学习率大小num_train_epochs=3.0,# 训练轮数max_samples=300,# 使用每个数据集中的 300 条样本max_grad_norm=1.0, # 将梯度范数裁剪至 1.0quantization_bit=4, # 使用 4 比特 QLoRAloraplus_lr_ratio=16.0, # 使用 LoRA+ 算法并设置 lambda=16.0use_unsloth=True,# 使用 UnslothAI 的 LoRA 优化来加快一倍的训练速度fp16=True, # 使用 float16 混合精度训练))torch_gc()
模型推理
from llmtuner import ChatModelfrom llmtuner.extras.misc import torch_gc%cd /content/LLaMA-Factory/chat_model = ChatModel(dict(model_name_or_path="unsloth/llama-3-8b-Instruct-bnb-4bit", # 使用 4 比特量化版 Llama-3-8b-Instruct 模型adapter_name_or_path="llama3_lora",# 加载之前保存的 LoRA 适配器finetuning_type="lora",# 和训练保持一致template="llama3", # 和训练保持一致quantization_bit=4,# 加载 4 比特量化模型use_unsloth=True, # 使用 UnslothAI 的 LoRA 优化来加快一倍的推理速度))messages = []while True:query = input("\nUser: ")if query.strip() == "exit":breakif query.strip() == "clear":messages = []torch_gc()print("History has been removed.")continuemessages.append({"role": "user", "content": query}) # 把提示词添加到消息中print("Assistant: ", end="", flush=True)response = ""for new_text in chat_model.stream_chat(messages):# 流式输出print(new_text, end="", flush=True)response += new_textprint()messages.append({"role": "assistant", "content": response}) # 把回答添加到消息中torch_gc()
Llama3的大模型测评
Llama3系列的基础预训练模型在多个评测基准的性能表现,相较于上一代的Llama2和Llama系列,性能得到了很大提升。
Llama3部署与应用
Meta AI,使用 Llama 3 构建
在线体验
本地部署
未来展望
Meta将发布多个具有新功能的模型,包括多模态、使用多种语言交谈的能力、更长的上下文窗口和更强大的整体功能。先一睹为快~
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费POC验证,效果达标后再合作。零风险落地应用大模型,已交付160+中大型企业
2025-10-24
法律人需要有自己的GitHub和Cursor
2025-10-24
MineContext:字节开源的主动式上下文感知 AI 工具,助力高效信息管理
2025-10-24
10 大开源 OCR 模型对比
2025-10-23
从ChatGPT到全模型适配:这个开源项目藏着1000+AI提示词「作弊码」
2025-10-22
DeepSeek 和百度,把 OCR 推到了新水准
2025-10-22
字节开源了一个让人上头的 Context 项目
2025-10-22
Zilliz,源于Milvus,高于Milvus
2025-10-22
OpenAgents:只需几条命令即可构建协作式 AI 网络
2025-08-20
2025-09-07
2025-08-05
2025-08-20
2025-07-29
2025-07-31
2025-07-29
2025-08-26
2025-07-27
2025-08-22
2025-10-13
2025-09-29
2025-09-17
2025-09-09
2025-09-08
2025-09-07
2025-09-01
2025-08-16