Git Product home page Git Product logo

metamorph's Introduction

MetaMorph: Learning Universal Controllers with Transformers

This is the code for the paper

MetaMorph: Learning Universal Controllers with Transformers
Agrim Gupta, Linxi Fan, Surya Ganguli, Fei-Fei Li

Multiple domains like vision, natural language, and audio are witnessing tremendous progress by leveraging Transformers for large scale pre-training followed by task specific fine tuning. In contrast, in robotics we primarily train a single robot for a single task. However, modular robot systems now allow for the flexible combination of general-purpose building blocks into task optimized morphologies. However, given the exponentially large number of possible robot morphologies, training a controller for each new design is impractical. In this work, we propose MetaMorph, a Transformer based approach to learn a universal controller over a modular robot design space. MetaMorph is based on the insight that robot morphology is just another modality on which we can condition the output of a Transformer. Through extensive experiments we demonstrate that large scale pre-training on a variety of robot morphologies results in policies with combinatorial generalization capabilities, including zero shot generalization to unseen robot morphologies. We further demonstrate that our pre-trained policy can be used for sample-efficient transfer to completely new robot morphologies and tasks.

Code Structure

The code consists of two main components:

  1. Metamorph: Code for joint pre-training of different robots.
  2. Environments and evaluation tasks: Three pre-training environments and two evaluation environments.

Benchmark

We also provide Unimal-100 benchmark. The benchmark consists of 100 train morphologies, 1600 morphologies with dynamics variations, 800 morphologies with kinematics variations, and 100 test morphologies.

# Install gdown
pip install gdown
# Download data
gdown 1LyKYTCevnqWrDle1LTBMlBF58RmCjSzM
# Unzip
unzip unimals_100.zip

Setup

We provide Dockerfile for easy installation and development. If you prefer to work without docker please take a look at Dockerfile and ensure that your local system has all the necessary dependencies installed.

Training

# Build docker container. Ensure that MuJoCo license is present: docker/mjkey.txt
./scripts/build_docker.sh
# Joint pre-training. Please change MOUNT_DIR location inside run_docker_gpu.sh
# Finally ensure that ENV.WALKER_DIR points to benchmark files and is accessible
# from docker.
./scripts/run_docker_gpu.sh python tools/train_ppo.py --cfg ./configs/ft.yaml

The default parameters assume that you are running the code on a machine with atlesat 1 GPU.

Citation

If you find this code useful, please consider citing:

@inproceedings{
    gupta2022metamorph,
    title={MetaMorph: Learning Universal Controllers with Transformers},
    author={Agrim Gupta and Linxi Fan and Surya Ganguli and Li Fei-Fei},
    booktitle={International Conference on Learning Representations},
    year={2022},
    url={https://openreview.net/forum?id=Opmqtk_GvYL}
}

Credit

This codebase would not have been possible without the following amazing open source codebases:

  1. ikostrikov/pytorch-a2c-ppo-acktr-gail
  2. hill-a/stable-baselines
  3. deepmind/dm_control
  4. openai/multi-agent-emergence-environments

metamorph's People

Contributors

agrimgupta92 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

metamorph's Issues

Trained Model

Great work!
Could you provide a trained model shown in the demo?

Thanks.

`obs` is not a dictionary but only has str `'proprioceptive'`.

I got an error at class UnimalHeightObs(gym.ObservationWrapper), def observation(self, obs): from hfield.py

  File "/home/bak/Projects/metamorph/metamorph/envs/wrappers/hfield.py", line 211, in observation
    obs["torso_height"] = round(z_pos - 1, 3)
TypeError: 'str' object does not support item assignment

The def observation(self, obs): is called from class UnimalEnv(gym.Env): in unimal.py. Though the obs is a dictionary and has 'proprioceptive', 'edges' keys at the end of def reset(self):, obs is just a str 'proprioceptive' at def observation(self, obs): class UnimalHeightObs(gym.ObservationWrapper).

From the viewpoint of the train loop, the error occurs when the code creates (or initializes) the world environment. At ppo.py, obs cannot create at def train(self):.

To solve above issue, I added self.obs_temp = obs at def reset(self): at def reset(self): class UnimalEnv(gym.Env): and obs = self.obs_temp at class UnimalHeightObs(gym.ObservationWrapper), def observation(self, obs):to preserve obs information.

  • unimal.py
class UnimalEnv(gym.Env):
    """Superclass for all Unimal tasks."""

...........
...........
    ###########################################################################
    # Reset sim
    ###########################################################################
    def reset(self):
        if self.sim is None or cfg.ENV.NEW_SIM_ON_RESET:
            self.sim = self._get_sim()
        else:
            self.sim.reset()

        self.step_count = 0

        if self.viewer is not None:
            self.viewer.update_sim(self.sim)
        obs = self.reset_model()
        self._set_action_space()
        # This is just a temp initialization, the final obs space will depend
        # on SelectKeysWrapper
        self.observation_space = spu.convert_obs_to_space(obs)
        self.metadata["video.frames_per_second"] = int(np.round(1.0 / self.dt))
        self.obs_temp = obs  ### what I added

        return obs
  • hfield.py
class UnimalHeightObs(gym.ObservationWrapper):
    def __init__(self, env):
        super().__init__(env)
        self.observation_space = spu.update_obs_space(env, {"torso_height": (1,)})

    def observation(self, obs):
        obs = self.obs_temp   ### what I added
        x_pos, y_pos, z_pos = self.sim.data.get_body_xpos("torso/0")
   ........
   ........

After that, I got an error like below.

Process ForkProcess-3:
Traceback (most recent call last):
  File "/home/bak/Projects/metamorph/metamorph/envs/vec_env/subproc_vec_env.py", line 27, in worker
    remote.send([env.reset() for env in envs])
  File "/home/bak/Projects/metamorph/metamorph/envs/vec_env/subproc_vec_env.py", line 27, in <listcomp>
    remote.send([env.reset() for env in envs])
  File "/home/bak/Projects/metamorph/metamorph/envs/wrappers/multi_env_wrapper.py", line 40, in reset
    obs = self._env.reset()
  File "/home/bak/Projects/metamorph/metamorph/algos/ppo/envs.py", line 187, in reset
    observation = super(RecordEpisodeStatistics, self).reset(**kwargs)
  File "/home/bak/anaconda3/envs/metamorph/lib/python3.8/site-packages/gym/core.py", line 323, in reset
    return self.env.reset(**kwargs)
  File "/home/bak/Projects/metamorph/metamorph/algos/ppo/envs.py", line 169, in reset
    return self.env.reset(**kwargs)
  File "/home/bak/anaconda3/envs/metamorph/lib/python3.8/site-packages/gym/wrappers/time_limit.py", line 68, in reset
    return self.env.reset(**kwargs)
  File "/home/bak/anaconda3/envs/metamorph/lib/python3.8/site-packages/gym/wrappers/order_enforcing.py", line 42, in reset
    return self.env.reset(**kwargs)
  File "/home/bak/anaconda3/envs/metamorph/lib/python3.8/site-packages/gym/wrappers/env_checker.py", line 47, in reset
    return self.env.reset(**kwargs)
  File "/home/bak/anaconda3/envs/metamorph/lib/python3.8/site-packages/gym/core.py", line 379, in reset
    obs, info = self.env.reset(**kwargs)
ValueError: too many values to unpack (expected 2)

How can I fix these problems and check the result of your experiments?

I used Anaconda environment with mujoco-2.1.0 rather than Docker due to using free version of mujoco and using mujoco-py. Unfortunately, using mujoco after 2.1.0 does not support mujoco-py due to it has its own python binding.

Bug or bad usage?

When I use:
gym.make("Unimal-v0", agent_name="floor-1409-1-13-01-12-18-30"),
it says:

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/home/miniconda3/lib/python3.9/site-packages/gym/envs/registration.py", line 676, in make

    return registry.make(id, **kwargs)

  File "/home/miniconda3/lib/python3.9/site-packages/gym/envs/registration.py", line 520, in make

    return spec.make(**kwargs)

  File "/home/miniconda3/lib/python3.9/site-packages/gym/envs/registration.py", line 140, in make

    env = cls(**_kwargs)

  File "/home/app/metamorph/metamorph/envs/tasks/task.py", line 17, in make_env

    env = globals()[env_func](xml, agent_name, **kwargs)

  File "/home/app/metamorph/metamorph/envs/tasks/locomotion.py", line 89, in make_env_locomotion

    env.reset()

  File "/home/app/metamorph/metamorph/envs/tasks/unimal.py", line 158, in reset

    obs = self.reset_model()

  File "/home/app/metamorph/metamorph/envs/tasks/unimal.py", line 185, in reset_model

    observation = self._get_obs()

  File "/home/app/metamorph/metamorph/envs/tasks/unimal.py", line 81, in _get_obs

    obs.update(module.observation_step(self, self.sim))

  File "/home/app/metamorph/metamorph/envs/modules/agent.py", line 231, in observation_step

    limb_obs = self.get_limb_obs(sim)

  File "/home/app/metamorph/metamorph/envs/modules/agent.py", line 149, in get_limb_obs

    obs["body_idx"] = self._get_one_hot_body_idx()

  File "/home/app/metamorph/metamorph/envs/modules/agent.py", line 195, in _get_one_hot_body_idx

    one_hot_encoding[rows, body_idxs] = 1

IndexError: index 8 is out of bounds for axis 1 with size 8

Have tried many agents in the test dir, no one works.

`manifest for nvidia` error

When I try setup by docker, the error occurred.

(simul) bak@bak:~/Projects/metamorph$ ./scripts/build_docker.sh
+ TAG=metamorph
+ PARENT=nvidia/cuda:11.1-cudnn8-devel-ubuntu20.04
+ INSTALL_SCRIPT=install_gpu_deps
++ id -u
+ USER_ID=1000
+ docker build -f docker/Dockerfile --build-arg PARENT_IMAGE=nvidia/cuda:11.1-cudnn8-devel-ubuntu20.04 --build-arg INSTALL_SCRIPT=install_gpu_deps --build-arg USER_ID=1000 -t metamorph .
Sending build context to Docker daemon  122.9MB
Step 1/35 : ARG PARENT_IMAGE
Step 2/35 : FROM $PARENT_IMAGE
manifest for nvidia/cuda:11.1-cudnn8-devel-ubuntu20.04 not found: manifest unknown: manifest unknown

Should I have to install cuda 11.1, cudnn8-devel version?

I created conda environment named simul. After the above error occurred, I installed cuda11.7 but it doesn't work.

Code for evaluation and visualization

Hello!

Thanks a lot for the great work and for providing the code!

Are there any code/scripts available for evaluation or visualization?

Thanks a lot your help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.