Home › Python Data & ML › PyTorch training CLAUDE.md

PyTorch training CLAUDE.md

CLAUDE.md for PyTorch 2.x model training repos: reproducible configs, data loaders, mixed precision, and checkpoints.

Claude Code (CLAUDE.md)Python Data & ML

How to use

Save this as CLAUDE.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

CLAUDE.mdDownload  
# CLAUDE.md: PyTorch training repo

## Commands
- Env: `uv sync` · Tests: `uv run pytest -q` · Lint: `uv run ruff check . && uv run ruff format --check .`
- Smoke run (must work on CPU in < 2 min): `uv run python train.py --config configs/debug.yaml`

## Code rules
- Config lives in YAML/dataclasses (`configs/`); no magic numbers in `train.py`. Every run logs its full resolved config.
- Seed everything (`torch.manual_seed`, `numpy`, `random`) from the config; note that full determinism also needs `torch.use_deterministic_algorithms(True)`.
- Device-agnostic code: pick `device` once (`cuda`, `mps`, `cpu`) and move tensors with `.to(device)`. No hard-coded `.cuda()`.
- Mixed precision via `torch.autocast(device_type, dtype=torch.bfloat16)`; use `GradScaler` only with float16.
- `model.train()` / `model.eval()` and `torch.inference_mode()` for evaluation.
- `DataLoader` with `num_workers`, `pin_memory` on CUDA, and dataset classes that do not load everything into memory.
- `torch.compile` is optional and behind a config flag.
- Checkpoints save model, optimizer, scheduler, step and config with `torch.save`; load with `weights_only=True` when loading only weights.
- Log metrics to the project's tracker (W&B, MLflow or TensorBoard), not print statements.

## Tests
Shape tests for models, a test that a batch overfits in a few steps, and data pipeline tests on a tiny fixture.

## Don't
Don't start long GPU runs, download large datasets, or delete `checkpoints/` without asking.

More: all Python Data & ML rules · all Claude Code (CLAUDE.md) rules

Related rules

Jupyter notebook hygiene rules

Cursor rules for Jupyter notebooks in data projects: reproducible cells, small outputs, and moving code into modules.

CursorPython Data & ML

Python data & ML CLAUDE.md

CLAUDE.md for data science / ML repos using pandas or polars, notebooks, and reproducible pipelines.

Claude Code (CLAUDE.md)Python Data & ML

Claude Agent SDK CLAUDE.md

CLAUDE.md for building agents with the Claude Agent SDK (Python/TypeScript): options, tools, permissions, and hooks.

Claude Code (CLAUDE.md)LLM apps & agents

MCP server (Python) CLAUDE.md

CLAUDE.md for building Model Context Protocol servers in Python with the official SDK (FastMCP), tools, and tests.

Claude Code (CLAUDE.md)MCP servers

RAG pipeline CLAUDE.md

CLAUDE.md for retrieval-augmented generation apps: chunking, embeddings, hybrid search, citations, and RAG evals.

Claude Code (CLAUDE.md)RAG & vector databases

CrewAI multi-agent AGENTS.md

AGENTS.md for CrewAI 1.x projects: YAML agents and tasks, crews and flows, tools, and cost-aware runs.

AGENTS.mdLLM apps & agents

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.