Skip to main content

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:

  1. LoRA (Low-Rank Adaptation) - Train only 1-2% of parameters
  2. 4-bit Quantization - Reduce memory by 75%
  3. Advanced Data Augmentation - Maximize learning from minimal data
  4. CPU Optimizations - Thread management, memory efficiency
  5. Gradient Checkpointing - Trade compute for memory
  6. 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 training
  • data_augmentation.py - Advanced augmentation techniques
  • cpu_optimization.py - CPU performance tuning
  • from_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


🗺️ 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

quetzal_ai-1.0.1.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quetzal_ai-1.0.1-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file quetzal_ai-1.0.1.tar.gz.

File metadata

  • Download URL: quetzal_ai-1.0.1.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for quetzal_ai-1.0.1.tar.gz
Algorithm Hash digest
SHA256 074c0078832183d3c7a6bd237ab910469b01f0c2678203e14729864c93307f3a
MD5 9c661886e2bc990e796fd255cae5ac3c
BLAKE2b-256 1d451f8803badeda7b7f6c44d70d8ec6fc69224965ebf8c110b0682a282302df

See more details on using hashes here.

File details

Details for the file quetzal_ai-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: quetzal_ai-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for quetzal_ai-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4fd62835676618583104a252f91de51aa63ad6d820dfa32e437fcf8e4d04a9a2
MD5 c78903b4519246512853578afe8761ee
BLAKE2b-256 a82aeaa52e8bdc5c5422d13cedcbdcf9013617a93de8290af6736ffac631e8e9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page