服务器LLama Factory Lora 微调模型过程记录

连接远程服务器

1、把训练需要的文件移动到服务端

bash 复制代码
scp wangfei@10.30.71.37:/Users/wangfei/Documents/code/python/smart_home_agent_v1/training/sft_train.json /home/ubuntu/lingzhi/wangf36_temp 

2、查看显卡占用情况

bash 复制代码
nvidia-smi

尴尬,有人在用

看看别人在干啥吧

js 复制代码
ps -fp 596080
ps -fp 596081
ps -fp 596082
ps -fp 596083

估计也在训练,只能等等了

查看dataset数据

json 复制代码
"smart_home_sft": {
    "file_name": "sft_train.json",
    "formatting": "sharegpt"
  }

把文件移动到data目录下面

bash 复制代码
mv /home/ubuntu/lingzhi/wangf36_temp/sft_train.json /home/ubuntu/lingzhi/LLaMA-Factory/data

查看训练文件

yaml 复制代码
### model
model_name_or_path: /home/ubuntu/lingzhi/base_model/Qwen3-4B-Instruct-2507
trust_remote_code: true

### method
stage: sft
do_train: true
finetuning_type: lora
lora_target: all

### lora config
lora_rank: 32
lora_alpha: 64
lora_dropout: 0.05

### dataset
dataset: smart_home_sft
dataset_dir: data
template: qwen
cutoff_len: 2048
overwrite_cache: true
preprocessing_num_workers: 8

### output
output_dir: saves/smart_home_lora_1
logging_steps: 5
save_steps: 50
plot_loss: true
overwrite_output_dir: true

### train
per_device_train_batch_size: 8
gradient_accumulation_steps: 2
learning_rate: 3.0e-4
num_train_epochs: 5.0
max_grad_norm: 1.0
lr_scheduler_type: cosine
warmup_ratio: 0.1
bf16: true

### distributed (4x H20)
ddp_timeout: 180000000
flash_attn: fa2

### eval
val_size: 0.1
per_device_eval_batch_size: 8
eval_strategy: steps
eval_steps: 50

开始训练

bash 复制代码
conda activate llama_factory
bash 复制代码
llamafactory-cli train /home/ubuntu/lingzhi/LLaMA-Factory/examples/train_lora/llama_factory_config.yaml
bash 复制代码
llamafactory-cli train examples/train_lora/llama_factory_config.yaml

合并lora权重

bash 复制代码
llamafactory-cli export \
  --model_name_or_path /home/ubuntu/lingzhi/base_model/Qwen3-4B-Instruct-2507 \
  --adapter_name_or_path /home/ubuntu/lingzhi/LLaMA-Factory/saves/smart_home_lora_1 \
  --finetuning_type lora \
  --export_dir /home/ubuntu/lingzhi/trained_models_real/smart_home_model_260422

使用vllm启动模型的api服务

bash 复制代码
python -m vllm.entrypoints.openai.api_server \
  --model /home/ubuntu/lingzhi/trained_models_real/smart_home_model_260422 \
  --host 0.0.0.0 \
  --port 8000 \
  --trust-remote-code \
  --served-model-name smart_home\
  --enable-auto-tool-choice \
  --tool-call-parser hermes 

本地测试

bash 复制代码
curl http://127.0.0.1:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "smart_home",
    "messages": [{"role": "user", "content": "打开客厅灯"}]
  }'

远程测试

bash 复制代码
curl http://172.21.12.16:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "smart_home",
    "messages": [{"role": "user", "content": "打开客厅灯"}]
  }'
js 复制代码
(llama_factory) ubuntu@VM-12-16-ubuntu:~/lingzhi/base_model/Qwen3-4B-Instruct-2507$ pwd
/home/ubuntu/lingzhi/base_model/Qwen3-4B-Instruct-2507
相关推荐
组合缺一10 小时前
Java AI 框架三国杀:Solon AI vs Spring AI vs LangChain4j 深度对比
java·人工智能·spring·ai·langchain·llm·solon
JaydenAI11 小时前
[Deep Agents:LangChain的Agent Harness-09]利用MemoryMiddleware构建能够自我学习和进化的Agent
langchain·middleware·deep agents
爱吃的小肥羊11 小时前
Claude Code 推出Agent View,一个人同时指挥十个 AI 写代码!
aigc·ai编程
devpotato11 小时前
人工智能(十六)- SSE 流式:让 Agent 像 ChatGPT 一样“边想边说“
人工智能·语言模型·langchain
紫小米12 小时前
OpenClaw的智能体和LangChain的智能体有什么区别?
langchain
叼馒女友郭芙蓉12 小时前
学习记录02——langChain : Runnable
langchain
爱吃的小肥羊12 小时前
又搞事情,OpenAI 开始关闭微调服务!
aigc·openai
imbackneverdie12 小时前
一天怎么完成论文初稿
人工智能·自然语言处理·aigc·ai写作·论文写作·论文投稿·科研工具
用户51914958484513 小时前
图片上传绕过与存储型XSS漏洞利用技术详解
人工智能·aigc
AI先驱体验官13 小时前
臻灵短剧平台 · 用户操作手册
大数据·人工智能·深度学习·重构·aigc