Agent skill · software engineering · affaan-m

pytorch-patterns

PyTorch deep learning patterns and best practices for building robust, efficient, and reproducible training pipelines, model architectures, and data loading.

Why this skill is useful

Provides specific idiomatic patterns and best practices for PyTorch that enhance model training and architecture design.

What it needs

About 5k tokens when loaded. Last updated 2026-08-06. 238,342 stars on the source repository.

What this skill does

PyTorch Development Patterns Idiomatic PyTorch patterns and best practices for building robust, efficient, and reproducible deep learning applications. When to Activate Writing new PyTorch models or training scripts Reviewing deep learning code Debugging training loops or data pipelines Optimizing GPU memory usage or training speed Setting up reproducible experiments Core Principles 1. Device-Agnostic Code Always write code that works on both CPU and GPU without hardcoding devices. 2. Reproducibility First Set all random seeds for reproducible results. 3. Explicit Shape Management Always document and verify tensor shapes. Model Architecture Patterns Clean nn.Module Structure Proper Weight Initialization Training Loop Patterns Standard Training Loop Validation Loop Data Pipeline Patterns Custom Dataset Efficient DataLoader Configuration Custom Collate for Variable-Length Data Checkpointing Patterns Save and Load Checkpoints Performance Optimization Mixed Precision Training Gradient Checkpointing for Large Models torch.compile for Speed Quick Reference: PyTorch Idioms Idiom Description ------- ------------- model.train() / model.eval() Always set mode before train/eval torch.nograd() Disable gradients for inference optimizer.zerograd(settonone=True) More efficient gradient clearing .to(device) Device-agnostic tensor/model placement torch.amp.autocast Mixed precision for 2x speed pinmemory=True Faster CPU→GPU data transfer torch.compile JIT compilation for speed (2.0+) weightsonly=True Secure model loading torch.manualseed Reproducible experiments gradientcheckpointing Trade compute for memory Anti-Patterns to Avoid Remember: PyTorch code should be device-agnostic, reproducible, and memory-conscious. When in doubt, profile with torch.profiler and check GPU memory with torch.cuda.memorysummary().

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills affaan-m/pytorch-patterns

View the source on GitHub

Browse the @skills marketplace