Baichuan2 Fine-Tuning
Use this sub-skill when the task is to prepare, explain, validate, or launch supervised fine-tuning for Baichuan2-7B-Base. It covers the training data format, the bundled supervised trainer, DeepSpeed ZeRO-3 launch structure, multi-machine hostfiles, LoRA toggling, and how to load the saved fine-tuned result.
Do not use this sub-skill for inference demos, chat APIs, quantized loading, or CPU deployment. Route those tasks to the appropriate inference or deployment guidance instead.
Read first
- For an end-to-end run plan, read
references/workflows.md.
- For JSON training data requirements and label construction, read
references/data-format.md.
- For ZeRO-3 and
ds_config interpretation, read references/deepspeed-config.md.
- For dependency expectations and environment checks, read
references/installation.md.
- For failure diagnosis, read
references/troubleshooting.md.
Bundled helpers
scripts/validate_training_data.py: validates Belle-style multi-turn JSON, can write a tiny fixture, and can optionally estimate token truncation with a Baichuan tokenizer.
scripts/train_supervised.py: self-contained supervised trainer adapted for Baichuan2-7B-Base with schema validation, dry-run mode, DeepSpeed config generation, and LoRA options.
Routing checklist
- Confirm the user is fine-tuning a Base checkpoint, normally
baichuan-inc/Baichuan2-7B-Base, not asking for inference or quantized deployment.
- Validate the JSON data before launching any distributed job.
- Decide full-parameter versus LoRA fine-tuning. Use LoRA when VRAM or wall-clock budget is limited, and keep
target_modules=W_pack unless the model architecture has been intentionally changed.
- Create or verify a DeepSpeed ZeRO-3 config and match it with the Hugging Face
TrainingArguments flags.
- For one machine, use an empty or omitted hostfile. For multiple machines, prepare a DeepSpeed hostfile with one
hostname slots=N line per node.
- After training, load a full fine-tuned output with
AutoModelForCausalLM.from_pretrained(...); load LoRA adapter output with peft.AutoPeftModelForCausalLM.from_pretrained(...).
Safe default posture
Before launching training, prefer:
python scripts/validate_training_data.py \
--data_path /path/to/train.json \
--model_max_length 512
python scripts/train_supervised.py \
--dry_run True \
--data_path /path/to/train.json \
--model_name_or_path baichuan-inc/Baichuan2-7B-Base \
--output_dir /path/to/output \
--model_max_length 512
Only move from dry-run validation to DeepSpeed training when dependencies, CUDA visibility, hostfile formatting, and data schema all pass.
1---2name: fine-tuning3description: "Route supervised fine-tuning, DeepSpeed, LoRA, data preprocessing,4 and post-training loading for Baichuan2-7B-Base."5metadata:6 source: https://skillmd.com/skills/vectorspacelab/fine-tuning7 disco-role: operating8disable-model-invocation: true9license: Apache 2.010---1112# Baichuan2 Fine-Tuning1314Use this sub-skill when the task is to prepare, explain, validate, or launch supervised fine-tuning for Baichuan2-7B-Base. It covers the training data format, the bundled supervised trainer, DeepSpeed ZeRO-3 launch structure, multi-machine hostfiles, LoRA toggling, and how to load the saved fine-tuned result.1516Do **not** use this sub-skill for inference demos, chat APIs, quantized loading, or CPU deployment. Route those tasks to the appropriate inference or deployment guidance instead.1718## Read first1920- For an end-to-end run plan, read [`references/workflows.md`](references/workflows.md).21- For JSON training data requirements and label construction, read [`references/data-format.md`](references/data-format.md).22- For ZeRO-3 and `ds_config` interpretation, read [`references/deepspeed-config.md`](references/deepspeed-config.md).23- For dependency expectations and environment checks, read [`references/installation.md`](references/installation.md).24- For failure diagnosis, read [`references/troubleshooting.md`](references/troubleshooting.md).2526## Bundled helpers2728- [`scripts/validate_training_data.py`](scripts/validate_training_data.py): validates Belle-style multi-turn JSON, can write a tiny fixture, and can optionally estimate token truncation with a Baichuan tokenizer.29- [`scripts/train_supervised.py`](scripts/train_supervised.py): self-contained supervised trainer adapted for Baichuan2-7B-Base with schema validation, dry-run mode, DeepSpeed config generation, and LoRA options.3031## Routing checklist32331. Confirm the user is fine-tuning a Base checkpoint, normally `baichuan-inc/Baichuan2-7B-Base`, not asking for inference or quantized deployment.342. Validate the JSON data before launching any distributed job.353. Decide full-parameter versus LoRA fine-tuning. Use LoRA when VRAM or wall-clock budget is limited, and keep `target_modules=W_pack` unless the model architecture has been intentionally changed.364. Create or verify a DeepSpeed ZeRO-3 config and match it with the Hugging Face `TrainingArguments` flags.375. For one machine, use an empty or omitted hostfile. For multiple machines, prepare a DeepSpeed hostfile with one `hostname slots=N` line per node.386. After training, load a full fine-tuned output with `AutoModelForCausalLM.from_pretrained(...)`; load LoRA adapter output with `peft.AutoPeftModelForCausalLM.from_pretrained(...)`.3940## Safe default posture4142Before launching training, prefer:4344```bash45python scripts/validate_training_data.py \46 --data_path /path/to/train.json \47 --model_max_length 5124849python scripts/train_supervised.py \50 --dry_run True \51 --data_path /path/to/train.json \52 --model_name_or_path baichuan-inc/Baichuan2-7B-Base \53 --output_dir /path/to/output \54 --model_max_length 51255```5657Only move from dry-run validation to DeepSpeed training when dependencies, CUDA visibility, hostfile formatting, and data schema all pass.