pytorch-training-loop — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited pytorch-training-loop (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
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.
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")model.train() before training, model.eval() before validation/inference (toggles dropout & batchnorm).optimizer.zero_grad() every step — gradients accumulate otherwise.torch.no_grad() (or inference_mode()) to save memory.loss.item(), not loss — keeping tensors leaks the graph and OOMs.import torch, numpy as np, random
def seed_everything(seed=42):
random.seed(seed); np.random.seed(seed)
torch.manual_seed(seed); torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False.item()) → memory explosion.pin_memory=True.ml-debugging skill.A checkpointed model + seed config that experiment-tracking logs and model-serving loads for inference.
~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.