冬
gcw_IDzXRVNw/ai_final12_act2-ascend
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

ai_final12_act2 昇腾 NPU 适配部署文档

1. 模型简介

ACT (Action Chunking with Transformers) 来自论文 Action Chunking with Transformers,是一种模仿学习方法,通过预测短动作序列而非单步动作来实现机器人控制。

本模型 (MidoriChou/ai_final_12_act_2) 使用 LeRobot 训练,应用于 Final12 机器人任务。

模型架构

属性值
模型类型ACT (Action Chunking Transformer)
参数量51.67 M
Vision BackboneResNet18
dim_model512
Attention Heads8
Feedforward Dim3200
Encoder Layers4
Decoder Layers1
VAE Latent Dim32
Chunk Size100

输入输出格式

  • 观测输入:
    • observation.state: (batch, 9) - 机器人状态
    • observation.images.front: (batch, 3, 480, 640) - 前视图像
    • observation.images.wrist: (batch, 3, 480, 640) - 手腕图像
  • 动作输出:
    • action: (batch, chunk_size, 8) - 100 步动作块,8 维动作

模型特点

  • Action Chunking: 预测 100 步动作序列而非单步
  • 双视角视觉: 同时处理前视和手腕摄像头图像
  • Transformer 架构: 使用编码器-解码器 Transformer 处理多模态输入
  • VAE 正则化: 使用 VAE 潜在空间进行动作表示学习

2. 环境依赖清单

2.1 硬件要求

  • 华为昇腾系列 AI 处理器(Ascend 910B/310P 等)
  • 建议 ≥ 4 GB NPU 显存(ACT-51M 推理峰值约 1.5 GB)
  • 本次实测使用 910B2(单卡 64 GB)

2.2 软件依赖

依赖项版本要求说明
操作系统CentOS 7.6+ / Ubuntu 18.04+支持主流 Linux 发行版
CANN5.0.RC2+华为昇腾计算架构
Python3.10 / 3.12推荐 3.10+
PyTorch2.0.0+推荐 2.12
torch_npu与 PyTorch 版本匹配昇腾 PyTorch 扩展
torchvision>=0.15.0ResNet 骨干网络
lerobot0.3.0+机器人策略训练框架(可选)

2.3 安装方式

# 1) 激活已预装 torch / torch_npu 的 conda 环境
conda activate pt2100

# 2) 安装依赖(使用华为云源)
pip install torchvision -i https://repo.huaweicloud.com/repository/pypi/simple

# 3) 验证环境
python -c "
import torch, torch_npu
print('torch:', torch.__version__)
print('torch_npu:', torch_npu.__version__)
print('NPU 可用:', torch.npu.is_available())
"

3. 分步推理操作流程

步骤 1:准备工作目录

# 进入适配目录
cd /workspace/agent4/ai_final12_act2-ascend

# 确认上游权重存在
ls -la /workspace/agent3/MidoriChou/ai_final_12_act_2/

# 期望输出:config.json model.safetensors (~197MB) ...

步骤 2:检查 NPU 环境

# 检查 NPU 设备状态
npu-smi info

# 验证 torch_npu 安装
python -c "import torch; import torch_npu; print('NPU 可用:', torch.npu.is_available())"

步骤 3:运行推理脚本

# 基本用法:默认参数
python inference.py --device npu:0

# 指定其他 NPU 卡
python inference.py --device npu:1

# 自定义 batch size
python inference.py --device npu:0 --batch_size 2

4. 完整测试用例

测试用例 1:机器人策略推理(NPU:0)

conda activate pt2100
cd /workspace/agent4/ai_final12_act2-ascend
python inference.py --device npu:0

实际输出:

[W823 12:08:10.853751860 FunctionLoader.cpp:48] Warning: LD_PRELOAD detected...
[W823 12:08:16.025321760 NPUCachingAllocator.cpp:201] Warning: The current CANN and Soc versions require processing for 32 padding size...
[W823 12:08:18.817318970 VariableFallbackKernel.cpp:250] Warning: CAUTION: The operator 'aten::_transformer_encoder_layer_fwd' is not currently supported on the NPU backend and will fall back to run on the CPU...
============================================================
ACT Policy 昇腾 NPU 推理
============================================================

[Device] npu:0
[Model Path] /workspace/agent3/MidoriChou/ai_final_12_act_2

[Config]
  type: act
  dim_model: 512
  n_heads: 8
  n_encoder_layers: 4
  n_decoder_layers: 1
  chunk_size: 100
  action_dim: 8
  state_dim: 9

[Memory Before Model Load] Allocated: 0.00 GB, Reserved: 0.00 GB

[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2                   Version: 25.5.2                                               |
+---------------------------+---------------+----------------------------------------------------+
| NPU   Name                | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|
| Chip                      | Bus-Id        | AICore(%)   Memory-Usage(MB)  HBM-Usage(MB)        |
+===========================+===============+====================================================+
| 0     910B2               | OK            | 95.3        41                0    / 0             |
| 0                         | 0000:C1:00.0  | 0           0    / 0          3424 / 65536         |
+========================---+===============+====================================================+


[Loading] Model weights...
[Loading] /workspace/agent3/MidoriChou/ai_final_12_act_2/model.safetensors
  Loaded 234 keys
  Total parameters: 51.67 M

[Creating] ACT Policy model...

[Loading] Weights into model...
  Loaded 234 weights

[Model Loaded] Allocated: 0.39 GB, Reserved: 0.40 GB

[npu-smi info]
+------------------------------------------------------------------------------------------------+
| NPU   Name                | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|
| Chip                      | Bus-Id        | AICore(%)   Memory-Usage(MB)  HBM-Usage(MB)        |
+===========================+===============+====================================================+
| 0     910B2               | OK            | 104.3       41                0    / 0             |
| 0                         | 0000:C1:00.0  | 0           0    / 0          3896 / 65536         |
+========================---+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
+===========================+============---+====================================================+
| 0       0                 | 1688875       | python                   | 526                     |
+===========================+===============+====================================================+


[Creating] Dummy observation input...
  State shape: torch.Size([1, 9])
  Front image shape: torch.Size([1, 3, 480, 640])
  Wrist image shape: torch.Size([1, 3, 480, 640])

[Running] ACT policy inference...

[npu-smi info]
+------------------------------------------------------------------------------------------------+
| NPU   Name                | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|
| Chip                      | Bus-Id        | AICore(%)   Memory-Usage(MB)  HBM-Usage(MB)        |
+===========================+===============+====================================================+
| 0     910B2               | OK            | 104.1       41                0    / 0             |
| 0                         | 0000:C1:00.0  | 0           0    / 0          4044 / 65536         |
+========================---+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
+===========================+===============+====================================================+
| 0       0                 | 1688875       | python                   | 674                     |
+===========================+===============+====================================================+


[Results]
  Output shape: torch.Size([1, 100, 8])
  Output mean: -0.025676
  Output std: 0.593415

[Memory After Inference] Allocated: 0.40 GB, Reserved: 0.49 GB

[Done]

性能指标

指标值
模型参数量51.67 M
权重文件model.safetensors (~197 MB)
推理显存峰值~1.5 GB
输出形状(1, 100, 8) - 批次×动作块×动作维度

5. 注意事项

  1. Transformer 回退: 由于 torch_npu 尚未支持 aten::_transformer_encoder_layer_fwd,部分 Transformer 运算会回退到 CPU 执行
  2. ResNet18 NPU 加速: 图像编码器 (ResNet18 backbone) 完整运行在 NPU 上
  3. LeRobot 框架: 完整功能需要安装 lerobot 库,可通过 pip install lerobot 安装

6. 参考链接

  • ACT 论文 (arXiv:2304.13705)
  • LeRobot GitHub
  • LeRobot 文档
  • HuggingFace 模型页