ml-training-recipes
What it does
This skill collects practical patterns for training neural networks across many fields, including language, vision and biomedical models. It is for machine learning practitioners who want reliable training results.
When to use it
- βWhen you are choosing a model and training approach for your type and amount of data.
- βWhen training shows a loss spike or runs out of memory and you need to debug it.
- βWhen you want to pick an optimizer or learning rate schedule for a new training run.
Skill link
https://github.com/Orchestra-Research/AI-Research-SKILLs/blob/main/10-optimization/ml-training-recipes/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βMy training loss suddenly spikes and then the run crashes with out of memory. Can you help me figure out what to change?β
5 new skills a week. 1 minute to read.
How it works
The agent matches your data type and size to a suitable architecture and training setup, then works through common causes of problems such as loss spikes or memory errors. It draws on reference notes for optimizers, domain specifics and scaling.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
ML Training Recipes
Battle-tested patterns for PyTorch training across domains. Drawn from production codebases (Karpathy's autoresearch/nanochat, torchvision, HuggingFace) and modern training practice.
Reference files (read when needed)
references/architecture.mdβ Transformer/LLM architecture code patterns, weight initreferences/optimizers.mdβ Muon, AdamW hybrid, per-group LR, compiled optimizer stepsreferences/domain-specific.mdβ Vision, diffusion, contrastive, distributed, checkpointing, data loadingreferences/scaling-and-selection.mdβ Scaling laws, compute budget tables, decision trees, DGX Sparkreferences/biomedical.mdβ Drug discovery, protein models, medical imaging, genomics, clinical NLPreferences/experiment-loop.mdβ Autonomous experiment loop (autoresearch keep/discard/revert)
Architecture Selection
Pick the right model by data type and data scale:
| Data Type | < 10K samples | 10K-100K | > 100K |
|---|---|---|---|
| Images | Pretrained CNN + fine-tune | Fine-tune ViT or CNN | ViT from scratch |
| Text (gen) | Few-shot prompting | Fine-tune GPT/LLaMA (LoRA) | Pretrain from scratch |
| Tabular | XGBoost/LightGBM | Still XGBoost | Neural viable |
| Audio | Pretrained Whisper | Fine-tune AST | Train from scratch |
| Molecules | Pretrained GNN | Fine-tune molecular LM | Train GNN from scratch |
| Proteins | ESM-2 embeddings + head | Fine-tune ESM-2 | Train protein LM |
| Medical img | Pretrained CNN | nnU-Net (auto-config) | Swin-UNETR / MedSAM |
Key principle: architecture matters less than training recipe at equal compute. A well-tuned ResNet beats a poorly-tuned ViT (ref: "ResNet Strikes Back", Wightman 2021).
For biomedical domains, see references/biomedical.md.
For sequence model selection and compute planning, see references/scaling-and-selection.md.
Scaling Laws
Chinchilla rule (Hoffmann et al., 2022)
Compute-optimal training: ~20 tokens per parameter.
| Model Size | Compute-Optimal | Inference-Optimal (100Γ) |
|---|---|---|
| 125M | 2.5B tokens | 12.5B tokens |
| 1B | 20B tokens | 100B tokens |
| 7B | 140B tokens | 700B tokens |
FLOPs β 6 Γ N Γ D (N=params, D=tokens). Data repetition limit: ~4 epochs before diminishing returns.
Training Loop
import gc, time, torch
torch.manual_seed(42)
torch.set_float32_matmul_precision("high") # TF32 on Ampere+
autocast_ctx = torch.amp.autocast(device_type="cuda", dtype=torch.bfloat16)
grad_accum_steps = total_batch_size // (batch_size * seq_len)
step = 0
while not done:
t0 = time.time()
for micro_step in range(grad_accum_steps):
with autocast_ctx:
loss = model(x, y)
(loss / grad_accum_steps).backward()
x, y = next(train_loader)
update_lr(optimizer, progress)
optimizer.step()
model.zero_grad(set_to_none=True) # frees memory vs zeroing
if loss.item() > 100: # fast-fail on divergence
print("FAIL: loss exploded"); exit(1)
torch.cuda.synchronize()
if step == 0:
gc.collect(); gc.freeze(); gc.disable() # avoid ~500ms GC stalls
step += 1
Key principles
- Gradient clipping:
clip_grad_norm_(params, 1.0)β near-universal for Transformers. Exception: Muon optimizer normalizes updates via orthogonalization, so clipping is optional. - Tensor Core alignment: batch size, hidden dims should be multiples of 8 (bf16) or 64 (A100).
- Time-based budgets make experiments comparable across hardware.
cudnn.benchmark = Truefor fixed-size vision inputs.
Optimizer Configuration
Modern LLM training uses different optimizers per parameter group:
| Parameter Type | Optimizer | LR (base) | Weight Decay |
|---|---|---|---|
| 2D weight matrices | Muon | 0.04 | 0.2 |
| Token embeddings | AdamW | 0.6 Γ scale | 0.0 |
| Unembedding (lm_head) | AdamW | 0.004 Γ scale | 0.0 |
| Per-layer scalars | AdamW | 0.005 Γ scale | 0.0 |
LR scaling by dimension: lr * (d_model / 768)^(-0.5) β keeps dynamics stable across sizes.
Rules of thumb
- Embeddings need higher LR (sparse updates). Never weight-decay embeddings.
- Weight decay scheduling: linearly decay WD to 0 over training.
- AdamW defaults:
FAQ
Does it only cover language models?
No. It also covers vision, diffusion, medical imaging, protein and drug discovery, and genomics.
What optimizers does it mention?
AdamW and Muon, along with how to set learning rates for each group of parameters.
Can it help run many experiments?
Yes. It includes an experiment loop that keeps changes that help and reverts the ones that do not.
Details
Original description by the author
Battle-tested PyTorch training recipes for all domains β LLMs, vision, diffusion, medical imaging, protein/drug discovery, spatial omics, genomics. Covers training loops, optimizer selection (AdamW, Muon), LR scheduling, mixed precision, debugging, and systematic experimentation. Use when training or fine-tuning neural networks, debugging loss spikes or OOM, choosing architectures, or optimizing GPU throughput.
Popularity
- GitHub stars
- 14k
- Ranking position
- #11162
- License
- MIT
- Updated
- 10/10/2026
Comments
- β¦
More skills from this repository
autoresearch
14kGuides your agent through a full AI research project, from literature review to experiments and writing, with a repeating cycle of testing and review.
prompt-guard
14kLets your agent screen text for prompt injection and jailbreak attempts before it reaches your AI app, using Meta's small classifier.
pytorch-fsdp2
14kShows your agent how to add PyTorch FSDP2 to a training script so large models are split across GPUs and saved correctly.
experiment-tracking-swanlab
14kHelps your agent set up SwanLab to record, compare and chart machine learning experiments, locally or on your own server.
Similar skills
pytorch-patterns
280kHelps your agent use PyTorch for machine learning models. It applies best practices for efficient model training and ensures reproducible results.
evm-token-decimals
280kHelps your agent avoid errors with decimal numbers across different blockchain networks. It ensures token values are accurate in transactions and calculations.
ito-inference
280kLets your agent check the availability of AI models for use. It connects the compute request with the ready model service.