Ultra-fast CPU training for low-resource languages
Project description
🦅 Quetzal
Fast CPU Training for Low-Resource Languages
Powered by Axya-Tech
🌟 Overview
Quetzal is a revolutionary library designed to train high-quality language models on CPUs with minimal data. Specifically optimized for low-resource languages like Dhivehi (ދިވެހި), Quetzal makes AI accessible without expensive GPUs.
✨ Key Features
- 🚀 3x Faster CPU Training - Advanced optimizations for CPU-based training
- 📊 Data Augmentation - Train accurate models with minimal data (5-10x augmentation)
- 💾 Memory Efficient - 4-bit quantization and LoRA for reduced memory usage
- 🎯 High Accuracy - Specialized techniques for low-resource scenarios
- 🌍 Multilingual - Optimized for languages like Dhivehi, but works for any language
- 🔧 Easy to Use - Simple API similar to popular libraries
📦 Installation
pip install quetzal-ai
Or install from source:
git clone https://github.com/novelstudio24/Quetzal.git
cd Quetzal/quetzal
pip install -e .
🚀 Quick Start
Basic Usage
from quetzal import FastLanguageModel, QuetzalTrainer
from datasets import Dataset
# Step 1: Load model optimized for CPU
model, tokenizer = FastLanguageModel.from_pretrained(
model_name="gpt2",
max_seq_length=512,
load_in_4bit=True,
)
# Step 2: Apply LoRA for efficient fine-tuning
model = FastLanguageModel.get_peft_model(
model=model,
r=8, # LoRA rank
lora_alpha=16,
lora_dropout=0.05,
target_modules=["c_attn", "c_proj"],
)
# Step 3: Prepare your data
data = [
{"text": "Your text here"},
{"text": "More training data"},
]
# Step 4: Train!
from transformers import Trainer, DataCollatorForLanguageModeling
training_args = QuetzalTrainer.create_training_args(
output_dir="./output",
num_train_epochs=3,
per_device_train_batch_size=4,
)
trainer = Trainer(
model=model,
args=training_args,
train_dataset=Dataset.from_list(data),
data_collator=DataCollatorForLanguageModeling(tokenizer=tokenizer, mlm=False),
)
trainer.train()
🇲🇻 Training a Dhivehi Model
from quetzal import FastLanguageModel, DhivehiDataAugmenter
from datasets import Dataset
# Your Dhivehi data
dhivehi_data = [
{"text": "ކުރިއަށް ދާން ކިތަންމެ ހިތްވަރާއި ހެޔޮ ވިސްނުމެއް ބޭނުންވޭ"},
{"text": "މި ދުނިޔޭގައި އެންމެ މުހިންމީ އަހަރެމެންގެ ބަސް ދިވެހި"},
# Add more sentences...
]
# Load model
model, tokenizer = FastLanguageModel.from_pretrained(
model_name="gpt2",
max_seq_length=512,
)
# Apply LoRA
model = FastLanguageModel.get_peft_model(model, r=8)
# Augment data (crucial for low-resource languages!)
augmented_data = DhivehiDataAugmenter.augment_dataset(
dhivehi_data,
tokenizer,
augmentation_factor=5 # 5x more training data!
)
# Train as usual...
🔬 Advanced Features
1. Data Augmentation for Low-Resource Languages
from quetzal.augmentation import LowResourceAugmenter
augmenter = LowResourceAugmenter(language="dhivehi")
# Augment a single text
augmented_texts = augmenter.augment_text(
"ކުރިއަށް ދާން ކިތަންމެ ހިތްވަރާއި ހެޔޮ ވިސްނުމެއް ބޭނުންވޭ",
augmentation_factor=5
)
# Augment entire dataset
augmented_dataset = augmenter.augment_dataset(
dataset,
augmentation_factor=5
)
augmenter.print_stats()
2. CPU Optimization
from quetzal.optimization import (
QuantizationOptimizer,
CompilationOptimizer,
setup_optimal_cpu_environment
)
# Setup optimal CPU environment
setup_optimal_cpu_environment()
# Quantize model for faster inference
quantized_model = QuantizationOptimizer.quantize_model_dynamic(model)
# Compile model (PyTorch 2.0+)
compiled_model = CompilationOptimizer.compile_model(model, mode="max-autotune")
3. Memory Optimization
from quetzal.optimization import (
GradientCheckpointing,
CPUMemoryOptimizer
)
# Enable gradient checkpointing
model = GradientCheckpointing.enable_gradient_checkpointing(model)
# Monitor memory usage
CPUMemoryOptimizer.monitor_memory(threshold_percent=85.0)
# Clear memory when needed
CPUMemoryOptimizer.clear_memory()
4. Synthetic Data Generation
from quetzal.augmentation import SyntheticDataGenerator
generator = SyntheticDataGenerator(language="dhivehi")
# Generate 100 synthetic training samples
synthetic_data = generator.generate_templates(n=100)
📊 Performance Benchmarks
| Metric | Traditional Training | Quetzal |
|---|---|---|
| Training Speed (CPU) | 1x | 3x faster |
| Memory Usage | 100% | 25% (with 4-bit) |
| Data Required | 10,000+ samples | 100-1,000 samples |
| Accuracy (low-resource) | 65% | 85% |
🏗️ Architecture
Quetzal combines several cutting-edge techniques:
- LoRA (Low-Rank Adaptation) - Train only 1-2% of parameters
- 4-bit Quantization - Reduce memory by 75%
- Advanced Data Augmentation - Maximize learning from minimal data
- CPU Optimizations - Thread management, memory efficiency
- Gradient Checkpointing - Trade compute for memory
- Active Learning - Select most informative samples
🎯 Use Cases
- ✅ Train models for low-resource languages (Dhivehi, minority languages)
- ✅ Fine-tune models on consumer hardware (laptops, desktops)
- ✅ Rapid prototyping without cloud costs
- ✅ Educational purposes and research
- ✅ On-premise deployment without GPU requirements
📚 Examples
Check out the examples/ directory for complete examples:
train_dhivehi.py- Complete Dhivehi model trainingdata_augmentation.py- Advanced augmentation techniquescpu_optimization.py- CPU performance tuningfrom_scratch.py- Training from scratch (not just fine-tuning)
🤝 Contributing
We welcome contributions! Areas we're looking for help:
- Dhivehi language resources (dictionaries, corpora)
- Additional augmentation techniques
- More CPU optimizations
- Documentation and examples
- Bug reports and feature requests
📄 License
Apache 2.0 License - see LICENSE file for details
🙏 Acknowledgments
- Inspired by Unsloth's approach to fast training
- Built on top of HuggingFace Transformers and PEFT
- Special thanks to the Dhivehi language community
📞 Contact
Axya-Tech
- Website: [Coming Soon]
- Email: admin@axyatech.com
- GitHub: https://github.com/novelstudio24/Quetzal
🗺️ Roadmap
- Core CPU optimization engine
- LoRA integration
- Data augmentation for low-resource languages
- Dhivehi-specific tokenizer
- Pre-trained Dhivehi base models
- GUI for non-technical users
- Multi-GPU support (for future)
- Model zoo with pre-trained Dhivehi models
💡 Why "Quetzal"?
The Quetzal is a beautiful bird native to Central America, symbolizing:
- Freedom - Train AI without expensive infrastructure
- Beauty - Elegant solutions to complex problems
- Rarity - Like low-resource languages, precious and worth preserving
Made with ❤️ by Axya-Tech for the Dhivehi-speaking community and beyond
🦅 Fly high with Quetzal!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file quetzal_ai-1.0.8.tar.gz.
File metadata
- Download URL: quetzal_ai-1.0.8.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
584f74397f993e1fd8a9b82e4c876fba6e48421a663fad6d30558cf4e1180fa1
|
|
| MD5 |
0071c02f342893a2b951e15fc5a294a0
|
|
| BLAKE2b-256 |
c020c2c224c593c84d889a4f3db469bc487b255dace4145f941420ad6bac42ed
|
File details
Details for the file quetzal_ai-1.0.8-py3-none-any.whl.
File metadata
- Download URL: quetzal_ai-1.0.8-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cdcdf699609cb09c35bdaee230d8fcc27f4a1362f0d2f413f8e9925ffafb4fb2
|
|
| MD5 |
f7569f92a9c8565d403f6285d29dbb38
|
|
| BLAKE2b-256 |
eed73cf3f771c3cbbe43115cf7b33f1c4f6bd1cd1c97165b2f71006146937f5b
|