test-refactor

Refactor PyTorch test files to classify test classes and remove hardware-specific assumptions.

6|8|Updated May 7, 2026
One-click install
npx skills add https://github.com/TorchedHat/ai-marketplace --skill test-refactor-torchedhat
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: test-refactor
Source: https://github.com/TorchedHat/ai-marketplace/tree/main/pytorch-test-refactor/skills/test-refactor
Command: npx skills add https://github.com/TorchedHat/ai-marketplace --skill test-refactor-torchedhat

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps modernize PyTorch test files that are tied to specific hardware, making them reusable across CPU, CUDA, XPU, MPS, and other accelerator backends without changing their intended behavior.

Core Features & Use Cases

  • Hardware Classification: Categorizes test classes as GENERIC, DEVICE_GENERIC, DEVICE_SPECIFIC, MULTI_DEVICE_GENERIC, or MULTI_DEVICE_SPECIFIC.
  • Structural Refactoring: Splits mixed test classes, adds hw_classification attributes, and applies the appropriate PyTorch testing infrastructure.
  • Device-Agnostic Conversion: Replaces hardcoded device references with self.device_type and preserves relevant decorators, fixtures, and test coverage.
  • Verification Guidance: Provides syntax checks, test execution steps, classification coverage checks, and a ready-to-use pull request checklist.
  • Use Case: Apply the Skill to a PyTorch test file containing CPU logic, CUDA-specific tests, and device-independent tensor operations to classify each group, split the classes correctly, and verify that no tests were lost.

Quick Start

Ask the test-refactor skill to refactor the attached PyTorch test file for device-agnostic execution and generate the corresponding verification plan.

Frequently Asked Questions about test-refactor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor PyTorch tests to run across CPU, CUDA, and other accelerators?

Refactoring PyTorch tests for device-agnostic execution involves classifying test classes into hardware categories like GENERIC or DEVICE_SPECIFIC, replacing hardcoded device references with self.device_type, and applying instantiate_device_type_tests to ensure compatibility across backends.

What is hardware classification in PyTorch test modernization?

Hardware classification in PyTorch test modernization categorizes test classes as GENERIC, DEVICE_GENERIC, DEVICE_SPECIFIC, MULTI_DEVICE_GENERIC, or MULTI_DEVICE_SPECIFIC to properly separate device-independent logic from accelerator-specific operations.

How do I split mixed PyTorch test classes containing both CPU and CUDA logic?

To split mixed PyTorch test classes, apply the test-refactor workflow to categorize CPU logic and CUDA-specific operations into separate classes, add hw_classification attributes, and apply the DeviceTypeTestBase framework to preserve test coverage and decorators.

Can I use instantiate_device_type_tests to preserve existing decorators and fixtures?

Yes, using instantiate_device_type_tests during structural refactoring preserves relevant decorators and fixtures while converting hardcoded device references to device-aware references, ensuring no tests are lost during the device-agnostic conversion process.

How do I verify test coverage after refactoring PyTorch test files for multiple accelerators?

Verify test coverage after refactoring by running syntax checks, executing the tests across target backends, and confirming that test counts match the original file, using the provided pull request checklist to validate classification coverage and structural integrity.

Does test refactoring support distributed testing workflows in PyTorch?

Test refactoring supports distributed testing workflows by classifying distributed behavior into MULTI_DEVICE_GENERIC or MULTI_DEVICE_SPECIFIC categories, ensuring distributed tests integrate correctly with the PyTorch device-type testing framework and accelerator backends.