Repository navigation
Extend libtorch-stable ABI compat for torch_musa 2.9 (vLLM v0.24.0 kernels) - #86
Merged
Merged
Conversation
…rface)
torch_musa 2.9's torch::stable predates several torch-2.10 stable APIs that newer libtorch-stable kernels call. Add torch::stable::Device, Tensor::{sizes,strides,device}() (patched into tensor_struct.h, gated on TORCHADA_STABLE_ACCESSORS), a non-template void* mutable_data_ptr(), and torch::stable::{empty,from_blob} (box header), all built on torch_musa's AOTI C-shim.
…os.h shims Three fixes for newer libtorch-stable kernels on torch_musa 2.9: move the headeronly Dispatch.h scalar_type into torchada_detail (torch_musa's ATen/Dispatch.h already defines ::detail::scalar_type for the same type -> ODR); add a cuda_runtime.h shim -> musa_runtime.h; add a torch/csrc/stable/macros.h shim -> library.h (the macros pre-date the 2.10 header split).
More torch-2.10 stable surface newer libtorch-stable kernels use: move Device into torch/csrc/stable/device.h with operator==/!= and is_cpu(); add torch::stable::flatten (aten::flatten.using_ints via the dispatcher); add a cublas_v2.h -> mublas.h shim.
v0.24 libtorch-stable kernels call const_data_ptr() without a template arg (like mutable_data_ptr()).
v0.24 libtorch-stable kernels: q_gemm compares device().type() against torch::stable::DeviceType::Meta (type() now returns the enum); minimax uses STD_CUDA_CHECK on musa runtime calls.
…ce ctors, kernel-launch check, cuda_bf16.h shim
…ead of redefining
Factor the tensor_struct.h accessor injection and the tensor_inl.h inline rewrite into module-level helpers, and warn when the numel() anchor is absent so a skipped backport surfaces immediately instead of as a later compiler error. Correct the empty() shim comment (the third positional slot is layout, not pin_memory) and give from_blob an explicit storage_offset. Add unit tests for the compat headers, the TORCH_BOX shim, and the backport transforms.
yeahdongcn
force-pushed
the
xd/stable-abi-v0240-accessors
branch
from
July 1, 2026 06:06
1d71468 to
292496d
Compare
🤖 Augment PR SummarySummary: This PR extends torchada’s libtorch-stable compatibility layer so vLLM v0.24.0 / SGLang stable-ABI kernels (written against newer torch::stable surfaces) can build and register on torch_musa 2.9 without patching kernel sources. Changes:
Technical Notes: Header backporting is best-effort and gated so normal 🤖 Was this summary useful? React with 👍 or 👎 |
…guard Give torch::stable::Device default member initializers so a default-constructed Device is well-defined (an unset device: is_cuda/is_cpu/is_privateuseone all false) rather than indeterminate. Rely on the regex's leading-inline lookahead alone for the tensor_inl.h inline rewrite's idempotency, dropping the "inline" substring guard that could skip a Tensor:: definition whose trailing comment contains "inline". Add regression tests for both.
Signed-off-by: Xiaodong Ye <xiaodong.ye@mthreads.com>
yeahdongcn
added a commit
that referenced
this pull request
Oct 10, 2026
The English and Chinese READMEs have not kept up with the May-October work. This documents what merged, moves the version-gated shims into one table, and refreshes the measured numbers that had gone stale. Feature table - CUDA memory-pool APIs, `torch.cuda.streams`, CUDA-graph executable rotation, `torch.cuda._get_device_index`, `get_memory_info()`, and the FlashAttention provider shims (#61, #98, #103, #106, #108, #115) - the "What Works" table goes back to one line per feature; the paragraph-sized `log_` / `isfinite` / `out_dtype` cells move into the new section below New "torch_musa Compatibility" section - one table of every version-gated shim with the release it is installed on: the four `< 2.11.0.post2` patches (#106, #113, #124), the `< 2.13.0` `mm`/`bmm` `out_dtype=` backport (#116), the stable-ABI header backport (#86, #96), asynchronous `isfinite` (#120), and `torch.cuda.streams` (#98) New "Environment Variables" section - the graph-rotation knobs (#72), `TORCHADA_PLATFORM`, the C++ operator-override switches (#61, #128), and the two variables that were already documented Corrected and extended details - torch.compile: FX `device` builtin (#124), Dynamo's device-index helper (#108), `MUSA_VISIBLE_DEVICES` mirroring (#106) - C++ extensions: nested `<torch/cuda.h>` porting (#95), stable-ABI `STABLE_TORCH_LIBRARY_IMPL` rekeying and stream helpers (#100), torch 2.6+ `include_paths`/`library_paths` signatures (#121), stale JIT build locks (#128) - MoE tables are generated from checked-in recipes (#115) - unsupported CUDA runtime APIs as no-ops (#65) - Performance: replace the 0.1.94 / torch_musa 2.7.1 numbers with the checked-in 0.1.95 / 2.11.0.post2 entry, and stop claiming every fast path is under 200ns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
torch_musa2.9.0'storch::stableruntime predates the torch 2.10 stable-ABIsurface that vLLM v0.24.0's
csrc/libtorch_stable/kernels (and the equivalentSGLang kernels) are written against. This extends torchada's libtorch-stable
compat layer so those kernels build and register on MUSA without patching the
kernels themselves.
What's added
torch::stable::Device/DeviceTypeshim (device.h) with the ctors and==/is_cpu/is_cuda/is_privateuseonepredicates the kernels use.torch::stable::Tensoraccessors backported intotensor_struct.hatbuild time —
sizes/strides/device/element_size/storage_offset, and the templatedmutable_data_ptr<T>/const_data_ptr<T>— gated on
TORCHADA_STABLE_ACCESSORSso a TU that does not force-include thebox header is untouched.
TORCH_BOXboxer (torchada_stable_box.h) synthesized over torch_musa'sfrom/toconversions, including spreadingstd::tuple/std::pairreturns across stack slots.
torch::stablefree functions torch_musa 2.9 lacks:contiguous,flatten,empty,from_blob.THO_DISPATCH_*shim (torch/headeronly/core/Dispatch.h) and atorch/csrc/stable/macros.hforward.cuda_runtime.h,cuda_bf16.h(+__nv_bfloat16{,2}alias),cuda_fp16.h,cuda_fp8.h, andcublas_v2.h→mublas.h.include_paths()auto-appends the compat include dir on MUSA,and the header backport runs lazily at extension-build time (never at import,
so a bare
import torchada/ inference run never mutates the torch headers).Testing
Added
TestStableCompatHeaders+TestStableHeaderBackporttotests/test_cuda_patching.py, covering the compat headers, theTORCH_BOXshim, and the accessor / inline-rewrite backport transforms (path helpers,
header content,
cuda_*→musa_*redirects, injectioninjected/already/
anchor-missingstatuses + idempotency, inline-rewrite skip rules).Full suite run in a MUSA container (MTT S5000,
torch_musa2.9.0 / musa 40305):Notes
torch_musa2.9's ABI specifically. The torch 2.11from_blobdeleter overload and the fully-defaulted / layout-enum
emptyforms areintentionally not shimmed — torch_musa 2.9's AOTI C-shim has no
deleter-capable
create_tensor_from_blob, so a dropped deleter would leak thebacking storage; kernels needing those forms stay out of the MUSA kernel set.
tensor_struct.hanchor isabsent, instead of silently skipping and failing later in the compiler.