affaan-m avatar

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-code

Installs 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
1composiohq avatarlead-research-assistantcomposiohq/awesome-claude-skillsIdentifies high-quality leads for your product or service by analyzing your business, searching for target companies, and providing actionable contact strategie5.7Kskills.sh installs
2samber avatardeep-researchsamber/cc-skillsDeep research skill — broad parallel web searches, multi-source validation, confidence tracking, cited Markdown report. Supports 11 research types: market (TAM/5.6Kskills.sh installs
3affaan-m avatarresearch-opsaffaan-m/eccEvidence-first current-state research workflow for ECC. Use when the user wants fresh facts, comparisons, enrichment, or a recommendation built from current pub5.5Kskills.sh installs
4affaan-m avatardeep-researchaffaan-m/everything-claude-codedeep research5.3Kskills.sh installs
5affaan-m avatarprediction-market-oracle-researchaffaan-m/eccResearch prediction markets as data sources or oracle signals for products, agents, dashboards, and corporate decision intelligence. Use for source-grounded ana5.3Kskills.sh installs
6claude-office-skills avatarcompany-researchclaude-office-skills/skillsConduct comprehensive company research and due diligence. Analyze business model, competitive landscape, management, and market position.5.3Kskills.sh installs