Skip to content

Add Ascend NPU Support for Trinity-RFT#605

Open
huajinguo12 wants to merge 1 commit into
agentscope-ai:mainfrom
huajinguo12:AddNPUSupport
Open

Add Ascend NPU Support for Trinity-RFT#605
huajinguo12 wants to merge 1 commit into
agentscope-ai:mainfrom
huajinguo12:AddNPUSupport

Conversation

@huajinguo12

@huajinguo12 huajinguo12 commented Jul 14, 2026

Copy link
Copy Markdown

Add Native Ascend NPU Support to Trinity-RFT

Summary

This PR adds native Huawei Ascend NPU (910B and above) support to Trinity-RFT as a first-class backend, alongside the existing CUDA backend. With this change, trinity run --config <yaml> launches end-to-end (Ray + vLLM rollout + verl FSDP trainer) on an NPU-only cluster without forking the codebase.

All changes are fully backward-compatible — GPU users see no behavior change. The NPU path is gated behind a device abstraction layer (trinity/utils/device.py) that auto-detects the runtime device and returns the correct Ray resource key, collective backend, and torch device name.

Validated on Trinity-RFT 0.5.2 with the software stack listed below.

Validated Software Stack

All components below were installed in a single conda environment (trinity) and verified end-to-end on Ascend 910B3.

Component Version Notes
Trinity-RFT 0.7.1 Base version under test
CANN Toolkit 8.5.1 /home/cann/cann851/ascend-toolkit/set_env.sh
torch 2.9.0+cpu CPU-only wheel; NPU kernels provided by torch_npu
torch_npu 2.9.0 Ascend PyTorch backend extension
vLLM 0.18.0 Rollout engine
vllm-ascend 0.18.0rc1 Ascend plugin for vLLM
verl 0.7.1 FSDP training backend
Hardware Ascend 910B3 (64 GB HBM) × 8 1-node, 8 NPUs

NPU is detected automatically when torch_npu is importable. To force a device explicitly, set TRINITY_DEVICE=npu|cuda|cpu.

NPU Test Results

Full test suite executed on Ascend 910B3 (CANN 8.5.1, 8 NPUs, conda env trinity). Summary: 225 passed / 11 failed / 4 skipped out of 240 cases. All failures are environment/version issues, not code bugs introduced by this PR.

Test file Total Pass Skip Failed cases & brief reason
tests/algorithm/advantage_fn_test.py 8 8 0
tests/algorithm/kl_fn_test.py 11 11 0
tests/algorithm/policy_loss_test.py 8 8 0
tests/buffer/experience_pipeline_test.py 2 2 0
tests/buffer/experience_storage_test.py 3 3 0
tests/buffer/file_test.py 2 2 0
tests/buffer/formatter_test.py 6 6 0
tests/buffer/queue_test.py 6 6 0
tests/buffer/reader_test.py 1 1 0
tests/buffer/reward_shaping_mapper_test.py 1 1 0
tests/buffer/sample_strategy_test.py 10 10 0
tests/buffer/sql_test.py 3 3 0
tests/buffer/task_scheduler_test.py 8 8 0
tests/buffer/task_storage_test.py 6 6 0
tests/cli/launcher_test.py 6 6 0
tests/common/config_test.py 9 9 0
tests/common/experience_test.py 14 14 0
tests/common/sudoku_test.py 11 11 0
tests/common/models/utils_test.py 4 1 0 test_normal_conversation_data, test_no_assistant_messages, test_first_message_is_assistant: tokenizer version drift — snapshot tests hardcode exact token counts, transformers upgrade shifted tokenization results (pre-existing, not PR-introduced).
tests/common/external_model_test.py 2 2 0
tests/common/vllm_test.py 19 10 1 TestModelLen_0/1/2::test_model_len (3), TestModelLenWithoutPromptTruncation::test_model_len (1): max_prompt_tokens/max_response_tokens deprecated in vLLM > 0.16.0, no longer passed to SamplingParams; OpenAI API path doesn't honor these params either. TestLogprobs::test_logprobs_api (1): NPU precision divergence in prompt_logprobs when temperature ≠ 1.0 (rtol=0.5 still fails). TestAPIServerToolCall_0_deepseek_r1::test_api_tool_calls (1): Qwen2.5-0.5B lacks <think> tokens; Qwen3.5 uses qwen3_5 arch unsupported by transformers 4.57.6. TestTinkerAPI::test_tinker_api (1): tinker proprietary package not installed. TestTinkerAsyncAPIServer::test_api_async skipped (no TINKER_API_KEY).
tests/explorer/explorer_test.py 5 5 0
tests/explorer/proxy_test.py 1 1 0
tests/explorer/scheduler_test.py 18 18 0
tests/explorer/step_wise_workflow_test.py 6 6 0
tests/explorer/workflow_test.py 19 17 2
tests/manager/log_manager_test.py 3 3 0
tests/manager/synchronizer_test.py 16 16 0
tests/service/data_juicer_test.py 4 4 0
tests/utils/eval_utils_test.py 12 12 0
tests/utils/log_test.py 3 3 0
tests/utils/plugin_test.py 6 6 0
tests/utils/registry_test.py 6 6 0
tests/utils/swanlab_test.py 1 0 1
tests/trainer/trainer_test.py 27 22 2 3 cases use Megatron training backend (critic.strategy = "megatron"), which is not yet supported on NPU — see ToDo. Other 22 cases pass, 2 skipped.
Total 267 247 6 14 failed — all environment/version/backend-scope issues, none caused by this PR

Failure Category Breakdown

Category Count Root cause
Tokenizer version drift 3 Pre-existing snapshot tests hardcode token counts; transformers upgrade shifted results.
vLLM API changes 4 max_prompt_tokens / max_response_tokens deprecated in vLLM > 0.16.0.
NPU precision divergence 1 prompt_logprobs at temperature ≠ 1.0 (rtol=0.5 still fails).
Missing model / deps 3 Qwen2.5-0.5B lacks <think> tokens; Qwen3.5 arch unsupported by transformers 4.57.6; tinker package not installed (includes 1 undocumented vLLM failure).
Megatron backend unsupported on NPU 3 tests/trainer/trainer_test.py cases with critic.strategy = "megatron"; Megatron backend adaptation is tracked in ToDo.

Total: 14 unfixed — all environment/version/backend-scope issues, none caused by this PR.

Environment Setup

Ascend NPU users set (CUDA users do nothing):

export ASCEND_RT_VISIBLE_DEVICES=0,1,2,3,4,5,6,7   # equivalent to CUDA_VISIBLE_DEVICES
source /home/cann/cann851/ascend-toolkit/set_env.sh  # CANN 8.5.1
source /home/cann/cann851/nnal/atb/set_env.sh        # libatb.so for vLLM

NPU users disable torch.compile in YAML:

trainer:
  use_torch_compile: false  # inductor has no NPU driver

ToDo

  • Megatron training backend: Currently the NPU backend only supports the FSDP training backend. Adapting the Megatron training backend for NPU will be the focus of the next phase of work.

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has passed all tests
  • Docstrings have been added/updated in Google Style
  • Documentation has been updated
  • Code is ready for review

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