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.5.tar.gz (20.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.5-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: quetzal_ai-1.0.5.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

Hashes for quetzal_ai-1.0.5.tar.gz
Algorithm Hash digest
SHA256 c3d607de8aaf6ea307538428d608104ab4449c34d8f05fa34ac29d51dd38bbf8
MD5 55c0e31abfe02fb9c64d21a1c49b041f
BLAKE2b-256 6f3c8784a06870d84f3fbf8982827b2999080b291b9a65a6fc36880f6abcea2b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: quetzal_ai-1.0.5-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

Hashes for quetzal_ai-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c27907c6c6c35168841e039e93049c4b04b9d0ef942eea83a220575f35039826
MD5 f05b5f0985a47470f4d528534666429a
BLAKE2b-256 8929a9721f4779291426b1211d05d77da507fb090fc1d71b5c4284c96ccf55bb

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