Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
8154a87
add lerobot dataset support
mehhl Dec 22, 2024
f11844a
fix indexing issue w/ gradient acc
mehhl Dec 22, 2024
0a15af2
prettify OpenVLALeRobotDataset
mehhl Dec 22, 2024
234b4cf
Update README.md
mehhl Dec 23, 2024
3262db0
added script for converting raw nomagic-ur5e to lerobot
mehhl Dec 27, 2024
3fd90e5
fixes and parametrizations to nomagic-ur5e converter
mehhl Dec 27, 2024
91a81ae
revamp of nomagic ur5e -> lerobot converter
mehhl Dec 28, 2024
93ab2aa
remove infinite tolerance from finetune.py
mehhl Dec 28, 2024
f12d327
fixed ep length calculation
mehhl Dec 28, 2024
180b9e4
added video clipping to match trajs
mehhl Dec 28, 2024
8cb586d
fix no frame match for last timestep issue
mehhl Dec 28, 2024
c718bc7
added action normalization and fixed __len__ in OpenVLALeRobotDataset
mehhl Dec 30, 2024
12eae3b
correct episode index writing into trajectory file
mehhl Dec 30, 2024
e896cb2
Numerous fixes
mehhl Dec 30, 2024
3579dd3
added fientune.py outdirs to .gitignore
mehhl Dec 30, 2024
2966fdb
fixes to loop design in finetune.py
mehhl Dec 31, 2024
50bfede
numerous fixes in conversion to lerobot
mehhl Jan 17, 2025
0ca0e83
updated finetune.py
Feb 11, 2025
202edc8
containerization
Feb 20, 2025
3758245
Public release: OpenVLA-OFT
moojink Feb 28, 2025
9bccb2a
Update README: Add arXiv link
moojink Feb 28, 2025
40d6c89
Update finetune.py: Sync model files on master process only
moojink Mar 1, 2025
a45877f
Update ALOHA.md: Add ALOHA fine-tuning & eval instructions
moojink Mar 1, 2025
588f9f9
Update LIBERO.md: Add lfs to git clone command
moojink Mar 7, 2025
2fde5e9
Update ALOHA eval instructions and VRAM usage note
moojink Mar 7, 2025
0b75f6f
Update openvla_utils.py: Add torch.inference_mode() to get_vla_action()
moojink Mar 7, 2025
7f9efa6
Update README: Update ALOHA VRAM usage to 18 GB
moojink Mar 7, 2025
d8bf499
Update aloha/constants.py: 25 Hz control, updated task configs
moojink Mar 8, 2025
b9d7702
Update ALOHA.md: Remove comment about Python 3.8.10
moojink Mar 8, 2025
edc1f9e
Update BibTeX in README
moojink Mar 9, 2025
d92167c
Merge remote-tracking branch 'finetuner/main' into merge-finetuner-ch…
Mar 13, 2025
408568d
moved lerobot submodule to third_party subdir
Mar 13, 2025
a90df8e
impl devcontainer
Mar 13, 2025
7a14a1b
rm unused submodule
Mar 13, 2025
54a215e
rm old lerobot conv script
Mar 13, 2025
b9307f6
merged manual create env script to new fork
Mar 13, 2025
9c34d07
debugging finetuning
Mar 13, 2025
baf52f0
Merge remote-tracking branch 'openvla-oft/main' into 4-investigate-an…
Mar 16, 2025
016412d
Merge commit '9c34d079d1269d68006073ae67317263c0f57a6c' into 4-invest…
Mar 17, 2025
55f2713
add ur5e constants
Mar 18, 2025
7d1b76c
properly stack wrist imgs onto side img
Mar 18, 2025
1f3b5fb
log to wandb using total step idx
Mar 18, 2025
b6d5a3b
Revert "log to wandb using total step idx"
mehhl Mar 18, 2025
fa91eb3
actually log to wandb using total step idx
mehhl Mar 18, 2025
19c4960
more explicit wrapping of image transforms
mehhl Mar 19, 2025
3e4bd34
separate utils location for lerobotdataset
mehhl Mar 19, 2025
b3b256d
utils to get dataset stats from lerobotd
mehhl Mar 19, 2025
52a8faf
rm dangling import
Mar 20, 2025
febdc9f
better traceback from no-norm-stats val error
Mar 20, 2025
c47a20f
minor fixes to new finetune utils
Mar 20, 2025
b217a5b
undo syntax error in finetune.py
Mar 20, 2025
4ed6286
rm unused code in finetune.py
Mar 20, 2025
705e292
trajectory-based train/val split
mehhl Mar 24, 2025
f8507eb
add param to pick constants.py cfg
mehhl Mar 24, 2025
2598f4b
Merge branch '4-investigate-and-likely-switch-to-openvla-oft' of http…
mehhl Mar 24, 2025
82e2aa9
adding robot_interface as dependency
Mar 29, 2025
2a32510
trajectory-based train/val split
mehhl Mar 24, 2025
090b6dd
add param to pick constants.py cfg
mehhl Mar 24, 2025
19d1059
Merge branch '4-investigate-and-likely-switch-to-openvla-oft' of http…
Mar 29, 2025
167dfcb
minor fixes to dockerfile
Mar 29, 2025
af33079
change base branch in dockerfile
Mar 29, 2025
3dbaff8
revert to 2598b4f
mehhl Apr 9, 2025
dd70fe4
6 debug data format differences between finetuning and evaluation (#7)
mehhl Apr 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "OpenVLA Development",
"dockerComposeFile": "docker-compose.yml",
"service": "devcontainer",
"workspaceFolder": "/workspace/openvla",
"containerEnv": {
"PYTHONPATH": "${containerWorkspaceFolder}"
},
"remoteEnv": {
// Environment variables will be loaded from .env
},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-toolsai.jupyter",
"github.copilot"
],
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.provider": "black",
"editor.formatOnSave": true,
"editor.rulers": [121]
}
}
},
"remoteUser": "root",
"postCreateCommand": "pip install -e .",
// Load environment variables from .env file
"features": {
"ghcr.io/devcontainers/features/dotnet:1": {}
}
}
28 changes: 28 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
services:
devcontainer:
build:
context: ..
dockerfile: ./Dockerfile
working_dir: /workspace/openvla
command: sleep infinity
volumes:
- ..:/workspace/openvla:cached
- finetuner-cache:/root/.cache
- ${HOME}/.cache/huggingface:/root/.cache/huggingface # use cached models/datasets from host
environment:
- WANDB_API_KEY=${WANDB_API_KEY}
- WANDB_MODE=online
- HF_HOME=/root/.cache/huggingface
- HF_TOKEN=${HF_TOKEN}
shm_size: 16gb
network_mode: host
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]

volumes:
finetuner-cache:
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Prevent these from being sent to Docker daemon
.git/
.venv/
__pycache__/
*.py[cod]
.DS_Store
.env
data/
.runs/
.adapter/
*.swp
*.swo
*.log
3 changes: 3 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
HF_TOKEN=
WANDB_API_KEY=
WANDB_PROJECT="ur5e"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,6 @@ data/
# Rollout videos and wandb logs
rollouts/
wandb/
.tmp
.runs
.preprocessors
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "third_party/lerobot"]
path = third_party/lerobot
url = https://github.com/huggingface/lerobot.git
158 changes: 158 additions & 0 deletions ALOHA.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# OpenVLA-OFT+ in Real-World ALOHA Robot Tasks

## Relevant Files

Evaluation
* `experiments/robot/aloha/`: ALOHA training and eval files
* `run_aloha_eval.py`: ALOHA eval script (CLIENT SIDE; see "SERVER SIDE" below)
* `aloha_utils.py`: ALOHA eval utils
* Other ALOHA robot environment files copied from the original [ALOHA GitHub repo](https://github.com/tonyzhaozh/aloha):
* `constants.py`
* `real_env.py`
* `robot_utils.py`
* `experiments/robot/`: General eval utils files
* `openvla_utils.py`: OpenVLA-specific eval utils
* `robot_utils.py`: Other eval utils
* `vla-scripts/deploy.py`: VLA server deploy script (SERVER SIDE)

Note: Unlike the LIBERO evaluation setup, we use a server-client interface here. This is particularly useful if the user's machine which commands the robot does not have access to a local GPU with sufficient specs to run the fine-tuned VLA policies.

Training
* `experiments/robot/aloha/`: ALOHA training and eval files
* `preprocess_split_aloha_data.py`: ALOHA data preprocessing script
* `vla-scripts/finetune.py`: VLA fine-tuning script

## Setup

Set up a conda environment for training policies and deploying them on the VLA server (see instructions in [SETUP.md](SETUP.md)).

## Fine-Tuning on ALOHA Robot Data

We assume that you have collected a set of expert demonstrations on the ALOHA robot already.

First, use our `preprocess_split_aloha_data.py` script to preprocess the raw ALOHA dataset: downsize images from 480x640 to 256x256 and split into training and validation sets. Below are examples for the `put X into pot` task in our paper (which has 3 possible target objects, 1 per episode):

```bash
python experiments/robot/aloha/preprocess_split_aloha_data.py \
--dataset_path /scr/moojink/data/aloha1_raw/put_green_pepper_into_pot/ \
--out_base_dir /scr/moojink/data/aloha1_preprocessed/ \
--percent_val 0.05
python experiments/robot/aloha/preprocess_split_aloha_data.py \
--dataset_path /scr/moojink/data/aloha1_raw/put_red_pepper_into_pot/ \
--out_base_dir /scr/moojink/data/aloha1_preprocessed/ \
--percent_val 0.05
python experiments/robot/aloha/preprocess_split_aloha_data.py \
--dataset_path /scr/moojink/data/aloha1_raw/put_yellow_corn_into_pot/ \
--out_base_dir /scr/moojink/data/aloha1_preprocessed/ \
--percent_val 0.05
```

Then, convert the preprocessed ALOHA datasets into a single RLDS dataset that is compatible with OpenVLA fine-tuning. This process is the same as in the original OpenVLA repo. See instructions for converting to RLDS [here](https://github.com/moojink/rlds_dataset_builder) (a sample ALOHA preprocessed-to-RLDS conversion script is available [here](https://github.com/moojink/rlds_dataset_builder/blob/main/aloha1_put_X_into_pot_300_demos/aloha1_put_X_into_pot_300_demos_dataset_builder.py); this script converts the three preprocessed datasets above into one unified RLDS dataset, with train/val splits).

After converting to RLDS, register the dataset (which, for the example task above, would be called `aloha1_put_X_into_pot_300_demos`) with our dataloader by adding an entry for it in `configs.py` ([here](prismatic/vla/datasets/rlds/oxe/configs.py#L680)), `transforms.py` ([here](prismatic/vla/datasets/rlds/oxe/transforms.py#L928)), and `mixtures.py` ([here](prismatic/vla/datasets/rlds/oxe/mixtures.py#L216)). For reference, in each of these files, there are sample entries for the ALOHA datasets that we used in our paper.

Before fine-tuning, set the desired ALOHA action chunk size in [`prismatic/vla/constants.py`](prismatic/vla/constants.py) (see `NUM_ACTIONS_CHUNK` in `ALOHA_CONSTANTS`). We set it to 25 by default because we used a control frequency of 25 Hz in our ALOHA setup to reduce storage costs and training time (while still maintaining smoothness in the robot's motions). If you use 50 Hz, we recommend setting `NUM_ACTIONS_CHUNK` to `50`. In general, 1 second-long action chunks are a good default. Do NOT modify `ACTION_PROPRIO_NORMALIZATION_TYPE`: Since the ALOHA robot action space is absolute joint angles, we do not want to use a normalization scheme that clips outlier values (like the Q1-Q99 normalization we used with the relative end-effector pose actions for LIBERO), since that would prevent the model from outputting certain robot joint angles that are crucial for solving the task.

Now begin fine-tuning! Below is a sample command to fine-tune OpenVLA using our OFT+ recipe on the `put X into pot` task above ("+" in "OFT+" means FiLM is included for enhanced language grounding). Replace `X` in the first line with the number of GPUs available to you.

```bash
torchrun --standalone --nnodes 1 --nproc-per-node X vla-scripts/finetune.py \
--vla_path openvla/openvla-7b \
--data_root_dir /PATH/TO/RLDS/DATASETS/DIR/ \
--dataset_name aloha1_put_X_into_pot_300_demos \
--run_root_dir /YOUR/CHECKPOINTS/AND/LOG/DIR/ \
--use_l1_regression True \
--use_diffusion False \
--use_film True \
--num_images_in_input 3 \
--use_proprio True \
--batch_size 4 \
--learning_rate 5e-4 \
--num_steps_before_decay 50000 \
--max_steps 100005 \
--use_val_set True \
--val_freq 10000 \
--save_freq 10000 \
--save_latest_checkpoint_only False \
--image_aug True \
--lora_rank 32 \
--wandb_entity "YOUR_WANDB_ENTITY" \
--wandb_project "YOUR_WANDB_PROJECT" \
--run_id_note parallel_dec--25_acts_chunk--continuous_acts--L1_regression--3rd_person_img--left_right_wrist_imgs--proprio_state--film
```

The above training command should reproduce our OpenVLA-OFT+ results on the `put X into pot` task if `X = 8` and the 100K step checkpoint is evaluated. It will fine-tune OpenVLA using 3 input images (1 third-person image + 2 wrist camera images). Note that we use learning rate decay after a certain point (50K steps in the command above) since doing so speeds up training convergence (train L1 loss spikes down from our experience).

Best practices for fine-tuning:
* In general, we recommend fine-tuning until training L1 loss goes below 0.01 and starts to plateau.
* One way to achieve this is to fine-tune using our default learning rate of `5e-4` until the loss starts to decrease very slowly, and then decay the learning rate by 10x to `5e-5` (which should make the loss spike down) and train until the training L1 loss finally plateaus.
* Depending on your dataset size, you may need to adjust some hyperparameters. For example, if you use a large dataset with over 300 demos, you may need to decay the learning rate later and train for longer for best performance. Decaying too earlier can lead to a suboptimal policy.
* If your task does not require good langauge grounding (e.g., if there is only one language instruction), FiLM is not necessary; consider setting `--use_film False` to train fewer model parameters.
* Please be sure to test your policy with the same device/GPU used to train it! Otherwise, performance may drop substantially. You may be able to avoid the performance drop if you merge the LoRA weights into the base model on the downstream device used for testing (e.g., if you train on H100 and then merge on A100 before testing on A100). You can see our script [vla-scripts/merge_lora_weights_and_save.py](vla-scripts/merge_lora_weights_and_save.py) for merging the LoRA adapter into the base model offline. It's okay if you already merged LoRA weights into the base OpenVLA model during fine-tuning; you can always redownload the base model and merge again as long as you still have the LoRA adapter (`merge_lora_weights_and_save.py` will handle this for you).

If you run into any issues, please open a new GitHub issue.

## Launching ALOHA Robot Evaluations

In the primary conda environment (`openvla-oft`) which you will use to launch the VLA server, install a few packages for the server-client interface:

```bash
conda activate openvla-oft
pip install uvicorn fastapi json-numpy
```

On the machine that you will use to command the robot, set up a second conda environment that will be used to run the robot environment, query the VLA server, and execute actions in the environment:

```bash
# Create and activate client conda environment
conda create -n openvla-oft-aloha python=3.10 -y
conda activate openvla-oft-aloha

# Install PyTorch
# Use a command specific to your machine: https://pytorch.org/get-started/locally/
pip3 install torch torchvision torchaudio

# Clone openvla-oft repo and pip install to download dependencies
git clone https://github.com/moojink/openvla-oft.git
cd openvla-oft
pip install -e .

# Install packages needed for the ALOHA robot environment
pip install -r experiments/robot/aloha/requirements_aloha.txt
```

Launch the VLA server on the machine that has the GPU you will use to run model inference (using the `openvla-oft` conda environment). Below is a sample command for this (change as needed):

```bash
python vla-scripts/deploy.py \
--pretrained_checkpoint /PATH/TO/FINETUNED/MODEL/CHECKPOINT/DIR/ \
--use_l1_regression True \
--use_film True \
--num_images_in_input 3 \
--use_proprio True \
--center_crop True \
--num_open_loop_steps 25 \
--unnorm_key aloha1_put_X_into_pot_300_demos
```

Then, run the ALOHA evaluation script. Specify the VLA server URL or IP address in the `vla_server_url` argument. Below is a sample command:

```bash
python experiments/robot/aloha/run_aloha_eval.py \
--center_crop True \
--num_open_loop_steps 25 \
--use_vla_server True \
--vla_server_url <URL OF VLA SERVER> \
--num_rollouts_planned <NUM TEST ROLLOUTS> \
--max_steps <MAX NUM STEPS PER ROLLOUT>
```

If you run into any issues, please open a new GitHub issue.

## Troubleshooting Tips

* Tip #1: If you run into a ROS error such as `ImportError: /lib/x86_64-linux-gnu/libp11-kit.so.0: undefined symbol: ffi_type_pointer, version LIBFFI_BASE_7.0`, try running the following command in your client conda environment (`openvla-oft-aloha`):

```
conda install -c conda-forge libffi
```
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM pytorch/pytorch:2.1.2-cuda12.1-cudnn8-devel

# Install system dependencies for flash-attn.
RUN apt-get update && apt-get install -y \
git \
ninja-build \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /workspace
RUN git clone -b merge-finetuner-changes https://github.com/nomagiclab/openvla.git && \
cd openvla && \
git submodule init third_party/lerobot && \
git submodule update --recursive --init third_party/lerobot

WORKDIR /workspace/openvla

RUN ls -la third_party/lerobot

# Editable install of openvla, then lerobot submodule, then reinstall newly
# missing openvla dependencies to negotiate dependency incompatibility.
# Then install flash-attn separately (per OpenVLA instructions)
# and download the openvla-7b model.
RUN pip install -e . && \
cd third_party/lerobot/ && \
pip install -e . && \
cd ../../ && \
pip check | awk '$1 ~ /openvla/ {gsub(/,/,"",$5); print $5}' | xargs pip install && \
pip install packaging ninja && \
pip install "flash-attn==2.5.5" --no-build-isolation && \
pip install huggingface-hub && \
huggingface-cli download openvla/openvla-7b
Loading