/tiran-skills:port-to-torch-stable-abifrom tiran-skills
Ports compiled PyTorch C++/CUDA/ROCm extensions to the stable ABI (torch::stable) so one wheel works across Torch versions, then assesses Python abi3 (Py_LIMITED_API). Use when a Torch extension is version-locked to a single release.
Ships in tiran-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Status: Beta — every rule is drawn from real, source-verified ports, but this packaged workflow has been exercised on only a few projects. Follow it, but have a human review the resulting diff and build.
Port a compiled Torch extension from the unstable libtorch ABI to the stable
ABI, then assess Python abi3. Work in the order below. Every rule comes from
real ports (reference/ports.md); prefer these concrete patterns over improvising.
Why both. Stable ABI + abi3 is the best outcome: one wheel across Torch versions (stable ABI) and across Python versions (abi3). The only axis left is CUDA / device code — a new build is needed only for a new CUDA version, not for each Torch or Python release. That remaining GPU axis is what PyPI wheel variants (PEP 825, provisional) are designed to resolve at install time. So do the stable-ABI port and the abi3 assessment — the two together are the payoff, not either alone.
Bundled references — open each at the step that cites it, not up front:
reference/substitutions.md — include / type / check / tensor-method / dispatch
swap tables (steps 5–10) and the device/stream snippet.reference/ports.md — the reference-ports matrix + torch_call_dispatcher
escape hatch for ops with no stable wrapper.reference/torch-compile.md — the fake/meta-kernel decision procedure for
torch.compile (step 12): detect the op's case, then act.reference/background.md — the "why" (ABI basics, CUDA/ROCm, abi3) for humans
or when you need rationale, not steps.Authoritative sources (if this skill disagrees with them, they win):
Tooling (recommended) — offer it in step 1, don't skip it.
pytorch-stable-abi-transform
(https://github.com/TorchedHat/pytorch-stable-abi-transform) is a deterministic
Clang AST rewriter that automates the mechanical parts of this port — the
audit/plan/rewrite modes cover steps 1 and 5–10, and compile-based
verification supports step 16. Prefer running it for the bulk edit and then
handling only what it flags (TensorOptions, PYBIND11_MODULE, project dispatch
macros), rather than rewriting every file by hand. It is a build-from-source
C++ tool (LLVM/Clang dev libs), not a pip package, and it ships its own
Claude Code skill (migrate-stable-abi) + CLAUDE.md. Proactively tell the
user it exists and offer to set it up at the start (step 1) — do not silently
hand-rewrite the whole extension when this tool would do the bulk deterministically.
Definition of done: the extension builds with -DTORCH_TARGET_VERSION (and
-DTORCH_STABLE_ONLY); a symbol audit finds zero at::/c10::/unstable
torch:: symbols in the .so; the test suite passes; and you have written the
abi3 assessment (step 17).
Guardrails. Read
../GUARDRAILS.mdand follow it unless the user says otherwise: work in a project-local.venvwith uv (never global/user site-packages); don't delete content or commit/push without approval (never straight tomain); ask before installing heavy packages or starting a heavy compile (Torch/CUDA are multi-GB); match the project's existing style and keep comments/docstrings terse. Capitalize "Torch" as the product name in prose, comments, and commit messages (thetorchimport/package stays lowercase).
First, check upstream for prior work (../GUARDRAILS.md →
Prior work): a stable-ABI port is exactly the kind of change a maintainer may
already have started. Find the upstream repo (git remote -v, [project.urls];
if this is a fork, gh repo view --json parent) and search its issues + PRs
(open/merged/closed) for stable ABI, torch::stable, STABLE_TORCH_LIBRARY,
TORCH_TARGET_VERSION, abi3. Report what you find before porting.
Then inventory and classify:
grep -rnE 'PYBIND11_MODULE|py::class_|torch::class_|TORCH_LIBRARY|nanobind' csrc/ src/
grep -rnE '\bat::|\bc10::|TORCH_CHECK|AT_DISPATCH|data_ptr<|\.dtype\(\)|getCurrentCUDAStream|CUDAGuard' csrc/ src/
grep -rnE 'torch\.version\.(cuda|hip)' --include=setup.py --include='*.py' \
--include=CMakeLists.txt --include='*.cmake' --include=meson.build . # how the build selects CUDA/HIP/CPU
find . -name '*.cu' | head ; ls setup.py pyproject.toml CMakeLists.txt 2>/dev/null
py::class_, no exotic ATen. Mechanical.py::class_/torch::class_) or takes real
Python objects. The stable ABI has no class equivalent — see step 13.Offer to set up pytorch-stable-abi-transform now (the Tooling note above)
— the deterministic rewriter that does the bulk of steps 5–10 and compile-verifies
the result. Don't quietly skip it and hand-rewrite everything. It is a
build-from-source C++ tool with LLVM/Clang deps, so ask the user before setting
it up (per ../GUARDRAILS.md → Footprint). Once they agree:
# LLVM/Clang dev libs + Ninja (tested with LLVM 19):
# Fedora: sudo dnf install clang-devel llvm-devel ninja-build
# Ubuntu: sudo apt install libclang-19-dev libclang-cpp19-dev llvm-19-dev ninja-build
git clone https://github.com/TorchedHat/pytorch-stable-abi-transform
cmake -GNinja -B build -S pytorch-stable-abi-transform && cmake --build build
./build/stable-abi-transform --init-config > .stable-abi.yaml # set pytorch_root / project_root
It also ships its own Claude Code skill (migrate-stable-abi) and a
CLAUDE.md; if the user prefers, point their agent at those and drive the tool
from there instead. Either way, use it for a first-pass inventory —
--mode=audit (read-only) and --mode=plan (dependency-aware file grouping)
give a richer, AST-level classification than the greps above.
The rewriter operates on .cpp TUs; CUDA .cu device code (kernels, launch
wrappers, atomics, dispatch macros, the data_ptr const-split) still needs
hand-porting. On a CPU-only box those .cu files are neither compiled nor
symbol-audited (step 16) — port them by hand and flag them for a GPU reviewer.
TORCH_TARGET_VERSION)Pick the lowest Torch version that has every stable API you call — it becomes the minimum Torch the wheel loads on. Default 2.10 unless forced higher:
| If you call… | Min floor | Encoding |
|---|---|---|
STABLE_TORCH_LIBRARY, torch::stable::Tensor, no-deleter from_blob | 2.10 † | 0x020a000000000000 |
torch::stable::from_blob with a deleter | 2.11 | 0x020b000000000000 |
Stream::nativeHandle() (else use the AOTI shim) | 2.13 | 0x020d000000000000 |
torch_tensor_from/to_pyobject | 2.14 | 0x020e000000000000 |
† STABLE_TORCH_LIBRARY / torch::stable::Tensor first appeared in 2.9, but
2.10 is the first release with C-shim version enforcement — so 2.10 is the
recommended floor even though these APIs are technically available on 2.9.
The table above is only the common cases. For any shim symbol, the
authoritative "which Torch version added this" list is
torch/csrc/stable/c/shim_function_versions.txt
in the pytorch tree — one function_name: TORCH_VERSION_MAJOR_MINOR_PATCH per
line (e.g. torch_from_blob: TORCH_VERSION_2_11_0); a symbol not listed there
was available before 2.10. Grep it for every shim your code calls and take the
max version as your floor. Check the copy that ships with your installed Torch
(python -c 'import torch,os; print(os.path.join(os.path.dirname(torch.__file__), "csrc/stable/c/shim_function_versions.txt"))')
so it matches the headers you build against, not just main.
The shim table does not cover the C++ torch::stable:: op wrappers.
shim_function_versions.txt lists only C shim symbols (aoti_torch_*,
torch_*). The C++ convenience wrappers in torch/csrc/stable/ops.h
(torch::stable::index_select, narrow, pad, amax, …) have their own
per-version availability it does not capture — many landed well after 2.10
(index_select first appears in 2.14). Your dev machine's newer ops.h
compiles calls that don't exist at your declared floor, so the wheel silently
requires a higher Torch than you claim. Guard it two ways:
ops.h for every torch::stable:: op you call
— not main, not your dev box:
grep -n 'inline .*\b<op>(' "$(python -c 'import torch,os;print(os.path.dirname(torch.__file__))')/include/torch/csrc/stable/ops.h".
The only real proof is a compile against the floor Torch (step 3).torch_call_dispatcher on the ATen schema (see how newer ops.h
implements it); replicate that as a small compat shim (ports.md) and keep your
low floor instead of raising it.setuptools projects usually compute the hex (0x0MMmm00000000000) from a
(major, minor) tuple defined once at module top level, so the floor lives in
a single place (causal-conv1d, state-spaces/mamba#1042):
TORCH_STABLE_ABI_MIN = (2, 10) # the one source of truth
TORCH_TARGET_VERSION = "0x{:02x}{:02x}000000000000".format(*TORCH_STABLE_ABI_MIN)
Reuse that same tuple for the runtime version pin so the build floor and the install requirement can never disagree:
install_requires = [
f"torch >= {TORCH_STABLE_ABI_MIN[0]}.{TORCH_STABLE_ABI_MIN[1]}",
...,
]
Don't hand-pack the hex any other way — the bit math is easy to get subtly wrong.
Use the bundled helper to get (or check) the token, and to decode a value read back
from _C.TORCH_TARGET_VERSION:
python scripts/torch_target_version.py encode 2.10 # -> 0x020a000000000000
python scripts/torch_target_version.py decode 0x020a000000000000 # -> 2.10
amd-quark passes the token TORCH_VERSION_2_10_0 instead; either works.
Pass both defines to cxx and nvcc. What must not drift is the value
(TORCH_TARGET_VERSION, from the one top-level tuple in step 2) — not the list
object. Either splat one shared list (xformers pattern) …
stable_args = [f"-DTORCH_TARGET_VERSION={TORCH_TARGET_VERSION}", "-DTORCH_STABLE_ONLY"]
extra_compile_args = {
"cxx": ["-std=c++17", *stable_args],
"nvcc": ["-std=c++17", *stable_args, "-DUSE_CUDA"],
}
… or repeat the two defines inline in each list — equally safe, and often
clearer since it shows exactly what each compiler gets (causal-conv1d, which also
carries -DUSE_CUDA on both host and device — see the stream note below):
extra_compile_args = {
"cxx": [
"-O3",
"-DUSE_CUDA",
f"-DTORCH_TARGET_VERSION={TORCH_TARGET_VERSION}",
"-DTORCH_STABLE_ONLY",
],
"nvcc": [
"-O3",
"-DUSE_CUDA",
f"-DTORCH_TARGET_VERSION={TORCH_TARGET_VERSION}",
"-DTORCH_STABLE_ONLY",
...,
],
}
CMake equivalent: target_compile_definitions(${tgt} PRIVATE TORCH_TARGET_VERSION=0x020a000000000000) plus -DUSE_CUDA/-DUSE_MPS where shim streams are used.
-DUSE_CUDA exposes aoti_torch_get_current_cuda_stream in shim.h (guarded
by #ifdef USE_CUDA only). Only add it if the extension actually calls the
current-stream shim — it is not a blanket "this is a GPU build" flag, and an
extension that never asks Torch for the current stream doesn't need it at all.
When you do need it, add it wherever the shim is compiled — .cpp files too,
not just .cu (torchvision gotcha). ROCm keeps the ..._cuda_stream name (HIP
masquerades as CUDA), so on ROCm the same condition applies: define
-DUSE_CUDA only for the stream shim, alongside -DUSE_ROCM=1 — not on
every HIP source file by default.pyproject.toml / install_requires
→ torch >= <floor>).-DTORCH_STABLE_ONLY is strongly recommended (step 4) but optional; torchvision
and amd-quark rely on discipline instead.Do most of the port on CPU-only Torch. The stable ABI is device-agnostic, so
the mechanical rewrites (steps 5–10), the CPU build, the symbol audit (step 16),
and the cross-Torch-version load test all work against
uv pip install torch --index-url https://download.pytorch.org/whl/cpu — a few
hundred MB, no nvcc, no GPU. Only reach for the CUDA Torch + nvcc wheels (below)
when you build .cu device code or run GPU smoke tests. See
../GUARDRAILS.md → Footprint.
Caveat — backend detection. Many extensions pick their CUDA / HIP / CPU build
path from torch.version.cuda and torch.version.hip (e.g.
if torch.version.hip: … elif torch.version.cuda: … else: CPU). The check may live
in setup.py, in CMakeLists.txt (an execute_process(... import torch ...)), or
in meson.build (a run_command(py, '-c', 'import torch; …')) — check all three.
On CPU-only Torch both are None, so such a build silently takes the CPU path
and skips the .cu/HIP sources entirely — useful for a fast CPU-path port, but it
means the device code isn't compiled or audited. Build once against the matching
CUDA (or ROCm) Torch before you call the port done. Note also that a ROCm Torch
reports torch.version.hip set and torch.version.cuda None, which is why
the HIP branch must key off torch.version.hip, not the absence of CUDA.
Verify against your floor Torch, not just the latest. Latest Torch provides
every stable API, so it silently hides calls that don't exist at your declared
floor — the C++ ops.h wrappers (step 2) and header-only helpers like
torch/headeronly/cuda/Atomic.h (2.14+) are the usual culprits. The floor is only
real once you've compiled the device code against a Torch at that floor:
uv pip install "torch==<floor>.*" --index-url https://download.pytorch.org/whl/<backend>
(pick the <backend> index — cpu, cu130, rocm7.0, … — from
https://pytorch.org/get-started/locally/, which lists every published version).
A handy shortcut: an older CUDA/ROCm wheel often is your floor (e.g. a ROCm image
pinned to an older Torch), so a device build there doubles as the floor test —
and covers both the .cu (CUDA) and hipified (ROCm) toolchains, which can fail
independently. When capturing the build to a log, check the real exit status —
a redirected tail can hide a non-zero setup.py/pip exit, so grep the log for
error:|fatal error|FAILED rather than trusting the last lines.
GPU device code (does not collapse with the ABI — one wheel per CUDA major +
per GPU arch; rationale in reference/background.md):
cudart matches the user's Torch.nvcc without a system toolkit: the CUDA compiler and libraries are
on PyPI as venv-local wheels — nvidia-cuda-nvcc-cu12 (nvcc),
nvidia-cuda-runtime-cu12, nvidia-cuda-cccl-cu12 (thrust/cub headers),
nvidia-cuda-nvrtc-cu12, nvidia-cublas-cu12, … (and a -cu11 line) — the same
components Torch's CUDA wheels pull in. uv pip install nvidia-cuda-nvcc-cu12
drops nvcc under site-packages/nvidia/cuda_nvcc/bin/ (no sudo, no system
install; see ../GUARDRAILS.md → Footprint). Match the
CUDA major/minor to build-Torch, point the build at it (CUDACXX=…/nvidia/cuda_nvcc/bin/nvcc
or CUDA_HOME), and remember these wheels omit profilers/debuggers and a host
C++ compiler.TORCH_CUDA_ARCH_LIST, e.g. "8.0 9.0 12.0+PTX".
All archs pack into one fatbinary in the .so; +PTX on the top arch adds
a driver-JIT fallback for newer GPUs. New GPU = add its sm_XX and rebuild.cuMem*, -lcuda, no .cu): no device code, no
cudart, no arch list — nearly CUDA-major-agnostic.-DUSE_ROCM=1 -D__HIP_PLATFORM_AMD__=1 (auto with
CUDAExtension; add manually with CppExtension) — this is the "build against
ROCm Torch" switch. It is separate from -DUSE_CUDA, which on ROCm gates
only the current-stream shim (add it just for that, per step 3 above — not
to every HIP file). Link amdhip64; archs via
PYTORCH_ROCM_ARCH (gfx*) → one bundled ("fat") code object. HIP-aware
source: use CppExtension to skip Torch's hipify (it rewrites/breaks headers).
hipify trap: it emits duplicate _hip.h for third-party headers on the include
path → route those as raw -I.TORCH_STABLE_ONLY and the pybind/fmt workaround-DTORCH_STABLE_ONLY makes any at::/c10::/non-stable torch:: use a hard
compile error — the single best guardrail. Defining TORCH_TARGET_VERSION
already implies it; setting it explicitly just makes intent obvious.
Gotcha (Torch < 2.13 only): Torch bundles pybind11 and fmt under torch/, and
on those versions the header-only, ABI-independent headers trip the guard. Torch
≥ 2.13 allow-lists pybind/fmt (pytorch/pytorch#174372), so the guard no longer
fires and the workaround below is unnecessary. If your floor is below 2.13 and a TU
still includes them, lift the guard around only those includes:
// Torch < 2.13 only: pybind11/fmt ship inside torch and trip the TORCH_STABLE_ONLY
// guard the target macro implies, though they are header-only and
// Torch-ABI-independent. 2.13+ allow-lists them, making this dance a no-op.
// See pytorch/pytorch#174372, meta-pytorch/torchcodec#1260.
#pragma push_macro("TORCH_STABLE_ONLY")
#pragma push_macro("TORCH_TARGET_VERSION")
#undef TORCH_STABLE_ONLY
#undef TORCH_TARGET_VERSION
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#pragma pop_macro("TORCH_TARGET_VERSION")
#pragma pop_macro("TORCH_STABLE_ONLY")
Apply this to every TU compiled with the stable defines that transitively
includes pybind — not just the PYBIND11_MODULE one. An implementation .cpp that
only pulls pybind in through a header (e.g. a cocoeval.cpp with no Torch calls of
its own) still trips the guard and still needs the dance.
Also: <torch/version.h> #errors when TORCH_TARGET_VERSION is defined, so you
cannot read TORCH_VERSION_MAJOR/MINOR in a stable TU. Treat "target defined"
as "≥ floor"; include version.h only when it is not defined.
Prefer pytorch-stable-abi-transform --mode=rewrite (deterministic Clang AST
rewriter) for this bulk: it applies includes (5), types (6), checks (7),
method→function (8), data_ptr disambiguation, and CUDA guards (9), then flags
what it can't do. Fall back to the swap tables in reference/substitutions.md
for hand edits and to understand each change: includes (5), types (6),
checks/error macros (7), tensor methods → stable free functions (8), device/stream
(9), dispatch macros (10). The non-obvious traps to keep in mind while you go:
t.stride(-1) → t.stride(t.dim()-1).data_ptr<T>() splits into const_data_ptr<T>() (read) /
mutable_data_ptr<T>() (write); const-ness propagates into kernel signatures..item() and element indexing are gone — read const_data_ptr<T>() + strides
(also avoids a per-element GPU→CPU sync).kInt8 → Char, kInt64 → Long; t.dtype() → t.scalar_type().C10_CUDA_CHECK /
C10_CUDA_KERNEL_LAUNCH_CHECK. Torch ships stable-ABI equivalents,
STD_CUDA_CHECK(expr) / STD_CUDA_KERNEL_LAUNCH_CHECK(), in
<torch/csrc/stable/macros.h> — present since the 2.10 floor (no version
bump), and they route through the C10 CUDA shim for proper error formatting.
Include that header (it expects cuda_runtime.h) and drop any bespoke macro
(causal-conv1d).reference/ports.md.Stay DRY (../GUARDRAILS.md → Style): the same swap
recurs across many TUs (the stream/device-guard helper, a boxed-op wrapper, a
const_data_ptr accessor). Factor each into one shared helper header the
.cpp/.cu files include — every surveyed port does (reference/substitutions.md
§9) — rather than pasting the snippet into each file.
Replace PYBIND11_MODULE/TORCH_LIBRARY with the stable macros. Schema strings
are the classic dispatcher schemas (Tensor(a!) mutated, Tensor? optional,
-> () void).
STABLE_TORCH_LIBRARY(myns, m) { // or STABLE_TORCH_LIBRARY_FRAGMENT to split across files
m.def("my_op(Tensor a, int n) -> Tensor");
}
STABLE_TORCH_LIBRARY_IMPL(myns, CUDA, m) { // CPU / CUDA / MPS / CompositeExplicitAutograd
m.impl("my_op", TORCH_BOX(&my_op_fn));
}
TORCH_BOX(&fn) needs an addressable symbol — wrap inline/lambda helpers
in a named free function first.CompositeExplicitAutograd and branch on
t.is_cuda(), or register separate CPU/CUDA impls.py::gil_scoped_release. Scalars cross
as int64_t/double.int→int64_t, float→double). A plain int
return against -> int can hit an ambiguous from(int) overload and fail to
box; widen to int64_t.Tensor(a!), (b!), …). An op
may mutate several out/scratch args and still return int/(). Over-declaring
an input as mutated is safe; under-declaring silently breaks functionalization
/ torch.compile.The stable C++ surface is forward-kernels only (torchvision is the reference):
torch.library.register_autograd("myns::op", bwd, setup_context=…).torch.library.Library("myns", "IMPL").impl(op, fn, "AutocastCUDA").torch.compile) → @torch.library.register_fake("myns::op"),
but only when the op returns tensors. An op that returns None and only
mutates pre-allocated outputs needs no fake (causal-conv1d); one that returns
tensors does, or fullgraph=True fails (state-spaces/mamba#1042); a
data-dependent output shape needs get_ctx().new_dynamic_size(). Whichever case,
mutates_args must be complete (step 11) — an undeclared mutation silently
corrupts the compiled graph. Detection procedure (incl. a CPU-only empirical
check), upstream citations, and per-case actions: reference/torch-compile.md.torch::class_ in the stable ABI)If the inventory found py::class_/torch::class_, pick one:
torch::stable::from_blob(ptr, {1}, {1}, cpu, kLong, deleter); the deleter
owns it. All-stable, torch.compile-safe..so (kvcached keeps PageAllocator).
Only tensor ops go stable; pass an int64 handle across. Needs the step-4
workaround; caps abi3 (step 17).Choose based on whether you also want abi3 (step 17):
torch.ops.load_library() (torchvision, xformers,
torchcodec). No PyInit_; ops register via static init. Override
get_export_symbols to [] (setuptools); keep the filename plain
(no_python_abi_suffix=True). Windows still needs a stub PyInit_<name>
returning nullptr.import mypkg._C and abi3. Hand-write a multi-phase init: PyModuleDef with
m_size = 0, a PyModuleDef_Slot array (add Py_mod_gil = Py_MOD_GIL_NOT_USED under #ifdef Py_GIL_DISABLED), and
PyMODINIT_FUNC PyInit__C() { return PyModuleDef_Init(&def); }.Either way, no TU built with the stable defines — including the pybind11 section —
may include <torch/extension.h>; it drags in unstable ATen and trips
TORCH_STABLE_ONLY. Include
<torch/csrc/stable/library.h> plus the narrow pybind headers instead.
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) still works: TORCH_EXTENSION_NAME is a
-D flag setuptools injects, not something torch/extension.h provides.
torch.ops.<ns>.<op>
(optionally alias old names to keep call sites working).torch-abi-audit on the built
.so (labels it stable/unstable, counts stable-shim vs unstable symbols), or
grep the .so: fail if any _ZN2at/_ZN3c10/_ZN5torch symbol (excluding
6stable/10headeronly) is defined, or if any shim newer than your floor is
imported. To know each imported shim's minimum version, cross-reference
shim_function_versions.txt
(step 2) — anything above your TORCH_TARGET_VERSION (e.g. torch_from_blob =
2.11 on a 2.10 floor) means the wheel silently won't load on the floor.
The raw _ZN2at/… grep only matches Itanium mangling (Linux/macOS,
gcc/clang); a Windows .pyd uses MSVC mangling (?…) that it misses.
De-mangle first so one audit works everywhere: pipe nm -D/dumpbin output
through pycxxfilt
(python -m pycxxfilt, or pycxxfilt.demangle()), which auto-detects Itanium
vs MSVC (vs Rust), then fail on any readable at:: / c10:: / non-stable
torch:: namespace. c++filt works too but is Itanium-only.import; run a create/op smoke
test on each. This is the single-wheel claim — it can't be checked by inspection.Complementary source check: pytorch-stable-abi-transform verifies each file
compiles against a shadow include tree of only stable headers — proof the source
is stable-clean before you build. Use it alongside the built-.so symbol audit.
Py_LIMITED_API)Do this after the Torch port and write the findings down. abi3 is orthogonal:
the Torch stable ABI collapses the Torch-version axis; abi3 collapses the
Python-version axis (one cpXY-abi3 wheel for all Python ≥ X.Y).
grep -rn 'pybind11\|py::class_' csrc/). pybind11
is incompatible with Py_LIMITED_API. A pybind11 section (step 13 option 2)
blocks abi3 until removed / converted to nanobind / hand-written via
PyType_FromSpec.py_limited_api=True
on the extension; derive the tag from
torch.utils.cpp_extension.min_supported_cpython
({"bdist_wheel": {"py_limited_api": f"cp{maj}{min}"}}) and set
python_requires. Use the real-CPython init (step 14) or the load_library
model (which sidesteps the CPython ABI entirely — a valid alternative).
Disable abi3 on free-threaded builds before CPython 3.15 (gate on
sysconfig.get_config_var("Py_GIL_DISABLED") — pip refuses abi3 there). From
Python 3.15, PEP 803 abi3t's compatible
interpreters are a superset of abi3's — a .abi3t.so loads on both
GIL-enabled and free-threaded 3.15+ — so the combined abi3.abi3t tag
ships one wheel for regular and free-threaded Python ≥3.15 once Torch's
tooling targets it.load_library).
Torch-stable ≠ abi3 — see the abi3? column in reference/ports.md.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub tiran/agent-skills --plugin tiran-skills12 skills in this plugin
/bootstrap-python-projectScaffold a new Python project from zero: src/ layout, PEP 621 metadata, a chosen build backend (hatchling for pure Python; meson-python / scikit-build-core / maturin for compiled) with dynamic VCS versioning, py.typed, ruff, a type checker, pytest + coverage, tox or nox via uv, and hardened GitHub Actions CI (SHA-pinned, Trusted Publisher, CodeQL/Scorecard/Dependabot). Always writes a README, LICENSE, and .gitignore. Orchestrates the choose-python-build-backend, modernize-python-metadata, ship-type-information, and secure-python-release-pipeline skills. Use when asked to start a new package, scaffold/bootstrap a Python project, set up a repo from zero, turn a loose script into a proper package, or bring an existing project up to this standard (adopt the layout, metadata, tooling, or CI it lacks)./choose-python-build-backendRecommend the right PEP 517 build backend for a new or existing Python package, and give enough context to migrate. Chooses by three axes: purelib (pure Python) vs platlib (compiled C/C++/Rust/Torch), static vs dynamic/VCS metadata, and native language/build system. Covers uv-build, flit-core, hatchling (incl. compiled via scikit-build-core[hatchling] / a custom build hook), meson-python, scikit-build-core, maturin, and setuptools (legacy). Weighs compiled-project concerns: Cython, PyTorch extensions, pybind11/nanobind bindings, the stable Python ABI (abi3 / limited API), and fast parallel builds (CMake+Ninja, Meson). Use when asked "which build backend should I use", to pick a backend for a new project, or to decide whether to move an existing project off setuptools./crypto-fips-auditAudit a Python package — and any C/C++/Go/Rust code it ships — for its use of cryptography, across three use cases: inventory what crypto a package uses at all (algorithms, providers, linkage, RNG, CA stores), find insecure or weak cryptography, and assess FIPS 140-3 / NIST compliance. Flags insecure use of approved primitives (AES-ECB, RSA PKCS#1 v1.5, static IV/nonce, `random` for secrets, timing-unsafe compares, disabled TLS verification), weak RSA/EC key sizes, and — for FIPS — refused hashes (MD5, MD4, RIPEMD-160), restricted ones (SHA-1), non-approved primitives (BLAKE2/3, ChaCha20-Poly1305, 3DES, scrypt/Argon2/bcrypt, X25519/X448 key agreement, secp256k1), vendored or statically linked crypto (bundled OpenSSL/BoringSSL/AWS-LC/NSS/GnuTLS/libgcrypt/ nettle/libsodium) that escapes the system validated module, hardcoded TLS versions/ciphers that bypass crypto-policies, bundled CA trust stores, and problematic PyPI deps (bcrypt, pycryptodome, pynacl, ecdsa, rsa, m2crypto, …). Source-first, then confirmed against the built wheel/binaries. Gathers evidence; does not certify compliance./modernize-python-metadataImprove a Python package's metadata and move it into a PEP 621 [project] table in pyproject.toml — filling in what's missing along the way. Covers the readme field (dropping the open().read() hack), SPDX license expressions, trove classifiers, well-known project URLs, authors/keywords/requires-python, dependency version constraints (avoid upper caps), PEP 735 dependency groups vs extras, and the build-system table. Keeps the existing build backend (setuptools is fine). Includes a Poetry → PEP 621 migration lens (the [tool.poetry] field map and caret/tilde → floor translation; PDM too). Use when asked to clean up packaging metadata, move metadata out of setup.py/setup.cfg, migrate a Poetry (or PDM) project to [project]/PEP 621, or improve a project's PyPI page./port-to-free-threaded-pythonMake a Python package work correctly on the free-threaded (no-GIL) CPython build (PEP 703; the cp313t/cp314t "t" ABI) and declare that it does, so importing it does not silently re-enable the GIL. Covers the pure-Python thread-safety pass (mutable global/class state, caches, contextvars vs threading.local) and, for C/C++/Cython/pybind11/nanobind/Rust-PyO3 extensions, declaring support (Py_mod_gil / PyUnstable_Module_SetGIL / the per-binding flag), fixing data races with critical sections (Py_BEGIN_CRITICAL_SECTION), PyMutex, atomics and thread-local state, the borrowed-reference hazards and their strong-reference replacements (PyList_GetItemRef, PyDict_GetItemRef), building cp3Xt wheels (meson-python, scikit-build-core, maturin, setuptools, cibuildwheel), and testing under load with ThreadSanitizer and pytest-run-parallel. Use to add free-threading / no-GIL / nogil / free-threaded / PEP 703 support, ship a cp313t/cp314t wheel, or stop the GIL being re-enabled. For a single stable-ABI abi3t wheel (3.15+) pair it with port-to-python-limited-api./port-to-meson-pythonBuild a Python package (usually with a compiled C/C++/Cython/Fortran/Rust extension) with the meson-python PEP 517 backend, or port one off a bespoke setuptools setup.py. Covers the pyproject.toml backend, the meson.build (project / extension_module / install_sources), VCS/dynamic versioning computed in meson.build, editable installs, config-settings, and abi3 / limited-API wheels. Use when asked to adopt meson-python or Meson, scaffold a new meson-python project, drop setup.py, or produce standards-based wheels.