ml-training-recipes
하는 일
이 스킬은 언어, 비전, 생의학 모델을 포함한 여러 분야의 신경망 학습 패턴을 모읍니다. 안정적인 학습 결과를 원하는 머신러닝 실무자를 위한 스킬입니다.
사용하는 경우
- ✓데이터의 종류와 양에 맞는 모델과 학습 방법을 고르고 있을 때.
- ✓학습에서 손실 급등이 나타나거나 메모리가 부족해서, 디버깅해야 할 때.
- ✓새 학습 실행을 위해 옵티마이저나 학습률 스케줄을 고르고 싶을 때.
스킬 링크
https://github.com/Orchestra-Research/AI-Research-SKILLs/blob/main/10-optimization/ml-training-recipes/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“학습 손실이 갑자기 치솟다가 실행이 메모리 부족으로 멈춥니다. 무엇을 바꿔야 할지 알려 줄 수 있나요?”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
에이전트는 데이터 종류와 규모에 맞는 아키텍처와 학습 설정을 고르고, 손실 급등이나 메모리 오류 같은 흔한 문제의 원인을 하나씩 살펴봅니다. 옵티마이저, 분야별 세부 사항, 확장에 대한 참고 자료를 활용합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 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:
자주 묻는 질문
언어 모델만 다루나요?
아니요. 비전, 확산 모델, 의료 영상, 단백질과 신약 개발, 유전체도 다룹니다.
어떤 옵티마이저를 언급하나요?
AdamW와 Muon이며, 파라미터 그룹마다 학습률을 설정하는 방법도 포함합니다.
많은 실험을 돌리는 데 도움이 되나요?
네. 효과가 있는 변경은 유지하고 효과가 없는 변경은 되돌리는 실험 루프가 포함되어 있습니다.
상세 정보
작성자의 원본 설명
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.
인기도
- GitHub 스타
- 14k
- 순위
- #11162
- 라이선스
- MIT
- 업데이트
- 2026. 10. 10.
댓글
- …
이 저장소의 다른 스킬
autoresearch
14k에이전트가 문헌 검토부터 실험과 글쓰기까지 AI 연구 프로젝트 전체를 진행하도록 안내합니다. 테스트와 검토를 반복하는 주기를 따릅니다.
prompt-guard
14k에이전트가 Meta의 작은 분류기로, AI 앱에 도달하기 전에 텍스트에서 프롬프트 인젝션과 탈옥 시도를 검사하도록 돕습니다.
pytorch-fsdp2
14k에이전트가 PyTorch FSDP2를 학습 스크립트에 추가해, 큰 모델을 여러 GPU에 나누고 올바르게 저장하도록 보여 줍니다.
experiment-tracking-swanlab
14k에이전트가 SwanLab을 설정해 머신러닝 실험을 내 컴퓨터나 자체 서버에서 기록하고, 비교하고, 차트로 그리도록 돕습니다.