param087/agent-ml-skills/pytorch-training-loop
Claude Code and agent skill by param087/agent-ml-skills
- community
Checking that the SKILL.md file is still in the repository.
Use when writing or reviewing a PyTorch training loop. Covers correct train/eval modes, gradient handling, mixed precision, checkpointing, reproducibility, and device management.
Install
npx vskill@latest install param087/agent-ml-skills/pytorch-training-loopSKILL.md
The same SKILL.md was published earlier as param087/agent-ml-skills/pytorch-training-loop.
PyTorch Training Loop
Overview
A correct PyTorch loop has a precise sequence of operations. Getting the order or the modes wrong produces silent bugs (no gradients, dropout active at eval, leaked compute graphs). This skill encodes the canonical, production-ready loop.
When to use
- Writing a training loop from scratch.
- Debugging a model that won't learn or OOMs.
- Reviewing PyTorch training code.
Canonical loop
Non-negotiable rules
model.train()before training,model.eval()before validation/inference (toggles dropout & batchnorm).optimizer.zero_grad()every step — gradients accumulate otherwise.- Wrap validation/inference in
torch.no_grad()(orinference_mode()) to save memory. - Detach when logging:
loss.item(), notloss— keeping tensors leaks the graph and OOMs. - Clip gradients for RNNs/transformers to prevent explosions.
Reproducibility header
Pitfalls
- Forgetting `zero_grad` → gradients pile up, training diverges.
- `eval()` never called → dropout/batchnorm corrupt validation metrics.
- Accumulating `total_loss += loss` (tensor, not
.item()) → memory explosion. - DataLoader with `num_workers=0` on large data → CPU-bound; raise workers +
pin_memory=True. - LR too high → NaN loss; see the
ml-debuggingskill.
Hand-off
A checkpointed model + seed config that experiment-tracking logs and model-serving loads for inference.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/pytorch-training-loop/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/param087/agent-ml-skills/pytorch-training-loop)