fcpig/Lure
025
Lure —— 基于 Qwen3.8-27B 的 LoRA 微调适配器
本仓库是 Qwen/Qwen3.8-27B 的 LoRA 微调权重(Adapter),使用 LLaMA-Factory(LLaMA Board WebUI)以 QLoRA(4-bit bitsandbytes 量化) 方式在自建多模态数据集 lure_v2 上完成监督微调(SFT)。
本仓库只包含微调部分权重(LoRA Adapter,约 223 MB)。使用前需先下载基座模型 `Qwen/Qwen3.8-27B`,加载本 Adapter 后自动合并生效。
1. 模型信息
2. 训练超参数
3. 训练结果
- 总计 372 个优化步(62 步/epoch × 6 epoch),246 条样本全部参与训练。
- 训练损失从初始 2.83 收敛至平均 0.2534(末段单步 loss 约 0.02–0.15)。
- 训练时长约 26.6 分钟(单张 GPU,QLoRA 4-bit)。
4. 训练环境
- LLaMA-Factory(LLaMA Board WebUI 发起训练)
- PEFT 0.18.1
- Transformers 5.8.0
- PyTorch 2.8.0+cu128
- Datasets 4.0.0
- Tokenizers 0.22.2
5. 快速开始(推理)
方式一:transformers + peft
import torch
from transformers import AutoProcessor, AutoModelForImageTextToText, BitsAndBytesConfig
from peft import PeftModel
BASE = "Qwen/Qwen3.8-27B"
ADAPTER = "fcpig/Lure" # 本仓库,或本地路径 ./train_0903
# 与训练时一致:4-bit 量化加载,降低显存占用(约 20GB 级显卡可运行)
bnb = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16,
bnb_4bit_use_double_quant=True,
)
model = AutoModelForImageTextToText.from_pretrained(
BASE, quantization_config=bnb, device_map="auto", trust_remote_code=True,
)
model = PeftModel.from_pretrained(model, ADAPTER)
processor = AutoProcessor.from_pretrained(ADAPTER) # 仓库内含 processor/tokenizer
messages = [{
"role": "user",
"content": [
{"type": "image", "image": "file://你的图片路径.jpg"},
{"type": "text", "text": "描述这张图片。"},
],
}]
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = processor(text=[text], images=["你的图片路径.jpg"], return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=512)
print(processor.batch_decode(out, skip_special_tokens=True)[0])方式二:LLaMA-Factory 命令行
llamafactory-cli chat \
--model_name_or_path Qwen/Qwen3.8-27B \
--adapter_name_or_path fcpig/Lure \
--template qwen3_8 \
--finetuning_type lora合并为完整权重(可选)
llamafactory-cli export \
--model_name_or_path Qwen/Qwen3.8-27B \
--adapter_name_or_path fcpig/Lure \
--template qwen3_8 \
--export_dir exports/train_0903-merged \
--export_size 206. 训练复现
- 安装环境(需 Transformers ≥ 5.2 以支持
qwen3_5/Qwen3.8 架构):
pip install "transformers>=5.2.0" peft==0.18.1 bitsandbytes
git clone https://github.com/hiyouga/LLaMA-Factory.git
cd LLaMA-Factory && pip install -e ".[torch,metrics]"- 准备数据集
lure_v2(246 条多模态样本,sharegpt 格式,含train.jsonl与对应图像文件),在data/dataset_info.json中注册:
{
"lure_v2": {
"file_name": "train.jsonl",
"formatting": "sharegpt",
"columns": { "messages": "conversations" },
"tags": { "image": "image" }
}
}- 使用与原始训练一致的配置
train_0903.yaml:
model_name_or_path: Qwen/Qwen3.8-27B
trust_remote_code: true
stage: sft
finetuning_type: lora
template: qwen3_8
enable_thinking: true
do_train: true
dataset: lure_v2
dataset_dir: data
cutoff_len: 2048
max_samples: 100000
preprocessing_num_workers: 16
per_device_train_batch_size: 2
gradient_accumulation_steps: 2
learning_rate: 5.0e-5
num_train_epochs: 6.0
lr_scheduler_type: cosine
warmup_steps: 0
max_grad_norm: 1.0
optim: adamw_torch
bf16: true
quantization_bit: 4
quantization_method: bnb
double_quantization: true
freeze_vision_tower: true
freeze_multi_modal_projector: true
lora_rank: 8
lora_alpha: 16
lora_dropout: 0.05
lora_target: all
image_max_pixels: 589824
image_min_pixels: 1024
video_max_pixels: 65536
video_min_pixels: 256
logging_steps: 5
save_steps: 100
plot_loss: true
report_to: none
seed: 42
output_dir: saves/train_0903- 启动训练:
llamafactory-cli train train_0903.yaml固定 seed: 42、相同软硬件环境下可基本复现训练曲线(量化训练存在少量非确定性,最终 loss 应收敛至 0.25 左右)。
7. 仓库文件说明
注:训练过程中的中间检查点(checkpoint-100/200/300/372)与最终权重内容一致(checkpoint-372 即第 372 步 = 6 epoch 结束),未随仓库上传;training_args.bin、WebUI 日志等运行时文件亦未包含。
8. 引用与许可
- 基座模型:Qwen/Qwen3.8-27B(Apache-2.0)
- 微调框架:LLaMA-Factory
- 本 Adapter 权重按 Apache-2.0 发布。
