feat(ascend): add deterministic collective Ascend C kernel - #355
Open
zhangj1an wants to merge 2 commits into
Open
feat(ascend): add deterministic collective Ascend C kernel#355zhangj1an wants to merge 2 commits into
zhangj1an wants to merge 2 commits into
Conversation
- csrc/ascend/distributed/deterministic_collective_ascend.asc: Ascend C
fixed-tree reduction kernel for the TP-invariant deterministic
collective (TP 1/2/4/8, same balanced tree as the CUDA
deterministic_collective.cu); every tree level rounds once in the
input dtype with round-to-nearest-even (fp16/bf16 partials are added
in fp32 and cast back with CAST_RINT, bitwise-identical to the CUDA
ordered_add semantics, verified against torch on tie-heavy data);
host state: staging + dtype dispatch
- rl_engine/distributed/collectives.py: DeterministicCollective gains an
Ascend NPU backend (HCCL all_gather of the staged inputs + local
fixed-tree kernel); CUDA IPC path unchanged
- pybind consolidated in csrc/ascend/ops_npu.asc (single PYBIND11_MODULE;
batch_invariant_logp_ascend.asc only drops its module block)
- setup.py: restores the Ascend extension build (bisheng + **/*.asc glob)
- tests/distributed/test_deterministic_{all_reduce,all_gather,reduce_scatter}_ascend.py:
8-rank cross-TP bitwise tests mirroring the CUDA contracts
- rl_engine/_C_npu.pyi: collective type stubs
zhangj1an
requested review from
Flink-ddd,
KJLdefeated,
bitborne and
inaniloquentee
as code owners
August 28, 2026 16:03
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UrCymbdZgpok6er4eCPmAH
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.
Latest Status [29 Aug 2026]
My 8x910C breaks on
libccl_kernel.so, so I cannot test this kernel across ranks. I do not have root access to that machine to re-build pytorch npu. It would be great if the community can help me verify this PR works e2e. Thanks in advance!Summary
Port of the CUDA deterministic collective (PR #312) to Ascend NPU.
_C_npu.deterministic_collective_reduce): same balanced fixed tree for TP 1/2/4/8 (ws=8: ((t0+t1)+(t2+t3))+((t4+t5)+(t6+t7))). Every level rounds once in the input dtype with round-to-nearest-even, matching CUDAordered_add(add.rn/__hadd), so results are bitwise identical across ranks, TP configs, and CUDA/Ascend.Addon this CANN, so each level adds fp32-exact partials and casts back withCAST_RINT(IEEE RN, verified bitwise against torch including tie lanes).[world_size, N]and runs the fixed-tree kernel locally. Reduction order never depends on the HCCL algorithm.DeterministicCollectivegains an NPU backend with the same public surface (all_reduce/all_gather/reduce_scatter,out=aliasing, shape validation, metadata exchange). CUDA IPC path unchanged.csrc/ascend/ops_npu.ascconsolidates the singlePYBIND11_MODULE(one per.ascfile, else Bisheng hits duplicatePyInit__C_npu— same pattern as PR [WS1][kernels] Deterministic attention Ascend C kernel #320);setup.pyrestores the Ascend extension build, which the currenttestbranch had lost.Files
csrc/ascend/distributed/deterministic_collective_ascend.asccsrc/ascend/ops_npu.asc_C_npupybind registration.csrc/ascend/batch_invariant_logp_ascend.ascPYBIND11_MODULEonly; kernel logic unchanged.rl_engine/distributed/collectives.pyrl_engine/_C_npu.pyitests/distributed/test_deterministic_{all_reduce,all_gather,reduce_scatter}_ascend.pysetup.pyTest
Environment: Ascend 910B, CANN 8.5.1 (Bisheng), torch 2.7.1 + torch_npu 2.7.1.
tests/test_batch_invariant_logp.pyregressionNotes
dist.all_gatheron plain HCCL (no RL-Kernel code) aborts inlibccl_kernel.so(RunAicpuKfcResInitV2, aicpu exception). The 8-rank tests are the first thing to run once HCCL is healthy.DeterministicCollective.ruff checkpasses.