Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx skills add param087/agent-ml-skills --skill pytorch-training-loopgit clone --depth 1 https://github.com/param087/agent-ml-skillsWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/param087/agent-ml-skills/pytorch-training-loop)<a href="https://agentmods.dev/skills/param087/agent-ml-skills/pytorch-training-loop"><img src="https://agentmods.dev/badge/skills/param087/agent-ml-skills/pytorch-training-loop/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/skills/param087/agent-ml-skills/pytorch-training-loop"><img src="https://agentmods.dev/badge/skills/param087/agent-ml-skills/pytorch-training-loop.svg" alt="Reviewed on agentmods" width="80" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00039 | $0.00796 |
| Opus 5.5 | $0.00016 | $0.00318 |
| Sonnet 5.5 | $0.00008 | $0.00159 |
| Haiku 4.5 | $0.00004 | $0.00080 |
Grade A, and why
pytorch-training-loop scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2mo ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 92 lines — stays where its author put it; the contents beside it link to each section on GitHub.
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
import torch
from torch.amp import autocast, GradScaler
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
optimizer = torch.optim.AdamW(model.parameters(), lr=3e-4, weight_decay=0.01)
scaler = GradScaler(enabled=(device == "cuda"))
best_val = float("inf")
for epoch in range(num_epochs):
# ---- TRAIN ----
model.train()
for x, y in train_loader:
x, y = x.to(device, non_blocking=True), y.to(device, non_blocking=True)
optimizer.zero_grad(set_to_none=True)
with autocast(device_type=device, enabled=(device == "cuda")):
out = model(x)
loss = criterion(out, y)
scaler.scale(loss).backward()
scaler.unscale_(optimizer)
torch.nn.utils.clip_grad_norm_(model.parameters(), max_norm=1.0)
scaler.step(optimizer)
scaler.update()
# ---- VALIDATE ----
model.eval()
val_loss = 0.0
with torch.no_grad():
for x, y in val_loader:
x, y = x.to(device), y.to(device)
val_loss += criterion(model(x), y).item() * x.size(0)
val_loss /= len(val_loader.dataset)
# ---- CHECKPOINT BEST ----
if val_loss < best_val:
best_val = val_loss
torch.save({"model": model.state_dict(),
"optimizer": optimizer.state_dict(),
"epoch": epoch}, "best.pt")
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.
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 2mo ago First seen · 92 lines · 39 tokens per session scan A 6b6c5504b965
pytorch-training-loop is a skill published in the GitHub repository param087/agent-ml-skills (13 stars, last pushed 5mo ago), licensed MIT. It adds 39 tokens to every session and 796 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.
pytorch-training-loop compared with skills from other repositories
| Mod | Type | Stars | Last push | Licence | Scan | Tokens | Works with |
|---|---|---|---|---|---|---|---|
| pytorch-training-loopparam087/agent-ml-skills | Skill | 13 | 5mo ago | MIT | A | 39 | Claude Code, Codex |
| yolo-trainingfcakyon/claude-codex-settings | Skill | 1.2k | yesterday | Apache-2.0 | A | 124 | Claude Code |
| alterlab-pyhealthAlterLab-IEU/AlterLab-Academic-Skills | Skill | 85 | yesterday | MIT | A | 132 | Claude Code |
| alterlab-esmAlterLab-IEU/AlterLab-Academic-Skills | Skill | 85 | yesterday | MIT | A | 101 | Claude Code |
| alterlab-deepchemAlterLab-IEU/AlterLab-Academic-Skills | Skill | 85 | yesterday | MIT | A | 127 | Claude Code |
| alterlab-hypogenicAlterLab-IEU/AlterLab-Academic-Skills | Skill | 85 | yesterday | MIT | A | 122 | Claude Code |
| alterlab-molfeatAlterLab-IEU/AlterLab-Academic-Skills | Skill | 85 | yesterday | MIT | A | 145 | Claude Code |