Skip to main content

olaverse-foundry

A general-purpose toolkit for building transformer models — decoder or encoder.

olaverse-foundry is the model-building layer of the Olaverse ecosystem. Where olaverse gives you ready-to-use models, foundry lets you build new ones — pretraining, distilling, growing, adding heads, quantizing, and evaluating them. It is model-agnostic: any HuggingFace model or your own nn.Module works.

pretrain / distil → grow → add heads → quantize → evaluate → serve

Install

# Core (schema validation, growth planning — no GPU required)
pip install olaverse-foundry

# GPU training
pip install olaverse-foundry[torch]

# LoRA skill packs
pip install olaverse-foundry[torch,lego]

# Everything
pip install olaverse-foundry[all]

Quick start — embedding distillation (200M student)

from foundry import DataPipeline, EmbeddingDistillTrainer, EmbeddingDistillConfig
from transformers import AutoModel, AutoTokenizer

# Load student and teacher
student = AutoModel.from_pretrained("microsoft/deberta-v3-base")
teacher = AutoModel.from_pretrained("BAAI/bge-large-en-v1.5")
tok     = AutoTokenizer.from_pretrained("microsoft/deberta-v3-base")

# Stream data
pipe = DataPipeline(
    source       = my_hf_dataset,
    tokenizer    = tok,
    batch_size   = 32,
    max_length   = 128,
    mode         = "embed",
    shuffle_buffer = 10_000,
)

# Train
trainer = EmbeddingDistillTrainer(
    student = student,
    teacher = teacher,
    config  = EmbeddingDistillConfig(
        loss         = "cosine",
        pool         = "mean",
        epochs       = 3,
        lr_scheduler = "cosine",
        warmup_steps = 200,
        torch_dtype  = "bfloat16",
        save_every   = 1000,
        save_dir     = "/checkpoints/embed-200m",
        log_backend  = "wandb",
    ),
)

result = trainer.train(pipe, eval_dataset=eval_pipe)
print(result["eval_losses"])

Quick start — causal LM distillation with multiple teachers

from foundry import (
    DataPipeline, TorchDistillTrainer, TorchTrainConfig,
    TeacherRegistry, FoundryRecipe,
)

# Build a registry of teachers
teachers = TeacherRegistry.from_names(
    ["meta-llama/Llama-3.1-70B", "Qwen/Qwen2-72B-Instruct"],
    weights=[1.0, 0.8],
)
teachers.load_all()

# Stream training data
pipe = DataPipeline(
    source     = my_dataset,
    tokenizer  = tok,
    batch_size = 8,
    max_length = 2048,
    mode       = "lm",
)

trainer = TorchDistillTrainer(
    student  = my_3b_model,
    teachers = teachers,
    config   = TorchTrainConfig(
        epochs                = 1,
        lr_scheduler          = "cosine",
        warmup_steps          = 500,
        torch_dtype           = "bfloat16",
        grad_accumulation_steps = 8,
        save_every            = 500,
        save_dir              = "/checkpoints/run1",
        eval_every            = 100,
        log_backend           = "wandb",
    ),
)

result = trainer.train(pipe, eval_dataset=eval_pipe)

Key components

Module What it does
DataPipeline Converts HF datasets, string lists, or numpy arrays into trainer-ready batches. Supports streaming and reservoir shuffle.
TorchDistillTrainer Single-GPU distillation: CE + KL loss against one or more teachers.
CachedDistillTrainer Like TorchDistillTrainer but caches teacher logits on disk after the first pass. Subsequent epochs are free. Supports accelerate for multi-GPU.
EmbeddingDistillTrainer MSE / cosine loss on pooled sentence vectors. Use for bi-encoder / reranker distillation.
MLMTrainer Masked-language-modeling pretraining of an encoder backbone from scratch (no teacher). WithMLMHead adds an MLM head to a custom encoder.
EncoderDistillTrainer Token-level hidden-state distillation from a teacher encoder into a smaller arch (auto projection).
SequenceClassificationTrainer / TokenClassificationTrainer Fine-tune classification / NER heads on any base. Full fine-tune or freeze_backbone. build_encoder_with_head attaches a head in one line.
prepare_qat / export_quantized Quantization-aware training (int8/int4 fake-quant) + int8 weight export and footprint report.
compare_encoders / evaluate_encoder Head-to-head accuracy / macro-F1 table across models.
load_for_inference / generate Load a built model (optional 4-bit/8-bit, optional skill pack) and generate.
TeacherRegistry Pool of HF teacher models with relative weights. Handles AutoModelForCausalLM and AutoModel (encoders).
LogitCache In-memory + on-disk cache for top-k teacher logit distributions.
GrowthPlan / plan_growth / detect_layer_prefix Depth up-scaling via SOLAR-style layer duplication. Native merge (no external deps); layer prefix auto-detected for any arch.
SkillPack / SkillRegistry Detachable LoRA adapters bound to a specific base model hash.
save_as_peft / load_from_peft PEFT-format adapter round-trip (no peft library required).
MinEDAlignment Cross-tokenizer vocabulary alignment via edit distance.
DataPipeline Unified dataset adapter — HF datasets, streaming, raw text, numpy. Labels for head training via label_column.
FoundryRecipe / EmbedRecipe Pydantic-validated YAML recipes — fail fast before GPU spend.

Training features

All trainers share the same production-ready feature set:

  • Mixed precisiontorch_dtype="bfloat16" or "float16"
  • Gradient accumulationgrad_accumulation_steps=N
  • LR scheduler"cosine" / "linear" / "constant" with linear warmup
  • Reproducibilityseed=42 sets torch + numpy + random before training
  • Checkpointingsave_checkpoint(path) / resume_from_checkpoint(path)
  • Auto-checkpointsave_every=N, save_dir="/path" saves every N steps
  • Eval loopeval_every=N evaluates on a held-out set every N steps
  • W&B / TensorBoardlog_backend="wandb" or "tensorboard"
  • OOM handling — CUDA OOM raises with actionable suggestions
  • Streaming datasetsDataPipeline wraps any HF IterableDataset
  • Dataset shufflingshuffle=True or shuffle_buffer=N for streaming

CLI

# Check your environment
foundry doctor

# Preview a recipe plan (no GPU spend)
foundry plan recipe.yaml

# Run a recipe
foundry run recipe.yaml

# Run an embedding distillation recipe
foundry embed recipe.yaml

# List fusion strategies
foundry strategies

Recipe YAML

# recipe.yaml — full causal-LM factory
seed:
  model: meta-llama/Llama-3.1-8B
  init: pretrained

grow:
  method: depth_upscale
  to_params: 15B

teachers:
  - role: reasoning
    model: meta-llama/Llama-3.1-70B
    weight: 1.0

fusion:
  strategy: min_ce
  align: min_ed
  cache: topk_64

heal:
  tokens: 100B
  alpha: 0.3

output:
  freeze_base: true
  skillpacks: [ola_math, ola_code]

Optional extras

Extra Installs When to use
[torch] torch, transformers, safetensors, accelerate Real training (incl. native SOLAR depth up-scaling)
[lego] peft LoRA skill packs
[data] datasets HuggingFace dataset streaming
[align] rapidfuzz Fast cross-tokenizer alignment (100× speedup)
[logging] wandb Experiment tracking
[docs] mkdocs-material Build the documentation site locally
[all] everything (runtime extras) Full setup

Documentation

Full docs: olaverse-labs.github.io/olaverse-foundry (auto-deployed from main).

Build or preview the site locally:

pip install -e ".[docs]"
mkdocs serve            # live preview at http://127.0.0.1:8000
mkdocs build --strict   # validate (no broken links / nav)

Links


License

Apache 2.0 — see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

olaverse_foundry-0.2.0.tar.gz (120.0 kB view details)

Uploaded Source

Built Distribution

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

olaverse_foundry-0.2.0-py3-none-any.whl (117.5 kB view details)

Uploaded Python 3

File details

Details for the file olaverse_foundry-0.2.0.tar.gz.

File metadata

  • Download URL: olaverse_foundry-0.2.0.tar.gz
  • Upload date:
  • Size: 120.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for olaverse_foundry-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fbe51f28341e8930ed11a1e18e06b2227b39490a23d3b7f63369ba22f62f47f0
MD5 d8a803a81f9c801fe279213a4a820abb
BLAKE2b-256 e57d758a23be0791954ae9a969948f2a7bff3810229169c57098c5b95dbd779a

See more details on using hashes here.

File details

Details for the file olaverse_foundry-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for olaverse_foundry-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b89e741bb8e49a96b8d6a41f0714d112c77eb6bed5c0b3c75d325d3f4470455
MD5 23724a39f65329bd6f72b76febe2a4dc
BLAKE2b-256 0f0083959f448e8711ac75bf7e608361a351bc93302a83cc7dae4e76fe7f4e69

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.1

2 files

This release

0.2.0 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page