X2I: Seamless Integration of Multimodal Understanding into Diffusion Transformer via Attention Distillation
Jian Ma1, Qirong Peng1, Xu Guo2, Chen Chen1, Haonan Lu1, Zhenyu Yang1
1OPPO AI Center, 2Tsinghua University
Powered by MLLM, our X2I acquires the ability to process multimodal inputs (text/image/video/audio) and generate corresponding images.
| Model | Checkpoints |
|---|---|
| X2I-MiniCPM-o-2.6 | Checkpoints |
| X2I-InternVL2.5-1B | Checkpoints |
| X2I-InternVL2.5-4B | Checkpoints |
| X2I-QwenVL2.5-3B | Checkpoints |
| X2I-QwenVL2.5-7B | Checkpoints |

Prepare the environment, install the required libraries:
$ cd x2i
$ conda create --name x2i python==3.11
$ conda activate x2i
$ # Install PyTorch 2.4.1 by selecting the appropriate command according to your environment's CUDA version. Refer to: https://pytorch.org/get-started/previous-versions/ for guidance.
$ pip install torch==2.4.1 torchvision==0.19.1 torchaudio==2.4.1 --index-url https://download.pytorch.org/whl/cu118
$ pip install -r requirements.txt
Note: If you are using MiniCPM, please downgrade transformers to version 4.48.0 using:
$ pip install transformers==4.48.0
X2I provides inference scripts for QwenVL, InternVL, and MiniCPM frameworks. The example demonstrates usage with MiniCPM-o-2_6 via inference_minicpm.py. For other models:
inference_internvl.pyinference_qwenvl.pyAll scripts follow analogous command patterns. Simply replace the script filename while maintaining consistent parameter configurations.
$ cd infer
$ python inference_minicpm.py
It will download openbmb/MiniCPM-o-2_6, shuttleai/shuttle-3-diffusion. If you want to use local model, you can inference like this:
$ python inference_minicpm.py --minicpm_path "local MiniCPM-o 2.6 path" --flux_path "local shuttle-3-diffusion or FLUX.1 schnell or FLUX.1 dev path" --num_steps 4 --num_gen_imgs 1 --task "all"
openbmb/MiniCPM-o-2_6shuttleai/shuttle-3-diffusion4, If using FLUX.1 dev, change to 281text2image/image2image/imagetext2image/video2image/audio2image/x2image/all, default: all.X2I supports generating images in multiple languages.
You can run the text2image task like this:
$ python inference_minicpm.py --minicpm_path "local MiniCPM-o 2.6 path" --flux_path "local shuttle-3-diffusion or FLUX.1 schnell or FLUX.1 dev path" --num_steps 4 --num_gen_imgs 1 --task "text2image"
X2I supports reference-guided image generation, celebrity, and multi-image composition tasks.
You can run the image2image task like this:
$ python inference_minicpm.py --minicpm_path "local MiniCPM-o 2.6 path" --flux_path "local shuttle-3-diffusion or FLUX.1 schnell or FLUX.1 dev path" --num_steps 4 --num_gen_imgs 1 --task "image2image"
X2I supports user-prompt-driven expression editing, along with single image or multi-image editing and fusion tasks. Furthermore, X2I support image generation based on multilingual text content in images.
You can run the imagetext2image task like this:
$ python inference_minicpm.py --minicpm_path "local MiniCPM-o 2.6 path" --flux_path "local shuttle-3-diffusion or FLUX.1 schnell or FLUX.1 dev path" --num_steps 4 --num_gen_imgs 1 --task "imagetext2image"
X2I can directly generate images based on the semantic content of input video sequences.
You can run the video2image task like this:
$ python inference_minicpm.py --minicpm_path "local MiniCPM-o 2.6 path" --flux_path "local shuttle-3-diffusion or FLUX.1 schnell or FLUX.1 dev path" --num_steps 4 --num_gen_imgs 1 --task "video2image"
Leveraging the audio comprehension capabilities of MLLMs such as MiniCPM-o, X2I can directly generate images based on audio.
You can run the audio2image task like this:
$ python inference_minicpm.py --minicpm_path "local MiniCPM-o 2.6 path" --flux_path "local shuttle-3-diffusion or FLUX.1 schnell or FLUX.1 dev path" --num_steps 4 --num_gen_imgs 1 --task "audio2image"
X2I can comprehend hybrid inputs combining audio, images, videos, and text prompts to generate images.
You can run the x2image task like this:
$ python inference_minicpm.py --minicpm_path "local MiniCPM-o 2.6 path" --flux_path "local shuttle-3-diffusion or FLUX.1 schnell or FLUX.1 dev path" --num_steps 4 --num_gen_imgs 1 --task "x2image"
X2I also supports image generation using MLLM's reasoning capabilities based on the answers obtained after reasoning.
You can run the reasoning2image like this:
$ python inference_qwenvl.py --use_answer True --task "all"
Equipped with multi-turn dialogue capabilities inherent in MLLMs, X2I demonstrates preserved fidelity and contextual coherence during conversational interactions, as illustrated in the figure below.
You can run the multi-turn2image like this:
$ python inference_multi_turn.py
We organize the dataset using the WebDataset format. Please replace the dataset in the training script. Then you can run:
For MiniCPM training
cd train
bash train_minicpm.sh
For QwenVL training
cd train
bash train_qwenvl.sh
For InternVL training
cd train
bash train_internvl.sh
For LightControl training
cd lightcontrol
bash train_lightcontrol.sh
This code is builds on the code from the diffusers, MiniCPM-o, InternVL, QwenVL, PEA-Diffusion, and Subject-Diffusion.
Python
97.7%
Roff
1.8%
X2I: Seamless Integration of Multimodal Understanding into Diffusion Transformer via Attention Distillation
Jian Ma1, Qirong Peng1, Xu Guo2, Chen Chen1, Haonan Lu1, Zhenyu Yang1
1OPPO AI Center, 2Tsinghua University
Powered by MLLM, our X2I acquires the ability to process multimodal inputs (text/image/video/audio) and generate corresponding images.
| Model | Checkpoints |
|---|---|
| X2I-MiniCPM-o-2.6 | Checkpoints |
| X2I-InternVL2.5-1B | Checkpoints |
| X2I-InternVL2.5-4B | Checkpoints |
| X2I-QwenVL2.5-3B | Checkpoints |
| X2I-QwenVL2.5-7B | Checkpoints |

Prepare the environment, install the required libraries:
$ cd x2i
$ conda create --name x2i python==3.11
$ conda activate x2i
$ # Install PyTorch 2.4.1 by selecting the appropriate command according to your environment's CUDA version. Refer to: https://pytorch.org/get-started/previous-versions/ for guidance.
$ pip install torch==2.4.1 torchvision==0.19.1 torchaudio==2.4.1 --index-url https://download.pytorch.org/whl/cu118
$ pip install -r requirements.txt
Note: If you are using MiniCPM, please downgrade transformers to version 4.48.0 using:
$ pip install transformers==4.48.0
X2I provides inference scripts for QwenVL, InternVL, and MiniCPM frameworks. The example demonstrates usage with MiniCPM-o-2_6 via inference_minicpm.py. For other models:
inference_internvl.pyinference_qwenvl.pyAll scripts follow analogous command patterns. Simply replace the script filename while maintaining consistent parameter configurations.
$ cd infer
$ python inference_minicpm.py
It will download openbmb/MiniCPM-o-2_6, shuttleai/shuttle-3-diffusion. If you want to use local model, you can inference like this:
$ python inference_minicpm.py --minicpm_path "local MiniCPM-o 2.6 path" --flux_path "local shuttle-3-diffusion or FLUX.1 schnell or FLUX.1 dev path" --num_steps 4 --num_gen_imgs 1 --task "all"
openbmb/MiniCPM-o-2_6shuttleai/shuttle-3-diffusion4, If using FLUX.1 dev, change to 281text2image/image2image/imagetext2image/video2image/audio2image/x2image/all, default: all.X2I supports generating images in multiple languages.
You can run the text2image task like this:
$ python inference_minicpm.py --minicpm_path "local MiniCPM-o 2.6 path" --flux_path "local shuttle-3-diffusion or FLUX.1 schnell or FLUX.1 dev path" --num_steps 4 --num_gen_imgs 1 --task "text2image"
X2I supports reference-guided image generation, celebrity, and multi-image composition tasks.
You can run the image2image task like this:
$ python inference_minicpm.py --minicpm_path "local MiniCPM-o 2.6 path" --flux_path "local shuttle-3-diffusion or FLUX.1 schnell or FLUX.1 dev path" --num_steps 4 --num_gen_imgs 1 --task "image2image"
X2I supports user-prompt-driven expression editing, along with single image or multi-image editing and fusion tasks. Furthermore, X2I support image generation based on multilingual text content in images.
You can run the imagetext2image task like this:
$ python inference_minicpm.py --minicpm_path "local MiniCPM-o 2.6 path" --flux_path "local shuttle-3-diffusion or FLUX.1 schnell or FLUX.1 dev path" --num_steps 4 --num_gen_imgs 1 --task "imagetext2image"
X2I can directly generate images based on the semantic content of input video sequences.
You can run the video2image task like this:
$ python inference_minicpm.py --minicpm_path "local MiniCPM-o 2.6 path" --flux_path "local shuttle-3-diffusion or FLUX.1 schnell or FLUX.1 dev path" --num_steps 4 --num_gen_imgs 1 --task "video2image"
Leveraging the audio comprehension capabilities of MLLMs such as MiniCPM-o, X2I can directly generate images based on audio.
You can run the audio2image task like this:
$ python inference_minicpm.py --minicpm_path "local MiniCPM-o 2.6 path" --flux_path "local shuttle-3-diffusion or FLUX.1 schnell or FLUX.1 dev path" --num_steps 4 --num_gen_imgs 1 --task "audio2image"
X2I can comprehend hybrid inputs combining audio, images, videos, and text prompts to generate images.
You can run the x2image task like this:
$ python inference_minicpm.py --minicpm_path "local MiniCPM-o 2.6 path" --flux_path "local shuttle-3-diffusion or FLUX.1 schnell or FLUX.1 dev path" --num_steps 4 --num_gen_imgs 1 --task "x2image"
X2I also supports image generation using MLLM's reasoning capabilities based on the answers obtained after reasoning.
You can run the reasoning2image like this:
$ python inference_qwenvl.py --use_answer True --task "all"
Equipped with multi-turn dialogue capabilities inherent in MLLMs, X2I demonstrates preserved fidelity and contextual coherence during conversational interactions, as illustrated in the figure below.
You can run the multi-turn2image like this:
$ python inference_multi_turn.py
We organize the dataset using the WebDataset format. Please replace the dataset in the training script. Then you can run:
For MiniCPM training
cd train
bash train_minicpm.sh
For QwenVL training
cd train
bash train_qwenvl.sh
For InternVL training
cd train
bash train_internvl.sh
For LightControl training
cd lightcontrol
bash train_lightcontrol.sh
This code is builds on the code from the diffusers, MiniCPM-o, InternVL, QwenVL, PEA-Diffusion, and Subject-Diffusion.
Python
97.7%
Roff
1.8%