Install any skill in seconds. Free to start, no credit card required.
Get Started Free →loulanyue/pytorch-patterns
PyTorch deep learning patterns and best practices for building robust, efficient, and reproducible training pipelines, model architectures, and data loading.
Passed 21 of 22 test cases with the skill, and 18 of 22 without it.
3 fixed18 passed either way1 still failing0 broke
Tokens, turns and time describe resource use, not a dollar price.
One of 3 test cases the skill fixed. Same model, same prompt, with and without the skill.
I need a Python function to evaluate my PyTorch image classification model on a validation DataLoader. It should return the average loss and total accuracy. Please write the function following standard PyTorch best practices.
| Checked | Without skill | With skill |
|---|---|---|
| The evaluation function uses the @torch.no_grad() decorator rather than an internal context manager block. | Missed | Passed |
| The evaluation function calls model.eval() before iterating through the validation dataloader. | Passed | Passed |
The instructions your model reads when the skill loads.
Idiomatic PyTorch patterns and best practices for building robust, efficient, and reproducible deep learning applications.
Always write code that works on both CPU and GPU without hardcoding devices.
# Good: Device-agnostic
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = MyModel().to(device)
data = data.to(device)
# Bad: Hardcoded device
model = MyModel().cuda() # Crashes if no GPU
data = data.cuda()
Set all random seeds for reproducible results.
# Good: Full reproducibility setup
def set_seed(seed: int = 42) -> None:
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
test cases passed, vs 18 / 22 without
Published skills whose descriptions closely match this one, with their headline benchmark lift.
More skills from the same source and nearby in the registry, with their headline benchmark lift.