mcpField
H
huawei-cloud-ascend-command

huawei-cloud-ascend-command

github.com/huaweicloud云与 DevOps59457 次安装2 天前更新
代码仓库

关于 huawei-cloud-ascend-command

通过将自然语言请求转换为 npu-smi 命令来管理 Huawei Ascend NPU 的技能,支持本地执行和 SSH 远程操作;敏感变更需确认。

主要功能

  1. 01将自然语言转换为 npu-smi 命令
  2. 02查询设备健康状态与利用率
  3. 03管理配置和固件
  4. 04处理 vNPU 与证书操作
  5. 05运行 FLOPS 测试

适用场景

  1. 01检查 NPU 健康状况、温度和内存
  2. 02经确认后修改 ECC 或风扇设置
  3. 03升级固件或管理 vNPU
  4. 04测试多设备计算性能

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/huaweicloud/huaweicloud-skills --skill huawei-cloud-ascend-command

安装后在 Claude Code 中输入/huawei-cloud-ascend-command确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
acceptance-criteria.md
certificate-management.md
configuration.md
device-queries.md
firmware-upgrade.md
troubleshooting.md
verification-method.md
virtualization.md
scripts/
__init__.py
executor.py
main.py
npu_client.py

详细介绍

提供华为 Ascend NPU 自然语言命令转换与执行功能。支持完整的 npu-smi 命令:设备查询、配置管理、固件升级、vNPU 虚拟化、证书管理和算力测试。

概述

此技能通过 npu-smi 命令,以自然语言管理华为 Ascend NPU 设备。支持本地直接执行和 SSH 远程模式。

相关技能:

  • huawei-cloud-ascend-remote-connect - 通用 SSH 远程操作(磁盘、Docker、日志、进程)
  • npu-smi-skill - 另一种 NPU 管理实现
  • model-deploy-test-skill - 在 Ascend DevServer 上进行模型部署和测试

功能:

  • 设备查询(健康状况、温度、功耗、HBM、ECC、拓扑)
  • 配置管理(ECC、风扇模式、风扇转速)
  • 固件升级和状态查询
  • vNPU 虚拟化
  • 证书管理
  • 算力测试(FLOPS)

架构

系统架构图
┌─────────────────────────────────────────────────────────────────────┐
│                         Agent Orchestration                         │
│  ┌─────────────────────────────────────────────────────────────┐    │
│  │  1. Parse user intent → Match Trigger keywords                        │    │
│  │  2. Prepare params → host, user, password explicit                 │    │
│  │  3. Invoke Skill → skill exec --name ascend-command            │    │
│  │  4. Return result → User                                          │    │
│  └────────────────────────────┬────────────────────────────────┘    │
│                               │ Explicit param passing (Rule 1)                │
│                               ▼                                     │
├─────────────────────────────────────────────────────────────────────┤
│                        User Interaction Layer                       │
│  ┌─────────────────────────────────────────────────────────────┐    │
│  │  Natural Language Commands / CLI Arguments                  │    │
│  │  (NPU health check, temperature, firmware upgrade)          │    │
│  └────────────────────────────┬────────────────────────────────┘    │
│                               │                                     │
│                               ▼                                     │
├─────────────────────────────────────────────────────────────────────┤
│                      Skill Core Components (Stateless (Rule 2))           │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐      │
│  │ Command Executor│←→│   NPU Client    │←→│ Trend Recorder  │      │
│  │  - NL Parsing   │  │  - npu-smi cmd  │  │  - Metric Log   │      │
│  │  - Command Route│  │  - Local/SSH    │  │  - Trend Analysis│      │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘      │
│         │                      │                                     │
│         ▼                      ▼                                     │
├─────────────────────────────────────────────────────────────────────┤
│                    Huawei Cloud Ascend Infrastructure               │
│  Data Flow: Agent → Skill(host,user,pwd) → SSH → npu-smi → Response │
└─────────────────────────────────────────────────────────────────────┘
Agent 编排流程
User request: "Query NPU status on 116.204.23.145"
         │
         ▼
┌─────────────────────────────────────────────────────────────┐
│ Agent parses intent                                               │
│   - Keyword "NPU" → Match ascend-command                       │
│   - IP address → SSH params needed                                  │
└─────────────────────────────────────────────────────────────┘
         │
         ▼
┌─────────────────────────────────────────────────────────────┐
│ Agent prepares params (explicit, Rule 1)                              │
│   --host 116.204.23.145                                      │
│   --user root                                                │
│   --password ***                                             │
│   --command "NPU list"                                       │
└─────────────────────────────────────────────────────────────┘
         │
         ▼
┌─────────────────────────────────────────────────────────────┐
│ Skill executes (Stateless, Rule 2)                                    │
│   - NpuClient(host, user, password) explicit receive                 │
│   - Execute npu-smi command                                        │
│   - Return result                                                 │
└─────────────────────────────────────────────────────────────┘
         │
         ▼
      Return to user
相关技能(由 Agent 编排,不直接调用,规则 3)
技能用途编排场景
huawei-cloud-ascend-remote-connectSSH 远程操作用户需要管理磁盘、Docker 或日志时,由 Agent 选择
npu-smi-skillNPU 管理另一种实现,由 Agent 根据场景选择
model-deploy-test-skill模型部署部署后使用 ascend-command 监控 NPU

注意:技能之间不会直接调用,而是由 Agent 根据用户意图进行编排。

先决条件

系统要求
  • Python 3.8+
  • 纯 Python 标准库实现,无需额外依赖
环境检查

先决条件检查:需要 Python3

python3 --version  # Python3 >= 3.8

身份验证

安全规则(必须遵守):

  • 禁止读取、回显或打印密码值
  • 禁止要求用户在对话中直接输入密码
  • 只允许从命令行参数读取凭据

参数确认

输入参数
参数必填说明
command是(单次执行)要执行的自然语言命令
host否SSH 远程主机 IP 地址
user否SSH 用户名
password否SSH 密码
确认要求

以下操作需要用户明确确认:

  • 启用/禁用 ECC
  • 更改风扇模式
  • 固件升级
  • 创建/删除 vNPU
  • 证书管理

核心工作流

任务 1:单次命令执行
python3 scripts/main.py --command "NPU health check"
任务 2:SSH 远程执行
python3 scripts/main.py --command "NPU list" --host 192.168.1.100 --user root --password xxx
任务 3:交互模式
python3 scripts/main.py

使用说明

设备查询
List all NPU devices
NPU health check
Get NPU temperature
Get NPU power usage
Get NPU memory info
配置管理
Set ECC mode
Set fan mode
固件升级
Query firmware version
Upgrade firmware
虚拟化
Query vNPU info
Create vNPU
FLOPS 测试
Run FLOPS test
Run FP32 FLOPS test
Run multi-device FLOPS test

输出格式

标准响应格式

所有命令输出均采用结构化格式:

{
  "status": "success",
  "command": "npu-smi info -l",
  "description": "List all NPU devices"
}
错误响应格式
[ERROR] <error-code>
Message: <error-description>
Suggestion: <troubleshooting-tip>

验证方法

基本验证步骤
  1. 环境检查

    python3 --version  # Verify Python 3.8+
    
  2. 本地命令测试

    python3 scripts/main.py --command "NPU list"
    
  3. 远程命令测试

    python3 scripts/main.py --host <ascend-ip> --user root --password <pwd> --command "NPU health check"
    
预期结果
测试用例预期输出
环境检查Python 版本 >= 3.8
本地命令NPU 设备信息或 "npu-smi not found"
远程命令远程服务上的 NPU 状态

脚本文件

入口文件
  • main.py:技能入口文件(必需)
    • 功能:提供交互模式、单次执行模式和 SSH 远程模式
    • 支持:命令行参数、交互提示词
核心脚本
  • executor.py:NPU 命令执行器(主入口)

    • 功能:自然语言解析、命令路由、敏感操作确认
    • 支持的命令:设备查询、配置、固件升级、虚拟化、证书管理
    • 核心方法:handle_command(text)、confirm_sensitive()
  • npu_client.py:NPU 客户端

    • 功能:封装 npu-smi 命令执行,支持本地和 SSH 远程执行
    • 核心方法:list_devices()、get_health()、get_temperature()、get_power()、get_memory()、set_ecc_enable()、upgrade_query()、create_vnpu()、get_tls_cert()
    • 优化:SSH ControlMaster、批量执行、并行 FLOPS 测试

命令映射

设备查询
自然语言命令描述
列出所有 NPU 设备npu-smi info -l列出所有 NPU 设备
NPU 卡信息npu-smi info -m卡与芯片映射
NPU 信息npu-smi info完整的 NPU 信息
健康检查
自然语言命令描述
NPU 健康检查npu-smi info -t health -i 0检查设备健康状况
检查 NPU 状态npu-smi info -t health -i 0检查设备健康状况
温度/功耗/内存
自然语言命令描述
NPU 温度npu-smi info -t temp -i 0 -c 0获取温度
NPU 功耗npu-smi info -t power -i 0 -c 0获取功耗
NPU 内存npu-smi info -t memory -i 0 -c 0获取内存信息
NPU 利用率npu-smi info -t usages -i 0 -c 0获取利用率
配置
自然语言命令描述
设置 ECCnpu-smi set -t ecc-enable -i 0 -c 0 -d 1启用 ECC(需要确认)
设置风扇模式npu-smi set -t pwm-mode -d 0设置风扇模式(需要确认)
固件升级
自然语言命令描述
固件版本npu-smi upgrade -b mcu -i 0查询固件版本
升级固件npu-smi upgrade -t mcu -i 0 -f file.hpm上传固件(需要确认)
虚拟化
自然语言命令描述
vNPU 信息npu-smi info -t info-vnpu -i 0 -c 0查询 vNPU 信息
模板信息npu-smi info -t template-info -i 0查询模板信息
创建 vNPUnpu-smi set -t create-vnpu -i 0 -c 0 -f vir04创建 vNPU(需要确认)
证书管理
自然语言命令描述
证书信息npu-smi info -t tls-cert -i 0 -c 0查看 TLS 证书
证书过期时间npu-smi info -t tls-cert-period -i 0 -c 0查询证书过期阈值
FLOPS 测试(ascend-dmi)

默认行为:单设备 FP16,快速返回(约 2 秒)

自然语言命令描述
FLOPS 测试ascend-dmi -f -d 0 -t fp16 -q默认:NPU 0、FP16
NPU FLOPSascend-dmi -f -d 0 -t fp16 -q同上
NPU 3 FLOPSascend-dmi -f -d 3 -t fp16 -q指定 NPU 3
FP32 FLOPSascend-dmi -f -d 0 -t fp32 -qFP32 精度
所有设备 FLOPS8 台设备异步并行同时测试所有 NPU

执行策略:

  • 单设备:直接执行,约 2 秒返回
  • 多设备:异步并行执行,总计约 2 秒(而非串行执行 16 秒)
  • 精度:默认 fp16,支持 fp32/bf16/int8/hf32

性能优化

优化项描述效果
SSH 持久连接复用 ControlMaster连接时间约为 0.1s
批量执行使用 execute_batch() 执行多条命令减少 SSH 往返次数
并行查询对 8 台设备进行 test_flops_parallel() 异步测试16s -> 2s
单次解析使用 parse_full_info() 一次性获取所有卡的信息O(N) -> O(1)

故障排除

无法识别命令
  • 检查输入是否包含受支持的关键词
  • 尝试使用更明确的命令
SSH 连接失败
  • 确认 SSH 参数正确
  • 确保目标机器上的 SSH 服务正在运行
npu-smi 不可用
  • 确保目标机器已安装 CANN 和 npu-smi
  • 检查 LD_LIBRARY_PATH 环境变量

注意事项

安全警告
  • 执行敏感操作前需要用户确认
  • 密码仅在会话期间存储于内存中
  • 被阻止的命令无法绕过
限制
  • 要求目标机器已安装 npu-smi 或 ascend-dmi
  • 仅支持 SSH 密码认证(不支持交互式密码提示)

最佳实践

最佳实践
  1. 选择连接模式

    • 本地直连:适用于 NPU 安装在本地机器上的情况
    • SSH 远程连接:适用于管理远程 Ascend 服务
  2. 命令执行提示

    • 敏感操作(固件升级、配置更改)需要用户确认
    • 批量操作前,先在单卡上测试
  3. 性能监控

    • 定期检查 NPU 温度和功耗
    • 监控 HBM 使用情况,避免 OOM
  4. 故障排除

    • 首先检查 NPU 健康状态:npu-smi info
    • 查看详细错误日志:npu-smi info -t board -i <npu_id>
    • 参见 troubleshooting.md
  5. 触发关键词

    • 中文:NPU、昇腾、显存、算力、温度、功耗、固件、虚拟化
    • 英文:npu、ascend、temperature、power、HBM、firmware、vNPU、FLOPS

目录结构

huawei-cloud-ascend-command/
├── SKILL.md                    # Skill description (required)
├── scripts/                    # Scripts directory (required)
│   ├── __init__.py             # Module export
│   ├── main.py                 # Skill entry file (required)
│   ├── executor.py             # NPU command executor
│   └── npu_client.py           # NPU client
└── references/                 # Reference documentation
    ├── acceptance-criteria.md  # Acceptance criteria
    ├── verification-method.md  # Verification steps
    ├── troubleshooting.md      # Troubleshooting guide
    ├── device-queries.md       # Device queries reference
    ├── configuration.md        # Configuration reference
    ├── firmware-upgrade.md     # Firmware upgrade reference
    ├── virtualization.md       # Virtualization reference
    └── certificate-management.md # Certificate management

参考资料

文档描述
acceptance-criteria.md技能验证的验收标准
verification-method.md验证步骤和测试方法
troubleshooting.md故障排除指南和常见问题
device-queries.md设备查询命令参考
configuration.md配置管理参考
firmware-upgrade.md固件升级参考
virtualization.md虚拟化管理参考
certificate-management.md证书管理参考

技术支持

评论

支持 Markdown