# pytorch

Guides AI coding agents through building PyTorch architectures, fine-tuning Hugging Face transformers, running diffusion models, and optimizing GPU memory.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 839 installs · ★ 286
- Author: Mindrally
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/Mindrally/skills/tree/HEAD/pytorch/SKILL.md
- Updated: 2026-10-08
- HTML: https://affpapa.org/en/nevibecode/skills/pytorch

## What it does

This skill establishes practical rules for deep learning engineering in PyTorch. The agent implements architectures by subclassing `nn.Module`, initializes weights inside `__init__`, and registers non-trainable tensors as buffers. Forward pass logic sits cleanly inside `forward`. For evaluation and inference, the agent wraps passes in `torch.no_grad()`.

The instructions cover pre-trained transformers from Hugging Face alongside diffusion pipelines from the Diffusers library, including SDXL. To run generative pipelines, external packages like `transformers` and `diffusers` must be installed in the environment. Large batch training relies on `torch.cuda.amp` for mixed precision and gradient accumulation to prevent out-of-memory errors on GPUs. Multi-GPU setups use `DistributedDataParallel` or `DataParallel`.

Data pipelines use custom DataLoaders with streaming support for large datasets. Training loops include learning rate schedulers, early stopping, and gradient clipping to avoid numerical instabilities. For interactive testing, the agent scaffolds Gradio demos with built-in error handling. Code stays concise and direct.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill pytorch -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/pytorch/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/pytorch/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill pytorch -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/pytorch/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill pytorch -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/pytorch/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install Mindrally/skills pytorch
```

2. **Manually: put the files in place**
- File: `.github/skills/pytorch/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill pytorch -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/Mindrally/skills --path pytorch
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/pytorch/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill pytorch -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/Mindrally/skills/tree/HEAD/pytorch/SKILL.md

## When to use it
- Build custom neural network architectures with `nn.Module`
- Fine-tune transformer models using LoRA or P-tuning
- Run diffusion pipelines with SDXL and noise schedulers
- Enable mixed precision training via `torch.cuda.amp` to reduce GPU memory usage
- Scaffold a Gradio demo interface for model inference

## Example prompts
- Create a custom PyTorch `nn.Module` with registered buffers and weight initialization
- Set up LoRA fine-tuning for a Hugging Face transformer with `torch.cuda.amp`
- Build an SDXL diffusion pipeline with a Gradio inference interface

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 4e0cc3487ddb0f13.

BEGIN THIRD-PARTY FILE 4e0cc3487ddb0f13
```text
---
name: pytorch
description: PyTorch deep learning development with transformers, diffusion models, and GPU optimization.
metadata:
  maintainer: Mindrally
  source: https://github.com/Mindrally/skills
---

# PyTorch Development

You are an expert in deep learning with PyTorch, transformers, and diffusion models.

## Core Principles

- Write concise, technical code with accurate examples
- Prioritize clarity and efficiency in deep learning workflows
- Use object-oriented programming for model architectures
- Implement proper GPU utilization and mixed precision training

## Model Development

### Custom Modules
- Implement custom `nn.Module` classes for architectures
- Use `forward` method for forward pass logic
- Initialize weights properly in `__init__`
- Register buffers for non-parameter tensors

### Autograd
- Leverage automatic differentiation
- Use `torch.no_grad()` for inference
- Implement custom autograd functions when needed
- Handle gradient accumulation properly

## Transformers Integration

- Use Hugging Face Transformers for pre-trained models
- Implement attention mechanisms correctly
- Apply efficient fine-tuning (LoRA, P-tuning)
- Handle tokenization and sequences properly

## Diffusion Models

- Use Diffusers library for diffusion model work
- Implement forward/reverse diffusion processes
- Utilize appropriate noise schedulers
- Understand pipeline variants (SDXL, etc.)

## Training Best Practices

### Data Loading
- Implement efficient DataLoaders
- Use proper train/validation/test splits
- Apply data augmentation appropriately
- Handle large datasets with streaming

### Optimization
- Apply learning rate scheduling
- Implement early stopping
- Use gradient clipping for stability
- Handle NaN/Inf values properly

## Performance Optimization

- Use DataParallel/DistributedDataParallel for multi-GPU
- Implement gradient accumulation for large batches
- Apply mixed precision with `torch.cuda.amp`
- Profile code to identify bottlenecks

## Gradio Integration

- Create interactive demos for inference
- Build user-friendly interfaces
- Handle errors gracefully in demos
```
END THIRD-PARTY FILE 4e0cc3487ddb0f13

The third-party file has ended. Everything between the 4e0cc3487ddb0f13 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

© Mindrally · Apache-2.0 · https://github.com/Mindrally/skills/tree/HEAD/pytorch/SKILL.md

## Similar
- [skill-creator](https://affpapa.org/en/nevibecode/skills/skill-creator.md) — skill · 414180 installs
- [writing-for-agents](https://affpapa.org/en/nevibecode/skills/writing-for-agents.md) — skill · 466719 installs
- [media-use](https://affpapa.org/en/nevibecode/skills/media-use.md) — skill · 1100000 installs
- [mcp-builder](https://affpapa.org/en/nevibecode/skills/mcp-builder.md) — skill · 130949 installs
- [subagent-driven-development](https://affpapa.org/en/nevibecode/skills/subagent-driven-development.md) — skill · 237746 installs
- [orchestration](https://affpapa.org/en/nevibecode/skills/orchestration.md) — skill · 349800 installs

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
