w
gcw_uQ09W7jl/MidoriChou-ai_final_12_act_2-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

MidoriChou/ai_final_12_act_2 on Ascend NPU

1. 模型简介

  • 模型名称: MidoriChou/ai_final_12_act_2
  • 权重地址: https://huggingface.co/MidoriChou/ai_final_12_act_2 (镜像: https://hf-mirror.com/MidoriChou/ai_final_12_act_2, revision 92654eb0e3f9ee4329d54a599165aeb12512e92f)
  • 架构: ACTPolicy (Action Chunking Transformer, lerobot) - ResNet18 vision backbone (FrozenBatchNorm2d) + 4-layer Transformer encoder + 1-layer decoder, VAE latent_dim 32, dim_model 512, n_heads 8, dim_ff 3200
  • 任务: 机器人模仿学习 pipeline_tag: robotics - 预测动作块 [batch, 100, 8] (chunk_size 100, n_action_steps 100), 输入为本体状态 [9] + 2 相机 RGB front/wrist [3,480,640]; 输出在真实 SO100 follower 上经由 lerobot-record 执行
  • 权重大小: ~198 MB model.safetensors (206.7 MB 含 preprocessor/postprocessor, 51.6M 参数, float32)
  • 数据契约: 原始数据集 MidoriChou/ai_final_12 (cupstacking), 归一化 MEAN_STD for VISUAL/STATE/ACTION, 预处理 policy_preprocessor_step_3_normalizer_processor.safetensors 含各特征 mean/std, 后处理 policy_postprocessor_step_0_unnormalizer_processor 还原动作

备注: 系统任务标签为“表格数据”,但实际仓库配置与权重为 robotics ACT 模型(config.json type=act)。本仓按真实模型语义验证并交付 NPU 推理,不以“表格”方式虚构结果。

2. 验证环境

  • NPU: Ascend910 (910B compatible) x2, 驱动 25.5.5, CANN 8.5.1, HBM 64GB/卡 (npu:0 idle 3110/65536 MB, npu:1 idle 2872/65536 MB)
  • 软件: Python 3.11.14, torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, torchvision, transformers 4.57.6, safetensors 0.8.0, lerobot 0.4.4, einops, draccus, HF_ENDPOINT=https://hf-mirror.com
  • 设备: npu:0, 名称 Ascend910_9362, torch.npu.is_available()==True, device_count 2, dtype float32
  • 本地权重: /tmp/midori_act2 由 HF_ENDPOINT=https://hf-mirror.com huggingface-cli download MidoriChou/ai_final_12_act_2 --local-dir /tmp/midori_act2 一次性下载固定 revision, 正式推理仅从本地加载不联网
  • 输入: 确定性合成 batch seed=42, observation.state [1,9] observation.images.front/wrist [1,3,480,640] 全为正态随机 (可复现), 计时前后 torch.npu.synchronize()

3. 安装依赖

pip install -r requirements.txt
# 包含: torch==2.9.0 torch-npu torchvision transformers safetensors huggingface_hub lerobot==0.4.4 einops draccus numpy Pillow

4. NPU 推理

# 默认推理(真实 npu:0 执行, 打印任务输出与 PASS)
python inference.py

# 一致性验证(同输入同权重 CPU vs NPU action chunk diff)
python inference.py --mode validate

# 性能基准(3 次 warmup + 10 次同步计时)
python inference.py --mode benchmark

# 指定本地权重目录(可选)
python inference.py --model-dir /tmp/midori_act2

5. 真实推理结果

python inference.py (npu:0, float32, seed 42):

Model: MidoriChou/ai_final_12_act_2
Model dir: /tmp/midori_act2
Weight URL: https://huggingface.co/MidoriChou/ai_final_12_act_2
Task: robotics ACT (action chunking transformer, vision ResNet18 + Transformer)
Loading backend: lerobot ACTPolicy (avoiding ResNet pretrained download)
Device: npu:0  torch_npu available: True
Device name: Ascend910_9362
Device count: 2
Dtype: float32
Config: chunk_size=100 n_action_steps=100 dim_model=512 n_heads=8 input [state 9 + 2x 480x640] output [100,8]
Model loaded: ACTPolicy (ACT) params: 51.60M
Model param device: npu:0
Backbone: resnet18 pretrained_weights=None
Input features: {'observation.state': PolicyFeature(type=<FeatureType.STATE: 'STATE'>, shape=(9,)), 'observation.images.wrist': PolicyFeature(type=<FeatureType.VISUAL: 'VISUAL'>, shape=(3, 480, 640)), 'observation.images.front': PolicyFeature(type=<FeatureType.VISUAL: 'VISUAL'>, shape=(3, 480, 640))}
Output features: {'action': PolicyFeature(type=<FeatureType.ACTION: 'ACTION'>, shape=(8,))}
Input batch: state [1, 9] front [1, 3, 480, 640] wrist [1, 3, 480, 640] device=npu:0
Output action chunk shape: [1, 100, 8] dtype=torch.float32 device=npu:0
Actions stats: min -1.0378 max 0.5410 mean -0.4532 std 0.5240
First action step (0): [0.5144097805023193, -0.8820395469665527, 0.1496983915567398, -1.0286544561386108, -0.8320924639701843, -0.18682166934013367, -0.8403946161270142, -0.5141306519508362]
Last action step (99): [0.5188236236572266, -0.834748387336731, 0.13544824719429016, -1.00600266456604, -0.8110915422439575, -0.1453414112329483, -0.8415082097053528, -0.5329388380050659]
Inference latency (synchronized, include transformer + ResNet18): 227.63 ms (first compile) / ~24 ms steady
PASS
  • 首轮耗时含图编译与缓存 (~227 ms), 稳态见第 7 节。
  • 真实 npu:0 参数设备已验证, 输出形状符合 ACT chunk 100×8。

6. CPU-NPU 一致性验证

python inference.py --mode validate (seed 42, 同输入同权重, float32):

CPU-NPU consistency (same seed=42, same input, float32):
  max_abs_diff 0.000627 mean 0.000317 median 0.000298
  Consistency: PASS (max_diff < 0.01)
  Sample CPU[0,0]: [0.5139882564544678, -0.8825832009315491, 0.1498299092054367, -1.0289244651794434, -0.8324450254440308, -0.18729375302791595, -0.8404298424720764, -0.5142483115196228]
  Sample NPU[0,0]: [0.5144097805023193, -0.8820395469665527, 0.1496983915567398, -1.0286544561386108, -0.8320924639701843, -0.18682166934013367, -0.8403946161270142, -0.5141306519508362]
PASS
  • Smoke consistency: 单 batch 1、100×8 动作块, 无 CPU fallback, 全量 npu:0 执行, 误差远小于表格类 1e-2 阈值。
  • 类型: 固定合成样例一致性验证 (非完整数据集轨迹评测)。

7. 性能测试

python inference.py --mode benchmark (batch 1, seed 42, float32, npu:0, 3 warmup + 10 measured, torch.npu.synchronize):

Benchmark (batch 1, state [9] + 2x [3,480,640], float32, npu:0):
  avg=24.03ms min=23.53ms max=25.08ms p50=23.76ms p90=24.59ms p95=24.83ms
  throughput: 41.62 samples/s (149819.7 windows/h)
  Peak HBM via npu-smi: idle ~3110 MB, with model ~3500 MB (<65536)
  • 首次 227 ms 为图编译开销, 稳态 24ms 为同步计时平均。
  • 资源: 单卡 51.6M 模型 + 双 480×640 ResNet18 激活 < 4GB, 远低于 64GB 上限。
  • 批量与精度说明: batch 1, float32, 预处理仅为随机生成 (不计时数据集加载)。

8. 自验证截图

  • assets/agent_workflow.png - 阶段日志: 下载、侦察、加载、NPU 推理、验证、性能
  • assets/npu_device_call.png - npu-smi info + torch.npu 可用性/设备名/参数 device/dtype/输入输出 device
  • assets/model_result.png - python inference.py 真实 NPU 输出与 PASS (xterm.js raw 渲染)

所有图片由 xterm.js 根据本次真实日志生成, 非手工绘制, 固定提示符仅为展示标签。

9. 已知限制

  • 单合成 batch 验证, 非 MidoriChou/ai_final_12 完整轨迹回放; 真实机器人需接入 lerobot dataset 的真实图像与归一化统计。
  • 规避了 ResNet18_Weights.IMAGENET1K_V1 的在线下载, 设 pretrained_backbone_weights=None 后由 model.safetensors 覆盖全部权重, 与官方训练权重一致但初始化路径不同。
  • 未启用 temporal_ensemble_coeff (为 None) 与 use_vae 训练模式差异; 推理时 latent 取零向量 (ACT 推理默认)。
  • 未测试多 batch、不同分辨率或 bfloat16; 仅验证 batch 1, 480×640, float32。
  • 需 trust_remote_code=False, 纯 lerobot + torch 实现, 无自定义 kernel, 未发生 CPU fallback。

10. 标签

Hardware: NPU, #NPU, Ascend, Ascend910, robotics, act, lerobot, action-chunking, diffusion-policy-variant

agent workflow npu device model result