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.

Note: Review and test before use. Provided as is, without warranty. See Terms.

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

pandas rules

Cursor rules for pandas 2.2+/3.x analysis code: Copy-on-Write, vectorized ops, dtypes, method chaining, and validation.

CursorPython Data & ML

Polars DataFrame rules

Cursor rules for Polars (1.x/2.x) data pipelines in Python: lazy queries, expressions, schemas, and no row-wise Python.

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

Streamlit app AGENTS.md

AGENTS.md for Streamlit data apps: the rerun model, caching, session state, forms and fragments, secrets, and testing.

AGENTS.mdPython 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

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.