Which trainer do I need?¶
Foundry ships nine trainers. You need one or two of them โ which ones depends entirely on what you're building and what you already have. Start from your goal:
I want a model that generates text (causal LM)¶
You need a teacher โ a bigger causal LM the student learns from.
| Situation | Use |
|---|---|
| Short run, one GPU, prototyping | TorchDistillTrainer โ teachers run live every step |
| Multiple epochs and/or multiple GPUs | CachedDistillTrainer โ teachers run once, logits cached to disk, later epochs are free |
Both accept several teachers at once with relative weights (TeacherRegistry).
I want an embedding model (search / retrieval / similarity)¶
| What you have | Use |
|---|---|
| A strong embedding teacher (bge, e5, โฆ) and raw text | EmbeddingDistillTrainer โ copy the teacher's sentence vectors into a smaller model |
{anchor, positive} pairs โ or the ability to synthesize them |
ContrastiveTrainer โ InfoNCE, the e5/bge training recipe |
| Both | Distil first, then contrastive fine-tune the result |
No pairs and no teacher? Synthetic data manufactures pairs from raw passages โ or from nothing in the target language, via translation.
Measure the result with retrieval evaluation (nDCG / Recall vs e5, LaBSE, โฆ).
I want an encoder base for classification / NER¶
This is a two-step build: make a base, then add a head (next section).
| What you have | Use |
|---|---|
| Only raw text โ no teacher | MLMTrainer โ masked-LM pretraining from scratch |
| A teacher encoder, limited raw text | EncoderDistillTrainer โ copy the teacher's per-token states; much more data-efficient than MLM from scratch |
| A teacher and in-domain text, student shares the teacher's vocab | DistilMLMTrainer โ distillation + MLM in one loss (the DistilBERT recipe) |
I have a base โ I want a task model¶
| Task | Use |
|---|---|
| Classification (topic, sentiment, langID, moderation) | SequenceClassificationTrainer |
| NER / token tagging | TokenClassificationTrainer |
build_encoder_with_head("./my-base", num_labels, task) attaches a fresh head in one line. Set freeze_backbone=True to train only the head โ many heads can then share one frozen encoder. Compare bases head-to-head with the evaluation harness.
I want the model smaller / cheaper to serve¶
| Goal | Use |
|---|---|
| int8/int4 weights | prepare_qat + export_quantized โ wrap the model before training with any trainer above, export packed weights after |
| Swappable task adapters instead of full fine-tunes | Skill packs โ detachable LoRA adapters with PEFT round-trip |
| A bigger model from the one you have | Growth โ SOLAR-style depth up-scaling |
Python, YAML recipes, or the CLI?¶
Three layers drive the same machinery โ pick by how repeatable the run needs to be:
| Layer | When |
|---|---|
| Python API (everything above) | Exploring, notebooks, custom loops โ the full feature set |
YAML recipes + foundry run |
A run you'll repeat or hand to someone else: the whole pipeline in one reviewable file |
| CLI | foundry doctor (check your install), foundry plan (preview a recipe's stages and cost) |
If in doubt, start with the Python API โ recipes cover the common paths, not every option.
Still unsure?¶
- New to the terminology? โ Concepts & glossary
- Want to see a full build? โ Small classifier ยท Low-resource retriever