
model.safetensors 865MB + preprocessor/postprocessor safetensors, FP32, ~0.45B 参数observation.state [8] (MEAN_STD归一, stats 8-dim), 语言指令 task (tokenizer HuggingFaceTB/SmolVLM2-500M-Video-Instruct, max_length 48, pad max_length)action [1, 50, 7] (50步, 7维 LIBERO末端控制), 经 postprocess 反归一, 有限浮点make_pre_post_processors 含 rename_observations, to_batch, smolvla_new_line, tokenizer (max 48, right padding), device_processor, normalizer (STATE MEAN_STD 8-dim, VISUAL IDENTITY, ACTION MEAN_STD 7-dim)/opt/atomgit/.cache/huggingface/hub/models--lerobot--smolvla_libero/snapshots/31d453f7edd78c839a8bbc39744a292686daf0de (865MB safetensors, 本地加载 local_files_only=True)smolvlm_with_expert.py:80 的 torch_dtype="bfloat16" 改为 "float32" 以支持 NPU (aclSearchSorted 不支持 BF16), groot_n1.py:175 加 kw_only=True 解决 Python 3.11 dataclass 继承错误; 未移动关键模块到 CPU, 所有浮点输入、模型参数、输出均在 npu:0pip install -r requirements.txt
# torch==2.9.0
# torch_npu==2.9.0.post1
# lerobot==0.4.4 (from /tmp/lerobot_v044/src, with float32 patch)
# transformers==4.51.3
# huggingface_hub==0.34.0
# tokenizers==0.21.1
# diffusers==0.40.0
# pyarrow==25.0.1
# safetensors, numpy==1.26.4, Pillow, einops, num2wordspython inference.py核心逻辑 (inference.py:1):
SmolVLAPolicy.from_pretrained(..., local_files_only=True).to("npu:0"), 验证 next(policy.parameters()).device == npu:0, vision_model/vlm/expert 均在 npu:0make_pre_post_processors 分别放至 cpu / npu:0torch.randn(1,50,32) 在 CPU 生成后 clone().to(npu:0) 保证对比公平torch.npu.synchronize() 前后, 预热 3次, 正式10次执行命令: python inference.py (在 npu:0 真实执行, 权重来自本地)
[MODEL] lerobot/smolvla_libero revision 31d453f7edd78c839a8bbc39744a292686daf0de
[ROUTE] manipulation-vla (SmolVLA LIBERO, chunk_size=50, action_dim=7, state_dim=6*->8, n_action_steps=50, num_steps=10, 3 cameras)
[INFO] torch_npu_available: True, device_count: 2, device_name: Ascend910_9362
[INFO] CPU policy loaded in 13.5s, device: cpu
[INFO] CPU chunk done 18.08s shape (1, 50, 7) device cpu
[INFO] NPU policy loaded in 11.4s, device: npu:0
[INFO] NPU input devices: observation.state npu:0, observation.images.camera1 npu:0, tokens npu:0
[INFO] Warmup done (3 runs)
[RUN 0] latency 266.03 ms, shape (1, 50, 7), device npu:0
[RUN 1] latency 265.28 ms, shape (1, 50, 7), device npu:0
...
[RESULT] Action chunk shape: (1, 50, 7), horizon 50, dim 7
[RESULT] First action (7 dims): [-0.323508, 0.128169, -0.304565, 0.113258, 0.342814, 0.349565, 0.971105]
[RESULT] Last action (7 dims): [-0.342580, 0.092388, 0.271305, -0.010859, 0.605292, 0.476812, -0.912551]
[RESULT] Finite: True, max_abs vs CPU: 0.000044, mae: 0.000006, tolerance FP32 0.001383
[RESULT] CPU_NPU_consistency: PASS (atol=1e-4 rtol=1e-3)
[PERF] avg 259.59 ms, min 249.22, max 266.03, p50 261.88, p90 266.03, p95 266.03
[PERF] actions/s 192.61, chunks/s 3.85, batch=1, 3x256x256->512, horizon 50, steps 10, dtype float32
[RESULT] PASStorch.randn(1,50,32) seed999再搬运至NPU)、同 dtype float32、同 10步 flow、同 predict_action_chunkpython .opencode/skills/npu_adapt_robotics/scripts/validate_policy_outputs.py --cpu /tmp/cpu_smolvla.json --npu /tmp/npu_smolvla.json --atol 1e-4 --rtol 1e-3atol 5e-3 rtol 5e-2 也为 true (tolerance 0.069)lerobot/policies/smolvla/smolvlm_with_expert.py:80 的 torch_dtype="bfloat16" 改为 "float32", 因 NPU 上 torch.bucketize 不支持 BF16, 并确保 embed_image 使用 float32; 未移动关键模块到 CPU, 所有浮点输入、模型参数、输出均在 npu:0 上 (已记录 device)python .opencode/skills/npu_adapt_robotics/scripts/benchmark_policy.py --latencies-ms /tmp/latencies.json --items-per-call 50 --unit actions{"actions_per_s": 192.61, "avg_ms": 259.59, "max_ms": 266.03, "min_ms": 249.22, "p50_ms": 261.88, "p90_ms": 266.03, "p95_ms": 266.03, "samples": 10}actions/s (50 actions per chunk), chunks/s 3.85, batch=1, 3x512x512 图像, horizon 50, steps 10, dtype float32, 含预处理后的纯模型计时 (torch.npu.synchronize 前后).
├── inference.py # 默认 python inference.py 一键 NPU 推理 + 一致性/性能打印
├── readme.md # 本文 (含三图引用)
├── requirements.txt # 精简依赖
└── assets/
├── agent_workflow.png
├── npu_device_call.png
└── model_result.pnginference.py 默认即验证: 打印模型/revision/route/backend/device/dtype/输入摘要/动作摘要/同步耗时/PASS/FAIL# 环境检查
npu-smi info
python .opencode/skills/npu_adapt_robotics/scripts/check_npu.py
# 推理 (自动含 CPU-NPU 对比与性能)
python inference.py
# 单独一致性 (已在 inference.py 内生成 /tmp/cpu_smolvla.json /tmp/npu_smolvla.json)
python .opencode/skills/npu_adapt_robotics/scripts/validate_policy_outputs.py --cpu /tmp/cpu_smolvla.json --npu /tmp/npu_smolvla.json
python .opencode/skills/npu_adapt_robotics/scripts/benchmark_policy.py --latencies-ms /tmp/latencies.json --items-per-call 50 --unit actionssnapshot_download lerobot/smolvla_libero 至 cache, 或自动回落至 Hub (已验证本地 865MB)HuggingFaceVLA/smolvla_libero (2相机 8-state) 与 lerobot/smolvla_base (3相机 6-state) 的验证仓