|
|
2 hafta önce | |
|---|---|---|
| .. | ||
| README_Qwen3.5_Local.md | 2 hafta önce | |
| colab_example.py | 2 hafta önce | |
| quantization_workflow.py | 2 hafta önce | |
| quantize_awq.py | 2 hafta önce | |
| quantize_gguf.py | 2 hafta önce | |
| quantize_gptq.py | 2 hafta önce | |
| quantize_lora_model.py | 2 hafta önce | |
| qwen3.5_0.8b_finetune.py | 2 hafta önce | |
| qwen3.5_0.8b_local_finetune.py | 2 hafta önce | |
打开 examples/qwen3.5_0.8b_local_finetune.py,修改以下配置:
# 本地模型路径(请根据实际情况修改)
local_model_path = "./models/Qwen3.5-0.8B"
# 示例路径:
# Windows: local_model_path = "D:\\AI_Models\\Qwen3.5-0.8B"
# Linux: local_model_path = "/home/user/models/Qwen3.5-0.8B"
python examples/qwen3.5_0.8b_local_finetune.py
脚本会自动:
python scripts/inference.py --model_path ./outputs/qwen3.5-0.8b-finetuned --interactive
在脚本中修改 config 对象:
config = QwenConfig(
model_name=local_model_path,
# LoRA 配置
lora_r=16, # LoRA 秩 (8, 16, 32)
lora_alpha=32, # LoRA alpha (通常是 r 的 2 倍)
lora_dropout=0.05, # Dropout 率
# 训练配置
per_device_train_batch_size=1,
gradient_accumulation_steps=4,
learning_rate=2e-4,
num_train_epochs=3,
max_seq_length=512,
# 量化配置
use_4bit=True, # 使用 4bit 量化节省显存
)
# 修改数据集路径
dataset_path = "path/to/your/dataset.json"
# 数据集格式:
[
{
"instruction": "你的指令",
"input": "输入(可选)",
"output": "期望输出"
}
]
如果显存不足,可以调整以下参数:
# 降低显存占用的配置
config = QwenConfig(
use_4bit=True, # 启用 4bit 量化
per_device_train_batch_size=1, # 减小批次大小
gradient_accumulation_steps=8, # 增加梯度累积
max_seq_length=256, # 减小序列长度
)
| 数据集大小 | Epochs | 批次大小 | 预计时间 (单卡) |
|---|---|---|---|
| 100 条 | 3 | 1 | ~10 分钟 |
| 1000 条 | 3 | 1 | ~1-2 小时 |
| 10000 条 | 3 | 2 | ~10-15 小时 |
注:时间取决于 GPU 性能
A: 确保路径正确,可以使用绝对路径:
local_model_path = "/absolute/path/to/Qwen3.5-0.8B"
A: 尝试:
use_4bit=Truemax_seq_lengthper_device_train_batch_sizegradient_accumulation_stepsA: 修改脚本,添加恢复检查点:
trainer.train(resume_from_checkpoint="./outputs/qwen3.5-0.8b-finetuned/checkpoint-100")
A: 使用推理脚本:
python scripts/inference.py --model_path ./outputs/qwen3.5-0.8b-finetuned --interactive
训练完成后,输出目录结构:
outputs/qwen3.5-0.8b-finetuned/
├── adapter_config.json # LoRA 配置
├── adapter_model.safetensors # LoRA 权重
├── tokenizer.json # Tokenizer
├── tokenizer_config.json # Tokenizer 配置
└── training_args.bin # 训练参数
# 在脚本最后添加:
trainer.push_to_hub("your-username/qwen3.5-0.8b-finetuned")
祝微调顺利!🚀