README.md

February 16, 2024 · View on GitHub

Vision-Language Foundation Models as Effective Robot Imitators

Python 3.8 arXiv Hugging Face

RoboFlamingo

RoboFlamingo is a pre-trained-VLM-based robotics learning framework that learns a wide variety of language-conditioned robot skills by fine-tuning on offline free-form imitation datasets. By exceeding the state-of-the-art performance with a large margin on the CALVIN benchmark, we show that RoboFlamingo can be an effective and competitive alternative to adapt VLMs to robot control. Our extensive experimental results also reveal several interesting conclusions regarding the behavior of different pre-trained VLMs on manipulation tasks. RoboFlamingo can be trained or evaluated on a single GPU server (GPU mem requirements depend on the model size), and we believe RoboFlamingo has the potential to be a cost-effective and easy-to-use solution for robotics manipulation, empowering everyone with the ability to fine-tune their own robotics policy.


This is also the official code repo for the paper Vision-Language Foundation Models as Effective Robot Imitators.

All our experiments are conducted on a single GPU server with 8 Nvidia A100 GPUs (80G).

Pre-trained models are available on Hugging Face.

Usage

Initializing a RoboFlamingo model

We support pre-trained vision encoders from the OpenCLIP package, which includes OpenAI's pre-trained models. We also support pre-trained language models from the transformers package, such as MPT, RedPajama, LLaMA, OPT, GPT-Neo, GPT-J, and Pythia models.

from robot_flamingo.factor import create_model_and_transforms

model, image_processor, tokenizer = create_model_and_transforms(
    clip_vision_encoder_path="ViT-L-14",
    clip_vision_encoder_pretrained="openai",
    lang_encoder_path="PATH/TO/LLM/DIR",
    tokenizer_path="PATH/TO/LLM/DIR",
    cross_attn_every_n_layers=1,
    decoder_type='lstm',
)

The cross_attn_every_n_layers argument controls how often cross-attention layers are applied and should be consistent with the VLM. The decoder_type argument controls the type of the decoder, currently, we support lstm, fc, diffusion (bugs exist for the dataloader), and GPT.

Performance

We report results on the CALVIN benchmark.

MethodTraining DataTest Split12345Avg Len
MCILABCD (Full)D0.3730.0270.0020.0000.0000.40
HULCABCD (Full)D0.8890.7330.5870.4750.3833.06
HULC (retrained)ABCD (Lang)D0.8920.7010.5480.4200.3352.90
RT-1 (retrained)ABCD (Lang)D0.8440.6170.4380.3230.2272.45
OursABCD (Lang)D0.9640.8960.8240.7400.664.09
MCILABC (Full)D0.3040.0130.0020.0000.0000.31
HULCABC (Full)D0.4180.1650.0570.0190.0110.67
RT-1 (retrained)ABC (Lang)D0.5330.2220.0940.0380.0130.90
OursABC (Lang)D0.8240.6190.4660.3310.2352.48
HULCABCD (Full)D (Enrich)0.7150.4700.3080.1990.1301.82
RT-1 (retrained)ABCD (Lang)D (Enrich)0.4940.2220.0860.0360.0170.86
OursABCD (Lang)D (Enrich)0.7200.4800.2990.2110.1441.85
Ours (freeze-emb)ABCD (Lang)D (Enrich)0.7370.5300.3850.2750.1922.12

Prerequisite:

Step 0

Follow the instructions in the OpenFlamingo and CALVIN to download the necessary dataset and VLM pretrained Models.

Download the CALVIN dataset, choose a split with:

cd $HULC_ROOT/dataset
sh download_data.sh D | ABC | ABCD | debug

Download the released OpenFlamingo models:

# paramsLanguage modelVision encoderXattn interval*COCO 4-shot CIDErVQAv2 4-shot AccuracyAvg LenWeights
3Banas-awadalla/mpt-1b-redpajama-200bopenai CLIP ViT-L/14177.345.83.94Link
3Banas-awadalla/mpt-1b-redpajama-200b-dollyopenai CLIP ViT-L/14182.745.74.09Link
4Btogethercomputer/RedPajama-INCITE-Base-3B-v1openai CLIP ViT-L/14281.849.03.67Link
4Btogethercomputer/RedPajama-INCITE-Instruct-3B-v1openai CLIP ViT-L/14285.849.03.79Link
9Banas-awadalla/mpt-7bopenai CLIP ViT-L/14489.054.83.97Link

Replace the ${lang_encoder_path} and ${tokenizer_path} of the path dictionary (e.g., mpt_dict) in robot_flamingo/models/factory.py for each pretrained VLM with your own paths.

Step 1

Clone this repo

git clone https://github.com/RoboFlamingo/RoboFlamingo.git

Install the required packages:

cd RoboFlamingo
conda create -n RoboFlamingo python=3.8
source activate RoboFlamingo
pip install -r requirements.txt

Training the model (using DDP):

torchrun --nnodes=1 --nproc_per_node=8 --master_port=6042 robot_flamingo/train/train_calvin.py \
    --report_to_wandb \
    --llm_name mpt_dolly_3b \
    --traj_cons \
    --use_gripper \
    --fusion_mode post \
    --rgb_pad 10 \
    --gripper_pad 4 \
    --precision fp32 \
    --num_epochs 5 \
    --gradient_accumulation_steps 1 \
    --batch_size_calvin 6 \
    --run_name RobotFlamingoDBG \
    --calvin_dataset ${calvin_dataset_path} \
    --lm_path ${lm_path} \
    --tokenizer_path ${tokenizer_path} \
    --openflamingo_checkpoint ${openflamingo_checkpoint} \
    --cross_attn_every_n_layers 4 \
    --dataset_resampled \
    --loss_multiplier_calvin 1.0 \
    --workers 1 \
    --lr_scheduler constant \
    --warmup_steps 5000 \
    --learning_rate 1e-4 \
    --save_every_iter 10000 \
    --from_scratch \
    --window_size 12 > ${log_file} 2>&1

${calvin_dataset_path} is the path to the CALVIN dataset;

${lm_path} is the path to the pre-trained LLM;

${tokenizer_path} is the path to the VLM tokenizer;

${openflamingo_checkpoint} is the path to the OpenFlamingo pre-trained model;

${log_file} is the path to the log file.

We also provide robot_flamingo/pt_run_gripper_post_ws_12_traj_aug_mpt_dolly_3b.bash to launch the training. This bash finetunes the MPT-3B-IFT version of the OpenFlamingo model, which contains the default hyperparameters to train the model, and corresponds to the best results in the paper.

Evaluating the model on the CALVIN benchmark

python eval_ckpts.py

By adding the checkpoint name and directory into eval_ckpts.py, the script would automatically load the model and evaluate it. For example, if you want to evaluate the checkpoint at path 'your-checkpoint-path', you can modify the ckpt_dir and ckpt_names variables in eval_ckpts.py, and the evaluation results would be saved as 'logs/your-checkpoint-prefix.log'.

Co-finetune with both robot data (CALVIN) and vision-language data (COCO caption, VQA)

The results shown below indicate that co-training could preserve most ability of the VLM backbone on VL tasks, while losing a bit of performance on robot tasks.

use

bash robot_flamingo/pt_run_gripper_post_ws_12_traj_aug_mpt_dolly_3b_co_train.bash

to launch co-train RoboFlamingo with CoCO, VQAV2 and CALVIN. You should update CoCO and VQA paths in get_coco_dataset and get_vqa_dataset in robot_flamingo/data/data.py.

Results on the CALVIN benchmark:

SplitSR 1SR 2SR 3SR 4SR 5Avg Len
Co-TrainABC->D82.9%63.6%45.3%32.1%23.4%
Fine-tuneABC->D82.4%61.9%46.6%33.1%23.5%
Co-TrainABCD->D95.7%85.8%73.7%64.5%56.1%
Fine-tuneABCD->D96.4%89.6%82.4%74.0%66.2%
Co-TrainABCD->D (Enrich)67.8%45.2%29.4%18.9%11.7%
Fine-tuneABCD->D (Enrich)72.0%48.0%29.9%21.1%14.4%

Results on VL tasks:

cocoVQA
BLEU-1BLEU-2BLEU-3BLEU-4METEORROUGE_LCIDErSPICEAcc
Fine-tune (3B, zero-shot)0.1560.0510.0180.0070.0380.1480.0040.0064.09
Fine-tune (3B, 4-shot)0.1660.0560.0200.0080.0420.1580.0040.0083.87
Co-Train (3B, zero-shot)0.2250.1580.1070.0720.1240.3340.3450.08536.37
Original Flamingo (80B, fine-tuned)------1.381-82.0

Acknowledgment

The logo is generated using MidJourney

This work uses code from the following open-source projects and datasets:

CALVIN

Original: https://github.com/mees/calvin License: MIT

OpenAI CLIP

Original: https://github.com/openai/CLIP License: MIT

OpenFlamingo

Original: https://github.com/mlfoundations/open_flamingo License: MIT

Cite our work:

@article{li2023vision,
  title     = {Vision-Language Foundation Models as Effective Robot Imitators},
  author    = {Li, Xinghang and Liu, Minghuan and Zhang, Hanbo and Yu, Cunjun and Xu, Jie and Wu, Hongtao and Cheang, Chilam and Jing, Ya and Zhang, Weinan and Liu, Huaping and Li, Hang and Kong, Tao},
  journal={arXiv preprint arXiv:2311.01378},
  year={2023}