Skip to content
Agentmart
Submit a tool

abi-stable

Migrate C++/CUDA PyTorch extension code to use the PyTorch stable ABI.

Skill by meta-pytorch

IndexedBSD-3-Clause★ 12
Write a review

Chalk Labs

Need help deploying abi-stable?

Chalk Labs sets up agents like this inside real teams: connected to your tools, tested on your data, with a human in the loop where it matters.

Book a call

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/meta-pytorch-abi-stable

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Migrate C++/CUDA PyTorch extension code to use the PyTorch stable ABI. Use when the user wants to make their project ABI stable, migrate to stable ABI, or use torch::stable APIs.

Use cases: ml

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/abi-stable

What's inside

Skill name
abi-stable
Description
Migrate C++/CUDA PyTorch extension code to use the PyTorch stable ABI. Use when the user wants to make their project ABI stable, migrate to stable ABI, or use torch::stable APIs.
License
BSD-3-Clause
Instructions
128 lines in SKILL.md · view on GitHub

Files (7)

  • SKILL.md
  • eval.yaml · evals/
  • extension.cpp · evals/fixtures/basic_tensor_migration/
  • extension.cu · evals/fixtures/cuda_extension_migration/
  • api-mapping.md · references/
  • common-issues.md · references/
  • migration-example.md · references/

SKILL.md (first lines)

# PyTorch Stable ABI Migration

Migrate C++/CUDA PyTorch extension code to the stable ABI so that extensions built
against one PyTorch version continue to work with future versions without recompilation.

## Prerequisites

**PyTorch 2.11+ is required.** Before making any changes, verify the installed version:

```bash
python3 -c "import torch; print(torch.__version__)"
```

If the version is below 2.11, stop and tell the user they need to upgrade PyTorch first.
The stable ABI headers (`torch/csrc/stable/`) were introduced in PyTorch 2.7 but the
API surface needed for most migrations was not complete until 2.11.

## Reference Documentation

Before starting a migration, read the project's reference documentation:

- **Official guide**: https://docs.pytorch.org/docs/stable/notes/libtorch_stable_abi.html
- **C++ API reference**: https://docs.pytorch.org/cppdocs/stable.html

For a concrete before/after example of a real migration, see
[references/migration-example.md](references/migration-example.md).

For the complete API mapping (old API -> stable ABI replacement), see
[references/api-mapping.md](references/api-mapping.md).

## Migration Workflow

### Step 1: Identify files to migrate

Find all `.cpp`, `.cu`, and `.cuh` files that include PyTorch headers like:
- `<torch/extension.h>`
- `<ATen/ATen.h>`
- `<ATen/cuda/CUDAContext.h>`
- `<c10/cuda/CUDAGuard.h>`
- `<torch/library.h>`

### Step 2: Update includes

Remove old includes and replace with stable ABI headers:

```cpp
// REMOVE these:
// #include <torch/extension.h>
// #include <ATen/ATen.h>
// #include <ATen/cuda/CUDAContext.h>
// #include <c10/cuda/CUDAGuard.h>
// #include <torch/library.h>

// ADD these (include only what you need):
#include <torch/csrc/stable/tensor.h>
#include <torch/csrc/stable/library.h>
#include <torch/csrc/stable/ops.h>
#include <torch/csrc/stable/accelerator.h>

#include <torch/headeronly/core/ScalarType.h>
#include <torch/headeronly/util/Exception.h>
#include <torch/headeronly/util/shim_utils.h>

// For CUDA stream access:
#include <torch/csrc/inductor/aoti_torch/c/shim.h>
#include <cuda_runtime.h>
```

### Step 3: Apply API replacements

Apply the replacements described in [references/api-mapping.md](references/api-mapping.md).
The most common ones are:

| Old API | Stable ABI Replacement |
|---------|----------------------|
| `at::Tensor` / `torch::Tensor` | `torch::stable::Tensor` |
| `TORCH_CHECK(...)` | `STD_TORCH_CHECK(...)` |
| `c10::cuda::CUDAGuard` | `torch::stable::accelerator::DeviceGuard` |
| `at::empty({...}, options)` | `torch::stable::new_empty(ref_tensor, {sizes}, dtype)` |
| `at::zeros({...}, options)` | `torch::stable::new_zeros(ref_tensor, {sizes}, dtype)` |
| `TORCH_LIBRARY_IMPL` | `STABLE_TORCH_LIBRARY_IMPL` |
| `m.impl("name", &func)` | `m.impl("name", TORCH_BOX(&func))` |

### Step 4: Update build configuration

In the project's `setup.py` (or CMakeLists.txt), add `-DUSE_CUDA` to **both** cxx
and nvcc compiler flags if using CUDA stream access via `aoti_torch_get_current_cuda_stream`.

### Step 5: Build and iterate

Build the project and fix compilation errors iteratively. Common issues are
documented in [references/common-issues.md](references/common-issues.md).

## Critical Rules

These are mistakes that AI models commonly make. Follow these strictly:

1. **Do NOT use `torch::stable::new_empty_strided`** - this API does not exist.
   To create a strided tensor, create a contiguous tensor with transposed dimensions
   and then call `torch::stable::transpose()`.

2. **Do NOT define a dummy `_C` module** that can be accessed from Python.

3. **Do NOT declare `aoti_torch_get_current_cuda_stream` yourself.** Include it from
   `torch/csrc/inductor/aoti_torch/c/shim.h`.

4. **Do NOT manually box kernels.** Use `TORCH_BOX(&func)` in `m.impl()` calls.

5. **Do NOT change switch statements into if/else blocks.** The stable ABI works
   fine with switch statements.

6. **When replacing `TORCH_CHECK` with `STD_TORCH_CHECK`, only replace the function
   name.** Do not change the content/arguments of the check.

7. **When replacing `tensor.data_ptr<T>()`**, use `tensor.const_data_ptr<T>()` for
   read-only access. Do not change the template type.

8. **For `DeviceGuard`**, pass `tensor.get_device_index()` not `tensor.device()`.

From meta-pytorch/skills, BSD-3-Clause.

Signals

Stars
12
Forks
2
Open issues
1
Last commit (this folder)
Jun 8, 2026 (4 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
BSD-3-Clause
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from meta-pytorch

Done for you

Rather not set it up yourself?

Chalk Labs scopes, builds and runs agents for your team: the task audit, the eval harness, the integrations and the weekly ops report. Fixed scope, priced before we start.

See how we build AI agents →Read the case studies

Chalk Labs is a two-founder AI and growth studio. We build AI agents, CRMs and MVPs for Web3 and AI companies, and have shipped 50+ product and token launches.

launches shipped
50+
launches shipped
media placements
500+
media placements
founders on every account
2
founders on every account

Press we've placed: Forbes · CoinDesk · Decrypt · Cointelegraph · The Block

Rahil Jain, Co-founder, Chalk Labs. Ex-Goldman Sachs engineer. You talk to the person who builds it.

Get abi-stable running in your business

Tell us what you want to automate. A founder replies within one working day with a plan, not a pitch deck.

Goes to the Chalk Labs founders, not the newsletter. Privacy

Need help deploying abi-stable?

CallGet help
Cite this page

abi-stable skill. Agent Mart. https://agentmart.dev/skills/meta-pytorch-abi-stable (last updated 2026-10-24)