Add graph-safe ops and Inductor heuristics - #106
Conversation
a2b22d8 to
39f0101
Compare
39f0101 to
dde6c15
Compare
e58ce73 to
2751120
Compare
2751120 to
a34ab87
Compare
|
|
||
| } // namespace | ||
|
|
||
| at::Tensor multinomial_musa_impl( |
There was a problem hiding this comment.
This duplicates a full operator implementation at the MUSA kernel layer. ATen schemas/signatures, generator/RNG semantics, dtype handling, and edge-case behavior can change across torch versions, so this can keep compiling while silently diverging from upstream. Could we first reuse the torch_musa/ATen implementation and keep only a thin compatibility shim, or introduce an explicit versioned adapter? If a custom override is required, please add differential tests across the target torch versions (generator, replacement, invalid/NaN/negative inputs, empty and boundary shapes).
|
|
||
| @patch_function | ||
| @requires_import("torch._inductor.template_heuristics.registry") | ||
| def _patch_inductor_template_heuristics(): |
There was a problem hiding this comment.
This copies the current CUDA heuristic registry only once during import. That will miss lazy/future registrations, and it relies on private registry/cache names and key shape. Also, copying a CUDA heuristic class under a musa key does not establish that its lowering/template/autotune path is MUSA-compatible. Could we move this compatibility to the registration/lookup boundary (or use an explicit versioned allowlist) and add a real torch.compile + Inductor/Triton MUSA smoke after lazy imports? Unsupported templates/torch versions should fail closed or fall back rather than silently appearing supported.
There was a problem hiding this comment.
Current registration process is:
import torch._inductor.template_heuristics.registry as registry
----register all torch native "triton::" heuristics from `torch/_inductor/template_heuristics/triton.py`
......
from torch._inductor.codegen.common import init_backend_registration
init_backend_registration()
----lazy register all musa heuristics from `torch_musa/_inductor/template_heuristics.py`
When we need to fully import custom heuristics, it is recommended to modify heuristic_registry after calling init_backend_registration().
a5fd652 to
86b7a04
Compare
86b7a04 to
fbcff52
Compare
Summary
Add the graph-safe MUSA compatibility required by CUDA-facing inference paths and bump torchada from
0.1.83to0.1.84:PrivateUse1overrides foraten::multinomial,aten::log, andaten::log_on affected torch_musa releasesMUSA_VISIBLE_DEVICEStoCUDA_VISIBLE_DEVICESwhen both are presenttorch_musa version boundary
The TorchAda graph-safe compatibility is temporary and is limited to torch_musa versions before
2.11.0.post2:The existing
_TORCH_MUSA_ACCELERATOR_FIX_VERSION = "2.11.0.post2"is reused for this decision. The version is read from the existingtorch.musa.__version__surface; no extra package-version helper or unconditionalimport torch_musais added just for version detection.On
torch_musa >= 2.11.0.post2:load_cpp_ops()returns before building/loading TorchAda's C++ override extensiontorch_musa/ATen ownslog,log_, andmultinomialdispatch directlymusa_ops.muThe currently published vLLM-MUSA image is still based on
torch_musa 2.11.0.post1+musa5.2.0, so it remains on the compatibility side of this boundary.Scope
This PR does not change global CUDA platform semantics:
torch.cuda.is_available()torch.cuda.get_device_capability()torch.loadmap locationsTesting
Focused validation was run with the PR source overlaid in the MUSA-enabled vLLM-MUSA image:
PYTHONPATH=src python -m pytest -q tests/test_cuda_patching.py \ -k "VisibleDevicesEnv or InductorTemplateHeuristics or TestAcceleratorModuleWrapper or test_cpp_ops_loaded_on_musa"Operator correctness and graph replay tests on the same post1 MUSA runtime:
The version-boundary tests cover the existing post2 accelerator gate, post2 native Inductor registration behavior, local-version suffixes such as
+musa5.2.0, and the post2+ no-C++-override behavior.git diff --checkand Python syntax compilation also pass.Downstream image validation
registry.mthreads.com/mcconline/inference/sglang:v0.5.12.post1-ph1-4.3.5-torch2.9.0-202608192.9.0/40305registry.mthreads.com/mcconline/inference/vllm:v0.24.0-ph1-5.2.0-torch2.11.0.post1-202608272.11.0.post1+musa5.2.0/50200A direct runtime probe in the latest image confirmed:
Request-level vLLM compile smoke
A request-level Qwen3-0.6B vLLM compile and GSM8K follow-up was run on MUSA with
CompilationMode.VLLM_COMPILE(mode=3) using the compatible imageregistry.mthreads.com/mcconline/inference/vllm:v0.24.0-ph1-5.2.0-torch2.9.1.post1-20260805.The service completed compilation, graph capture, a direct completion request, and the official 200-question GSM8K evaluator:
The server log contained no runtime exception, backend compiler failure, graph break, or eager fallback during evaluation.
Limitations
torch_musa 2.11.0.post2wheel/tag is available yet; post2 behavior is covered by version-boundary tests and the code path is fail-safe for unknown versions.20260819and20260824Qwen3 startup attempts hit a pre-existing vLLM-MUSAis_neoxsignature mismatch, so request-level evaluation used the compatible20260805image.