Axolotl is becoming popular in the fine-tuning space, especially for LLMs (Large Language Models).
🦎 What is Axolotl?
Axolotl is an open-source framework designed to make fine-tuning large language models (LLMs) simple, efficient, and flexible.
It's built to handle LoRA (Low-Rank Adaptation) and other parameter-efficient fine-tuning techniques with ease.
It is inspired by libraries like Hugging Face's Transformers, but adds convenient tools specifically for customizing, training, and managing LLM fine-tuning.
🔑 Key Features of Axolotl:
-
Supports various fine-tuning methods:
- Full fine-tuning.
- LoRA (most commonly used!)
- QLoRA (Quantized LoRA).
-
Supports multiple model families:
- LLaMA, Mistral, Falcon, GPT-NeoX, etc.
-
Highly configurable with YAML files.
-
Integrated with Hugging Face, so you can load pre-trained models easily.
🚀 Fine-tuning Example Workflow:
Objective:
Fine-tune a pre-trained LLaMA-2-7B model on a custom dataset of Q&A pairs using LoRA.
1️⃣ Install Axolotl
pip install axolotl
2️⃣ Prepare Data (JSONL Format)
Example dataset.jsonl:
{"instruction": "What is the capital of France?", "input": "", "output": "Paris"}
{"instruction": "Who wrote Hamlet?", "input": "", "output": "William Shakespeare"}
3️⃣ Create Config File (YAML)
Example config.yaml:
base_model: 'meta-llama/Llama-2-7b-hf'
dataset:
path: './dataset.jsonl'
format: 'alpaca' # Supports various formats, alpaca-style Q&A is common
lora:
r: 8
alpha: 16
dropout: 0.05
target_modules: 'all-linear'
training:
epochs: 3
batch_size: 8
learning_rate: 2e-4
output:
output_dir: './llama2-finetuned'
4️⃣ Run Fine-tuning
axolotl train config.yaml
✅ That’s it! It handles:
- Loading the base model.
- Applying LoRA adapters.
- Preparing the dataset.
- Training loop & saving the output.
5️⃣ Inference Using Fine-tuned Model:
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained('./llama2-finetuned')
tokenizer = AutoTokenizer.from_pretrained('meta-llama/Llama-2-7b-hf')
input_text = "What is the capital of France?"
inputs = tokenizer(input_text, return_tensors='pt')
outputs = model.generate(**inputs)
print(tokenizer.decode(outputs[0]))
🌟 Advantages of Axolotl:
- Simplifies fine-tuning for large models.
- No need to write complex training scripts.
- Easy LoRA integration to save GPU memory.
- Supports advanced techniques like QLoRA, 4-bit quantization, etc.
- YAML-based configs make experiments reproducible.
🔥 Use Cases:
| Use Case | How Axolotl Helps |
|---|---|
| Fine-tuning chatbots | Quickly fine-tune Llama or Mistral on Q&A datasets. |
| Domain adaptation | Train models on specific industry datasets (e.g., legal, medical). |
| Language-specific models | Fine-tune multilingual models for a specific language. |
| Low-resource environments | Use LoRA/QLoRA to fine-tune big models with limited hardware. |
Here's a ready-to-run Axolotl fine-tuning setup tailored for you.
🎯 Objective:
Fine-tune a pre-trained LLaMA-2-7B model using LoRA on a custom Q&A dataset.
🟢 Folder Structure:
project/
├── dataset.jsonl # Your Q&A dataset
├── config.yaml # Axolotl config
└── run.sh # Script to start training
project/
├── dataset.jsonl # Your Q&A dataset
├── config.yaml # Axolotl config
└── run.sh # Script to start training
1️⃣ Prepare Dataset (dataset.jsonl):
Each line is a JSON object:
{"instruction": "What is the capital of France?", "input": "", "output": "Paris"}
{"instruction": "Who developed Python?", "input": "", "output": "Guido van Rossum"}
2️⃣ Create Config File (config.yaml):
base_model: 'meta-llama/Llama-2-7b-hf'
dataset:
path: './dataset.jsonl'
format: 'alpaca'
lora:
r: 8
alpha: 16
dropout: 0.05
target_modules: 'all-linear'
training:
epochs: 3
batch_size: 4
learning_rate: 2e-4
save_every_n_steps: 500
output:
output_dir: './llama2-finetuned'
tokenizer:
truncation_side: 'left'
padding_side: 'right'
max_length: 2048
base_model: 'meta-llama/Llama-2-7b-hf'
dataset:
path: './dataset.jsonl'
format: 'alpaca'
lora:
r: 8
alpha: 16
dropout: 0.05
target_modules: 'all-linear'
training:
epochs: 3
batch_size: 4
learning_rate: 2e-4
save_every_n_steps: 500
output:
output_dir: './llama2-finetuned'
tokenizer:
truncation_side: 'left'
padding_side: 'right'
max_length: 2048
3️⃣ Create Training Script (run.sh):
#!/bin/bash
# Install dependencies
pip install axolotl transformers datasets
# Start training
axolotl train config.yaml
#!/bin/bash
# Install dependencies
pip install axolotl transformers datasets
# Start training
axolotl train config.yaml
Make it executable:
chmod +x run.sh
4️⃣ Run Fine-tuning:
./run.sh
./run.sh
5️⃣ Inference After Fine-tuning:
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained('./llama2-finetuned')
tokenizer = AutoTokenizer.from_pretrained('meta-llama/Llama-2-7b-hf')
input_text = "Who developed Python?"
inputs = tokenizer(input_text, return_tensors='pt')
outputs = model.generate(**inputs, max_length=50)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained('./llama2-finetuned')
tokenizer = AutoTokenizer.from_pretrained('meta-llama/Llama-2-7b-hf')
input_text = "Who developed Python?"
inputs = tokenizer(input_text, return_tensors='pt')
outputs = model.generate(**inputs, max_length=50)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
🚀 Quick Customization:
-
Different Model:
Change base_model in config.yaml to any supported Hugging Face model, e.g., mistralai/Mistral-7B-v0.1.
-
Dataset Format:
Supports alpaca, vicuna, oasst, etc.
You can adjust based on dataset style.
-
LoRA Parameters:
Tune r, alpha, dropout depending on memory budget.
Different Model:
Change base_model in config.yaml to any supported Hugging Face model, e.g., mistralai/Mistral-7B-v0.1.
Dataset Format:
Supports alpaca, vicuna, oasst, etc.
You can adjust based on dataset style.
LoRA Parameters:
Tune r, alpha, dropout depending on memory budget.
Hardware Requirements:
- Minimum: 1 GPU (24GB VRAM recommended for 7B models with LoRA)
- For QLoRA: You can even run with lower VRAM (12-16GB) using quantization!
Summary:
Axolotl = Lightweight, configurable, and efficient framework to fine-tune large language models (LLMs), especially with LoRA/QLoRA.
Comments
Post a Comment