惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
S
Secure Thoughts
T
Tailwind CSS Blog
博客园 - 三生石上(FineUI控件)
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Troy Hunt's Blog
阮一峰的网络日志
阮一峰的网络日志
博客园 - 叶小钗
博客园 - 司徒正美
NISL@THU
NISL@THU
小众软件
小众软件
宝玉的分享
宝玉的分享
Hugging Face - Blog
Hugging Face - Blog
T
Threat Research - Cisco Blogs
Hacker News: Ask HN
Hacker News: Ask HN
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园_首页
罗磊的独立博客
S
Securelist
N
News | PayPal Newsroom
大猫的无限游戏
大猫的无限游戏
T
Tenable Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Visual Studio Blog
爱范儿
爱范儿
Spread Privacy
Spread Privacy
V2EX - 技术
V2EX - 技术
J
Java Code Geeks
V
V2EX
人人都是产品经理
人人都是产品经理
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
I
Intezer
腾讯CDC
P
Privacy & Cybersecurity Law Blog
SecWiki News
SecWiki News
Google DeepMind News
Google DeepMind News
P
Palo Alto Networks Blog
Cloudbric
Cloudbric
Apple Machine Learning Research
Apple Machine Learning Research
N
News and Events Feed by Topic
Latest news
Latest news
L
LINUX DO - 最新话题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
博客园 - 【当耐特】
Last Week in AI
Last Week in AI
The Cloudflare Blog

LLaMA Factory – 百品博客

暂无文章

AI部署实践:Colab部署AI模型进行Fine Tuning - 百品博客
MX文章作者勇敢打破裂缝,阳光就会洒满其中。 · 2026-03-17 · via LLaMA Factory – 百品博客

准备

首先进入Google Colab,点选“代码执行程序”,将GPU改为T4,以确保算力足够。

VLLM-Based

然后安装相关环境:

! pip install uv #安装UV以保证安装速度
!uv pip install vllm --torch-backend=auto --extra-index-url https://wheels.vllm.ai/nightly #安装VLLM

安装ai模型。到Hugging Face Hub上选用模型并部署。这里笔者使用2026年2月刚刚发布的新模型Qwen3.5-0.8B,参数量选择使用0.8B的小模型来加快速度。同时声明类型为float16以适应T4 GPU。

# 为防止出现错误,升级相关库:
!pip install --upgrade grpcio
!pip install --upgrade protobuf
!vllm serve Qwen/Qwen3.5-0.8B --port 8000 --tensor-parallel-size 1 --max-model-len 262144 --dtype float16  #安装Qwen3.5-0.8B

安装时间大概需要30mins+。(但是最终等不及放弃了,接下来将会使用LLaMA演示)

LLaMA Factory

如果使用LLaMA Factory部署将会非常方便。

如果使用LLaMA Factory,则运行文档中提供的代码:

%cd /content/
%rm -rf LLaMA-Factory
!git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git
%cd LLaMA-Factory
%ls
!pip install -e .[torch,bitsandbytes]
import torch
try:
  assert torch.cuda.is_available() is True
except AssertionError:
  print("Please set up a GPU before using LLaMA Factory: https://medium.com/mlearning-ai/training-yolov4-on-google-colab-316f8fff99c6")
import json

%cd /content/LLaMA-Factory/

NAME = "Llama-3"
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)

升级相关库,安装Chinese库以供预测:

!pip install --upgrade transformers
!pip install rouge_chinese

部署Board:

%cd /content/LLaMA-Factory/
!GRADIO_SHARE=1 DISABLE_VERSION_CHECK=1 llamafactory-cli webui
# 注意设置取消环境版本检查

执行

得到board地址,打开,调整Fine-tuning参数。设置checkpoint_path = 留空,如果报错,第一次微调时就填”Qwen/Qwen2.5-0.5B”(和Model Path一致)(原本打算使用3.5-0.8B模型,但发现T4的GPU带不动)

https://baipin.pw/wp-content/uploads/2026/03/image-1.png

其余保持不变即可,其中的Training model可以根据自己的喜好选择。Learning rate(控制在训练过程中每次更新权重的幅度), Batch size(每次前向/反向传播过程中使用的训练样本数量), Number of epochs(整个数据集在训练过程中被模型训练的次数)等等都可以自己手动调整来观察训练的结果变化。

然后滑动到页面底部,选择“start”开始Fine-tuning。这个过程大概持续30~40min。

完成之后,点选到Evaluate & Predict选项卡查看模型效果,之后可以再选择其余的Finetuning method,以体验不同Finetuning模式下的差异。最后可以自己到Chat选项卡体验成品效果,和自己训练的模型对话。

保存模型

在Colab中运行如下代码以保存工作目录下的模型及日志:

!zip -r my_folder.zip /content/LLaMA-Factory/saves  # 结尾为要压缩的目标文件夹
from google.colab import files
files.download("my_folder.zip")

或者只保留日志文件:

!cd /content/LLaMA-Factory/saves && find . -type f \( -name "*.json" -o -name "*.jonl" -o -name "*.txt" -o -name "*.yaml" -o -name "*.bin" -o -name "*.png" \) | zip -@ ../elected_files.zip