This project is the official implementation of 'LLMGA: Multimodal Large Language Model based Generation Assistant', ECCV2024 Oral
395
stars
2
commits
Python
primary language
Jun 2, 2025
updated
Bin Xia, Shiyin Wang, Yingfan Tao, Yitong Wang, and Jiaya Jia
New Version (Accepted by ECCV2024):
Old Version:
Abstract: In this paper, we introduce a Multimodal Large Language Model-based Generation Assistant (LLMGA), leveraging the vast reservoir of knowledge and proficiency in reasoning, comprehension, and response inherent in Large Language Models (LLMs) to assist users in image generation and editing. Diverging from existing approaches where Multimodal Large Language Models (MLLMs) generate fixed-size embeddings to control Stable Diffusion (SD), our LLMGA provides a detailed language generation prompt for precise control over SD. This not only augments LLM context understanding but also reduces noise in generation prompts, yields images with more intricate and precise content, and elevates the interpretability of the network. To this end, we curate a comprehensive dataset comprising prompt refinement, similar image generation, inpainting & outpainting, and instruction-based editing. Moreover, we propose a two-stage training scheme. In the first stage, we train the MLLM to grasp the properties of image generation and editing, enabling it to generate detailed prompts. In the second stage, we optimize SD to align with the MLLM's generation prompts. Additionally, we propose a reference-based restoration network to alleviate texture, brightness, and contrast disparities between generated and preserved regions during inpainting and outpainting. Extensive results show that LLMGA has promising generation and editing capabilities and can enable more flexible and expansive applications in an interactive manner.
Please follow the instructions below to install the required packages.
git clone https://github.com/dvlab-research/LLMGA.git
conda create -n llmga python=3.9 -y
conda activate llmga
cd LLMGA
pip install --upgrade pip # enable PEP 660 support
pip install -e .
cd ./llmga/diffusers
pip install .
pip install -e ".[train]"
pip install -r requirements.txt
pip install flash-attn --no-build-isolation
pip install datasets
pip install albumentations
pip install ninja
We provide the training data for LLMGA training.
please download LLMGA datasets and LLaVA pretrain datasets.
Besides, download LLaVA1.5 instruction tuning datasets llava_v1_5_mix665k.json, and download the images from constituting datasets:
.jpgPlease organize these downloaded data as in Structure.
We recommend users to download the pretrained MLP projector weights. Then put them in ./checkpoints following Structure.
Please download MLLM Models and SD models from the following links. For example, you can download LLMGA-MLLM7b and LLMGA-SDXL-T2I to realize LLMGA7b-T2I functionality. Please organize them as in Structure.
| MLLM Model (support English) | Pretrained Models |
|---|---|
| llmga-vicuna 7b | Download |
| llmga-mistral 7b | Download |
| llmga-llama3 8b | Download |
| llmga-qwen2 0.5b | Download |
| llmga-qwen2 1.5b | Download |
| llmga-qwen2 7b | Download |
| llmga-phi3 3b | Download |
| llmga-gemma 2b | Download |
| MLLM Model (further support Chinese and English) | Pretrained Models |
|---|---|
| llmga-cn-vicuna 7b | Download |
| llmga-cn-llama3 8b | Download |
| llmga-cn-gemma 2b | Download |
| llmga-cn-qwen2 0.5b | Download |
| SD Model | Pretrained Models |
|---|---|
| LLMGA-SD15-T2I | Download |
| LLMGA-SD15-Inpainting | Download |
| LLMGA-SDXL-T2I | Download |
| LLMGA-SDXL-Inpainting | Download |
The folder structure should be organized as follows before training.
LLMGA
├── llmga
├── scripts
├── work_dirs
├── checkpoints
│ ├── llmga-Phi-3-mini-128k-pretrain
│ ├── llmga-Qwen2-0.5B-pretrain
│ ├── llmga-llama3-8b-pretrain
│ ├── llmga-mistral-pretrain
│ ├── llmga-vicuna-7b-v1.5-pretrain
│ ├── llmga-Phi-3-mini-128k-full-finetune
│ ├── llmga-Qwen2-0.5B-full-finetune
│ ├── llmga-llama3-8b-it-full-finetune
│ ├── llmga-mistral_instruct-full-finetune
│ ├── llmga-vicuna-7b-v1.5-full-finetune
│ ├── llmga-cn-vicuna-7b-v1.5-full-finetune
│ ├── llmga-cn-Qwen2-0.5B-full-finetune
│ ├── llmga-sdxl-t2i
│ ├── llmga-sd15-inpainting-v2
│ ├── llmga-sd15-t2i-v2
├── data
│ │── jsons
│ │ ├── llmga-data
│ │ │ ├── Edit/train.json
│ │ │ ├── inpainting/train.json
│ │ │ ├── SG/train.json
│ │ │ ├── T2I/train.json
│ │ ├── text-data
│ │ │ ├── alpaca_gpt4_sharegpt_en_clean2.json
│ │ │ ├── lima.json
│ │ │ ├── oasst2.json
│ │ ├── llava_v1_5_mix665k.json
│ ├── llmga-imgs
│ │ ├── COCO
│ │ ├── LAION
│ │ ├── JourneyDB
│ ├── llava_pretrain
│ │ ├──images
│ ├── llava-imgs
│ │ ├── coco
│ │ │ ├── train2017
│ │ ├── gqa
│ │ │ ├── images
│ │ ├── ocr_vqa
│ │ │ ├── images
│ │ ├── textvqa
│ │ │ ├── train_images
│ │ ├── vg
│ │ │ ├── VG_100K
│ │ │ ├── VG_100K_2
LLMGA is trained on 8 A100 GPUs with 80GB memory. To train on fewer GPUs, you can reduce the per_device_train_batch_size and increase the gradient_accumulation_steps accordingly. Always keep the global batch size the same: per_device_train_batch_size x gradient_accumulation_steps x num_gpus.
Please make sure you download and organize the data following Preparation before training. Here, we just take training llmga vicuna 7b as an example. For more model training scripts, please check the ./scripts folder.
bash scripts/pretrain_vicuna_7b.sh
bash scripts/train_llmga_s1_7b_vicuna.sh
train LLMGA based on SD1.5-T2I
bash scripts/train_llmga_s2_sd15_t2i.sh
train LLMGA based on SD1.5-Inpainting
bash scripts/train_llmga_s2_sd15_inpaint.sh
Use LLMGA without the need of Gradio interface. It also supports multiple GPUs, 4-bit and 8-bit quantized inference. With 4-bit quantization. Here, we just give some examples for T2I, inpainting and instruction-based editing. For more model inference scripts, please check the ./scripts folder.
For T2I generation task.
bash scripts/test-llmga-sdxl-t2i.sh
For inpainting or outpainting task.
bash scripts/test-llmga-sd15-inpainting.sh
For instruction based editing task.
bash scripts/test-llmga-sd15-editing.sh
bash scripts/run_gradio_t2i.sh
If you find this repo useful for your research, please consider citing the paper
@article{xia2023llmga,
title={LLMGA: Multimodal Large Language Model based Generation Assistant},
author={Xia, Bin and Wang, Shiyin, and Tao, Yingfan and Wang, Yitong and Jia, Jiaya},
journal={ECCV},
year={2024}
}
We would like to thank the following repos for their great work:
2 commits
Python
99.5%
This project is the official implementation of 'LLMGA: Multimodal Large Language Model based Generation Assistant', ECCV2024 Oral
395
stars
2
commits
Python
primary language
Jun 2, 2025
updated
Bin Xia, Shiyin Wang, Yingfan Tao, Yitong Wang, and Jiaya Jia
New Version (Accepted by ECCV2024):
Old Version:
Abstract: In this paper, we introduce a Multimodal Large Language Model-based Generation Assistant (LLMGA), leveraging the vast reservoir of knowledge and proficiency in reasoning, comprehension, and response inherent in Large Language Models (LLMs) to assist users in image generation and editing. Diverging from existing approaches where Multimodal Large Language Models (MLLMs) generate fixed-size embeddings to control Stable Diffusion (SD), our LLMGA provides a detailed language generation prompt for precise control over SD. This not only augments LLM context understanding but also reduces noise in generation prompts, yields images with more intricate and precise content, and elevates the interpretability of the network. To this end, we curate a comprehensive dataset comprising prompt refinement, similar image generation, inpainting & outpainting, and instruction-based editing. Moreover, we propose a two-stage training scheme. In the first stage, we train the MLLM to grasp the properties of image generation and editing, enabling it to generate detailed prompts. In the second stage, we optimize SD to align with the MLLM's generation prompts. Additionally, we propose a reference-based restoration network to alleviate texture, brightness, and contrast disparities between generated and preserved regions during inpainting and outpainting. Extensive results show that LLMGA has promising generation and editing capabilities and can enable more flexible and expansive applications in an interactive manner.
Please follow the instructions below to install the required packages.
git clone https://github.com/dvlab-research/LLMGA.git
conda create -n llmga python=3.9 -y
conda activate llmga
cd LLMGA
pip install --upgrade pip # enable PEP 660 support
pip install -e .
cd ./llmga/diffusers
pip install .
pip install -e ".[train]"
pip install -r requirements.txt
pip install flash-attn --no-build-isolation
pip install datasets
pip install albumentations
pip install ninja
We provide the training data for LLMGA training.
please download LLMGA datasets and LLaVA pretrain datasets.
Besides, download LLaVA1.5 instruction tuning datasets llava_v1_5_mix665k.json, and download the images from constituting datasets:
.jpgPlease organize these downloaded data as in Structure.
We recommend users to download the pretrained MLP projector weights. Then put them in ./checkpoints following Structure.
Please download MLLM Models and SD models from the following links. For example, you can download LLMGA-MLLM7b and LLMGA-SDXL-T2I to realize LLMGA7b-T2I functionality. Please organize them as in Structure.
| MLLM Model (support English) | Pretrained Models |
|---|---|
| llmga-vicuna 7b | Download |
| llmga-mistral 7b | Download |
| llmga-llama3 8b | Download |
| llmga-qwen2 0.5b | Download |
| llmga-qwen2 1.5b | Download |
| llmga-qwen2 7b | Download |
| llmga-phi3 3b | Download |
| llmga-gemma 2b | Download |
| MLLM Model (further support Chinese and English) | Pretrained Models |
|---|---|
| llmga-cn-vicuna 7b | Download |
| llmga-cn-llama3 8b | Download |
| llmga-cn-gemma 2b | Download |
| llmga-cn-qwen2 0.5b | Download |
| SD Model | Pretrained Models |
|---|---|
| LLMGA-SD15-T2I | Download |
| LLMGA-SD15-Inpainting | Download |
| LLMGA-SDXL-T2I | Download |
| LLMGA-SDXL-Inpainting | Download |
The folder structure should be organized as follows before training.
LLMGA
├── llmga
├── scripts
├── work_dirs
├── checkpoints
│ ├── llmga-Phi-3-mini-128k-pretrain
│ ├── llmga-Qwen2-0.5B-pretrain
│ ├── llmga-llama3-8b-pretrain
│ ├── llmga-mistral-pretrain
│ ├── llmga-vicuna-7b-v1.5-pretrain
│ ├── llmga-Phi-3-mini-128k-full-finetune
│ ├── llmga-Qwen2-0.5B-full-finetune
│ ├── llmga-llama3-8b-it-full-finetune
│ ├── llmga-mistral_instruct-full-finetune
│ ├── llmga-vicuna-7b-v1.5-full-finetune
│ ├── llmga-cn-vicuna-7b-v1.5-full-finetune
│ ├── llmga-cn-Qwen2-0.5B-full-finetune
│ ├── llmga-sdxl-t2i
│ ├── llmga-sd15-inpainting-v2
│ ├── llmga-sd15-t2i-v2
├── data
│ │── jsons
│ │ ├── llmga-data
│ │ │ ├── Edit/train.json
│ │ │ ├── inpainting/train.json
│ │ │ ├── SG/train.json
│ │ │ ├── T2I/train.json
│ │ ├── text-data
│ │ │ ├── alpaca_gpt4_sharegpt_en_clean2.json
│ │ │ ├── lima.json
│ │ │ ├── oasst2.json
│ │ ├── llava_v1_5_mix665k.json
│ ├── llmga-imgs
│ │ ├── COCO
│ │ ├── LAION
│ │ ├── JourneyDB
│ ├── llava_pretrain
│ │ ├──images
│ ├── llava-imgs
│ │ ├── coco
│ │ │ ├── train2017
│ │ ├── gqa
│ │ │ ├── images
│ │ ├── ocr_vqa
│ │ │ ├── images
│ │ ├── textvqa
│ │ │ ├── train_images
│ │ ├── vg
│ │ │ ├── VG_100K
│ │ │ ├── VG_100K_2
LLMGA is trained on 8 A100 GPUs with 80GB memory. To train on fewer GPUs, you can reduce the per_device_train_batch_size and increase the gradient_accumulation_steps accordingly. Always keep the global batch size the same: per_device_train_batch_size x gradient_accumulation_steps x num_gpus.
Please make sure you download and organize the data following Preparation before training. Here, we just take training llmga vicuna 7b as an example. For more model training scripts, please check the ./scripts folder.
bash scripts/pretrain_vicuna_7b.sh
bash scripts/train_llmga_s1_7b_vicuna.sh
train LLMGA based on SD1.5-T2I
bash scripts/train_llmga_s2_sd15_t2i.sh
train LLMGA based on SD1.5-Inpainting
bash scripts/train_llmga_s2_sd15_inpaint.sh
Use LLMGA without the need of Gradio interface. It also supports multiple GPUs, 4-bit and 8-bit quantized inference. With 4-bit quantization. Here, we just give some examples for T2I, inpainting and instruction-based editing. For more model inference scripts, please check the ./scripts folder.
For T2I generation task.
bash scripts/test-llmga-sdxl-t2i.sh
For inpainting or outpainting task.
bash scripts/test-llmga-sd15-inpainting.sh
For instruction based editing task.
bash scripts/test-llmga-sd15-editing.sh
bash scripts/run_gradio_t2i.sh
If you find this repo useful for your research, please consider citing the paper
@article{xia2023llmga,
title={LLMGA: Multimodal Large Language Model based Generation Assistant},
author={Xia, Bin and Wang, Shiyin, and Tao, Yingfan and Wang, Yitong and Jia, Jiaya},
journal={ECCV},
year={2024}
}
We would like to thank the following repos for their great work:
2 commits
Python
99.5%