feat: add NPU device support for embedded-python model executor.#2009
Open
yingxudeng wants to merge 1 commit into
Open
feat: add NPU device support for embedded-python model executor.#2009yingxudeng wants to merge 1 commit into
yingxudeng wants to merge 1 commit into
Conversation
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Collaborator
Author
TP2 End-to-End VerificationBranch: Environment
Startup CommandASCEND_RT_VISIBLE_DEVICES=2,3 \
LD_LIBRARY_PATH=/usr/local/python3.11.15/lib/python3.11/site-packages/torch_npu/lib:$LD_LIBRARY_PATH \
./build/lib.linux-aarch64-cpython-311/xllm/xllm \
--model /export/home/models/Qwen3-4B \
--port 8199 --host 0.0.0.0 \
--max_seqs_per_batch 4 \
--python_graph_backend eager \
--model_impl pythonService Logs (key lines)Inference Results
|
Collaborator
Author
## NPU Python Graph TP=2 精度验证报告
### 环境
| 项目 | 值 |
|------|-----|
| 容器 | `dyx-xllm-cann9-main-0723` (from `dyx-xllm-cann9-main:backup-20260722`) |
| CANN | 9.0.0 |
| torch_npu | 2.9.0.post4+git44b5898 |
| 模型 | Qwen3-4B |
| TP | 2 (多进程, nnodes=2) |
| 设备 | NPU 14, 15 |
| Commit | aeb03a24 |
### 复现步骤
#### 1. 编译
```bash
docker exec -w /export/home/dengyingxu1/projects/xllm-feat-qwen3-npu-python-graph \
dyx-xllm-cann9-main-0723 bash -lc 'python setup.py build --device npu'编译时 2. 启动 TP=2 服务 (多进程)CONTAINER=dyx-xllm-cann9-main-0723
CHECKOUT=/export/home/dengyingxu1/projects/xllm-feat-qwen3-npu-python-graph
MODEL=/export/home/models/Qwen3-4B
XLLM_BIN="./build/lib.linux-aarch64-cpython-311/xllm/xllm"
# ⚠️ 关键:Python executor 需要 torch_npu >= post4 的 .so(含 npu_extension_functions 符号)。
# 系统 /usr/local/libtorch_npu/lib/ 是 post2(ATB backend 使用),不能替换。
# 通过 LD_LIBRARY_PATH 前置 pip 安装的 post4 路径,让 ld.so 优先加载 post4 版本。
# 这样 ATB backend 启动时不加此变量,仍使用 post2,互不影响。
TORCH_NPU_LIB="/usr/local/python3.11.15/lib/python3.11/site-packages/torch_npu/lib"
# Rank 0
docker exec $CONTAINER bash -c "
export ASCEND_RT_VISIBLE_DEVICES=14,15
export LD_LIBRARY_PATH=$TORCH_NPU_LIB:\$LD_LIBRARY_PATH
cd $CHECKOUT
nohup $XLLM_BIN \
--model $MODEL --port 8199 --host 0.0.0.0 \
--max_seqs_per_batch 4 \
--model_impl python --python_graph_backend off \
--nnodes 2 --node_rank 0 --master_node_addr=127.0.0.1:19888 \
--enable_prefix_cache=false --enable_chunked_prefill=false \
> /tmp/xllm_tp2_rank0.log 2>&1 &"
# Rank 1
docker exec $CONTAINER bash -c "
export ASCEND_RT_VISIBLE_DEVICES=14,15
export LD_LIBRARY_PATH=$TORCH_NPU_LIB:\$LD_LIBRARY_PATH
cd $CHECKOUT
nohup $XLLM_BIN \
--model $MODEL --port 8200 --host 0.0.0.0 \
--max_seqs_per_batch 4 \
--model_impl python --python_graph_backend off \
--nnodes 2 --node_rank 1 --master_node_addr=127.0.0.1:19888 \
--enable_prefix_cache=false --enable_chunked_prefill=false \
> /tmp/xllm_tp2_rank1.log 2>&1 &"3. 精度评测docker exec $CONTAINER bash -c "
evalscope eval \
--model Qwen3-4B \
--api-url http://localhost:8199/v1 \
--api-key dummy \
--datasets gsm8k \
--limit 10 \
--eval-batch-size 4 \
--timeout 180 \
--work-dir /tmp/evalscope_tp2"结果~~ 关键说明:LD_LIBRARY_PATH 机制Python executor 依赖 torch_npu post4 的
策略:不替换系统 .so,启动时 LD_LIBRARY_PATH 切换。
两条路径互不干扰。长期方案:验证 post4 对 ATB 完全向后兼容后,统一升级系统 .so,删除 LD_LIBRARY_PATH 覆盖。 其他注意事项
|
yingxudeng
force-pushed
the
feat/qwen3-npu-python-graph
branch
2 times, most recently
from
July 24, 2026 03:55
8afb8c6 to
ccef9ac
Compare
yingxudeng
force-pushed
the
feat/qwen3-npu-python-graph
branch
2 times, most recently
from
July 24, 2026 06:16
a4d53f3 to
bafae1e
Compare
Collaborator
Author
|
LD_LIBRARY_PATH 不用管了,已经统一都用 whl 包下面的 .so 了 |
Enable --model_impl=python on NPU with multi-process TP, using the same architecture as the CUDA path (one xllm process per device, HCCL ProcessGroup for collectives). Key changes: - xllm.cpp: extract init_npu_python_runtime() called for all NPU processes — initializes Python + torch_npu before any tensor allocation (required by torch_npu's GIL-aware empty_with_format). - master.cpp: auto-force npu_kernel_backend=TORCH when model_impl=python, bypassing ATB C++ kernels. - collectives.py: native Python ProcessGroupHCCL for NPU TP communication. - npu_ops_library.cpp: register update_decode_graph_metadata stub so the Python ops module imports without error on NPU. - scripts/deps/torch_npu_install.py: auto-install torch_npu post2 wheel from open-source xLLM-AI/pytorch releases (aarch64 + x86_64). - scripts/build_support/env.py: auto-detect pip torch_npu path, symlink missing torch_npu.h header, prepend lib/ to LD_LIBRARY_PATH. - device.cpp: Python path uses SetDevice only (full init done in main). Verified: Qwen3-4B TP=2 multi-process, GSM8K score=1.0 (10/10), ~33 tok/s. ATB backend unaffected (TP=2 ATB also verified working).
yingxudeng
force-pushed
the
feat/qwen3-npu-python-graph
branch
from
July 24, 2026 13:25
bafae1e to
f49ecad
Compare
yingxudeng
marked this pull request as ready for review
July 24, 2026 13:26
yingxudeng
requested review from
Clement-Wang26,
DongheJin,
DragonFive,
JimHsiung,
Kang-Meng,
RobbieLeung,
XuZhang99,
liujinguang0125,
liutongxuan,
walsonyang,
xiao-yu-chen and
yq33victor
as code owners
July 24, 2026 13:26
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.
Description
Related Issues
Change Type
Pull Request Checklist
Thank you for contributing to xLLM. Before requesting review, please make sure the following items are complete.
PR Title and Commit Messages
<type>: <subject>.Pre-commit Checks
pre-commitby runningpip install pre-commitor an equivalent command.pre-commit install.pre-commit run --all-filesand fixed any reported issues.Self Review
.agents/skills/code-review/references/custom-code-style.md, especially code written or assisted by AI.mainbranch.Build and Test Coverage
python setup.py build testhas passed on a CUDA machine.python setup.py build testhas passed on an NPU machine.python setup.py build testhas passed on an MLU machine.Reviewer Notes