Files
2026-05-12 17:01:39 +08:00

115 lines
2.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# SFT Full-Log Qwen3.5-2B Server Bundle
这个目录可以直接拷到服务器上做 full-log SFT。
## 包含内容
- `data/train_sft.jsonl`
- `data/dev_sft.jsonl`
- `scripts/train_sft.py`
- `scripts/analyze_sft_lengths.py`
- `scripts/compare_eval_results.py`
- `scripts/build_sft_dataset.py`
- `run_train.sh`
- `requirements.txt`
- `manifest.json`
## 数据说明
- 训练格式是 chosen-only 的对话式 SFT。
- 每条样本是单个 `messages` 字段,包含:
- `system`
- `user`
- `assistant`
- 数据来源是 full-log preference pairs 的 `chosen` 侧。
- 这意味着训练分布比之前压缩版 DPO 更接近 benchmark baseline 的原始长日志输入。
## 默认模型
默认就是:
```bash
Qwen/Qwen3.5-2B
```
## GPU 参数
`run_train.sh` 支持:
- `--gpu-count 0`:只用 GPU 0
- `--gpu-count 1`:只用 GPU 1
- `--gpu-count 2`:双卡
这里双卡仍然是 `torchrun` 数据并行,不是模型切分,所以默认长度不会因为双卡自动放大。
## 默认训练配置
- `max_length=4096`
- `max_prompt_length=3584`
- `max_completion_length=512`
- `reference-free` 不再相关,因为这是 SFT 不是 DPO
- `sdpa`
- `QLoRA + 4bit + bf16`
## 训练
先装依赖:
```bash
pip install -r requirements.txt
```
训练前先看长度:
```bash
python scripts/analyze_sft_lengths.py --model-name Qwen/Qwen3.5-2B --train-file data/train_sft.jsonl --dev-file data/dev_sft.jsonl
```
双卡训练:
```bash
bash run_train.sh --gpu-count 2 --model-name Qwen/Qwen3.5-2B
```
单卡 0
```bash
bash run_train.sh --gpu-count 0 --model-name Qwen/Qwen3.5-2B
```
单卡 1
```bash
bash run_train.sh --gpu-count 1 --model-name Qwen/Qwen3.5-2B
```
如果显存还有余量,再手动抬长度:
```bash
MAX_LENGTH=6144 MAX_PROMPT_LENGTH=5632 MAX_COMPLETION_LENGTH=512 bash run_train.sh --gpu-count 2 --model-name Qwen/Qwen3.5-2B
```
## 训练前后对比
建议继续用 benchmark 的 baseline prompt 做主对比,命令风格保持你之前那套:
训练前:
```bash
python eval_api.py --model Qwen/Qwen3.5-2B --api-base http://localhost:8000/v1 --api-key not-needed --temperature 0 --no_thinking --output-dir results/qwen35_2b_before
```
训练后:
```bash
python eval_api.py --model your-sft-model --api-base http://localhost:8000/v1 --api-key not-needed --temperature 0 --no_thinking --output-dir results/qwen35_2b_after_sft
```
对比:
```bash
python scripts/compare_eval_results.py --before ../results/qwen35_2b_before --after ../results/qwen35_2b_after_sft
```
如果你把 bundle 放到别的目录,`--before` / `--after` 直接传两个结果目录或两个 `summary.json` 路径即可。