Repository navigation
Open
Description
Motivation
Ascend NPUs (昇腾) — manufactured by Huawei — are the dominant AI accelerator in China's data centers, especially for LLM fine-tuning and inference. With the growing demand for domestic AI infrastructure, many users run unsloth as their primary LoRA fine-tuning framework but are blocked by the lack of NPU support.
We'd like to contribute an Ascend NPU backend. Initial work has already landed in two PRs:
- fix(chat_templates): remove CUDA hardcoded device from stopping criteria #10684 — Removed a CUDA-hardcoded default device in
chat_templates.py(stopping criteria) - feat(device_type): add Ascend NPU device detection #10686 — Extended
device_type.pyto detect NPU viatorch.npu.is_available()and report proper device stats
Scope of the full NPU backend
Complete NPU support would require changes in several layers:
- Device abstraction (
device_type.py) — make_DEVICE_MODULE,clean_gpu_cache(),get_current_device()NPU-aware (partially done in feat(device_type): add Ascend NPU device detection #10686) - Kernel compatibility — verify and potentially shim the custom CUDA kernels (RMS layernorm, attention dispatch, cross-entropy, MoE, FP8 quantization) on Ascend hardware. Some may work through torch_npu's existing op coverage; others may need device-agnostic fallback paths.
- Model loading — ensure
.to()/ device inference works correctly in llama.py, gemma.py, sentence_transformer.py, etc. for non-CUDA devices.
We estimate the kernel layer is the main engineering effort and would submit it as incremental, reviewable PRs.
Questions for the community
- Is this direction welcome? Would the maintainers accept contributed NPU backend support, or are there concerns about the maintenance burden?
- Preferred approach? Case-by-case shims as device-agnostic
isinstancechecks, or a more structured backend plugin system? - Any existing NPU/Ascend-related work we should be aware of before starting the full port?
- Test expectations — would we need CI integration, or is manual NPU-probe verification acceptable for initial contributions?
Happy to split the work into small, reviewable chunks and handle the ongoing maintenance for the Ascend backend.
Metadata
Metadata
Assignees
Labels
No labels
Activity
SunXT-0719 commentedon Oct 31, 2026
Hi @li-lizhe @danielhanchen, I’m interested in contributing to the Ascend NPU support discussed in this RFC. What is the preferred process for proposing a new backend feature: continue the design discussion here, or open a focused draft PR linked to this issue? In particular, should initial platform compatibility work target Core or Zoo, and what hardware-test evidence or CI coverage would you require? I’d appreciate guidance on the preferred scope for a first contribution.
SunXT-0719 commentedon Oct 31, 2026
Following up on the contribution-process question: I have opened a focused Zoo draft, unslothai/unsloth-zoo#2326, for redundant activation/result casts in the generated PEFT Linear forward under NPU BF16 autocast. It retains FP32 LoRA weight/gradient paths and limits the optimization to a tested plain-Linear configuration. The PR includes reproducible CPU routing/registration tests and opt-in actual NPU output/all-gradient parity tests. This is separate from the eager bootstrap draft #16279.
Feedback on the proposed scope and preferred NPU hardware-test/CI process would be appreciated. I will keep technical follow-up in the new PR.
The upstream Tests/Lint/Wheel/MLX workflows currently report
action_required; a maintainer may need to approve the fork's workflow runs before CI can execute.SunXT-0719 commentedon Oct 31, 2026
Hi @li-lizhe @danielhanchen, I would like to propose PTO-based kernels as an optional Ascend backend feature and discuss the integration approach here before opening kernel PRs.
We have implemented an experimental Unsloth Ascend backend using PTO/PTO-ISA kernels, including SwiGLU forward/backward, RMSNorm, RoPE and attention paths, with PyTorch/autograd integration. We have exercised it in LoRA SFT and GRPO generation/training. The implementation also uses decoder graph replay and host/dispatch optimizations, so the figures below describe the combined backend, not the speedup of any individual PTO operator.
Our strongest qualified representative result so far is 2.34x steady full-optimizer-step throughput for Qwen3-1.7B GRPO against a same-precision native torch_npu/HF fused-SDPA reference. To distinguish that earlier result from the more recent upstream-pinned SFT work:
Both comparisons used a predeclared fresh A1/B1/B2/A2 order, 16 updates per process, discarding the first 4 and taking the median of the remaining 12, with no profiler, checkpoint writes or compilation in timed steps. The reported factors are geometric means of the two order-specific ratios. The GRPO raw ratios were 2.372x/2.311x. Sampling trajectories differed: native generated 2,176 tokens versus 2,289 for PTO over each 16-step run. A predeclared prompt-wise work-sensitivity calculation gave 2.26x, but this is not an identical-token benchmark or a universal cost bound.
The SFT comparison retained upstream LoRA/CE/Trainer behavior at Core
caf0a3bb7a9429c4390c4c42d8ef257f95437b54/ Zooe2bef95e9077e5707919fbc057f1e51f3b7e565a, with shared Ascend compatibility support. It has not reproduced 2x against that pinned baseline; graph preparation took about 59 seconds and dominates the short cold run. Neither result is a claim about unmodified current-main Unsloth, all Ascend models, or a single operator.For stability, we completed a representative SFT 512-update run and an independent 256->512 resume with exact actual sample/token/target/loss and 770 final-state tensor comparisons. For the earlier GRPO configuration, PTO graph and same-arithmetic PTO eager references each completed 64 updates and their own 32->64 resumes; actual tokens/rewards/loss and 898 state tensors matched. These exactness claims concern the stated reference/resume comparisons, not identical native-vs-PTO GRPO sampling. Held-out quality checks passed their predefined retention thresholds; GRPO accuracy was 90/128 before and 89/128 after, so we do not claim improved quality or asymptotic convergence. The native GRPO performance reference has short-run/recovery validation, not a full native 64-update quality comparison.
Hardware/environment: single Ascend910_9362, Linux aarch64, Torch 2.6 / torch_npu 2.6.0.post3, CANN 8.5. These are local fixed-environment results, not multi-day, multi-device or independently reproduced cross-machine qualifications.
Before preparing the first kernel contribution, could you advise:
The existing bootstrap draft #16279 and cast-removal draft unslothai/unsloth-zoo#2326 are separate compatibility/optimization changes; neither submits the PTO kernel backend. We will wait for feedback on this RFC before submitting PTO kernel PRs.
li-lizhe commentedon Oct 31, 2026
Thanks for picking this up, @SunXT-0719 — good to see movement on it.
On process, this is what has worked for us so far: six small PRs, each removing one CUDA-only assumption and each with a test that fails before / passes after — #10686, #10684, #10843, #11461, #12284, #13438, all merged or closed now. One mechanism per PR, diff small enough to review in one sitting, and a plain statement of what was and wasn't run on real hardware. That shape has been easy for reviewers to take.
On scope — Core vs Zoo, and whether an optional kernel backend belongs in the project at all — that is a decision for the maintainers (@danielhanchen). I've only contributed device-agnostic fixes, so my view on the kernel direction wouldn't carry much weight next to theirs.
Happy to review or test Ascend-side changes as they come up.
SunXT-0719 commentedon Nov 12, 2026
Hi @danielhanchen, a brief follow-up on the optional PTO backend proposal above. Thanks @li-lizhe for the guidance on keeping contributions small and for offering Ascend-side review/testing.
Before we prepare a kernel PR, would an optional PTO-based Ascend backend be welcome? If so, would you prefer the integration in Core, Zoo, or an external backend package? If another maintainer owns this area, could you point us to the appropriate reviewer?
We can keep the first contribution focused on SwiGLU forward/backward, with source build instructions, PyTorch/autograd integration, explicit supported configurations, native fallback and real-NPU validation. We will hold off on PTO kernel PRs until we have feedback on the direction. Thank you!