Skip to content

fix(musa): support float64 in-place log - #113

Merged
yeahdongcn merged 9 commits into
MooreThreads:mainfrom
yingzhou-bjtu:fix/musa-float64-log-inplace
Sep 18, 2026
Merged

yeahdongcn merged 9 commits into
MooreThreads:mainfrom
yingzhou-bjtu:fix/musa-float64-log-inplace

Conversation

@yingzhou-bjtu

@yingzhou-bjtu yingzhou-bjtu commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Why this change

On the validated MUSA runtime, Tensor.log_() still rejects float64
in-place execution, even though the equivalent out-of-place torch.log()
operation works. This matters for CUDA-oriented code that uses log_() and is
otherwise expected to run unchanged on MUSA.

What changed

This patch adds a small compatibility handler to torchada's existing patch
registry. For MUSA float64 tensors on torch_musa < 2.11.0.post2, it computes
the result with the supported out-of-place operation and copies it back. That
keeps the in-place contract while leaving the native path untouched on newer
torch_musa releases.

The patch is deliberately limited to this case. CPU, CUDA, other dtypes, and
the public API are unchanged. The version check reuses torchada's existing
semantic-version helper, and the version-gated behavior is documented in both
README files.

The unit tests now cover both the version gate and the in-place fallback path
in tests/test_cuda_patching.py under TestTensorLogPatch. Those tests are
CPU-runnable.

Validation

CPU unit tests for _patch_tensor_log_():

PYTHONPATH=src python3 -m pytest -q tests/test_cuda_patching.py \
  -k 'float64_log or torch_musa_version_boundary' --tb=short

Result: 15 passed, 226 deselected in 0.21s.

That subset covers:

  • test_torch_musa_version_boundary
  • test_float64_log_patch_respects_torch_musa_version
  • test_float64_log_patch_uses_out_of_place_copy_on_musa

The focused float64 log tests alone:

PYTHONPATH=src python3 -m pytest -q tests/test_cuda_patching.py \
  -k float64_log --tb=short

Result: 2 passed, 239 deselected in 0.04s.

py_compile and git diff --check pass for the changed source.

MUSA tests on torch_musa 2.11.0.post1+musa5.2.0:

python3 -m pytest -q tests/test_log.py --tb=short

Result: 3 passed in 3.22s.

Compatibility

The change is MUSA-specific and keeps the existing CUDA path intact. It is
enabled only for torch_musa versions below 2.11.0.post2; newer versions use
their native implementation.

Related SGLang-Omni integration:
sgl-project/sglang-omni#2167

Related shared Graph execution-mode change:
sgl-project/sglang-omni#2168

Comment thread src/torchada/_patch.py
Comment thread src/torchada/_patch.py
Add a CPU-runnable unit test for the MUSA float64 Tensor.log_()
compatibility patch so the version gate and in-place fallback path
are both covered without requiring a MUSA device.
Replace remaining 0.1.86 version strings, including the historical
benchmark snapshot, so the package version is consistent across the tree.
@yingzhou-bjtu
yingzhou-bjtu force-pushed the fix/musa-float64-log-inplace branch from 99062f6 to dfc9271 Compare September 18, 2026 03:03
The float64 log_ backport already requires torch_musa. Read
torch.musa.__version__ instead of wrapping the known attributes in
getattr.
Read torch.musa.__version__ directly for the float64 log_ gate, document
that 2.11.0.post2 also owns the native log_ fix, and restore the dated
benchmark snapshot to 0.1.86.
Sign the in-place log_ workaround comment and move the CPU coverage out
of TestAcceleratorModuleWrapper into TestTensorLogPatch.
@yeahdongcn
yeahdongcn merged commit ba77965 into MooreThreads:main Sep 18, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants