Skip to content

fix(auto): detect Ascend NPU and configure Ray/server config by device type - #419

Open
Liuchenbing-2026 wants to merge 1 commit into
modelscope:mainfrom
Liuchenbing-2026:fix/auto-server-npu-support-20261122
Open

Liuchenbing-2026 wants to merge 1 commit into
modelscope:mainfrom
Liuchenbing-2026:fix/auto-server-npu-support-20261122

Conversation

@Liuchenbing-2026

Copy link
Copy Markdown
Contributor

PR type

  • Bug Fix
  • New Feature
  • Document Updates
  • More Models or Datasets Support

PR information

Closes #370.

twinkle.server already supports 'npu' via TrainingConfig.device_type and Platform.get_platform('npu'), but twinkle-auto (_ServerTools) previously assumed CUDA only (nvidia-smi / torch.cuda, hardcoded device_type: cuda, CUDA_VISIBLE_DEVICES, and --num-gpus).

Changes

  • src/twinkle_client/auto/agent/server_tools.py:
    • Add _detect_npu_count_from_smi() to parse npu-smi info -l (Chip Count lines with Total Count fallback).
    • Add _detect_accelerator() -> tuple[str, int] checking CUDA (nvidia-smi / torch.cuda) and then Ascend NPU (torch.npu / npu-smi info -l), keeping _detect_gpu_count() delegating to it.
    • Propagate detected device_type through _tool_start_server() into _generate_server_config() (updating training and non-CPU sampler device_group and device_mesh entries while keeping processor on 'CPU') and _start_ray_cluster() (setting ASCEND_RT_VISIBLE_DEVICES and --resources='{"NPU": <n>}' for 'npu', while preserving CUDA_VISIBLE_DEVICES and --num-gpus for 'cuda').
  • tests/twinkle_client/test_auto_agent_tools.py:
    • Add unit tests for CUDA/NPU detection (including npu-smi info -l single- and dual-chip outputs), NPU server config generation, Ray CLI/env args, and _tool_start_server end-to-end wiring.

Experiment results

  • Targeted unit tests (pytest -v tests/twinkle_client/test_auto_agent_tools.py):
    • Before fix (same test file SHA-256 c518c3335d91545d187c7273ae0de6f41fcf901f4a953b72ea176540effd5230): 9 failed, 14 passed.
    • After fix: 23 passed.
  • Verified real-host unmocked _detect_accelerator() via npu-smi info -l on an 8-NPU Ascend host returning ('npu', 8).
  • Repository style checks (pre-commit run --all-files): all 11 hooks passed (flake8, isort, yapf, pyupgrade, trailing-whitespace, check-yaml, end-of-file-fixer, requirements-txt-fixer, double-quote-string-fixer, check-merge-conflict, mixed-line-ending).
  • Scope note: Ray process launch and live NPU server startup were validated via subprocess/mocked unit tests rather than a live Ray + NPU cluster E2E run; 1 collection error (hypothesis) and 7 tests in unrelated tests/twinkle_client/ modules did not pass in the minimal client test environment due to missing optional peft/tinker packages.

…e type

Detect Ascend NPUs alongside CUDA GPUs in _ServerTools via torch.npu and npu-smi info -l fallback, propagate device_type into generated server_config.yaml device groups and meshes, and start Ray nodes with ASCEND_RT_VISIBLE_DEVICES and --resources={"NPU": n} on NPU hosts while preserving existing CUDA behavior.

Signed-off-by: liuchenbing <chenliumail@163.com>
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.

twinkle-auto: start_server cannot start on Ascend NPU (nvidia-smi-only detection, hard-coded device_type: cuda)

2 participants