CANN Pi0.5昇腾训推实践
LeRobot 框架具身 VLA 模型昇腾训推实践【免费下载链接】cann-recipes-embodied-intelligence本项目针对具身智能业务中的典型模型、加速算法提供基于CANN平台的优化样例项目地址: https://gitcode.com/cann/cann-recipes-embodied-intelligence下表展示了在昇腾 A2 NPU 平台上基于 LeRobot 框架运行多项 LIBERO 典型任务的推理效果。通过必要的框架适配与环境配置昇腾平台成功实现了 VLA 模型在多任务场景下的端到端推理验证了训推方案的可用性和一致性。libero_spatial:pick up the black bowl from table center and place it on the platelibero_object:pick up the salad dressing and place it in the basketlibero_goal:put the wine bottle on top of the cabinetlibero_10:turn on the stove and put the moka pot on it围绕 LeRobot 在昇腾平台上的训推实践本文主要介绍环境准备、代码同步、训练、profiling 和评估的使用方式。关于pi05在昇腾上的性能优化细节、保留优化项和量化收益会在 doc/README.md 中展开。项目背景LeRobot是一个面向真实世界机器人应用的前沿机器学习框架致力于为模仿学习与强化学习提供高质量的模型、数据集和工具链。LeRobot 基于 PyTorch 构建旨在降低机器人学习的入门门槛推动社区在真实场景中的模型共享、数据协作与算法复用。框架集成了多种经验证可在真实机器人系统中有效部署的最先进方法并已发布一系列预训练模型、人工采集的演示数据集以及仿真实验环境便于研究者和开发者快速上手。所有模型与数据均托管于 LeRobot Hugging Face 页面支持一键加载与复现。在本案例中我们在昇腾 A2 AI 加速器上完成了 LeRobot 框架的迁移适配成功运行了多种视觉-语言-动作Vision-Language-Action, VLA模型在多个机器人基准测试任务上实现了端到端的训练与推理。此外还围绕 π₀.₅ 模型在 LIBERO 上的模仿学习训练做了针对昇腾平台的性能分析与优化。环境准备与代码同步CANN 相关环境配置安装 CANN 软件包。本样例的编译执行依赖 CANN 开发套件包cann-toolkit与 CANN 二进制算子包cann-kernels支持的 CANN 软件版本为8.3.RC1。请从软件包下载地址下载Ascend-cann-toolkit_8.3.RC1_linux-aarch64.run与Ascend-cann-kernels-910b_8.3.RC1_linux-aarch64.run并参考 CANN 安装文档依次进行安装。LeRobot 相关环境配置与安装完成 CANN 环境配置后可通过以下步骤获取样例代码并初始化环境。setup.sh作为总入口会编排setup_lerobot.sh、setup_cmake.sh、setup_deps.sh三个模块完成 LeRobot 指定版本同步、conda 环境准备、基础依赖安装以及 PI05 所需额外依赖和脚本覆盖。cd your-workdir git clone https://gitcode.com/cann/cann-recipes-embodied-intelligence.git chmod x cann-recipes-embodied-intelligence/manipulation/pi05/train/src/scripts/setup.sh ./cann-recipes-embodied-intelligence/manipulation/pi05/train/src/scripts/setup.sh网络受限环境可先指定 CMake 国内镜像备用地址默认已内置清华镜像可按需覆盖export CMAKE3_MIRROR_URLhttps://mirrors.tuna.tsinghua.edu.cn/kitware/cmake/v3.28/cmake-3.28.3.tar.gz ./cann-recipes-embodied-intelligence/manipulation/pi05/train/src/scripts/setup.sh默认目录关系如下your-workdir/ ├── cann-recipes-embodied-intelligence/ └── lerobot/当前样例默认锁定到以下经过 Python 3.10 / CANN 8.3 实测兼容的版本组合避免后续 LeRobot 或 PyTorch 继续更新导致适配失效LeRobot versionv0.4.4LeRobot commit8fff0fde7c79f23a93d845d1a50e985de01f8b8aPython3.10torch2.8.0torchvision0.23.0torch_npu2.8.0.post2torch_npu 运行时依赖pyyaml attrs psutil decorator cloudpickle scipy tornado ml-dtypestorch_npu 可复用依赖absl-py若运行环境中已存在系统预装且只读的absl-py脚本会检测到后直接复用不再强制升级torchcodec固定为0.7.0对应 git tagv0.7.0aarch64 下需要源码安装当前 PI05/transformers 导入链必需torchcodec 源码获取优先级已安装的torchcodec0.7.0-TORCHCODEC_LOCAL_DIR/ 默认${ROOT_DIR}/torchcodec本地缓存 -TORCHCODEC_GIT_PRIMARY_URL默认 GitCode 镜像- GitHub 官方仓库torchcodec 构建前置在 conda 环境中执行conda install -y -c conda-forge ffmpeg7.1.1 pkg-configtorchcodec 构建参数设置TORCHCODEC_DISABLE_COMPILE_WARNING_AS_ERROR1避免ffmpeg 7.1.1的弃用告警导致v0.7.0编译失败torchcodec 库发现脚本会导出PKG_CONFIG_PATH${CONDA_PREFIX}/lib/pkgconfig:${CONDA_PREFIX}/share/pkgconfig:${PKG_CONFIG_PATH}并检查libavdevice libavfilter libavformat libavcodec libavutil libswresample libswscaleCMake 源码下载默认先尝试官方地址失败后自动回退到CMAKE3_MIRROR_URL默认清华镜像CANN8.3.RC1如需切换 LeRobot 代码版本请显式传入--lerobot-ref commit|tag|branch若仅需要同步源码到指定目录可传入--sync-only --lerobot-dir path若确认要覆盖目标lerobot目录中的本地修改可追加--force。如需单独手动安装torchcodec推荐在lerobot环境中执行以下命令conda activate lerobot conda install -y -c conda-forge ffmpeg7.1.1 pkg-config cd /home/ma-user/work/torchcodec git fetch --tags --force git checkout -f v0.7.0 export TORCHCODEC_DISABLE_COMPILE_WARNING_AS_ERROR1 export CMAKE/home/ma-user/.local/cmake3/bin/cmake export CMAKE_PREFIX_PATH$(python -m pybind11 --cmakedir):/home/ma-user/.local/cmake3:${CONDA_PREFIX}:${CMAKE_PREFIX_PATH} export PKG_CONFIG_PATH${CONDA_PREFIX}/lib/pkgconfig:${CONDA_PREFIX}/share/pkgconfig:${PKG_CONFIG_PATH} python -m pip install -e . --no-build-isolation -v完成上述操作之后对应的项目文件结构请参考附录部分正确安装后项目文件结构。分布式训练与 Profiling本目录下训练与 profiling 的入口脚本分别为训练脚本manipulation/pi05/train/src/scripts/run_train.shprofiling 脚本manipulation/pi05/train/src/scripts/run_profiling.sh如果你只是想先把流程跑通用这里的命令即可如果你还想知道当前默认训练路径里已经包含了哪些优化、这些优化为什么有效以及 profiling 结果应该怎么看再去看 doc/README.md。从零开始复现时建议按下面的顺序执行先执行src/scripts/setup.sh完成 LeRobot 代码同步、conda 环境准备和依赖安装。模块化入口分别为src/scripts/setup_lerobot.sh、src/scripts/setup_cmake.sh、src/scripts/setup_deps.sh默认由setup.sh自动编排。激活lerobot环境后进入src/scripts/目录。训练使用./run_train.sh pi05 --nproc 2 --disable-outer-suffix-checkpoint。profiling 使用./run_profiling.sh pi05 --nproc 2 --foreground --disable-outer-suffix-checkpoint --profile-wait 1 --profile-warmup 1 --profile-active 2 --profile-repeat 1。如模型和数据已缓存到本地可再打开HF_HUB_OFFLINE1、TRANSFORMERS_OFFLINE1和HF_DATASETS_OFFLINE1缩短启动等待时间。推荐训练命令cd cann-recipes-embodied-intelligence/manipulation/pi05/train/src/scripts ./run_train.sh pi05 --nproc 2 --disable-outer-suffix-checkpoint推荐 profiling 命令cd cann-recipes-embodied-intelligence/manipulation/pi05/train/src/scripts ./run_profiling.sh pi05 \ --nproc 2 \ --foreground \ --disable-outer-suffix-checkpoint \ --profile-wait 1 \ --profile-warmup 1 \ --profile-active 2 \ --profile-repeat 1补充说明--disable-outer-suffix-checkpoint是当前建议显式保留的启动参数是性能优化收益最大的一项。其他已经验证保留的优化例如sample_betafast path、PaliGemma QKV fusion、npu_fusion_attention、Gemma MLP grouped GEMM 以及 PI05 的 DDP 默认配置已经吸收到当前脚本和模型实现中不需要额外手工打开。评估脚本使用说明本案例提供了一个通用的评估启动脚本run_eval.sh用于在昇腾单机环境下启动 VLA 模型的评估任务。该脚本对以下功能进行了统一封装自动配置无头渲染环境Xvfb OSMesa支持多种评估环境libero/aloha/pusht等自动加载评估配置并执行推理输出目录与日志自动管理快速开始确保已激活包含lerobot和 PyTorch 的 conda 环境并完成 Ascend 驱动与 CANN 环境配置后执行以下命令cd cann-recipes-embodied-intelligence/manipulation/pi05/train/src/scripts chmod x run_eval.sh ./run_eval.sh支持的命令行选项脚本支持两种使用方式默认评估无参数时运行官方smolvla的libero评估任务。自定义评估传入参数时直接透传给lerobot_eval脚本支持所有lerobot_eval的命令行选项。常用lerobot_eval选项包括选项说明--policy.path path指定模型策略路径例如 Hugging Face 模型或本地 checkpoint--env.type type评估环境类型例如libero、aloha、pusht--env.task task具体任务名称例如libero_object、libero_spatial--eval.batch_size N评估批次大小默认1--eval.n_episodes N评估回合数默认1--policy.device device指定设备例如npu、cuda--output_dir path输出目录路径-h,--help显示lerobot_eval的帮助信息使用示例# 示例 1运行默认评估任务smolvla libero_object ./run_eval.sh # 示例 2评估自定义模型在 libero_spatial 任务上 ./run_eval.sh --policy.path/path/to/your/model --env.typelibero --env.tasklibero_spatial --eval.n_episodes10 --output_dir./my_eval_output # 示例 3评估 aloha 环境中的任务 ./run_eval.sh --policy.pathHuggingFaceVLA/smolvla_aloha --env.typealoha --env.taskaloha_mobile --policy.devicenpu # 示例 4查看所有可用选项 ./run_eval.sh --help补充说明脚本会自动启动虚拟显示Xvfb并配置 OSMesa 无头渲染确保在无 GUI 环境下正常运行。评估结果会保存在指定的output_dir中包括日志、视频和性能指标。如需保存控制台日志可使用./run_eval.sh eval.log 21的方式重定向。在昇腾环境上执行时请确认--policy.devicenpu已正确设置。Citationmisc{cadene2024lerobot, author {Cadene, Remi and Alibert, Simon and Soare, Alexander and Gallouedec, Quentin and Zouitine, Adil and Palma, Steven and Kooijmans, Pepijn and Aractingi, Michel and Shukor, Mustafa and Aubakirova, Dana and Russi, Martino and Capuano, Francesco and Pascal, Caroline and Choghari, Jade and Moss, Jess and Wolf, Thomas}, title {LeRobot: State-of-the-art Machine Learning for Real-World Robotics in Pytorch}, howpublished \url{https://github.com/huggingface/lerobot}, year {2024} }附录正确安装后项目文件结构├── cann-recipes-embodied-intelligence/ # CANN 具身智能案例仓库主目录 │ └── manipulation/ │ └── pi05/ │ └── train/ # pi05 模型昇腾训推项目目录 │ ├── assets/ # 示例图片资源 │ ├── doc/ │ │ └── README.md # 性能优化、profiling 与最佳实践统一说明 │ ├── src/ │ │ ├── scripts/ # 一键部署与运行脚本 │ │ │ ├── setup.sh # 总入口调用模块脚本完成初始化与依赖安装 │ │ │ ├── setup_lerobot.sh # LeRobot 同步与基础环境准备 │ │ │ ├── setup_cmake.sh # CMake 3.x 检查、下载与安装 │ │ │ ├── setup_deps.sh # PI05/Libero/torchcodec/torch_npu 依赖安装 │ │ │ ├── run_train.sh # 分布式训练启动脚本 │ │ │ ├── run_eval.sh # 模型评估启动脚本 │ │ │ └── run_profiling.sh # 分布式训练性能采集脚本 │ └── README.md # LeRobot 昇腾训推项目使用说明 │ └── lerobot/ # LeRobot 智能机器人基础框架 ├── configs/ │ ├── pi05.yaml # Pi05 模型训练配置文件 │ └── xxx.yaml # 其他模型配置文件 └── src/ └── lerobot/ ├── policies/ │ └── pi05/ │ └── modeling_pi05.py # Pi05 模型架构代码 ├── scripts/ │ ├── lerobot_train.py # LeRobot 通用训练入口 │ ├── lerobot_eval.py # LeRobot 通用评估入口 │ └── lerobot_train_profiling.py # 支持 Ascend Profiling 的训练脚本 └── utils/ └── utils.py # 工具函数适配昇腾NPU【免费下载链接】cann-recipes-embodied-intelligence本项目针对具身智能业务中的典型模型、加速算法提供基于CANN平台的优化样例项目地址: https://gitcode.com/cann/cann-recipes-embodied-intelligence创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考