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-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/everything-claude-code
Category
Data Science & ML
First seen
Apr 16, 2026

More from affaan-m/everything-claude-code

All 256
1grafana avatarml-aigrafana/skillsTurn on AI + ML features in Grafana Cloud — Grafana Assistant (NL → PromQL/LogQL/TraceQL, dashboard build, incident investigation, MCP integration), Dynamic Ale4.4Kskills.sh installs
2vinvcn avatarresearchvinvcn/mattpocock-skills-zh-cn对照高可信一手来源调研问题,并把发现保存为仓库中的 Markdown 文件。适用于用户想调研主题、收集文档或 API 事实,或把阅读工作委托给后台代理时。4.2Kskills.sh installs
3anthropics avataruser-researchanthropics/knowledge-work-pluginsPlan, conduct, and synthesize user research. Trigger with "user research plan", "interview guide", "usability test", "survey design", "research questions", or w4.1Kskills.sh installs
4jeffallan avatarml-pipelinejeffallan/claude-skillsDesigns and implements production-grade ML pipeline infrastructure: configures experiment tracking with MLflow or Weights & Biases, creates Kubeflow or Airflow 4.1Kskills.sh installs
5langchain-ai avatarweb-researchlangchain-ai/deepagentsSearches multiple web sources, synthesizes findings, and produces cited research reports using delegated subagents. Use when the user asks to research a topic o3.9Kskills.sh installs
6openai avatarnotion-research-documentationopenai/skillsResearch across Notion and synthesize into structured documentation; use when gathering info from multiple Notion sources to produce briefs, comparisons, or rep3.9Kskills.sh installs