
Pytorch Patterns
This is a collection of PyTorch idioms that will save you from common mistakes like hardcoding CUDA calls or forgetting to set model.train() and model.eval(). It covers the full stack: device-agnostic code, reproducibility setup with proper seeding, shape-annotated forward passes, training loops with mixed precision and gradient clipping, and DataLoader configurations that actually use your CPU cores. The checkpoint patterns include optimizer state, which people forget surprisingly often. If you're writing PyTorch from scratch or reviewing someone else's training code, this gives you the patterns that separate working code from production-ready code.
- skills.sh installs
- 5.8K
- GitHub stars
- 300.3K
- last updated
- Aug 21, 2026
Install
$ npx -y skills add affaan-m/ecc --skill pytorch-patterns --agent claude-codeInstalls into .claude/skills of the current project.
Files
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.
# Good: Device-agnostic
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = MyModel().to(device)
data = data.to(device)
# Bad: Hardcoded device
model = MyModel().cuda() # Crashes if no GPU
data = data.cuda()
2. Reproducibility First
Set all random seeds for reproducible results.
# Good: Full reproducibility setup
def set_seed(seed: int = 42) -> None:
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
Sponsors
Details
- Repository
- github.com/affaan-m/ecc
- Category
- Data Science & ML
- First seen
- Jul 14, 2026
More from affaan-m/ecc
All 263- Hexagonal Architecture5.8K
- Flutter Dart Code Review5.8K
- Frontend A11y5.8K
- Error Handling5.8K
- Ui Demo5.8K
- Agentic Engineering5.8K
- Vite Patterns5.8K
- Bun Runtime5.8K
- Agent Architecture Audit5.8K
- Nodejs Keccak2565.8K
- Security Scan5.8K
- Cpp Testing5.8K
- Django Tdd5.8K
- Dashboard Builder5.7K
- Redis Patterns5.7K
- Eval Harness5.7K
- Manim Video5.7K
- Content Engine5.7K
- Springboot Tdd5.7K
- Motion Patterns5.7K
- Configure Ecc5.7K
- Token Budget Advisor5.7K
- Investor Materials5.7K
- Agent Introspection Debugging5.7K