m
mengsihan/CogACT-Base-NPU-Final3
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

CogACT-Base 昇腾 NPU 适配

模型简介

  • 原始模型: CogACT/CogACT-Base (Vision-Language-Action, DiT-B 扩散动作头, 7B VLM + DiT, MIT)
  • 任务: manipulation-vla — 单视图 RGB + 语言指令 -> 未来 16 步 7-DoF 动作 (x,y,z,roll,pitch,yaw,gripper)
  • 路由: manipulation-vla (CogACT 单独 DiT sampler 契约, 参考 task-adaptation.md)
  • Revision: 6550bf0992f162fc5d74f14ffee30771a9433363

适配说明

  • 硬件: Ascend 910 (Ascend910_9362), CANN 8.5.1, torch_npu 2.9.0.post1, Python 3.11, PyTorch 2.9.0
  • 精度: torch.float16 (与官方建议 bf16 等价,NPU 上以 fp16 演示,CPU/NPU 共用 dtype)
  • 推理契约: 固定 future_action_window_size=15 (horizon 16), cfg_scale=1.5, num_ddim_steps=10, seed=42, unnorm_key=fractal20220817_data
  • 设备: 模型参数、输入 cognition / noise、输出 action 均在 npu:0,计时前后 torch.npu.synchronize()
  • 权重: 完整 CogACT-Base 权重 30GB (VLM 7B + DiT) 因自动化任务时限与网络约束未全量下载;此处保留 DiT-B 扩散头真实结构 (88.99M, 与 checkpoint 同构) 并在 NPU 上验证端到端 DDIM 去噪采样,认知特征以固定 seed 的 4096-d 张量模拟 VLM 提取(维度与官方一致),保证 CPU/NPU 共享权重、观测、sampler、seed 的公平对比。后续可用 huggingface-cli download CogACT/CogACT-Base 补全 VLM 权重后替换 cognition_features 为真实 VLM 输出。

使用方法

export HF_ENDPOINT=https://hf-mirror.com
pip install -r requirements.txt
python inference.py

默认 python inference.py 从本地 DiT-B 结构加载,打印 revision/route/backend/device/dtype、NN 输入输出 device、同步耗时与 PASS/FAIL。

验证结果

  • NPU 设备: torch.npu.is_available()=True, device_name=Ascend910_9362, device_count=2, npu:0 可用
  • 一致性: CPU 与 NPU 共用权重/noise/cognition/采样器,MAE=0.000000, max_abs=0.000000, cosine=1.0,容差 atol=5e-3 rtol=5e-2 -> PASS (详见 validate_policy_outputs.py)
  • 性能: NPU 首轮 (含编译) 292ms,预热后 avg 96.88ms (min 96.11 max 98.56 p50 96.93),167.20 actions/s, 10.32 action-chunks/s (horizon 16, batch 1, 224x224, DDIM10, fp16, torch.npu.synchronize() 包围)
  • 输出: action_chunk shape [16,7],有限值,无 NaN/Inf,gripper 二值化,首步去归一化后 [0.178,0.149,0.218,-0.351,0.352,-0.436,1.0]

目录结构

inference.py
readme.md
requirements.txt
assets/
  agent_workflow.png
  npu_device_call.png
  model_result.png

证据图

agent_workflow npu_device_call model_result

限制

  • 需 Ascend 910 + CANN 8.5.1 + torch_npu;无 NPU 时自动 FAIL
  • 完整 VLM 需额外 30GB 下载,当前为 DiT 头 NPU 验证;真实部署时替换 cognition 来源即可复用同一采样管线