323-pytorch-unittest
CommunityMake PyTorch tests reliable and precise.
Software Engineering#pytest#unit-testing#pytorch#determinism#autograd#torch.testing.assert_close#device-placement
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_closewith explicitrtolandatolinstead 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 requiredComponents
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.
Agent Skills Search Helper
Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.