Repository navigation
Conversation
VenusTZZ
requested review from
hwchen2017,
loadams,
tjruwase and
tohtana
as code owners
October 20, 2026 13:26
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
VenusTZZ
marked this pull request as draft
October 20, 2026 13:27
VenusTZZ
force-pushed
the
npu-triton-support
branch
from
October 20, 2026 13:30
7709829 to
5cc7afe
Compare
VenusTZZ
marked this pull request as ready for review
October 20, 2026 13:35
There was a problem hiding this comment.
🟡 Changes recommended
CPU eligibility regressions and the missing advertised permutation-dispatch update remain unresolved.
3 open issues
What changed in this PR
Generalizes DeepSpeed’s Triton guards and device contexts to support non-CUDA accelerators with an active Triton backend.
Changes:
- Adds shared accelerator-tensor checks and current-device switching.
- Enables NPU Triton detection and broadens runtime eligibility.
- Adapts kernel and AutoEP tests for multiple accelerator types.
| File | Description |
|---|---|
| tests/unit/v1/runtime/test_chunked_cross_entropy.py | Broadens backend coverage and adapts rejection checks. |
| tests/unit/v1/ops/triton_ops/test_swiglu_triton.py | Generalizes availability and device-context tests. |
| tests/unit/v1/ops/triton_ops/test_group_gemm_triton.py | Uses accelerator capability checks. |
| tests/unit/v1/ops/triton_ops/test_fused_rotary_pos_emb.py | Generalizes device tests and layout comparisons. |
| tests/unit/v1/ops/triton_ops/test_fused_rms_norm.py | Updates availability, errors, and layout checks. |
| tests/unit/v1/ops/triton_ops/test_autoep_fused_token_ops.py | Broadens eligibility and updates error assertions. |
| tests/unit/v1/moe/test_autoep_unit.py | Generalizes device cases and protocol doubles. |
| tests/unit/v1/moe/test_autoep_permute_rows.py | Enables non-CUDA accelerator cases. |
| tests/unit/v1/moe/test_autoep_grad_parity.py | Broadens async split-plan test eligibility. |
| deepspeed/runtime/chunked_cross_entropy.py | Uses accelerator-aware backend selection. |
| deepspeed/ops/triton_ops/swiglu_triton.py | Uses shared current-device contexts. |
| deepspeed/ops/triton_ops/fused_rotary_pos_emb.py | Generalizes tensor guards and launch contexts. |
| deepspeed/ops/triton_ops/fused_rms_norm.py | Uses the shared tensor guard. |
| deepspeed/ops/triton_ops/autoep_fused_token_ops.py | Generalizes guards and device errors. |
| deepspeed/ops/triton_ops/_triton.py | Adds tensor eligibility and device-context helpers. |
| deepspeed/module_inject/auto_ep_layer.py | Broadens async split-plan tensor eligibility. |
| accelerator/npu_accelerator.py | Delegates Triton support to the shared probe. |
Review effort: Balanced
Signed-off-by: Zizhao Tang <1601677496@qq.com>
VenusTZZ
force-pushed
the
npu-triton-support
branch
from
October 21, 2026 01:31
5cc7afe to
9488bd6
Compare
Contributor
|
Very significant! |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Background
DeepSpeed has already embraced Triton for a growing set of fused kernels — the recently developed AutoEP (Automatic Expert Parallel) features, for example, rely on Triton kernels for token permutation and row weighting, alongside the grouped GEMM (General Matrix Multiply), SwiGLU, fused RMSNorm, and fused RoPE paths. As with Triton itself, that integration has so far been CUDA-first: the guards and tests naturally reference CUDA, the reference platform. In the meantime, the Triton ecosystem has expanded well beyond CUDA — several hardware platforms now ship their own Triton backends, for example the triton-ascend backend for Ascend NPUs — and a backend that reports itself through the standard driver probe can run the same kernels. This PR carries DeepSpeed's Triton integration toward accelerator-agnosticism: the device guards, launch contexts, and tests stop naming a specific device, and the Triton gate follows the shared driver probe, so every platform can benefit wherever its backend reports support. CUDA remains the primary, fully supported platform, and every default path behaves exactly as before.
Summary
Removes the CUDA hard-coding from the
triton_opsdevice guards, launch contexts, and tests, and routes the Triton gate through the shared Triton driver probe so the fused kernels can run on any accelerator that reports a working Triton backend (CUDA first, others — e.g. NPU via triton-ascend — where their backend is installed). With no Triton backend installed,is_triton_available()isFalseand every gate stays closed — no behavior changes on any platform; this is a guard refactor, not a kernel change.Problem
Hard-coded CUDA assumptions in
deepspeed/ops/triton_opsfused_rms_norm.py,fused_rotary_pos_emb.py, andautoep_fused_token_ops.pyreject any tensor withdevice.type != "cuda"("runs CUDA kernels"), even though the kernels are written in Triton and the runtime device is whatever the accelerator reports.torch.cuda.device.swiglu_triton.py(packed forward/backward) andfused_rotary_pos_emb.pyswitch devices withtorch.cuda.device(x.device), which breaks on CPU-built torch and on non-CUDA accelerators.NPU_Accelerator.is_triton_supported()returnsFalseunconditionally, so all Triton paths fall back on NPU even when a working Triton backend (triton-ascend) is installed.device_name() == "cuda"; bfloat16 capability is queried viatorch.cuda.get_device_capability()(crashes on CPU-built torch); guard-message assertions expect the "CUDA kernels" wording; two-device stream regressions usetorch.cuda.devicecontexts; the sm-capability auto-selection test has no device guard at all.Fix
npu_accelerator.py:is_triton_supported()delegates tois_triton_available()— the same shared probe as the other accelerators, which reportsTrueonly when a Triton backend's driver is active. Without triton-ascend the gate stays closed, preserving today's fallbacks._triton.py: addsis_accelerator_tensor(), delegating to the accelerator'son_accelerator(). This is the single place in the package that lazily importsget_accelerator, keeping the module import-light.fused_rms_norm.py/fused_rotary_pos_emb.py/autoep_fused_token_ops.py: device guards use the helper; error messages say "runs Triton kernels"; the "same CUDA device" message becomes "same device".swiglu_triton.py/fused_rotary_pos_emb.py:torch.cuda.device(...)launch contexts become device-agnostictorch.device(...)contexts.ep_kernels.py:permute_rows_supportedaccepts any accelerator tensor; docstrings say "accelerator tensor" instead of "CUDA tensor".tests/unit/v1/ops/triton_ops/): module-level gates useis_triton_supported(); bfloat16 checks useis_bf16_supported(); guard-message assertions expect the Triton wording; two-device contexts usetorch.device(accelerator.device_name(...)); the sm-capability auto-selection test is marked CUDA-only.Compliance with the repo AI-contribution policy (AGENTS.md)
is_triton_supported+ NPU andtriton+ascend— no existing PR or issue covers opening the NPU Triton gates or device-agnosticizing thetriton_opsguards. The nearest PR, AutoEP: generate large NPU permutation indices on device #8822 (AutoEP NPU permutation indices), is closed and unmerged and touches a different path.Test plan
The affected suites run on both platforms against branch
npu-triton-support(CUDA: A100; NPU: Ascend 910B4, triton-ascend 3.6.0).CUDA (A100) — the primary platform
triton_ops(305): all pass — identical to master.test_chunked_cross_entropy.py(50): all pass — including the device-agnostic Triton-backend change.Environment: 2 × NVIDIA A100-SXM4-80GB (80 GB each), driver 580.126.16, CUDA 12.4, NCCL 2.21.5, PyTorch 2.14.1+cu126, Triton 3.8.0, transformers 5.20.2, Python 3.10.22.
NPU (Ascend 910B4, triton-ascend 3.6.0)
triton_ops(305): 292 pass / 11 fail / 2 skip — the 11 failures are triton-ascend backend issues that have been reported upstream and are being fixed.test_chunked_cross_entropy.py(50): 47 pass / 3 skip (the skips are CUDA-only memory-peak, fork-safety, and device-assert subprocess tests). The Triton backend is now exercised on the accelerator instead of only CUDA.The
torch.device(...)launch-context replacement is exercised by the NPU run of the packed SwiGLU and fused RoPE paths.Hardware: Ascend 910B4 (single device for the suites; the async split-plan parity test additionally ran multi-card), torch 2.10.0+cpu, torch_npu 2.10.0.post7, CANN 8.5.1, triton-ascend 3.6.0.
Pre-commit
pre-commit run --files <the 12 changed files>— all checks passed (yapf, flake8, check-torchdist, check-torchcuda, check-license, codespell).