
Pytorch Patterns
This one walks you through the PyTorch patterns that actually matter in production: device-agnostic code, proper reproducibility setup with seed management, explicit tensor shape tracking, and clean training loops with mixed precision support. It covers the full stack from nn.Module architecture (how to initialize weights correctly, when to use Sequential vs functional) to DataLoader optimization (pin_memory, persistent_workers) and proper checkpointing that saves optimizer state. The examples are opinionated about things like using set_to_none for gradient zeroing and @torch.no_grad() decorators. If you're moving past tutorials into real training pipelines or reviewing someone else's deep learning code, this gives you the patterns that prevent the common GPU memory bugs and reproducibility headaches.
- skills.sh installs
- 4.7K
- GitHub stars
- 229.1K
- last updated
- Jul 14, 2026
Install
$ npx -y skills add affaan-m/everything-claude-code --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/everything-claude-code
- Category
- Data Science & ML
- First seen
- Apr 16, 2026
More from affaan-m/everything-claude-code
All 256- Ralphinho Rfc Pipeline4.7K
- Carrier Relationship Management4.6K
- Context Budget4.6K
- Crosspost4.6K
- Energy Procurement4.6K
- Fal Ai Media4.6K
- Kotlin Exposed Patterns4.6K
- Logistics Exception Management4.6K
- Mcp Server Patterns4.6K
- Production Scheduling4.6K
- Quality Nonconformance4.6K
- Videodb4.6K
- Agent Eval4.5K
- Claude Devfleet4.5K
- Dmux Workflows4.5K
- Perl Patterns4.5K
- Perl Security4.5K
- Perl Testing4.5K
- Returns Reverse Logistics4.5K
- Team Builder4.5K
- X Api4.5K
- Design System4.4K
- Nuxt4 Patterns4.4K
- Browser Qa4.3K