微信扫码
添加专属顾问
我要投稿
北京时间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+中大型企业
2026-02-03
Claude Code——智能路由与切换工具
2026-02-03
作为投资方,我们试了试Kimi K2.5
2026-02-03
暴涨11.7k Star!复刻Manus上下文工程的开源Skills,Claude code等多个平台即插即用
2026-02-03
ollama v0.15.4 更新:OpenClaw全面上线,优化集成流程与工具解析能力大升级!
2026-02-03
阶跃星辰 Step 3.5 Flash 上线!更快更强更稳的 Agent 大脑,开源!
2026-02-02
一分钟部署OpenClaw+QQ,国内最爽的一键启动!
2026-02-02
这家字节系AI初创,推出首个开源Agent Skills Builder!对话Refly.AI李锦威:大多数Agent都停留在专业用户层面,没有做到真正的普惠
2026-02-02
OCR又出宠OpenDoc,速度超MinerU6倍
2025-11-19
2026-01-27
2025-12-22
2025-12-10
2025-11-17
2026-01-12
2025-11-07
2025-12-23
2026-01-29
2026-01-06
2026-01-28
2026-01-26
2026-01-21
2026-01-21
2026-01-20
2026-01-16
2026-01-02
2025-12-24