at-dispatch-v2

Official PyTorch guidance for converting AT_DISPATCH macros to AT_DISPATCH_V2.

at-dispatch-v2 is an official skill from the PyTorch source repository for converting legacy AT_DISPATCH macros to the newer AT_DISPATCH_V2 interface. It targets developers working on ATen C++ files, CUDA kernels, and native operator implementations in the PyTorch source tree. According to the provider, the skill is especially useful when macros such as AT_DISPATCH_ALL_TYPES_AND, AT_DISPATCH_FLOATING_TYPES, or related variants need to move to the new explicitly composable format. This makes the entry a focused source-maintenance guide rather than a standalone package, compiler, or general introduction to C++ macros.

Purpose and classification

The guide points to aten/src/ATen/Dispatch_v2.h as the definition of the new API. The important change is argument ordering. The scalar type and debug name come first, followed by the lambda and then explicit type groups. A conversion therefore is not just a spelling change; the original semantics must be understood and represented in the new form. The skill helps make the actual supported type set visible during that work. This matters when a kernel accepts several integral, floating-point, complex, or quantized types.

Practical conversion

According to the provider, the first step is adding the Dispatch_v2.h include near the existing Dispatch include. The older include remains because other code in the file may still need its definitions. The macro usage is then classified. A base macro for all types can become an AT_ALL_TYPES group, while floating-point, integral, or complex groups use their corresponding AT_EXPAND expressions. Extra types such as Half, BFloat16, or individual Float8 variants are listed separately at the end. The lambda is wrapped with AT_WRAP. That wrapper is important when the lambda contains commas in template arguments or function calls, because it keeps macro parsing from splitting the body into unintended arguments.

Review and quality

A safe migration covers every affected macro invocation, operator name, and extra type. Mechanical replacement can accidentally change the supported type set, reorder arguments incorrectly, or omit an include dependency. Review the result against Dispatch_v2.h and the concrete kernel implementation. Confirm that the new form covers the same data types as the old path and that diagnostics still retain a useful operator name. According to the provider, the skill is scoped to ATen code and native operator work; it does not claim that an arbitrary third-party macro definition is compatible.

Boundaries and safety

The guide does not modify an installed PyTorch version or execute changes automatically. It assumes a controlled local checkout, C++ knowledge, PyTorch build familiarity, and awareness of the relevant backend files. Before editing, inspect the branch, commit, and local working tree. Unknown scripts, generated files, and commands with external side effects should not enter the workflow without review. The conversion guarantees neither identical runtime nor identical numerical results; those properties require the relevant PyTorch tests and a review of the affected kernel.

Source and compatibility

The primary source is https://github.com/pytorch/pytorch/tree/main/.claude/skills/at-dispatch-v2. The complementary official PyTorch documentation at https://docs.pytorch.org/docs/stable/notes/extending.html explains how extensions and native operator work fit into the project. The PyTorch source tree is licensed under BSD-3-Clause. This description was reviewed on September 9, 2026. GitHub stars are not stored because the Skill model has no github_stars field. Compatibility with Claude Code follows from publication as a resource under .claude/skills; technical review must still be performed against the concrete PyTorch revision in use.

Free
Provider
PyTorch
License
BSD-3-Clause
Last reviewed
09.09.2026

Repository and documentation

Categories

Compatible with

Claude Code