[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6EX1DQDHD0AVCMP8GZ4V99G":3,"skill-same:01M6EX1DQDHD0AVCMP8GZ4V99G":80},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":28,"publishedAt":46,"linkOnly":47,"markdownContent":48,"markdownBody":49,"frontMatter":50,"refName":51,"commitSha":52,"skillDirectory":53,"forksCount":54,"repositoryHtmlUrl":55,"repositoryHomepageUrl":56,"ownerHtmlUrl":57,"ownerBlogUrl":6,"ownerDescription":58,"updatedAt":59,"install":60,"resources":73},"01M6EX1DQDHD0AVCMP8GZ4V99G","at-dispatch-v2",null,"Convert PyTorch AT_DISPATCH macros to AT_DISPATCH_V2 format in ATen C++ code. Use when porting AT_DISPATCH_ALL_TYPES_AND*, AT_DISPATCH_FLOATING_TYPES*, or other dispatch macros to the new v2 API. For ATen kernel files, CUDA kernels, and native operator implementations.","ComeOnOliver\u002Fskillshub","ComeOnOliver","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43215937?v=4","01M6E5JNFECJAAVFE0W7SMWWD2","Haoran Shu","01M6E5JNNDQS7AJZDYFQ8TPZCK",66,"MIT","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fpytorch\u002Fat-dispatch-v2\u002FSKILL.md",[18,23],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发","SCENARIO","使用场景",{"categoryNo":24,"categoryName":25,"taxonomyType":26,"taxonomyTypeDesc":27},"01JBSEEDCAT000000000000030","开发工程师","PROFESSION","适用职业",[29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45],"dispatch","at dispatch v2","code","operator","api","convert","format","use","kernel","files","cuda","macros","cuda kernels","c++","native","types","pytorch","2026-11-10 10:12:30",false,"---\nname: at-dispatch-v2\ndescription: Convert PyTorch AT_DISPATCH macros to AT_DISPATCH_V2 format in ATen C++ code. Use when porting AT_DISPATCH_ALL_TYPES_AND*, AT_DISPATCH_FLOATING_TYPES*, or other dispatch macros to the new v2 API. For ATen kernel files, CUDA kernels, and native operator implementations.\n---\n\n# AT_DISPATCH to AT_DISPATCH_V2 Converter\n\nThis skill helps convert PyTorch's legacy AT_DISPATCH macros to the new AT_DISPATCH_V2 format, as defined in `aten\u002Fsrc\u002FATen\u002FDispatch_v2.h`.\n\n## When to use this skill\n\nUse this skill when:\n- Converting AT_DISPATCH_* macros to AT_DISPATCH_V2\n- Porting ATen kernels to use the new dispatch API\n- Working with files in `aten\u002Fsrc\u002FATen\u002Fnative\u002F` that use dispatch macros\n- User mentions \"AT_DISPATCH\", \"dispatch v2\", \"Dispatch_v2.h\", or macro conversion\n\n## Quick reference\n\n**Old format:**\n```cpp\nAT_DISPATCH_ALL_TYPES_AND3(kBFloat16, kHalf, kBool, dtype, \"kernel_name\", [&]() {\n  \u002F\u002F lambda body\n});\n```\n\n**New format:**\n```cpp\nAT_DISPATCH_V2(dtype, \"kernel_name\", AT_WRAP([&]() {\n  \u002F\u002F lambda body\n}), AT_EXPAND(AT_ALL_TYPES), kBFloat16, kHalf, kBool);\n```\n\n## Key transformations\n\n1. **Reorder arguments**: `scalar_type` and `name` come first, then lambda, then types\n2. **Wrap the lambda**: Use `AT_WRAP(lambda)` to handle internal commas\n3. **Expand type groups**: Use `AT_EXPAND(AT_ALL_TYPES)` instead of implicit expansion\n4. **List individual types**: Add extra types (kHalf, kBFloat16, etc.) after expanded groups\n5. **Add include**: `#include \u003CATen\u002FDispatch_v2.h>` near other Dispatch includes\n\n## Instructions\n\n### Step 1: Add the Dispatch_v2.h include\n\nAdd the v2 header near the existing `#include \u003CATen\u002FDispatch.h>`:\n\n```cpp\n#include \u003CATen\u002FDispatch.h>\n#include \u003CATen\u002FDispatch_v2.h>\n```\n\nKeep the old Dispatch.h include for now (other code may still need it).\n\n### Step 2: Identify the old dispatch pattern\n\nCommon patterns to convert:\n\n- `AT_DISPATCH_ALL_TYPES_AND{2,3,4}(type1, type2, ..., scalar_type, name, lambda)`\n- `AT_DISPATCH_FLOATING_TYPES_AND{2,3}(type1, type2, ..., scalar_type, name, lambda)`\n- `AT_DISPATCH_ALL_TYPES_AND_COMPLEX_AND{2,3}(type1, ..., scalar_type, name, lambda)`\n- `AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES_AND{2,3}(type1, ..., scalar_type, name, lambda)`\n\n### Step 3: Map the old macro to type groups\n\nIdentify which type group macro corresponds to the base types:\n\n| Old macro base | AT_DISPATCH_V2 type group |\n|----------------|---------------------------|\n| `ALL_TYPES` | `AT_EXPAND(AT_ALL_TYPES)` |\n| `FLOATING_TYPES` | `AT_EXPAND(AT_FLOATING_TYPES)` |\n| `INTEGRAL_TYPES` | `AT_EXPAND(AT_INTEGRAL_TYPES)` |\n| `COMPLEX_TYPES` | `AT_EXPAND(AT_COMPLEX_TYPES)` |\n| `ALL_TYPES_AND_COMPLEX` | `AT_EXPAND(AT_ALL_TYPES_AND_COMPLEX)` |\n\nFor combined patterns, use multiple `AT_EXPAND()` entries:\n```cpp\n\u002F\u002F Old: AT_DISPATCH_ALL_TYPES_AND_COMPLEX_AND2(...)\n\u002F\u002F New: AT_EXPAND(AT_ALL_TYPES), AT_EXPAND(AT_COMPLEX_TYPES), type1, type2\n```\n\n### Step 4: Extract the individual types\n\nFrom `AT_DISPATCH_*_AND2(type1, type2, ...)` or `AT_DISPATCH_*_AND3(type1, type2, type3, ...)`, extract the individual types (type1, type2, etc.).\n\nThese become the trailing arguments after the type group:\n```cpp\nAT_DISPATCH_V2(..., AT_EXPAND(AT_ALL_TYPES), kBFloat16, kHalf, kBool)\n                                             ^^^^^^^^^^^^^^^^^^^^^^^^\n                                             Individual types from AND3\n```\n\n### Step 5: Transform to AT_DISPATCH_V2\n\nApply the transformation:\n\n**Pattern:**\n```cpp\nAT_DISPATCH_V2(\n  scalar_type,           \u002F\u002F 1st: The dtype expression\n  \"name\",                \u002F\u002F 2nd: The debug string\n  AT_WRAP(lambda),       \u002F\u002F 3rd: The lambda wrapped in AT_WRAP\n  type_groups,           \u002F\u002F 4th+: Type groups with AT_EXPAND()\n  individual_types       \u002F\u002F Last: Individual types\n)\n```\n\n**Example transformation:**\n```cpp\n\u002F\u002F BEFORE\nAT_DISPATCH_ALL_TYPES_AND3(\n    kBFloat16, kHalf, kBool,\n    iter.dtype(),\n    \"min_values_cuda\",\n    [&]() {\n      min_values_kernel_cuda_impl\u003Cscalar_t>(iter);\n    }\n);\n\n\u002F\u002F AFTER\nAT_DISPATCH_V2(\n    iter.dtype(),\n    \"min_values_cuda\",\n    AT_WRAP([&]() {\n      min_values_kernel_cuda_impl\u003Cscalar_t>(iter);\n    }),\n    AT_EXPAND(AT_ALL_TYPES),\n    kBFloat16, kHalf, kBool\n);\n```\n\n### Step 6: Handle multi-line lambdas\n\nFor lambdas with internal commas or complex expressions, AT_WRAP is essential:\n\n```cpp\nAT_DISPATCH_V2(\n    dtype,\n    \"complex_kernel\",\n    AT_WRAP([&]() {\n      gpu_reduce_kernel\u003Cscalar_t, scalar_t>(\n        iter,\n        MinOps\u003Cscalar_t>{},\n        thrust::pair\u003Cscalar_t, int64_t>(upper_bound(), 0)  \u002F\u002F Commas inside!\n      );\n    }),\n    AT_EXPAND(AT_ALL_TYPES)\n);\n```\n\n### Step 7: Verify the conversion\n\nCheck that:\n- [ ] `AT_WRAP()` wraps the entire lambda\n- [ ] Type groups use `AT_EXPAND()`\n- [ ] Individual types don't have `AT_EXPAND()` (just `kBFloat16`, not `AT_EXPAND(kBFloat16)`)\n- [ ] Argument order is: scalar_type, name, lambda, types\n- [ ] Include added: `#include \u003CATen\u002FDispatch_v2.h>`\n\n## Type group reference\n\nAvailable type group macros (use with `AT_EXPAND()`):\n\n```cpp\nAT_INTEGRAL_TYPES      \u002F\u002F kByte, kChar, kInt, kLong, kShort\nAT_FLOATING_TYPES      \u002F\u002F kDouble, kFloat\nAT_COMPLEX_TYPES       \u002F\u002F kComplexDouble, kComplexFloat\nAT_QINT_TYPES         \u002F\u002F kQInt8, kQUInt8, kQInt32\nAT_ALL_TYPES          \u002F\u002F INTEGRAL_TYPES + FLOATING_TYPES\nAT_ALL_TYPES_AND_COMPLEX  \u002F\u002F ALL_TYPES + COMPLEX_TYPES\nAT_INTEGRAL_TYPES_V2  \u002F\u002F INTEGRAL_TYPES + unsigned types\nAT_BAREBONES_UNSIGNED_TYPES  \u002F\u002F kUInt16, kUInt32, kUInt64\nAT_FLOAT8_TYPES       \u002F\u002F Float8 variants\n```\n\n## Common patterns\n\n### Pattern: AT_DISPATCH_ALL_TYPES_AND2\n\n```cpp\n\u002F\u002F Before\nAT_DISPATCH_ALL_TYPES_AND2(kHalf, kBFloat16, dtype, \"op\", [&]() {\n  kernel\u003Cscalar_t>(data);\n});\n\n\u002F\u002F After\nAT_DISPATCH_V2(dtype, \"op\", AT_WRAP([&]() {\n  kernel\u003Cscalar_t>(data);\n}), AT_EXPAND(AT_ALL_TYPES), kHalf, kBFloat16);\n```\n\n### Pattern: AT_DISPATCH_FLOATING_TYPES_AND3\n\n```cpp\n\u002F\u002F Before\nAT_DISPATCH_FLOATING_TYPES_AND3(kHalf, kBFloat16, kFloat8_e4m3fn,\n    tensor.scalar_type(), \"float_op\", [&] {\n  process\u003Cscalar_t>(tensor);\n});\n\n\u002F\u002F After\nAT_DISPATCH_V2(tensor.scalar_type(), \"float_op\", AT_WRAP([&] {\n  process\u003Cscalar_t>(tensor);\n}), AT_EXPAND(AT_FLOATING_TYPES), kHalf, kBFloat16, kFloat8_e4m3fn);\n```\n\n### Pattern: AT_DISPATCH_ALL_TYPES_AND_COMPLEX_AND2\n\n```cpp\n\u002F\u002F Before\nAT_DISPATCH_ALL_TYPES_AND_COMPLEX_AND2(\n    kComplexHalf, kHalf,\n    self.scalar_type(),\n    \"complex_op\",\n    [&] {\n      result = compute\u003Cscalar_t>(self);\n    }\n);\n\n\u002F\u002F After\nAT_DISPATCH_V2(\n    self.scalar_type(),\n    \"complex_op\",\n    AT_WRAP([&] {\n      result = compute\u003Cscalar_t>(self);\n    }),\n    AT_EXPAND(AT_ALL_TYPES),\n    AT_EXPAND(AT_COMPLEX_TYPES),\n    kComplexHalf,\n    kHalf\n);\n```\n\n## Edge cases\n\n### Case 1: No extra types (rare)\n\n```cpp\n\u002F\u002F Before\nAT_DISPATCH_ALL_TYPES(dtype, \"op\", [&]() { kernel\u003Cscalar_t>(); });\n\n\u002F\u002F After\nAT_DISPATCH_V2(dtype, \"op\", AT_WRAP([&]() {\n  kernel\u003Cscalar_t>();\n}), AT_EXPAND(AT_ALL_TYPES));\n```\n\n### Case 2: Many individual types (AND4, AND5, etc.)\n\n```cpp\n\u002F\u002F Before\nAT_DISPATCH_FLOATING_TYPES_AND4(kHalf, kBFloat16, kFloat8_e4m3fn, kFloat8_e5m2,\n    dtype, \"float8_op\", [&]() { kernel\u003Cscalar_t>(); });\n\n\u002F\u002F After\nAT_DISPATCH_V2(dtype, \"float8_op\", AT_WRAP([&]() {\n  kernel\u003Cscalar_t>();\n}), AT_EXPAND(AT_FLOATING_TYPES), kHalf, kBFloat16, kFloat8_e4m3fn, kFloat8_e5m2);\n```\n\n### Case 3: Lambda with no captures\n\n```cpp\n\u002F\u002F Before\nAT_DISPATCH_ALL_TYPES_AND2(kHalf, kBool, dtype, \"op\", []() {\n  static_kernel\u003Cscalar_t>();\n});\n\n\u002F\u002F After\nAT_DISPATCH_V2(dtype, \"op\", AT_WRAP([]() {\n  static_kernel\u003Cscalar_t>();\n}), AT_EXPAND(AT_ALL_TYPES), kHalf, kBool);\n```\n\n## Benefits of AT_DISPATCH_V2\n\n1. **No arity in macro name**: Don't need different macros for AND2, AND3, AND4\n2. **Composable type sets**: Mix and match type groups with `AT_EXPAND()`\n3. **Extensible**: Easy to add more types without hitting macro limits\n4. **Clearer**: Type groups are explicit, not implicit in macro name\n\n## Important notes\n\n- Keep `#include \u003CATen\u002FDispatch.h>` - other code may need it\n- The `AT_WRAP()` is mandatory - prevents comma parsing issues in the lambda\n- Type groups need `AT_EXPAND()`, individual types don't\n- The v2 API is in `aten\u002Fsrc\u002FATen\u002FDispatch_v2.h` - refer to it for full docs\n- See the header file for the Python script to regenerate the macro implementation\n\n## Workflow\n\nWhen asked to convert AT_DISPATCH macros:\n\n1. Read the file to identify all AT_DISPATCH uses\n2. Add `#include \u003CATen\u002FDispatch_v2.h>` if not present\n3. For each dispatch macro:\n   - Identify the pattern and extract components\n   - Map the base type group\n   - Extract individual types\n   - Construct the AT_DISPATCH_V2 call\n   - Apply with Edit tool\n4. Show the user the complete converted file\n5. Explain what was changed\n\nDo NOT compile or test the code - focus on accurate conversion only.\n","# AT_DISPATCH to AT_DISPATCH_V2 Converter\n\nThis skill helps convert PyTorch's legacy AT_DISPATCH macros to the new AT_DISPATCH_V2 format, as defined in `aten\u002Fsrc\u002FATen\u002FDispatch_v2.h`.\n\n## When to use this skill\n\nUse this skill when:\n- Converting AT_DISPATCH_* macros to AT_DISPATCH_V2\n- Porting ATen kernels to use the new dispatch API\n- Working with files in `aten\u002Fsrc\u002FATen\u002Fnative\u002F` that use dispatch macros\n- User mentions \"AT_DISPATCH\", \"dispatch v2\", \"Dispatch_v2.h\", or macro conversion\n\n## Quick reference\n\n**Old format:**\n```cpp\nAT_DISPATCH_ALL_TYPES_AND3(kBFloat16, kHalf, kBool, dtype, \"kernel_name\", [&]() {\n  \u002F\u002F lambda body\n});\n```\n\n**New format:**\n```cpp\nAT_DISPATCH_V2(dtype, \"kernel_name\", AT_WRAP([&]() {\n  \u002F\u002F lambda body\n}), AT_EXPAND(AT_ALL_TYPES), kBFloat16, kHalf, kBool);\n```\n\n## Key transformations\n\n1. **Reorder arguments**: `scalar_type` and `name` come first, then lambda, then types\n2. **Wrap the lambda**: Use `AT_WRAP(lambda)` to handle internal commas\n3. **Expand type groups**: Use `AT_EXPAND(AT_ALL_TYPES)` instead of implicit expansion\n4. **List individual types**: Add extra types (kHalf, kBFloat16, etc.) after expanded groups\n5. **Add include**: `#include \u003CATen\u002FDispatch_v2.h>` near other Dispatch includes\n\n## Instructions\n\n### Step 1: Add the Dispatch_v2.h include\n\nAdd the v2 header near the existing `#include \u003CATen\u002FDispatch.h>`:\n\n```cpp\n#include \u003CATen\u002FDispatch.h>\n#include \u003CATen\u002FDispatch_v2.h>\n```\n\nKeep the old Dispatch.h include for now (other code may still need it).\n\n### Step 2: Identify the old dispatch pattern\n\nCommon patterns to convert:\n\n- `AT_DISPATCH_ALL_TYPES_AND{2,3,4}(type1, type2, ..., scalar_type, name, lambda)`\n- `AT_DISPATCH_FLOATING_TYPES_AND{2,3}(type1, type2, ..., scalar_type, name, lambda)`\n- `AT_DISPATCH_ALL_TYPES_AND_COMPLEX_AND{2,3}(type1, ..., scalar_type, name, lambda)`\n- `AT_DISPATCH_FLOATING_AND_COMPLEX_TYPES_AND{2,3}(type1, ..., scalar_type, name, lambda)`\n\n### Step 3: Map the old macro to type groups\n\nIdentify which type group macro corresponds to the base types:\n\n| Old macro base | AT_DISPATCH_V2 type group |\n|----------------|---------------------------|\n| `ALL_TYPES` | `AT_EXPAND(AT_ALL_TYPES)` |\n| `FLOATING_TYPES` | `AT_EXPAND(AT_FLOATING_TYPES)` |\n| `INTEGRAL_TYPES` | `AT_EXPAND(AT_INTEGRAL_TYPES)` |\n| `COMPLEX_TYPES` | `AT_EXPAND(AT_COMPLEX_TYPES)` |\n| `ALL_TYPES_AND_COMPLEX` | `AT_EXPAND(AT_ALL_TYPES_AND_COMPLEX)` |\n\nFor combined patterns, use multiple `AT_EXPAND()` entries:\n```cpp\n\u002F\u002F Old: AT_DISPATCH_ALL_TYPES_AND_COMPLEX_AND2(...)\n\u002F\u002F New: AT_EXPAND(AT_ALL_TYPES), AT_EXPAND(AT_COMPLEX_TYPES), type1, type2\n```\n\n### Step 4: Extract the individual types\n\nFrom `AT_DISPATCH_*_AND2(type1, type2, ...)` or `AT_DISPATCH_*_AND3(type1, type2, type3, ...)`, extract the individual types (type1, type2, etc.).\n\nThese become the trailing arguments after the type group:\n```cpp\nAT_DISPATCH_V2(..., AT_EXPAND(AT_ALL_TYPES), kBFloat16, kHalf, kBool)\n                                             ^^^^^^^^^^^^^^^^^^^^^^^^\n                                             Individual types from AND3\n```\n\n### Step 5: Transform to AT_DISPATCH_V2\n\nApply the transformation:\n\n**Pattern:**\n```cpp\nAT_DISPATCH_V2(\n  scalar_type,           \u002F\u002F 1st: The dtype expression\n  \"name\",                \u002F\u002F 2nd: The debug string\n  AT_WRAP(lambda),       \u002F\u002F 3rd: The lambda wrapped in AT_WRAP\n  type_groups,           \u002F\u002F 4th+: Type groups with AT_EXPAND()\n  individual_types       \u002F\u002F Last: Individual types\n)\n```\n\n**Example transformation:**\n```cpp\n\u002F\u002F BEFORE\nAT_DISPATCH_ALL_TYPES_AND3(\n    kBFloat16, kHalf, kBool,\n    iter.dtype(),\n    \"min_values_cuda\",\n    [&]() {\n      min_values_kernel_cuda_impl\u003Cscalar_t>(iter);\n    }\n);\n\n\u002F\u002F AFTER\nAT_DISPATCH_V2(\n    iter.dtype(),\n    \"min_values_cuda\",\n    AT_WRAP([&]() {\n      min_values_kernel_cuda_impl\u003Cscalar_t>(iter);\n    }),\n    AT_EXPAND(AT_ALL_TYPES),\n    kBFloat16, kHalf, kBool\n);\n```\n\n### Step 6: Handle multi-line lambdas\n\nFor lambdas with internal commas or complex expressions, AT_WRAP is essential:\n\n```cpp\nAT_DISPATCH_V2(\n    dtype,\n    \"complex_kernel\",\n    AT_WRAP([&]() {\n      gpu_reduce_kernel\u003Cscalar_t, scalar_t>(\n        iter,\n        MinOps\u003Cscalar_t>{},\n        thrust::pair\u003Cscalar_t, int64_t>(upper_bound(), 0)  \u002F\u002F Commas inside!\n      );\n    }),\n    AT_EXPAND(AT_ALL_TYPES)\n);\n```\n\n### Step 7: Verify the conversion\n\nCheck that:\n- [ ] `AT_WRAP()` wraps the entire lambda\n- [ ] Type groups use `AT_EXPAND()`\n- [ ] Individual types don't have `AT_EXPAND()` (just `kBFloat16`, not `AT_EXPAND(kBFloat16)`)\n- [ ] Argument order is: scalar_type, name, lambda, types\n- [ ] Include added: `#include \u003CATen\u002FDispatch_v2.h>`\n\n## Type group reference\n\nAvailable type group macros (use with `AT_EXPAND()`):\n\n```cpp\nAT_INTEGRAL_TYPES      \u002F\u002F kByte, kChar, kInt, kLong, kShort\nAT_FLOATING_TYPES      \u002F\u002F kDouble, kFloat\nAT_COMPLEX_TYPES       \u002F\u002F kComplexDouble, kComplexFloat\nAT_QINT_TYPES         \u002F\u002F kQInt8, kQUInt8, kQInt32\nAT_ALL_TYPES          \u002F\u002F INTEGRAL_TYPES + FLOATING_TYPES\nAT_ALL_TYPES_AND_COMPLEX  \u002F\u002F ALL_TYPES + COMPLEX_TYPES\nAT_INTEGRAL_TYPES_V2  \u002F\u002F INTEGRAL_TYPES + unsigned types\nAT_BAREBONES_UNSIGNED_TYPES  \u002F\u002F kUInt16, kUInt32, kUInt64\nAT_FLOAT8_TYPES       \u002F\u002F Float8 variants\n```\n\n## Common patterns\n\n### Pattern: AT_DISPATCH_ALL_TYPES_AND2\n\n```cpp\n\u002F\u002F Before\nAT_DISPATCH_ALL_TYPES_AND2(kHalf, kBFloat16, dtype, \"op\", [&]() {\n  kernel\u003Cscalar_t>(data);\n});\n\n\u002F\u002F After\nAT_DISPATCH_V2(dtype, \"op\", AT_WRAP([&]() {\n  kernel\u003Cscalar_t>(data);\n}), AT_EXPAND(AT_ALL_TYPES), kHalf, kBFloat16);\n```\n\n### Pattern: AT_DISPATCH_FLOATING_TYPES_AND3\n\n```cpp\n\u002F\u002F Before\nAT_DISPATCH_FLOATING_TYPES_AND3(kHalf, kBFloat16, kFloat8_e4m3fn,\n    tensor.scalar_type(), \"float_op\", [&] {\n  process\u003Cscalar_t>(tensor);\n});\n\n\u002F\u002F After\nAT_DISPATCH_V2(tensor.scalar_type(), \"float_op\", AT_WRAP([&] {\n  process\u003Cscalar_t>(tensor);\n}), AT_EXPAND(AT_FLOATING_TYPES), kHalf, kBFloat16, kFloat8_e4m3fn);\n```\n\n### Pattern: AT_DISPATCH_ALL_TYPES_AND_COMPLEX_AND2\n\n```cpp\n\u002F\u002F Before\nAT_DISPATCH_ALL_TYPES_AND_COMPLEX_AND2(\n    kComplexHalf, kHalf,\n    self.scalar_type(),\n    \"complex_op\",\n    [&] {\n      result = compute\u003Cscalar_t>(self);\n    }\n);\n\n\u002F\u002F After\nAT_DISPATCH_V2(\n    self.scalar_type(),\n    \"complex_op\",\n    AT_WRAP([&] {\n      result = compute\u003Cscalar_t>(self);\n    }),\n    AT_EXPAND(AT_ALL_TYPES),\n    AT_EXPAND(AT_COMPLEX_TYPES),\n    kComplexHalf,\n    kHalf\n);\n```\n\n## Edge cases\n\n### Case 1: No extra types (rare)\n\n```cpp\n\u002F\u002F Before\nAT_DISPATCH_ALL_TYPES(dtype, \"op\", [&]() { kernel\u003Cscalar_t>(); });\n\n\u002F\u002F After\nAT_DISPATCH_V2(dtype, \"op\", AT_WRAP([&]() {\n  kernel\u003Cscalar_t>();\n}), AT_EXPAND(AT_ALL_TYPES));\n```\n\n### Case 2: Many individual types (AND4, AND5, etc.)\n\n```cpp\n\u002F\u002F Before\nAT_DISPATCH_FLOATING_TYPES_AND4(kHalf, kBFloat16, kFloat8_e4m3fn, kFloat8_e5m2,\n    dtype, \"float8_op\", [&]() { kernel\u003Cscalar_t>(); });\n\n\u002F\u002F After\nAT_DISPATCH_V2(dtype, \"float8_op\", AT_WRAP([&]() {\n  kernel\u003Cscalar_t>();\n}), AT_EXPAND(AT_FLOATING_TYPES), kHalf, kBFloat16, kFloat8_e4m3fn, kFloat8_e5m2);\n```\n\n### Case 3: Lambda with no captures\n\n```cpp\n\u002F\u002F Before\nAT_DISPATCH_ALL_TYPES_AND2(kHalf, kBool, dtype, \"op\", []() {\n  static_kernel\u003Cscalar_t>();\n});\n\n\u002F\u002F After\nAT_DISPATCH_V2(dtype, \"op\", AT_WRAP([]() {\n  static_kernel\u003Cscalar_t>();\n}), AT_EXPAND(AT_ALL_TYPES), kHalf, kBool);\n```\n\n## Benefits of AT_DISPATCH_V2\n\n1. **No arity in macro name**: Don't need different macros for AND2, AND3, AND4\n2. **Composable type sets**: Mix and match type groups with `AT_EXPAND()`\n3. **Extensible**: Easy to add more types without hitting macro limits\n4. **Clearer**: Type groups are explicit, not implicit in macro name\n\n## Important notes\n\n- Keep `#include \u003CATen\u002FDispatch.h>` - other code may need it\n- The `AT_WRAP()` is mandatory - prevents comma parsing issues in the lambda\n- Type groups need `AT_EXPAND()`, individual types don't\n- The v2 API is in `aten\u002Fsrc\u002FATen\u002FDispatch_v2.h` - refer to it for full docs\n- See the header file for the Python script to regenerate the macro implementation\n\n## Workflow\n\nWhen asked to convert AT_DISPATCH macros:\n\n1. Read the file to identify all AT_DISPATCH uses\n2. Add `#include \u003CATen\u002FDispatch_v2.h>` if not present\n3. For each dispatch macro:\n   - Identify the pattern and extract components\n   - Map the base type group\n   - Extract individual types\n   - Construct the AT_DISPATCH_V2 call\n   - Apply with Edit tool\n4. Show the user the complete converted file\n5. Explain what was changed\n\nDo NOT compile or test the code - focus on accurate conversion only.\n",{"name":5,"description":7},"main","def8531e65114c0fca8fb8551c1871ee0eed705c","skills\u002Faiskillstore\u002Fmarketplace\u002Fpytorch\u002Fat-dispatch-v2",24,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub","https:\u002F\u002Fskillshub.wtf","https:\u002F\u002Fgithub.com\u002FComeOnOliver","AI & Blockchain Engineer\r\n","2026-06-24 22:07:19",{"source":8,"skillName":5,"commands":61,"prompt":71,"zipAvailable":72},[62,65,68],{"tool":63,"command":64},"npx","npx skills add ComeOnOliver\u002Fskillshub --skill at-dispatch-v2",{"tool":66,"command":67},"bunx","bunx skills add ComeOnOliver\u002Fskillshub --skill at-dispatch-v2",{"tool":69,"command":70},"pnpm","pnpm dlx skills add ComeOnOliver\u002Fskillshub --skill at-dispatch-v2","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fpytorch\u002Fat-dispatch-v2\u002FSKILL.md",true,[74],{"path":75,"resourceType":76,"resourceTypeDesc":77,"sizeBytes":78,"sourceHtmlUrl":79},"skill-report.json","REFERENCE","参考文档",9879,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fpytorch\u002Fat-dispatch-v2\u002Fskill-report.json",[81,91,101,110,116,123],{"skillNo":82,"name":83,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":87,"publishedAt":46},"01M6FKJN13GMG4KY57J3QD8GY5","model-hierarchy-skill","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzscole\u002Fmodel-hierarchy-skill\u002Fmodel-hierarchy-skill\u002FSKILL.md",[86],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},[88,89,90],"model","model hierarchy","model hierarchy skill",{"skillNo":92,"name":93,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":94,"categories":95,"keywords":97,"publishedAt":46},"01M6FKJJJ6GCAMR4PPPRD12M5X","zoom-mcp","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-mcp\u002FSKILL.md",[96],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},[98,99,100],"MCP","zoom","zoom mcp",{"skillNo":102,"name":103,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":104,"categories":105,"keywords":106,"publishedAt":46},"01M6FKJE3KYT3KPEZMEEHYKA6K","zoom-apps-sdk","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-apps-sdk\u002FSKILL.md",[],[107,108,109,99],"sdk","zoom apps sdk","apps",{"skillNo":111,"name":112,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":113,"categories":114,"keywords":115,"publishedAt":46},"01M6FKJ9EDH9Q5VWDF8HAJRSP0","windows","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwindows\u002FSKILL.md",[],[112],{"skillNo":117,"name":118,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":119,"categories":120,"keywords":122,"publishedAt":46},"01M6FKJ666BEEFC3AE9GJ72Q93","whiteboard","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwhiteboard\u002FSKILL.md",[121],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},[118],{"skillNo":124,"name":125,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":126,"categories":127,"keywords":128,"publishedAt":46},"01M6FKJ21WFCDGTJQ2Q91T9DVW","websockets","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwebsockets\u002FSKILL.md",[],[125]]