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.
Summary
Add the minimal torchada compatibility needed by CUDA-compatible MUSA model paths and bump the package version from
0.1.83to0.1.84:PrivateUse1overrides for graph-safeaten::multinomial,aten::log, andaten::log_triton::mmandtriton::mmwithaddmm0.1.84Scope
This PR keeps torchada behavior narrow and avoids changing global platform semantics:
torch.cuda.is_available()torch.cuda.get_device_capability()torch.loadmap locations globallyThe intent is to preserve existing CUDA-facing behavior while adding the missing MUSA-safe operator and Inductor coverage required by downstream graph-enabled paths.
Testing
Result: passed.
Result on a MUSA-enabled runtime:
Runtime probe on the same MUSA-enabled runtime:
Additional SGLang-Omni integration smoke with the latest SGLang, SGLang-Omni, and torchada changes:
Qwen/Qwen3-ASR-1.7B/v1/audio/transcriptionswith a WAV inputQwen/Qwen3-TTS-12Hz-0.6B-Base/v1/audio/speechwith graph enabled and reduced capture rangeQwen/Qwen3-Omni-30B-A3B-FP8MiniMaxAI/MiniMax-Music3/v1/audio/speechmusic generationMUSA Triton heuristic regression coverage
The review follow-up adds focused unit coverage for
_patch_inductor_template_heuristicsusing representative keys observed in downstream inference images (triton::bmm,triton::mm, andtriton::mmwithaddmm).Covered behavior:
_HEURISTIC_CACHEonly when the registry changesMUSA_VISIBLE_DEVICESauthoritative when both MUSA and CUDA visibility variables are setFocused unit test:
PYTHONPATH=src python -m pytest -q tests/test_cuda_patching.py \ -k "VisibleDevicesEnv or InductorTemplateHeuristics"Result:
Image-level regression matrix with the PR source overlaid:
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-202608242.11.0.post1+musa5.2.0/50200A request-level Qwen3-0.6B vLLM compile and GSM8K follow-up was run on a MUSA GPU with the PR source overlaid, using the compatible image
registry.mthreads.com/mcconline/inference/vllm:v0.24.0-ph1-5.2.0-torch2.9.1.post1-20260805andCompilationMode.VLLM_COMPILE(mode=3). The log confirmed:A direct
/v1/completionsrequest returned readable text and the correct numerical answer. The official vLLM GSM8K endpoint evaluator then completed 200 questions with 5-shot prompting, temperature 0, and 256 maximum output tokens:All 200 requests returned HTTP 200; the server log contained no runtime exception, backend compiler failure, graph break, or eager fallback during evaluation.