Code release for Offline Reinforcement Learning as One Big Sequence Modeling Problem.
New: Also see Alexander Nikulin's fork with attention caching and vectorized rollouts!
All python dependencies are in environment.yml
. Install with:
conda env create -f environment.yml
conda activate trajectory
pip install -e .
For reproducibility, we have also included system requirements in a Dockerfile
(see installation instructions), but the conda installation should work on most standard Linux machines.
Train a transformer with: python scripts/train.py --dataset halfcheetah-medium-v2
To reproduce the offline RL results: python scripts/plan.py --dataset halfcheetah-medium-v2
By default, these commands will use the hyperparameters in config/offline.py
. You can override them with runtime flags:
python scripts/plan.py --dataset halfcheetah-medium-v2 \
--horizon 5 --beam_width 32
A few hyperparameters are different from those listed in the paper because of changes to the discretization strategy. These hyperparameters will be updated in the next arxiv version to match what is currently in the codebase.
We have provided pretrained models for 16 datasets: {halfcheetah, hopper, walker2d, ant}-{expert-v2, medium-expert-v2, medium-v2, medium-replay-v2}
. Download them with ./pretrained.sh
The models will be saved in logs/$DATASET/gpt/pretrained
. To plan with these models, refer to them using the gpt_loadpath
flag:
python scripts/plan.py --dataset halfcheetah-medium-v2 \
--gpt_loadpath gpt/pretrained
pretrained.sh
will also download 15 plans from each model, saved to logs/$DATASET/plans/pretrained
. Read them with python plotting/read_results.py
.
python plotting/table.py
. This will print a table that can be copied into a Latex document. (Expand to view table source.)python plotting/plot.py
.
(Expand to view plot.)Copy your MuJoCo key to the Docker build context and build the container:
cp ~/.mujoco/mjkey.txt azure/files/
docker build -f azure/Dockerfile . -t trajectory
Test the container:
docker run -it --rm --gpus all \
--mount type=bind,source=$PWD,target=/home/code \
--mount type=bind,source=$HOME/.d4rl,target=/root/.d4rl \
trajectory \
bash -c \
"export PYTHONPATH=$PYTHONPATH:/home/code && \
python /home/code/scripts/train.py --dataset hopper-medium-expert-v2 --exp_name docker/"
Launching jobs on Azure requires one more python dependency:
pip install git+https://github.com/JannerM/doodad.git@janner
Tag the image built in the previous section and push it to Docker Hub:
export DOCKER_USERNAME=$(docker info | sed '/Username:/!d;s/.* //')
docker tag trajectory ${DOCKER_USERNAME}/trajectory:latest
docker image push ${DOCKER_USERNAME}/trajectory
Update azure/config.py
, either by modifying the file directly or setting the relevant environment variables. To set the AZURE_STORAGE_CONNECTION
variable, navigate to the Access keys
section of your storage account. Click Show keys
and copy the Connection string
.
Download azcopy
: ./azure/download.sh
Launch training jobs with python azure/launch_train.py
and planning jobs with python azure/launch_plan.py
.
These scripts do not take runtime arguments. Instead, they run the corresponding scripts (scripts/train.py
and scripts/plan.py
, respectively) using the Cartesian product of the parameters in params_to_sweep
.
To rsync the results from the Azure storage container, run ./azure/sync.sh
.
To mount the storage container:
./azure/make_fuse_config.sh
./azure/mount.sh
to mount the storage container to ~/azure_mount
To unmount the container, run sudo umount -f ~/azure_mount; rm -r ~/azure_mount
@inproceedings{janner2021sequence,
title = {Offline Reinforcement Learning as One Big Sequence Modeling Problem},
author = {Michael Janner and Qiyang Li and Sergey Levine},
booktitle = {Advances in Neural Information Processing Systems},
year = {2021},
}
The GPT implementation is from Andrej Karpathy's minGPT repo.