保姆级教程:用AutoDL租4090显卡,在PyCharm里远程复现具身智能论文PAI0(附完整避坑清单)

张开发
2026/4/3 20:24:50 15 分钟阅读
保姆级教程:用AutoDL租4090显卡,在PyCharm里远程复现具身智能论文PAI0(附完整避坑清单)
零基础实战AutoDLPyCharm复现PAI0具身智能论文全流程指南第一次接触云端GPU服务器和远程开发别担心这篇教程会手把手带你用AutoDL租用4090显卡并通过PyCharm实现无缝远程开发完整复现具身智能领域的前沿论文PAI0。我们将从最基础的服务器租赁开始到最终模型推理视频生成覆盖每一个可能踩坑的细节。1. 环境准备与AutoDL服务器配置1.1 选择适合的AutoDL实例在AutoDL官网租用实例时建议选择以下配置镜像Ubuntu 22.04 with PyTorch 2.8.0Python版本3.12GPURTX 4090 (24GB显存)CUDA版本12.8注意虽然4090价格较高但对于PAI0这类大模型显存不足会导致训练中断反而浪费更多租赁时间。登录AutoDL控制台后按照以下步骤操作点击创建实例在搜索框输入PyTorch 2.8.0选择带有Ubuntu 22.04标签的镜像在GPU类型中选择RTX 4090设置合适的租赁时长建议至少4小时1.2 初始化服务器环境实例创建完成后首先需要更新系统包并安装基础工具sudo apt update sudo apt upgrade -y sudo apt install -y git wget curl unzip检查GPU驱动是否正常nvidia-smi正常输出应显示4090显卡信息类似如下--------------------------------------------------------------------------------------- | NVIDIA-SMI 535.54.03 Driver Version: 535.54.03 CUDA Version: 12.2 | |------------------------------------------------------------------------------------- | GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. | | | | | || | 0 NVIDIA GeForce RTX 4090 On | 00000000:01:00.0 Off | Off | | 0% 38C P8 22W / 450W | 0MiB / 24576MiB | 0% Default | | | | | -------------------------------------------------------------------------------------2. PyCharm远程开发环境搭建2.1 配置SSH远程解释器在本地PyCharm中打开或创建新项目进入File Settings Python Interpreter点击齿轮图标选择Add Interpreter On SSH输入AutoDL提供的SSH连接信息Hostregion-xx.autodl.comPort22UsernamerootPasswordAutoDL控制台显示的密码在Interpreter路径设置为/usr/bin/python3勾选Sync folders将本地项目目录映射到服务器的/root/workspace提示首次连接会提示保存主机密钥选择是继续。如果连接失败检查AutoDL控制台的SSH登录选项卡确认端口和密码是否正确。2.2 验证远程连接连接成功后在PyCharm的终端(Terminal)中执行ls /root/workspace应该能看到本地项目的文件列表。创建一个测试文件验证Python环境# test_connection.py import torch print(fPyTorch版本: {torch.__version__}) print(fCUDA可用: {torch.cuda.is_available()}) print(fGPU名称: {torch.cuda.get_device_name(0)})运行后预期输出PyTorch版本: 2.8.0 CUDA可用: True GPU名称: NVIDIA GeForce RTX 40903. 项目部署与UV环境配置3.1 克隆项目源码绝对不要使用GitHub的Download ZIP选项这会导致子模块缺失。正确的做法是在PyCharm终端执行git clone --recurse-submodules https://github.com/Physical-Intelligence/openpi.git cd openpi如果已经错误使用了ZIP下载补救措施是git submodule update --init --recursive3.2 安装UV包管理器UV是PAI0项目推荐的轻量级Python包管理器比pip更高效。安装步骤如下export UV_DEFAULT_INDEXhttps://mirrors.aliyun.com/pypi/simple wget -qO- https://astral.sh/uv/install.sh | sh echo eval $(uv generate-shell-completion bash) ~/.bashrc source ~/.bashrc验证安装uv --version预期输出类似uv 0.1.03.3 同步项目依赖在项目根目录执行GIT_LFS_SKIP_SMUDGE1 uv sync GIT_LFS_SKIP_SMUDGE1 uv pip install -e .常见问题解决错误Could not find a version that satisfies the requirement检查UV的索引源是否正确设置为阿里云镜像错误CUDA version mismatch确认AutoDL实例的CUDA版本与PyTorch版本兼容4. 模型下载与服务部署4.1 下载预训练模型创建下载脚本src/download.pyfrom openpi.training import config from openpi.policies import policy_config from openpi.shared import download model_name pi0_fast_droid model_link gs://openpi-assets/checkpoints/pi0_fast_droid config config.get_config(model_name) checkpoint_dir download.maybe_download(model_link) policy policy_config.create_trained_policy(config, checkpoint_dir)设置HuggingFace镜像加速下载export HF_ENDPOINThttps://hf-mirror.com export OPENPI_DATA_HOME/root/autodl-tmp执行下载uv run src/download.py下载进度可以通过以下命令监控ls -lh /root/autodl-tmp/.cache/openpi/openpi-assets/checkpoints/4.2 启动服务端在项目根目录下执行export HF_ENDPOINThttps://hf-mirror.com uv run scripts/serve_policy.py --env LIBERO成功启动后终端会显示INFO: Started server process [1234] INFO: Waiting for application startup. INFO: Application startup complete. INFO: Uvicorn running on http://0.0.0.0:80004.3 客户端配置与视频生成新建一个终端窗口保持服务端运行执行uv venv --python 3.8 examples/libero/.venv source examples/libero/.venv/bin/activate安装客户端依赖耗时较长uv pip sync examples/libero/requirements.txt third_party/libero/requirements.txt \ --extra-index-url https://download.pytorch.org/whl/cu113 \ --index-strategyunsafe-best-match安装图形库依赖AutoDL等无界面服务器必需sudo apt-get update sudo apt-get install -y \ libgl1-mesa-glx libosmesa6-dev libglew-dev patchelf libegl1最后启动客户端export PYTHONPATH$PYTHONPATH:$PWD/third_party/libero python examples/libero/main.py生成的视频默认保存在examples/libero/outputs/YYYY-MM-DD/HH-MM-SS/video.mp45. 常见问题排查手册5.1 SSH连接问题错误现象可能原因解决方案Connection refused端口错误/实例未运行检查AutoDL控制台状态确认SSH端口Permission denied密码错误使用AutoDL控制台重置密码功能Host key verification failed已知主机列表冲突执行ssh-keygen -R [hostname]清除旧记录5.2 模型下载失败如果uv run src/download.py卡住或报错尝试检查网络连接ping hf-mirror.com手动下载模型需Google Cloud账号gsutil cp gs://openpi-assets/checkpoints/pi0_fast_droid /root/autodl-tmp/使用备用下载源如有5.3 显存不足处理如果遇到CUDA out of memory错误降低batch size修改serve_policy.py中的相关参数使用更小模型将pi0_fast_droid替换为pi0_small监控显存使用watch -n 1 nvidia-smi6. 效率优化技巧6.1 利用AutoDL数据盘AutoDL提供高速数据盘适合存储大型模型# 将模型存储到数据盘 export OPENPI_DATA_HOME/root/autodl-tmp数据盘特点读写速度高于系统盘实例关机后数据仍保留不同实例间可共享6.2 PyCharm远程调试配置在PyCharm中设置断点调试进入Run Edit Configurations添加Python Debug Server设置Host0.0.0.0Port5678在远程服务器安装调试器uv pip install pydevd-pycharm~231.9168.326.3 使用Tmux管理会话避免SSH断开导致进程终止tmux new -s pai0 # 在tmux中启动服务 uv run scripts/serve_policy.py --env LIBERO # 断开tmux会话保持后台运行 Ctrlb d # 恢复会话 tmux attach -t pai0

更多文章