Jianwei Yang*1† Reuben Tan1† Qianhui Wu1† Ruijie Zheng2‡ Baolin Peng1‡ Yongyuan Liang2‡
Yu Gu1 Mu Cai3 Seonghyeon Ye4 Joel Jang5 Yuquan Deng5 Lars Liden1 Jianfeng Gao1▽
1 Microsoft Research; 2 University of Maryland; 3 University of Wisconsin-Madison
4 KAIST; 5 University of Washington
* Project lead † First authors ‡ Second authors ▽ Leadership
The Path Towards Multimodal AI Agents

python agents/robot_traj/app.py to start the demo!We will be releasing all the following contents: - [x] Model inference code - [x] Add UI and Gaming agent Demos - [x] Model checkpoint - [x] Training code - [x] Open-XE pretraining data with traces - [x] Video pretraining data with traces - [ ] SeeClick and Vision2UI pretraining data with SoM - [ ] UI/Libero finetuning script - [ ] Video finetune script

Magma is a foundation model for multimodal AI agents. As the bedrock for multimodal agentic models, it should possess strong capabilities to perceive the multimodal world AND takes goal-driven actions precisely (see above figure). With this in mind, we are striving for the following goals:
With this in mind, we developed a new pretraining data, which mostly consists of unlabeled videos in the wild plus the existing annotated agentic data, and a new pretraining framework, which unifies the training of all three modalities (text, image, and action), to train a new foundation model for multimodal AI agents, named Magma.

We pursue the goal through two dimensions:
Large-scale heterogeneous training data: we curate a large amount of data in the wild, including existing multimodal understanding data, UI navigation data, and robotics manipulation data, and unlabeled videos in the wild. We also propose a new data collection pipeline to collect unlabeled videos in the wild, which is scalable and cost-effective. To attain useful action supervision from raw videos and robotics trajectories, we meticulously removed the camera motions in the videos and then transform the motions into "action" supervisions for our model training. These provide unique signals for the model to learn the cross-modal connections and long-horizon action prediction and planning.
Universal pretraining objectives: texts and actions are inherently different and thus cause a huge gap, while visual tokens are continuous. We propose a universal pretraining framework that unifies the training of all three modalities, and we show that this is crucial for the model to learn the cross-modal connections. More specifically, we proposed Set-of-Mark and Trace-of-Mark as the auxiliary tasks for our model pretraining, as the bridge of different output modalities. In this way, we are building a great alignment between the text and action modalities, and also between the image and action modalities.
git clone https://github.com/microsoft/Magma
cd Magma
conda create -n magma python=3.10 -y
conda activate magma
pip install --upgrade pip
pip install -e .
pip install -e ".[train]"
pip install -e ".[agent]"
Other probably needed packages:
Co-tracker
# Install co-tracker
git clone https://github.com/facebookresearch/co-tracker
cd co-tracker
pip install -e .
pip install imageio[ffmpeg]
cd ../
# Install kmeans_pytorch, note: install with pip will leads to error
git clone https://github.com/subhadarship/kmeans_pytorch
cd kmeans_pytorch
pip install -e .
cd ../
# Install others packages
pip install ipython
pip install faiss-cpu
pip install decord
⚠️ Please make sure you have installed the transformers with correct version (>=4.49.0). If you see some abnormal behavior, please check the version of transformers, and probably see below for the customized transformers.
Click to expand
⚠️ One important thing to note is that our model uses ConvNext as the backbone, which contains a layer scaler parameter gamma. This leads to a bug of Transformers library as it automatically replace the 'gamma' with 'weight' when loading the model. To fix this, we need to modify the 'transformers/models/auto/modeling_auto.py' file as follows:
if "gamma" in key and "clip_vision_model" not in key:
key = key.replace("gamma", "weight")
This bug still exists in the latest transformer version. So please make sure you install the following bug-free customized version of transformers as lised in pyproject.toml:
pip install git+https://github.com/jwyang/transformers.git@dev/jwyang-v4.44.1
or the newest version:
pip install git+https://github.com/jwyang/transformers.git@dev/jwyang-v4.48.2
As shown in Table 1 of our paper, we apply SoM and ToM on both robotics data and instructional videos. To ensure reproducibility, we provide the code to generate SoM and ToM for instructional videos. The code is located in tools/som_tom/demo.py. You can run the following command to generate SoM and ToM for the robotics data:
python tools/som_tom/demo.py
And then you can find two videos in the tools/som_tom/videos folder. The original trace extracted from CoTracker is shown in orig_trace.mp4, and the SoM-ToM video is named som_tom.mp4.
We provide the instructions to pretrain LLama-3-8B-Instruct on Open-X-Embodiment and finetune Magma-8B on different downstream tasks.
Download Open-X-Embodiment from the official site. Then edit the data config file openx.yaml accordingly. The data config file should look like this:
# a list of all the data paths
DATA_PATH:
- "/path/to/open-x"
IMAGE_FOLDER:
- "siglip-224px+mx-oxe-magic-soup"
LANGUAGE_PATH:
- ""
Once set up the dataset and config, you can run the following command to finetune the model:
sh scripts/pretrain/pretrain_openx.sh
Download annotation file from MagmaAI/Magma-820K. Please prepare the image data according to the dataset list in the dataset page. Once finished, please edit magma_820k.yaml file accordingly.
# a list of all the data paths
DATA_PATH:
- "/path/to/magma_820k.json"
IMAGE_FOLDER:
- "/root/to/magma_820k/images"
Once set up the dataset and config, you can run the following command to finetune the model:
$ claude mcp add Magma \
-- python -m otcore.mcp_server <graph>