323-pytorch-unittest

Community

Make PyTorch tests reliable and precise.

Authorulf1
Version1.0.0
Installs0

System Documentation

What problem does it solve?

This Skill prevents flaky or misleading unit tests for PyTorch by enforcing correct tensor comparisons, tolerance handling, dtype/shape/device checks, deterministic RNG usage, and gradient-flow validation.

Core Features & Use Cases

  • Robust Tensor Assertions: Use torch.testing.assert_close with explicit rtol and atol instead of unsafe == checks for tensors, avoiding incorrect boolean semantics and brittle equality failures.
  • Invariant Validation: Assert shapes, dtypes, and device placement so silent upcasts, reshaping errors, or CPU/GPU mismatches are caught immediately.
  • Autograd & Determinism Checks: Verify gradients after backward() and ensure deterministic behavior via controlled seeding for reproducible results.
  • Use Cases: Testing tensor math correctness, validating custom layers and loss functions, checking training-loop gradients, and ensuring model outputs are stable across refactors.

Quick Start

Use the 323-pytorch-unittest skill when writing or reviewing any pytest/unittest that imports torch so your assertions verify values, shapes/dtypes, device placement, gradients, and determinism with appropriate tolerances.

Dependency Matrix

Required Modules

None required

Components

references

💻 Claude Code Installation

Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.

Please help me install this Skill:
Name: 323-pytorch-unittest
Download link: https://github.com/ulf1/trading-regime/archive/main.zip#323-pytorch-unittest

Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
View Source Repository

Agent Skills Search Helper

Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.