Arguments
$0(ssh-host): SSH connection string, e.g.,user@192.168.1.100or justhostname(required)$1(image): Docker image name. If not provided, auto-detect the highest versionvllm-ascendimage on the remote machine$2(devices): NPU devices to use, e.g.,0,1,2,3. If not provided, detect available devices$3(test-command): The command to run inside the container. If not provided, enter interactive mode
Instructions
Step 1: Test SSH Connection
- Test connectivity to the SSH server:
ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no $0 "echo 'SSH connection successful'" - If connection fails, report the error and ask the user to verify:
- Host address and port
- SSH key or password authentication
- Network connectivity
- On success, proceed to Step 2.
Step 2: Detect or Validate Docker Image
If user specified an image ($1 is provided):
- Verify the image exists on the remote server:
ssh $0 "docker images --format '{{.Repository}}:{{.Tag}}' | grep -w '$1'" - If not found, ask the user whether to pull it or select another.
If no image specified ($1 is empty):
- Auto-detect the highest version vllm-ascend image:
ssh $0 "docker images --format '{{.Repository}}:{{.Tag}}' | grep 'vllm-ascend' | sort -V -t: -k2 | tail -1" - If no vllm-ascend image found, report the error and ask the user to provide an image name or pull one.
Step 3: Detect NPU Devices
If user specified devices ($2 is provided):
- Use the specified devices directly.
If no devices specified ($2 is empty):
- Detect available NPU devices on the remote server:
ssh $0 "npu-smi info -t board 2>/dev/null || npu-smi info 2>/dev/null" - Parse the output to identify available NPU device IDs.
- If detection fails, default to device
0and inform the user.
Step 4: Create and Run Docker Container
Create the Docker container with the required device mappings and volume mounts:
ssh $0 "docker run -d \\
-it \\ #必须
--name $NAME \\
--shm-size=1g \\
--net=host \\
--privileged \\
--device /dev/davinci_manager \\
--device /dev/hisi_hdc \\
--device /dev/devmm_svm \\
$(for d in $(echo $DEVICES | tr ',' ' '); do echo "--device /dev/davinci\$d \\\\"; done) \\
-v /usr/local/Ascend/driver:/usr/local/Ascend/driver \\
-v /usr/local/dcmi:/usr/local/dcmi \\
-v /usr/local/sbin:/usr/local/sbin \\
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \\
-v /etc/ascend_install.info:/etc/ascend_install.info \\
-v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime \\
-v /home/:/home \\
-v /data:/data \\
-e ASCEND_RT_VISIBLE_DEVICES=$DEVICES \\
-it $IMAGE bash -c '$TEST_CMD'"
Where:
$DEVICES= comma-separated NPU device IDs (e.g.,0,1,2,3)$IMAGE= the resolved Docker image name$TEST_CMD= the user's test command (if provided)$NAME= the docker container name must end with _claude
Important device mapping rules:
- Always include the paramater
-it - Always include the three mandatory devices:
/dev/davinci_manager,/dev/hisi_hdc,/dev/devmm_svm - Always include the mandatory volume mounts:
/usr/local/Ascend/driver,/usr/local/dcmi,/usr/local/sbin,/usr/local/bin/npu-smi,/etc/ascend_install.info - Map each NPU device as
/dev/davinciNwhere N is the device ID - Set
ASCEND_RT_VISIBLE_DEVICESenvironment variable to control which NPUs are visible - Forbidden to do any delete file or dir operation
If no test command provided:
- Enter interactive mode with
-itflag andbashas the command. - Inform the user they are now inside the container.
Step 5: Handle Dependency Issues
If the test command fails due to missing dependencies:
-
Capture the error output and identify missing packages.
-
Install all missing dependencies inside the container:
docker exec vllm-ascend-env pip install <missing-package-1> <missing-package-2> ... -i $PIP_MIRRORSPrioritize using the following pip mirror for downloads: https://mirrors.huaweicloud.com/repository/pypi/simple https://pypi.tuna.tsinghua.edu.cn/simple https://mirrors.aliyun.com/pypi/simple/ only cannot find the package on all three above mirrors then can use the default mirrors.
-
After all dependencies are installed, generate
requirements_ai.txtwith the complete list of newly installed packages:docker exec vllm-ascend-env pip freeze > requirements_ai.txt -
Copy the requirements file back to the host:
ssh $0 "docker cp vllm-ascend-env:/requirements_ai.txt /tmp/requirements_ai.txt" scp $0:/tmp/requirements_ai.txt ./requirements_ai.txt -
Inform the user about the generated
requirements_ai.txtfile.
Step 6: Error Reporting
If any errors block the script, you should record and fix that. But keep in mind, there is no need to fix all the problems.
-
Create or append to
report.txtwith the following information:- Timestamp
- Error description
- Full error output/stack trace
- Attempted solutions
- Suggested next steps
-
Actively think about solutions:
- Check if the error is a known issue with vllm-ascend
- Suggest alternative approaches (different image version, different device configuration)
- Propose code fixes if the error is in the test script
-
Report findings to the user with actionable recommendations.
Step 7: Generate Summary Report
After the test completes (success or failure), generate a comprehensive summary report and save it to report.txt:
-
Collect all execution information:
- Start time and end time
- Total execution duration
- SSH connection details (host, user)
- Docker image used
- NPU devices used and their status
- Container name
-
Record test results:
- Test script path and name
- List of processed files (if applicable)
- Inference time for each file
- Model output scores (color_score, sub_scores, etc.)
- Any warnings during execution
-
Document issues and fixes:
- List of missing dependencies that were installed
- Code modifications made for compatibility (e.g., torch.compile fixes)
- System-level installations (fonts, libraries)
- Version conflicts resolved
-
Write the report in the following format:
ssh $0 "cat > /home/l00910600/report.txt << 'EOF'
================================================================================
NPU Test Execution Report
================================================================================
【基本信息】
执行时间: $START_TIME ~ $END_TIME
总耗时: $DURATION
服务器: $SSH_HOST
Docker 镜像: $IMAGE
NPU 设备: $DEVICES (设备名称: $DEVICE_NAME)
容器名称: $CONTAINER_NAME
【测试脚本】
脚本路径: $TEST_SCRIPT
测试命令: $TEST_CMD
【推理结果】
$(for each processed file):
文件: $FILENAME
$OUTPUT(the full output of the target script)
【依赖安装】
$(list all installed packages)
【代码修改】
$(list all code changes made):
1. $FILE_PATH:$LINE - $DESCRIPTION
2. ...
【警告信息】
$(list any warnings):
- $WARNING_1
- $WARNING_2
【输出文件】
结果保存路径: $OUTPUT_PATH
requirements 文件: $REQUIREMENTS_PATH
================================================================================
报告生成时间: $REPORT_TIME
================================================================================
EOF"
-
Also save the report locally (optional):
scp $0:/home/l00910600/report.txt ./report_$(date +%Y%m%d_%H%M%S).txt -
Display summary to user:
- Print a condensed version of the report in the terminal
- Highlight key metrics (total time, success/failure, files processed)
- Mention the full report file location
Workflow Summary
SSH Connection Test
│
▼
┌────┴────┐
│ Connected?│
└────┬────┘
Yes│ No → Report & ask user
▼
Detect/Validate Image
│
▼
Detect NPU Devices
│
▼
Create Docker Container
│
▼
Run Test Command
│
▼
┌────┴────┐
│ Success? │
└────┬────┘
Yes│ No → Check error type
│ │
│ ┌────┴────┐
│ │Dep issue?│
│ └────┬────┘
│ Yes│ No → Record in report.txt
│ ▼
│ Install deps
│ Generate requirements_ai.txt
▼
┌─────────────┐
│ Step 7: │
│ Generate │
│ Summary │
│ Report │
└──────┬──────┘
│
▼
┌─────────────┐
│ Write to │
│ report.txt │
│ on server │
└──────┬──────┘
│
▼
Display Results
to User
Conventions
- Always use
-o ConnectTimeout=10and-o StrictHostKeyChecking=nofor SSH commands - Use
set -ein shell scripts to fail fast on errors - Quote all variables to prevent word splitting
- Use
tr ',' ' 'to convert comma-separated device list to space-separated for iteration - Prefer
pip installoverpip3 installinside Docker containers (usually the default) - Always clean up Docker containers after use (the
--rmflag handles this) - Use
scpto transfer files between local and remote machines - Append to
report.txtrather than overwriting to preserve error history
Examples
Example 1: Basic NPU test with auto-detected image
/npu-test user@192.168.1.100
This will SSH to the server, find the highest version vllm-ascend image, detect available NPUs, and enter interactive mode.
Example 2: Specific image and devices
/npu-test user@192.168.1.100 vllm-ascend:v0.7.3 0,1,2,3 "python /data/test_model.py"
This will use the specified image, devices 0-3, and run the test script.
Example 3: Run with all available NPUs
/npu-test user@192.168.1.100 "" all "python benchmark.py --model /data/models/llama"
This will auto-detect the image, use all available NPUs, and run the benchmark command.