mirror of
https://github.com/zenlm/zen-family.git
synced 2026-11-02 03:10:56 +00:00
Rewrite dead HF links to live successors, refresh stale Zen4 / old Zen-3 chat lineups to current Zen5 canonical + Zen3 specialty, and strip upstream brand mentions from user-facing prose (attribution and base_model chains preserved). Co-authored-by: zooqueen <[email protected]>
10 KiB
10 KiB
Zoo-Gym Complete Training Framework Guide
For Zen AI Models - September 2025
Zoo-gym is the official training framework for all Zen AI models, providing state-of-the-art training capabilities for models ranging from 600M to 480B parameters.
🚀 Quick Start
Installation
# Install from PyPI
pip install zoo-gym
# Install from source (recommended for latest features)
git clone https://github.com/zooai/gym
cd gym
pip install -e .
# Install with all dependencies
pip install zoo-gym[all]
Basic Usage
from zoo_gym import ZooGym
# Initialize with any Zen model
gym = ZooGym("zenlm/zen-eco")
# Train
gym.train(
dataset="data.jsonl",
epochs=3,
learning_rate=2e-5
)
📚 Supported Models (September 2025)
| Model | Architecture | Parameters | Zoo-gym Support |
|---|---|---|---|
| Zen-Nano | Qwen3-0.6B Dense | 600M | ✅ Full |
| Zen-Eco | Qwen3-4B Dense | 4B | ✅ Full |
| Zen-Coder | Qwen3-Coder-480B-A35B MoE | 480B/35B | ✅ Full + MoE |
| Zen-Omni | Qwen3-Omni-30B-A3B MoE | 30B/3B | ✅ Full + Multimodal |
| Zen-Next | Qwen3-Next-80B-A3B MoE | 80B/3B | ✅ Full + Ultra-Sparse |
🎯 Training Examples
1. Zen-Nano (600M) - Edge Deployment
from zoo_gym import ZooGym
from zoo_gym.configs import ZenNanoConfig
config = ZenNanoConfig(
base_model="zenlm/zen-nano-qwen3-0.6b",
learning_rate=5e-5,
batch_size=64,
use_lora=True,
lora_rank=8,
quantization="int4"
)
gym = ZooGym(config)
gym.train("mobile_assistant_data.jsonl")
2. Zen-Eco (4B) - Balanced Training
from zoo_gym import ZooGym
gym = ZooGym("zenlm/zen-eco-qwen3-4b")
# With automatic mixed precision
gym.train(
dataset="general_data.jsonl",
fp16=True,
gradient_checkpointing=True,
push_to_hub=True,
hub_model_id="your-org/zen-eco-custom"
)
3. Zen-Coder (480B-A35B) - MoE Code Training
from zoo_gym import ZooGym, MoEConfig
config = MoEConfig(
base_model="zenlm/zen-coder-qwen3-moe",
num_experts=64,
experts_per_token=8,
expert_specialization={
"python": [0,7],
"javascript": [8,15],
"systems": [16,23],
# ... more specializations
},
deepspeed_config="zero3"
)
gym = ZooGym(config)
gym.train_moe("code_dataset.jsonl")
4. Zen-Omni (30B-A3B) - Multimodal Training
from zoo_gym import ZooGym, MultimodalConfig
config = MultimodalConfig(
base_model="zenlm/zen-omni-qwen3-moe",
modalities=["text", "vision", "audio"],
cross_attention_layers=[4, 8, 12, 16, 20, 24],
contrastive_learning=True
)
gym = ZooGym(config)
gym.train_multimodal({
"image_text": "coco_captions.json",
"audio_text": "audiocaps.json",
"video_text": "webvid.json"
})
5. Zen-Next (80B-A3B) - Ultra-Sparse Training
from zoo_gym import ZooGym, UltraSparseConfig
config = UltraSparseConfig(
base_model="zenlm/zen-next-qwen3-moe",
num_experts=128,
experts_per_token=2, # Ultra-sparse
expert_offloading="lru",
expert_cache_size=16
)
gym = ZooGym(config)
gym.train_ultra_sparse("high_quality_data.jsonl")
🔄 Recursive Self-Improvement
Zoo-gym's flagship feature - models learn from their own outputs:
from zoo_gym import ZooGym, RecursiveImprovement
gym = ZooGym("zenlm/zen-eco")
rais = RecursiveImprovement(
rounds=5,
quality_threshold=0.8,
synthetic_ratio=0.3
)
# Model improves itself over multiple rounds
final_model = gym.recursive_train(
initial_data="seed_data.jsonl",
improvement_system=rais
)
# Typical results: 15-30% performance improvement
🖥️ Interfaces
Web UI
from zoo_gym.ui import WebInterface
# Launch interactive web interface
web = WebInterface()
web.launch(port=7860, share=True)
Features:
- Real-time training monitoring
- Interactive model testing
- Hyperparameter tuning
- Dataset preview and analysis
- Export to multiple formats
CLI
# Basic training
zoo-gym train --model zenlm/zen-eco --dataset data.jsonl
# MoE training
zoo-gym train-moe \
--model zenlm/zen-5-coder-gguf \
--num-experts 64 \
--experts-per-token 8
# Multimodal training
zoo-gym train-multimodal \
--model zenlm/zen-omni \
--image-data images.json \
--audio-data audio.json
# Recursive improvement
zoo-gym recursive \
--model zenlm/zen-eco \
--rounds 5 \
--quality-threshold 0.8
# Evaluation
zoo-gym evaluate \
--model ./finetuned \
--benchmarks mmlu,gsm8k,humaneval
# Model conversion
zoo-gym convert \
--input model.pt \
--output model.gguf \
--quantization q4_k_m
🎮 Training Strategies
LoRA Fine-tuning
| Model | Rank | Alpha | Target Modules | Memory |
|---|---|---|---|---|
| Zen-Nano | 8 | 16 | q,v,o,gate | 100MB |
| Zen-Eco | 16 | 32 | q,k,v,o,gate | 200MB |
| Zen-Coder | 32 | 64 | router,experts | 500MB |
| Zen-Omni | 16 | 32 | cross_attn | 300MB |
| Zen-Next | 64 | 128 | sparse_experts | 600MB |
Quantization Options
# INT8 Quantization
gym.train(load_in_8bit=True)
# INT4 Quantization
gym.train(load_in_4bit=True, bnb_4bit_compute_dtype="bfloat16")
# GPTQ Quantization
gym.quantize_model("gptq", bits=4)
# AWQ Quantization
gym.quantize_model("awq", w_bit=4)
Distributed Training
# Multi-GPU
gym.train(
strategy="ddp",
devices=[0, 1, 2, 3]
)
# DeepSpeed Zero3
gym.train(
strategy="deepspeed",
deepspeed_config={
"stage": 3,
"offload_optimizer": True,
"offload_param": True
}
)
# FSDP (Fully Sharded Data Parallel)
gym.train(
strategy="fsdp",
fsdp_config={
"sharding_strategy": "FULL_SHARD",
"cpu_offload": True
}
)
📊 Benchmarking
from zoo_gym import Benchmarker
bench = Benchmarker(gym.model)
# Standard benchmarks
results = bench.evaluate([
"mmlu", # Knowledge
"gsm8k", # Math
"humaneval", # Code
"hellaswag", # Common sense
])
# Code-specific (Zen-Coder)
code_results = bench.evaluate_code([
"humaneval",
"mbpp",
"apps",
"code_contests"
])
# Multimodal (Zen-Omni)
mm_results = bench.evaluate_multimodal([
"vqav2",
"coco_caption",
"audiocaps",
"mmmu"
])
🚢 Deployment
Export Formats
# Export to different formats
gym.export("pytorch") # .pt
gym.export("safetensors") # .safetensors
gym.export("gguf", quantization="q4_k_m") # For llama.cpp
gym.export("mlx") # For Apple Silicon
gym.export("onnx") # Cross-platform
gym.export("tensorrt") # NVIDIA optimization
Optimization for Deployment
# Mobile optimization (Zen-Nano)
gym.optimize_for_mobile(
target_size_mb=250,
quantization="int4",
compile=True
)
# Server optimization (Zen-Coder)
gym.optimize_for_server(
batch_size=32,
use_flash_attention=True,
compile_model=True
)
# Edge optimization (Zen-Omni/Next)
gym.optimize_for_edge(
active_params_only=True,
expert_offloading=True,
cache_size=16
)
🔬 Advanced Features
Custom Callbacks
class CustomCallback(gym.Callback):
def on_epoch_end(self, epoch, logs):
print(f"Epoch {epoch}: Loss {logs['loss']:.4f}")
def on_batch_end(self, batch, logs):
if batch % 100 == 0:
self.save_checkpoint()
gym.train(callbacks=[CustomCallback()])
Hyperparameter Search
from zoo_gym import HyperparameterSearch
search = HyperparameterSearch(
gym,
param_space={
"learning_rate": [1e-5, 5e-5, 1e-4],
"batch_size": [16, 32, 64],
"lora_rank": [8, 16, 32]
}
)
best_params = search.run(n_trials=10)
Data Augmentation
from zoo_gym.augmentation import TextAugmenter
augmenter = TextAugmenter(
techniques=["paraphrase", "backtranslation", "insertion"],
augmentation_rate=0.3
)
gym.train(
dataset="data.jsonl",
augmenter=augmenter
)
📈 Performance Optimization Tips
-
Memory Management
- Use gradient checkpointing for large models
- Enable CPU offloading for MoE models
- Use mixed precision training (fp16/bf16)
-
Speed Optimization
- Use Flash Attention 2 for long contexts
- Enable torch.compile() for 20-30% speedup
- Use efficient data loaders with prefetching
-
Quality Improvements
- Use recursive self-improvement
- Implement curriculum learning
- Apply data quality filtering
-
MoE Specific
- Balance expert utilization
- Use auxiliary losses for routing
- Implement expert dropout for robustness
🐛 Troubleshooting
Common Issues
# OOM Error
gym.train(
gradient_accumulation_steps=8,
batch_size=4, # Reduce batch size
gradient_checkpointing=True
)
# Slow Training
gym.train(
use_flash_attention=True,
compile_model=True,
num_workers=8
)
# Poor Convergence
gym.train(
learning_rate=1e-5, # Lower LR
warmup_ratio=0.1, # More warmup
weight_decay=0.01 # Add regularization
)
📚 Resources
- GitHub: github.com/zooai/gym
- Documentation: docs.zoo-gym.ai
- Models: huggingface.co/zenlm
- Discord: discord.gg/zoo-gym
- Examples: github.com/zooai/gym-examples
📄 Configuration File
Create zoo-gym-config.yaml:
version: "2.0.0"
organization: "zenlm"
models:
zen-eco:
base_model: "zenlm/zen-eco-qwen3-4b"
learning_rate: 2e-5
batch_size: 32
lora:
rank: 16
alpha: 32
training:
mixed_precision: "bf16"
gradient_checkpointing: true
save_steps: 100
deployment:
push_to_hub: true
quantization: "int8"
🎉 Success Stories
- 1.48M+ models trained with zoo-gym
- 94% improvement in reasoning with recursive training
- 96.25% compute reduction with ultra-sparse training
- 15-30% performance gains through self-improvement
Built with ❤️ by Zoo Labs Foundation
Last Updated: September 25, 2025