ml-training-recipes

Provides PyTorch training recipes covering optimizers, LR scheduling, mixed precision, and debugging across ML domains.

13.0k|930|Updated Nov 3, 2025
One-click install
npx skills add https://github.com/Orchestra-Research/AI-research-SKILLs --skill ml-training-recipes-orchestra-research
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: ml-training-recipes
Source: https://github.com/Orchestra-Research/AI-research-SKILLs/tree/main/10-optimization/ml-training-recipes
Command: npx skills add https://github.com/Orchestra-Research/AI-research-SKILLs --skill ml-training-recipes-orchestra-research

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch>=2.0.0, and includes references (resource) components.

What problem does it solve? Training neural networks involves dozens of interdependent decisions — optimizer choice, learning rate schedules, mixed precision setup, memory management, and debugging loss spikes or OOM errors — and getting any of them wrong wastes GPU hours or produces broken models. This Skill consolidates production-tested PyTorch training patterns into actionable recipes so you can configure, train, and debug models correctly the first time. ## Core Features & Use Cases - Optimizer & LR Configuration: Per-parameter-group setups combining Muon for 2D weight matrices with AdamW for embeddings, plus cosine, WSD, and time-based LR schedules with dimension-based scaling rules. - Domain-Specific Guidance: Architecture selection tables and training patterns for LLMs, vision, diffusion, medical imaging, protein/drug discovery, genomics, single-cell omics, and clinical NLP. - Debugging & Performance: Systematic checklists for loss explosions, NaN, low MFU, OOM resolution steps, and silent failures like data leakage or tokenizer mismatch. - Use Case: You are pretraining a small LLM and hit a loss spike at step 2,000. Use this Skill to apply the debugging checklist — reduce LR, add gradient clipping, verify logit soft capping — then reconfigure the optimizer with the Muon/AdamW hybrid recipe and resume training with proper MFU monitoring. ## Quick Start Ask the AI to set up a PyTorch training loop for your model with the recommended optimizer configuration, mixed precision, and learning rate schedule from the ml-training-recipes skill.

Frequently Asked Questions about ml-training-recipes

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix loss spikes or NaN during PyTorch training?▼

Reduce the learning rate by 3-10x, add gradient clipping with clip_grad_norm_(params, 1.0), and check inputs for inf/nan values. For transformers, add logit soft capping and QK-norm in attention, and verify weight initialization uses zero-init output projections.

What optimizer should I use for LLM training: AdamW or Muon?▼

Use a hybrid approach: Muon for 2D weight matrices (attention, MLP) with lr around 0.04, and AdamW for embeddings, unembedding, and per-layer scalars. AdamW settings should use betas (0.9, 0.95) and eps 1e-10 rather than PyTorch defaults.

How many tokens do I need to train a language model?▼

The Chinchilla rule recommends approximately 20 tokens per parameter for compute-optimal training, so a 7B model needs about 140B tokens. For inference-optimal deployment, train on 100-200x tokens per parameter since inference is the ongoing cost.

How do I fix CUDA out of memory errors during training?▼

Reduce device batch size and increase gradient accumulation steps, set PYTORCH_ALLOC_CONF=expandable_segments:True, and use model.zero_grad(set_to_none=True). If still OOM, apply meta device initialization, activation checkpointing, or an 8-bit optimizer for about 30% memory savings.

Should I use bf16 or fp16 for mixed precision training?▼

Use bf16 on Ampere or newer GPUs since it has the same exponent range as fp32 and needs no loss scaling. Reserve fp16 with GradScaler only for V100 or older hardware, and enable TF32 with torch.set_float32_matmul_precision("high").

When should I use XGBoost instead of a neural network?▼

Use XGBoost or LightGBM for tabular data under roughly 50K rows, where tree-based models almost always outperform deep learning. Neural methods like FT-Transformer only become competitive on tabular data above 50K-500K rows.