Axolotl Fine-Tuning Tutorial 2026
Training scripts grow into 500 lines of boilerplate that nobody can reproduce. Axolotl puts every training decision into one YAML: data, quantization, LoRA rank, packing, parallelism. Here is a minimal config that runs.
📜 Table of Contents
Axolotl Fine-Tuning Tutorial 2026: Config-Driven LLM Training With Real Code
A training script grows into 500 lines of boilerplate: data loading, chat templates, quantization, gradient accumulation, checkpoints, logging — rewritten for every model, with no guarantee two runs match.
Axolotl puts every decision into one YAML. LoRA? A config line. 4-bit? Two lines. Sequence packing, gradient checkpointing, chat templates, DeepSpeed — all config. The benefit is not brevity: the whole recipe goes into Git, diffs, rolls back, and survives code review.
Who this fits
Teams that need reviewable, reproducible training; multi-GPU, FSDP and DeepSpeed setups; hyperparameter sweeps by editing YAML. For a single-GPU one-off LoRA, Unsloth is faster to start.
A QLoRA config that actually runs
base_model: Qwen/Qwen2.5-7B-Instruct
load_in_4bit: true
adapter: lora
lora_r: 16
lora_alpha: 32
lora_dropout: 0.05
lora_target_linear: true
datasets:
- path: data/train.jsonl
type: alpaca
val_set_size: 0.05
sequence_len: 2048
sample_packing: true
pad_to_sequence_len: true
micro_batch_size: 2
gradient_accumulation_steps: 4
num_epochs: 1
optimizer: adamw_torch
lr_scheduler: cosine
learning_rate: 2e-4
gradient_checkpointing: true
flash_attention: true
output_dir: ./out
| Key | Purpose | Typical |
|---|---|---|
load_in_4bit |
4-bit base weights (QLoRA) | true |
lora_r / lora_alpha |
Adapter capacity | 16/32, up to 32/64 |
lora_target_linear |
Attach to all linear layers | true |
sequence_len |
Training sequence length | 2048, drop to 1024 on OOM |
sample_packing |
Pack short samples into one sequence | true |
micro_batch_size × accumulation |
Effective batch | 8-16 total |
learning_rate |
LR | 2e-4 LoRA, 2e-5 full fine-tune |
gradient_checkpointing |
Trade time for memory | true |
sample_packing is the most overlooked performance switch. Instruction samples are often a few hundred tokens; without packing, most of a 2048-token sequence is padding and the GPU computes nothing useful. The side effect is a variable number of samples per step, which changes how you read the loss curve.
Install and run
git clone https://github.com/axolotl-ai-cloud/axolotl
cd axolotl && pip install -e .
pip install -U flash-attn --no-build-isolation
axolotl preprocess config.yml
accelerate launch -m axolotl.cli.train config.yml
Merge afterwards:
axolotl merge-lora config.yml
# older versions: python -m axolotl.cli.merge_lora config.yml
Data format: type decides parsing
| type | Fields | Use |
|---|---|---|
alpaca |
instruction / input / output |
Standard instruction data |
sharegpt |
conversations with from/value |
Multi-turn |
chat_template |
messages with role/content |
Uses the model's own template — recommended |
completion |
text |
Continued pretraining |
For multi-turn, prefer chat_template with train_on_inputs: false so loss is computed on answers only.
Data quality beats format. 500-5000 self-consistent samples beat tens of thousands of inconsistent ones. Label 100, train one epoch, read the output, then label the rest.
Does it work? Verify in four steps
- Hold out 50-100 samples and compare base vs tuned on the same prompts.
- Check the loss trend; below 0.1 usually means memorization.
- Rerun 20 in-dataset prompts; watch for verbatim parroting.
- Ask a few unrelated questions to catch general-ability regression.
Axolotl or something else
| Situation | Pick |
|---|---|
| Team, config in Git | Axolotl |
| Multi-GPU, FSDP, DeepSpeed | Axolotl |
| One quick single-GPU LoRA | Unsloth |
| Custom training loop | TRL/PyTorch |
FAQ
Unknown config field? The schema changed across minor versions. Compare against the matching YAML under examples/ in the repo rather than old blog posts.
OOM? Lower sequence_len, then micro_batch_size with higher accumulation, confirm load_in_4bit, and only then reduce lora_r.
Resume after a crash? --resume_from_checkpoint ./out/checkpoint-500. Keep the checkpoint directory intact.
How many tokens and steps? The startup log prints sample count, packed step count and effective batch — check those before reading loss.
Multimodal models? Some are supported with a different config shape; use the official multimodal example.
Note: config fields evolve by version. Examples reflect the common 2026 structure; verify against the repo's
examples/and official docs.
Related
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.