olaverse-foundry
Small, specialised models from big general ones โ even when your language has no training data
What is olaverse-foundry?¶
The normal way to train a model assumes you have data. olaverse-foundry is the pipeline for when you don't: synthesize the training data (MT translation into 400+ languages, LLM query generation, mined hard negatives), distil or contrastively train a small model on it, and prove it head-to-head against mBERT / e5 / LaBSE โ one library, one afternoon. Every artifact is a standard HuggingFace directory; production code needs only transformers.
The same machinery covers the data-rich cases too โ a compact classifier distilled from a 178M-parameter teacher, an int8 encoder that runs on CPU, a multi-teacher causal-LM student โ and it is model-agnostic: pass an HF AutoModel*, or your own module that returns .logits / .last_hidden_state.
Start here: 60-second quickstart ยท Which trainer do I need? ยท Concepts & glossary
The flagship walkthrough: a retriever for a language with no training data โ
What you can do¶
lm / embed modes, reservoir shuffle, and labels for head training.foundry doctor checks your environment, foundry plan previews a recipe, foundry run / foundry embed execute it.Install¶
# Core โ schema validation, growth planning, recipe parsing (no GPU required)
pip install olaverse-foundry
# Real training + inference (torch, transformers, safetensors, accelerate)
pip install "olaverse-foundry[torch]"
# LoRA skill packs
pip install "olaverse-foundry[torch,lego]"
# HuggingFace dataset streaming
pip install "olaverse-foundry[torch,data]"
# Fast cross-tokenizer alignment (rapidfuzz)
pip install "olaverse-foundry[torch,align]"
# W&B experiment tracking
pip install "olaverse-foundry[torch,logging]"
# Everything
pip install "olaverse-foundry[all]"
Quantized inference additionally needs bitsandbytes; QAT and growth need only [torch].
Trainers at a glance¶
| Trainer | Builds | Teacher? | Notes |
|---|---|---|---|
TorchDistillTrainer |
causal LM | yes (1+) | CE + KL, teachers run every step |
CachedDistillTrainer |
causal LM | yes (1+) | caches teacher logits; multi-GPU via accelerate |
EmbeddingDistillTrainer |
embedding model | yes | pooled MSE / cosine for bi-encoders / rerankers |
MLMTrainer |
encoder base | no | masked-LM pretraining from scratch |
EncoderDistillTrainer |
encoder base | yes | token-level hidden-state distillation |
DistilMLMTrainer |
encoder base | yes | distillation + MLM in one loss (DistilBERT objective) |
ContrastiveTrainer |
retrieval embeddings | no | InfoNCE on pairs; in-batch + hard negatives |
SequenceClassificationTrainer |
classifier head | โ | sequence labels; full or frozen backbone |
TokenClassificationTrainer |
token head (NER) | โ | token labels; full or frozen backbone |
Every trainer shares the same production feature set: mixed precision, gradient accumulation, LR scheduler with warmup, reproducible seed, checkpoint save/resume, auto-checkpoint, eval loop, OOM handling, and W&B / TensorBoard logging.
Quick example โ distil a causal LM¶
import torch, numpy as np
from foundry import TorchDistillTrainer, TorchTrainConfig, TeacherRegistry
from foundry.teachers import ToyTeacher
student = torch.nn.Linear(16, 32) # any model with .logits
teachers = TeacherRegistry([ToyTeacher(vocab=32)]) # or HFTeacher(...)
data = [np.random.randint(0, 32, (4, 16)) for _ in range(50)]
trainer = TorchDistillTrainer(student, teachers, TorchTrainConfig(
epochs=2, lr_scheduler="cosine", warmup_steps=5,
save_every=25, save_dir="/tmp/run",
))
result = trainer.train(data)
print(result["losses"][-1])
Links¶
- GitHub โ Olaverse-Labs/olaverse-foundry
- PyPI โ pypi.org/project/olaverse-foundry
- olaverse SDK โ ready-to-use models