Small Model Fine-tuning Toolkit
A complete toolkit for fine-tuning small language models (< 4B parameters) and deploying them anywhere - phones, edge devices, or desktop.
| Model | Size | Phone Ready | Best For |
|---|---|---|---|
| Qwen3-0.6B | 472MB | β | General use (recommended) |
| Gemma3-270M | 550MB | β | Fastest inference |
| FunctionGemma-270M | 550MB | β | Function calling |
| Qwen2.5-0.5B | 400MB | β | Smallest size |
| Qwen2.5-1.5B | 1.2GB | β | Better quality |
| Qwen3-4B | 3.2GB | β οΈ | High quality (larger devices) |
# Clone the repository
git clone https://github.com/yourusername/tagforge
cd tagforge
# Install dependencies
pip install -e .
# Or use the setup command
tagforge setup
# Full pipeline: generate data β train β test
tagforge all --model qwen3-0.6b --num-samples 1000 --epochs 3
# 1. Prepare your data (JSON with text-label pairs)
tagforge prepare --input my_data.json --output data/train.json
# 2. Train
tagforge train --model qwen3-0.6b --dataset data/train.json --epochs 3
# 3. Test
tagforge test --model-path models/trained_model
# 4. Export
tagforge export gguf --model-path models/trained_model
Prepare a JSON file with your training examples:
[
{
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"},
{"role": "assistant", "content": "The capital of France is Paris."}
]
}
]
Use a larger LLM to generate training data from raw text:
# Download classic books from Project Gutenberg
tagforge download-gutenberg --num-books 50
# Generate training data using Ollama (local)
tagforge llm-generate \
--input data/gutenberg/gutenberg_chunks.jsonl \
--provider ollama \
--model qwen2.5:7b
# Or use OpenAI/Anthropic
tagforge llm-generate \
--input my_texts.txt \
--provider openai \
--model gpt-4o-mini
# Generate from built-in samples
tagforge generate --num-samples 1000
# Include public datasets (AG News, IMDB)
tagforge generate --num-samples 2000 --include-public
| Command | Description |
|---|---|
setup | Install dependencies |
models list | List available models |
models info <model> | Show model details |
download-gutenberg | Download books from Project Gutenberg |
llm-generate | Generate training data using LLM |
generate | Generate training dataset (built-in) |
prepare | Convert custom data to training format |
train | Fine-tune a model |
test | Test the fine-tuned model |
run | Interactive inference |
export gguf | Export to GGUF (llama.cpp) |
export phone | Export for phone (ExecuTorch) |
all | Run full pipeline |
tagforge train \
--model qwen3-0.6b \
--dataset data/train.json \
--epochs 3 \
--lora-r 16 \
--lora-alpha 32
tagforge train \
--model qwen3-0.6b \
--load-4bit \
--batch-size 2
tagforge train \
--model qwen3-0.6b \
--phone-deployment \
--epochs 3
# Export to GGUF
tagforge export gguf --model-path models/trained_model
# With specific quantization
tagforge export gguf --model-path models/trained_model --quantization q4_k_m
# List quantization options
tagforge export gguf --list-quantizations
# Export for phone
tagforge export phone \
--model-path models/trained_model \
--model-family qwen3 \
--max-context-length 1024
Performance:
| Device | Model | Tokens/sec |
|---|---|---|
| Pixel 8 | Qwen3-0.6B | ~50 |
| iPhone 15 Pro | Qwen3-0.6B | ~50 |
| Pixel 8 | Gemma3-270M | ~60 |
tagforge/
βββ main.py # Main CLI
βββ src/
β βββ models/
β β βββ registry.py # Model registry
β βββ data/
β β βββ tagging_dataset_generator.py
β βββ export/
β βββ gguf_exporter.py
β βββ phone_exporter.py
βββ scripts/
β βββ download_gutenberg.py # Gutenberg downloader
β βββ generate_with_llm.py # LLM data generation
β βββ ...
βββ docs/
βββ PHONE_DEPLOYMENT.md
βββ FINETUNING.md
βββ DEPLOYMENT.md
torch>=2.1.0
transformers>=4.40.0
unsloth>=2024.8
trl>=0.8.0
peft>=0.10.0
torchao>=0.14.0
executorch
pytorch_tokenizers
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
Small Model Fine-tuning Toolkit
A complete toolkit for fine-tuning small language models (< 4B parameters) and deploying them anywhere - phones, edge devices, or desktop.
| Model | Size | Phone Ready | Best For |
|---|---|---|---|
| Qwen3-0.6B | 472MB | β | General use (recommended) |
| Gemma3-270M | 550MB | β | Fastest inference |
| FunctionGemma-270M | 550MB | β | Function calling |
| Qwen2.5-0.5B | 400MB | β | Smallest size |
| Qwen2.5-1.5B | 1.2GB | β | Better quality |
| Qwen3-4B | 3.2GB | β οΈ | High quality (larger devices) |
# Clone the repository
git clone https://github.com/yourusername/tagforge
cd tagforge
# Install dependencies
pip install -e .
# Or use the setup command
tagforge setup
# Full pipeline: generate data β train β test
tagforge all --model qwen3-0.6b --num-samples 1000 --epochs 3
# 1. Prepare your data (JSON with text-label pairs)
tagforge prepare --input my_data.json --output data/train.json
# 2. Train
tagforge train --model qwen3-0.6b --dataset data/train.json --epochs 3
# 3. Test
tagforge test --model-path models/trained_model
# 4. Export
tagforge export gguf --model-path models/trained_model
Prepare a JSON file with your training examples:
[
{
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"},
{"role": "assistant", "content": "The capital of France is Paris."}
]
}
]
Use a larger LLM to generate training data from raw text:
# Download classic books from Project Gutenberg
tagforge download-gutenberg --num-books 50
# Generate training data using Ollama (local)
tagforge llm-generate \
--input data/gutenberg/gutenberg_chunks.jsonl \
--provider ollama \
--model qwen2.5:7b
# Or use OpenAI/Anthropic
tagforge llm-generate \
--input my_texts.txt \
--provider openai \
--model gpt-4o-mini
# Generate from built-in samples
tagforge generate --num-samples 1000
# Include public datasets (AG News, IMDB)
tagforge generate --num-samples 2000 --include-public
| Command | Description |
|---|---|
setup | Install dependencies |
models list | List available models |
models info <model> | Show model details |
download-gutenberg | Download books from Project Gutenberg |
llm-generate | Generate training data using LLM |
generate | Generate training dataset (built-in) |
prepare | Convert custom data to training format |
train | Fine-tune a model |
test | Test the fine-tuned model |
run | Interactive inference |
export gguf | Export to GGUF (llama.cpp) |
export phone | Export for phone (ExecuTorch) |
all | Run full pipeline |
tagforge train \
--model qwen3-0.6b \
--dataset data/train.json \
--epochs 3 \
--lora-r 16 \
--lora-alpha 32
tagforge train \
--model qwen3-0.6b \
--load-4bit \
--batch-size 2
tagforge train \
--model qwen3-0.6b \
--phone-deployment \
--epochs 3
# Export to GGUF
tagforge export gguf --model-path models/trained_model
# With specific quantization
tagforge export gguf --model-path models/trained_model --quantization q4_k_m
# List quantization options
tagforge export gguf --list-quantizations
# Export for phone
tagforge export phone \
--model-path models/trained_model \
--model-family qwen3 \
--max-context-length 1024
Performance:
| Device | Model | Tokens/sec |
|---|---|---|
| Pixel 8 | Qwen3-0.6B | ~50 |
| iPhone 15 Pro | Qwen3-0.6B | ~50 |
| Pixel 8 | Gemma3-270M | ~60 |
tagforge/
βββ main.py # Main CLI
βββ src/
β βββ models/
β β βββ registry.py # Model registry
β βββ data/
β β βββ tagging_dataset_generator.py
β βββ export/
β βββ gguf_exporter.py
β βββ phone_exporter.py
βββ scripts/
β βββ download_gutenberg.py # Gutenberg downloader
β βββ generate_with_llm.py # LLM data generation
β βββ ...
βββ docs/
βββ PHONE_DEPLOYMENT.md
βββ FINETUNING.md
βββ DEPLOYMENT.md
torch>=2.1.0
transformers>=4.40.0
unsloth>=2024.8
trl>=0.8.0
peft>=0.10.0
torchao>=0.14.0
executorch
pytorch_tokenizers
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.