Skip to content

Add minimal Moore Threads MUSA GPU support via torchada - #1809

Open
Destinykami wants to merge 1 commit into
modelscope:mainfrom
Destinykami:musa-adapter
Open

Destinykami wants to merge 1 commit into
modelscope:mainfrom
Destinykami:musa-adapter

Conversation

@Destinykami

Copy link
Copy Markdown

Summary

Add a minimal integration with torchada to enable DiffSynth-Studio to run supported CUDA-oriented code paths on Moore Threads MUSA GPUs.

The adapter is initialized once at the package entry point, avoiding repeated imports or device-specific changes across models, pipelines, and examples.

Changes

Conditional adapter initialization

  • Detect a MUSA-enabled PyTorch build using getattr(torch.version, "musa", None).
  • Import torchada before initializing diffsynth.core, allowing its CUDA API redirection to take effect before device detection and other initialization.
  • Leave non-MUSA environments unchanged; torchada is not added as a mandatory dependency.

Installation and usage documentation

Add MUSA instructions to the English and Chinese Setup.md and GPU_support.md guides, covering:

  • Driver, MUSA SDK, and torch_musa prerequisites.
  • Installing torchada and DiffSynth-Studio from the official repository.
  • Setting TORCHADA_FORCE_CUDA_AVAILABLE=1 before launch for code paths that rely on torch.cuda.is_available(), including DiffSynth-Studio's automatic device detection.
  • Optional MUSA FlashAttention-3, MATE, and MATE-MUBIN installation, tested versions, and dependency compatibility considerations.
  • The requirement for MUSA-compatible implementations of CUDA-only third-party extensions.

Scope

This PR is limited to adapter initialization and documentation.

It does not introduce model-specific patches, attention backend fixes, distributed checkpoint fixes, training optimizations, or changes to the project's dependency requirements. It also does not force environment variables or override attention backend selection in library code.

Validation

Conditional import tests

  • Non-MUSA builds do not import torchada.
  • MUSA builds import torchada before diffsynth.core.
  • Missing torchada on a MUSA build produces an explicit import error.
  • Python syntax and git diff --check pass.

MUSA hardware smoke test

Tested the PR source in an isolated directory on one Moore Threads MTT S5000 GPU, using:

  • PyTorch: 2.7.1.post1
  • torch_musa: 2.7.1.post1
  • torchada: 0.1.102
  • TORCHADA_FORCE_CUDA_AVAILABLE=1

The test script did not manually import torchada; it was loaded automatically by import diffsynth.

Verified:

  • The PR source was loaded rather than the existing checkout.
  • CUDA availability and framework device detection worked with the documented environment variable.
  • Tensors created with device="cuda" were allocated on MUSA.
  • Matrix multiplication, scalar loss computation, and backward propagation succeeded.
  • DiffSynth-Studio's attention_forward completed BF16 forward and backward passes with finite outputs and Q/K/V gradients, using input shape [1, 4, 128, 64].
  • The default registered backend, flash_attention_2, was used without a backend override.

Validation Limitations

  • Hardware validation covers a single-GPU smoke test, not full-model inference or multi-GPU training.
  • The hardware test used torchada 0.1.102; the documented installation recommendation is >=0.1.106.
  • MUSA FlashAttention-3 was not registered in the smoke-test environment. This PR does not address its existing import compatibility issue.
  • Compatibility with individual models and third-party extensions depends on their MUSA support.

Conditionally import torchada when a MUSA-enabled PyTorch build is detected,
before initializing diffsynth.core. This enables supported CUDA API calls
to be redirected to MUSA without duplicating adapter imports across models
or examples.

Document MUSA setup and usage in the English and Chinese guides, including:
- torch_musa prerequisites and torchada installation
- Installation from the official DiffSynth-Studio repository
- TORCHADA_FORCE_CUDA_AVAILABLE for CUDA-based device detection
- Optional MUSA FlashAttention-3, MATE, and MATE-MUBIN dependencies
- Version compatibility and third-party CUDA extension limitations
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.

1 participant