nanoresearch-experimen…
Generate a Python code skeleton from an experiment blueprint
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
$ npx -y skills add OpenRaiser/NanoResearch --skill ml-training-recipes --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/ml-training-recipesContext preview
The summary Claude sees to decide when to auto-load this skill.
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
name: ml-training-recipes description: 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. version: 1.0.0 author: dailycafi license: MIT tags: [PyTorch, Training, Optimization, LLM, Vision, Diffusion, Biomedical, Muon, AdamW, Debugging] dependencies: [torch>=2.0.0]
Battle-tested patterns for PyTorch training across domains. Drawn from production codebases (Karpathy's autoresearch/nanochat, torchvision, HuggingFace) and modern training practice.
---
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`.
---
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.
---
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 += 1Exception: Muon optimizer normalizes updates via orthogonalization, so clipping is optional.
---
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.
For Muon details (polar express orthogonalization, NorMuon), see `references/optimizers.md`.
---
def get_lr_multiplier(progress): # progress = elapsed_time / time_budget
if progress < warmup_ratio:
return progress / warmup_ratio
elif progress < 1.0 - warmdown_ratio:
return 1.0
else:
cooldown = (1.0 - progress) / warmdown_ratio
return cooldown + (1 - cooldown) * final_lr_fracdef get_lr(step, total_steps, max_lr, min_lr, warmup_steps):
if step < warmup_steps:
return max_lr * step / warmup_steps
progress = (step - warmup_steps) / (total_steps - warmup_steps)
retu端到端自主 AI 科研引擎 — 从研究想法到完整论文,全程自动化 快速开始 · 效果展示 · 流水线 · Claude Code · 飞书机器人 🔬 NanoResearch 真正运行计算实验——它不仅生成代码,还能将代码提交到 GPU 集群执行训练,收集真实实验结果,生成论文配图,最终输出一篇有实验数据支撑的完整 LaTeX 论文。论文中的每一个数据、表格、图表都来自实际运行的实验结果,而非 LLM 编造。
Generate a Python code skeleton from an experiment blueprint
Search academic literature and generate research hypotheses
Produce an experiment blueprint from a research hypothesis
Draft a LaTeX research paper from all previous stage outputs
Orchestrates end-to-end autonomous AI research projects using a two-loop architecture. The inner loop runs rapid experiment iterations with clear optimization…
Generates publication-quality figures for ML papers from research context. Given a paper section or description, extracts system components and relationships…