Add Ascend NPU Support for Trinity-RFT#605
Open
huajinguo12 wants to merge 1 commit into
Open
Conversation
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.
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./home/cann/cann851/ascend-toolkit/set_env.shtorch_npuNPU 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.tests/algorithm/advantage_fn_test.pytests/algorithm/kl_fn_test.pytests/algorithm/policy_loss_test.pytests/buffer/experience_pipeline_test.pytests/buffer/experience_storage_test.pytests/buffer/file_test.pytests/buffer/formatter_test.pytests/buffer/queue_test.pytests/buffer/reader_test.pytests/buffer/reward_shaping_mapper_test.pytests/buffer/sample_strategy_test.pytests/buffer/sql_test.pytests/buffer/task_scheduler_test.pytests/buffer/task_storage_test.pytests/cli/launcher_test.pytests/common/config_test.pytests/common/experience_test.pytests/common/sudoku_test.pytests/common/models/utils_test.pytest_normal_conversation_data,test_no_assistant_messages,test_first_message_is_assistant: tokenizer version drift — snapshot tests hardcode exact token counts,transformersupgrade shifted tokenization results (pre-existing, not PR-introduced).tests/common/external_model_test.pytests/common/vllm_test.pyTestModelLen_0/1/2::test_model_len(3),TestModelLenWithoutPromptTruncation::test_model_len(1):max_prompt_tokens/max_response_tokensdeprecated in vLLM > 0.16.0, no longer passed toSamplingParams; OpenAI API path doesn't honor these params either.TestLogprobs::test_logprobs_api(1): NPU precision divergence inprompt_logprobswhen 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 usesqwen3_5arch unsupported by transformers 4.57.6.TestTinkerAPI::test_tinker_api(1):tinkerproprietary package not installed.TestTinkerAsyncAPIServer::test_api_asyncskipped (noTINKER_API_KEY).tests/explorer/explorer_test.pytests/explorer/proxy_test.pytests/explorer/scheduler_test.pytests/explorer/step_wise_workflow_test.pytests/explorer/workflow_test.pytests/manager/log_manager_test.pytests/manager/synchronizer_test.pytests/service/data_juicer_test.pytests/utils/eval_utils_test.pytests/utils/log_test.pytests/utils/plugin_test.pytests/utils/registry_test.pytests/utils/swanlab_test.pytests/trainer/trainer_test.pycritic.strategy = "megatron"), which is not yet supported on NPU — see ToDo. Other 22 cases pass, 2 skipped.Failure Category Breakdown
transformersupgrade shifted results.max_prompt_tokens/max_response_tokensdeprecated in vLLM > 0.16.0.prompt_logprobsat temperature ≠ 1.0 (rtol=0.5 still fails).<think>tokens; Qwen3.5 arch unsupported by transformers 4.57.6;tinkerpackage not installed (includes 1 undocumented vLLM failure).tests/trainer/trainer_test.pycases withcritic.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):
NPU users disable
torch.compilein YAML:ToDo
Checklist
Please check the following items before code is ready to be reviewed.