Skip to content
affaan-m avatar

Pytorch Patterns

PyTorch training, architecture, and data loading patterns covering device handling, reproducibility, and efficient pipelines.

CCM score
71 of 100
skills.sh installs
12.3K
GitHub stars
312.6K
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers device-agnostic code, seed control, shape annotations, module structure, weight initialization, training and validation loops, datasets, DataLoader tuning, and checkpointing
  • Includes annotated Good and Bad code pairs for each pattern, such as hardcoded .cuda() calls versus torch.device selection
  • Enforces model.train() and model.eval() mode switching, set_to_none=True gradient zeroing, and gradient clipping at a max norm of 1.0
  • Designed for writing or reviewing training scripts, or debugging runs that will not reproduce

Install

$ npx -y skills add affaan-m/ecc --skill pytorch-patterns -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

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

Details

Repository
github.com/affaan-m/ecc
Categories
Data Science & Analytics, AI Agents & LLM Apps, Python
First seen
Jul 14, 2026

Questions

What is the pytorch-patterns skill for?

The pytorch-patterns skill gives the agent PyTorch deep learning patterns and best practices for building robust, efficient, and reproducible training pipelines, model architectures, and data loading. It covers device-agnostic code, seed setup for reproducible runs, shape management, nn.Module structure, training and validation loops, custom datasets, DataLoader configuration, and checkpointing.

When should I use the pytorch-patterns skill?

Use it when writing or reviewing PyTorch training loops, model architectures, or data loading. It also applies when a training run will not reproduce, or when you want to optimize GPU memory use or training speed.

How do I install the pytorch-patterns skill?

Run npx -y skills add affaan-m/ecc --skill pytorch-patterns -y in your project. After that, the agent can write and review PyTorch code using the skill's device handling, seeding, mixed precision training, and checkpoint patterns.

Where does pytorch-patterns rank in its category?

It is in the Data Science & Analytics category and ranks in the top 25 on that category page. Other skills in the category that lead it include azure-kusto, analyze-project, run-train, explore-run, and python-executor, while this skill focuses on PyTorch deep learning code specifically.

More from affaan-m/ecc

All 257

Similar to Pytorch Patterns

More Data Science & Analytics