Set up the PyTorch AT_DISPATCH_V2 skill

at-dispatch-v2 is an official PyTorch skill that automatically converts AT_DISPATCH macros in ATen C++ code into the new AT_DISPATCH_V2 format.

  • Skill Road
  • Set up the PyTorch AT_DISPATCH_V2 skill

Published on 09.09.2026

What at-dispatch-v2 is and why it is needed

The at-dispatch-v2 skill comes directly from the official pytorch/pytorch repository, where it lives under .claude/skills as part of the project's own tooling for coding agents. According to the provider, the PyTorch project itself, the skill helps convert legacy AT_DISPATCH macros in the ATen C++ core into the newer AT_DISPATCH_V2 format, as defined in the file aten/src/ATen/Dispatch_v2.h. ATen is the tensor library that PyTorch is built on, and the AT_DISPATCH macros control which data types a given compute kernel is compiled for and selected at runtime. The old macro system needed a separate macro variant, such as AND2, AND3, or AND4, for every additional combination of types, which made the code hard to follow. For developers contributing to PyTorch's internal CUDA or CPU kernels, this skill is relevant because it automates the mechanical, error-prone rewriting work while correctly preserving argument order.

Prerequisites

To make meaningful use of the skill, you need access to the PyTorch source code, typically via a local checkout of the repository, plus a coding agent such as Claude Code that automatically reads the .claude/skills directory. Basic C++ knowledge and an understanding of the ATen dispatch mechanism are helpful for reviewing the changes the agent proposes. Since the skill explicitly does not run a compile or test step, the toolchain used by PyTorch's build system, such as CMake and a suitable C++ compiler, must be available separately to verify the conversion afterward.

Setting it up step by step

Because the skill is part of the official PyTorch repository, it does not need to be installed separately once the repository is checked out locally and Claude Code is started inside the project directory. The agent automatically recognizes when a file contains AT_DISPATCH_ALL_TYPES_AND-style macros or when the user explicitly asks for a dispatch-v2 conversion. In its workflow, the agent first reads the affected file, adds the Dispatch_v2.h include if it is missing, identifies the macro pattern in use, maps the type group to the matching AT_EXPAND entry, extracts any individual extra types, and assembles the new AT_DISPATCH_V2 call from those pieces. Finally, the agent shows the complete modified file and explains the changes made so a developer can review them before committing.

Security and best practices

Because this is a source-code transformation in a security-sensitive, widely used framework, the skill explicitly states that the agent should not compile or test the code but should focus strictly on an accurate conversion. That reduces the risk of automated test runs triggering unintended side effects, but it shifts responsibility for verification to the human reviewer. Before merging a conversion, the regular PyTorch build and test process should therefore always be run, including the project's own CI checks. It is also important not to remove the old Dispatch.h include, since other parts of the code may still depend on it, something the skill correctly accounts for.

A practical example and its limits

A typical example is converting AT_DISPATCH_ALL_TYPES_AND3(kBFloat16, kHalf, kBool, iter.dtype(), "min_values_cuda", [&]() { ... }) into the new form using AT_DISPATCH_V2, where the lambda is wrapped in AT_WRAP and the type group is given explicitly as AT_EXPAND(AT_ALL_TYPES). The limits of the skill are that it is designed exclusively for this one, very specific refactoring task within the PyTorch codebase and has no application outside that context, for instance in other C++ projects with their own dispatch mechanisms. For PyTorch contributors, it is nonetheless a useful, narrowly scoped tool that speeds up repetitive migration work.

Published on 09.09.2026

Categories

Frequently asked questions

Is the conversion only a rename?

No. Argument order, type groups, and lambda wrapping must be represented and reviewed according to the V2 API.

Are GitHub stars stored?

No. The Skill model has no github_stars field, so that metric is not invented or stored.