eardoi/folding-latest-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

folding_latest 昇腾NPU部署文档

1. 模型简介

模型名称: folding_latest 模型链接: https://ai.gitcode.com/hf_mirrors/lerobot/folding_latest 模型描述: LeRobot π₀.₅ (Pi05) Vision-Language-Action 机器人折叠策略模型,基于 PaliGemma 3B 视觉语言模型与 Gemma 300M action expert,输入 3 路相机图像、16 维关节状态与任务文本,输出 16 维动作序列,适用于布料折叠等灵巧操作任务。 模型架构: VLA (Vision-Language-Action),PaliGemma 3B + Gemma 300M action expert + Diffusion 动作生成 参数规模: 3.62B(3616.8M)


1.5 适配说明(NPU)

本仓库为 folding_latest(Pi0.5 VLA 策略)在昇腾 NPU 上的部署实现,关键适配点:

  1. transformers fix/lerobot_openpi 分支:PI05 checkpoint 的 gemma_expert 使用新版 transformers 的 dense/adarms 结构(input_layernorm.dense.weight),必须使用 lerobot 官方指定的 fix/lerobot_openpi 分支(transformers 4.53.3)才能正确加载全部权重(813 keys 完整加载)。
  2. siglip check 兼容:注入 transformers.models.siglip.check mock 模块,跳过版本检查(推理本身不依赖)。
  3. relative/absolute actions 处理器:lerobot 0.4.4 注册表缺少这两个步骤,提供 relative_action_processor.py 兼容实现并在导入时注册,同时配对 preprocessor 的 relative 步骤给 postprocessor 的 absolute 步骤。
  4. dtype 统一:模型内部 vision_tower(fp32)与 projector(bf16)混用会导致 NPU LayerNorm 报 aclnnLayerNorm EZ1001(输入/权重 dtype 不一致),统一为 bf16 解决。
  5. config 字段过滤:config.json 含 type/use_relative_actions 等 lerobot 0.4.4 不支持的遗留字段,加载时按 PI05Config 合法字段过滤。

1.6 复现文档

完整的从零复现步骤(环境、依赖版本坑、权重下载、代码补丁、常见问题)见 REPRODUCE.md。

⚠️ 复现注意点(速览)

  1. transformers 必须用 fix/lerobot_openpi 分支(4.53.3):PI05 的 gemma_expert 权重含 input_layernorm.dense.weight 等 dense/adarms 结构,普通 pip 版 transformers 无法对齐(加载会大量 Missing keys)。inference.py 会自动优先加载 /opt/atomgit/tf_openpi_install 目录;配套 tokenizers 需 0.21.x(<0.22)。
  2. paligemma tokenizer 需本地化:模型配置引用 google/paligemma-3b-pt-224(gated 仓库无法直接下载),需从 GitCode 镜像 clone 并用 --tokenizer_dir 指定。
  3. 模型 dtype 统一 bf16:vision_tower(fp32)与 projector(bf16)混用会导致 NPU LayerNorm 报 aclnnLayerNorm EZ1001,脚本已内置 to(dtype=torch.bfloat16) 修复。
  4. lerobot 0.4.4 + Python 3.10:需给 groot_n1.py 的 GR00TN15Config 补 default=None(详见 REPRODUCE.md 坑 3),否则 make_pre_post_processors 导入失败。
  5. 权重下载:GitCode LFS 需认证,推荐 LFS batch API 拿 CDN 直链 + aria2c 16 线程(~28MB/s),详见 REPRODUCE.md 坑 4。

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch / torch_npu2.1.0+昇腾NPU推理
transformers>= 4.45.0HuggingFace 库
昇腾驱动CANN 8.0.RC2+推荐最新版

安装命令:

pip install torch torch_npu transformers sentencepiece

3. 推理步骤

3.1 环境准备

# 检查 NPU 设备
npu-smi info

3.2 运行推理

# 单条输入推理
python inference.py --input "测试输入内容" --model_path ./folding_latest

# 批量输入推理
python inference.py --input_file test_samples.txt --model_path ./folding_latest

3.3 推理参数说明

参数类型默认值说明
--inputstr-输入文本/图像路径
--input_filestr-批量输入文件路径
--model_pathstrfolding_latest模型路径
--max_lengthint2048最大生成长度

4. 测试样例及输出结果

样例 1:折叠衬衫任务(fold the shirt)

输入:

fold the shirt

输出:

动作序列形状 (5, 1, 16),首步动作: [0.9795, 0.8474, 0.3059, 5.1778, 2.64, 1.0784, -1.5538, -0.9359, 0.7393, -1.5548, -1.4784, 6.0992, -2.1656, -1.5668, 2.7531, -8.5305]

耗时: 1.08s(30 步动作,npu:0)

样例 2:折叠毛巾任务(fold the towel)

输入:

fold the towel

输出:

动作序列形状 (5, 1, 16),首步动作: [0.9649, 1.2778, 0.963, 5.4601, ...]

耗时: 0.65s(30 步动作,npu:0)

样例 3:折叠T恤任务(fold a t-shirt)

输入:

fold a t-shirt

输出:

动作序列形状 (5, 1, 16),首步动作: [0.5099, 1.1189, -0.0008, 5.5222, ...]

耗时: 0.65s(30 步动作,npu:0)


5. Agent适配截图

5.1 Agent适配全过程截图

Agent 适配流程

5.2 NPU设备调用截图

NPU 设备调用

5.3 模型适配结果截图

模型适配结果


6. NPU运行验证信息

测试样例NPU输出耗时是否成功运行
fold the shirt动作序列 (30,1,16),首步 [0.9795, 0.8474, 0.3059, 5.1778, ...1.08s✅ 成功
fold the towel动作序列 (30,1,16),首步 [0.9649, 1.2778, 0.963, 5.4601, ...0.65s✅ 成功
fold a t-shirt动作序列 (30,1,16),首步 [0.5099, 1.1189, -0.0008, 5.5222, ...0.66s✅ 成功

结论: 模型已在 NPU 上成功运行推理,满足验收要求。 说明: 根据最新规则,不再强制精度1%验证,本章节记录 NPU 运行验证结果。


7. 注意事项

  • 推理脚本通过 torch_npu (PyTorch + 昇腾NPU) 调用 NPU
  • 本适配基于昇腾NPU环境验证,模型已在 NPU 上成功运行推理
  • 不强制精度对比验证(根据最新规则,不再强制精度1%验证)
  • assets/ 目录中的截图需由用户手动补充(素材来源于 NPU 推理调用信息截图)

文档生成时间:2026-08-15 23:46:33