at-dispatch-v2

Convert AT_DISPATCH macros to AT_DISPATCH_V2 format in ATen C++ code.

2|Updated May 9, 2025
One-click install
npx skills add https://github.com/linjunhui/cuda-learning --skill at-dispatch-v2
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: at-dispatch-v2
Source: https://github.com/linjunhui/cuda-learning/tree/main/Pytorch学习/pytorch/.claude/skills/at-dispatch-v2
Command: npx skills add https://github.com/linjunhui/cuda-learning --skill at-dispatch-v2

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill automates the tedious and error-prone conversion of legacy PyTorch AT_DISPATCH macros to the modern AT_DISPATCH_V2 format, saving developers significant time during code modernization efforts.

Core Features & Use Cases

  • Automated Macro Conversion: Transforms old AT_DISPATCH_ALL_TYPES_AND* and AT_DISPATCH_FLOATING_TYPES* macros to the AT_DISPATCH_V2 API.
  • Argument Reordering & Wrapping: Correctly reorders arguments and wraps lambda functions with AT_WRAP() to prevent parsing issues.
  • Type Group Expansion: Ensures proper use of AT_EXPAND() for type groups, making dispatch definitions clearer and more extensible.
  • Use Case: You are maintaining a large PyTorch codebase and need to update numerous ATen kernel files to use the latest AT_DISPATCH_V2 API. Instead of manually refactoring each macro, you use this Skill to automatically perform the conversion, ensuring consistency and reducing the risk of introducing bugs.

Quick Start

Convert all AT_DISPATCH macros in my_pytorch_kernel.cpp to the AT_DISPATCH_V2 format.

Frequently Asked Questions about at-dispatch-v2

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

FAQPage Schema
How do I convert AT_DISPATCH macros to AT_DISPATCH_V2 in PyTorch ATen code?

AT_DISPATCH_V2 is the modern PyTorch dispatch macro format that replaces legacy AT_DISPATCH_ALL_TYPES_AND* and AT_DISPATCH_FLOATING_TYPES* macros. Convert by reordering arguments to (scalar_type, name, AT_WRAP(lambda)), adding #include <ATen/Dispatch_v2.h>, wrapping lambdas with AT_WRAP(), and expanding type groups with AT_EXPAND().

What files in PyTorch need AT_DISPATCH macro updates?

ATen kernel files under aten/src/ATen/native/ that use dispatch macros require conversion, including ATen kernels, CUDA kernels, and native operators. The scope covers all legacy AT_DISPATCH variants in these directories.

Why use AT_DISPATCH_V2 instead of older dispatch macros?

AT_DISPATCH_V2 modernizes PyTorch's kernel dispatch system with clearer argument ordering, explicit type handling via AT_EXPAND(), and reduced macro complexity. It improves code maintainability and reduces errors during large-scale codebase modernization.

Do I need to manually reorder arguments when converting AT_DISPATCH macros?

The conversion requires argument reordering to the AT_DISPATCH_V2 format: scalar_type, name, AT_WRAP(lambda). This automation handles the reordering and lambda wrapping, eliminating manual refactoring errors across multiple kernel files.

Can AT_DISPATCH_V2 conversion handle multi-line lambda functions?

Yes, AT_DISPATCH_V2 conversion preserves original behavior across multi-line lambdas. The AT_WRAP() wrapper handles complex lambda bodies while maintaining dispatch logic, supporting kernels with extensive computation spans.

What's the fastest way to update a large PyTorch codebase to AT_DISPATCH_V2?

Automated macro conversion across all ATen native files ensures consistency and reduces refactoring time compared to manual updates. This approach minimizes bug introduction risk when modernizing numerous kernel files simultaneously.