Coder Social home page Coder Social logo

NExT-GPT: Any-to-Any Multimodal LLM

Shengqiong Wu, Hao Fei*, Leigang Qu, Wei Ji, and Tat-Seng Chua. (*Correspondence )

NExT++, School of Computing, National University of Singapore


License YouTube

This repository hosts the code, data and model weight of NExT-GPT, the first end-to-end MM-LLM that perceives input and generates output in arbitrary combinations (any-to-any) of text, image, video, and audio and beyond.


πŸŽ‰ News

  • [2023.09.15] πŸš€πŸš€ Release the code of NExT-GPT in version 7b_tiva_v0.
  • [2023.09.27] πŸ”¨πŸ§© Added modality-blended batch sampler .
  • [2023.10.01] πŸ“’πŸ“’ Release the T2M instruction dataset.
  • [2023.10.04] πŸ‘πŸ‘ Release the checkpoint of NExT-GPT in version 7b_tiva_v0 .
  • [2023.10.15] πŸ”¨πŸš€ Update of NExT-GPT in version 7b_tiva_v0 .

πŸ‘‰ TODO

  • Release MosIT data.
  • Updating NExT-GPT in more types&sizes of LLMs.
  • Empowering NExT-GPT with more modalities of inputs&outputs.
  • ...

Example Demos

Here we showcase examples generated from NExT-GPT. For more examples, kindly visit the webpage, or the online live demo.

example_5_Trim.mp4
example_6_Trim.mp4
example_9_Trim.mp4

Brief Introduction

NExt-GPT is built on top of existing pre-trained LLM, multimodal encoder and SoTA diffusion models, with sufficient end-to-end instruction tuning.

Video-LLaMA

  • Multimodal Encoding Stage. Leveraging established encoders to encode inputs in various modalities, where these representations are projected into language-like representations comprehensible to the LLM through a projection layer.
  • LLM Understanding and Reasoning Stage. Harnessing an existing open-sourced LLM as the core to process input information for semantic understanding and reasoning. The LLM not only directly generates text tokens but also produces unique β€œmodality signal” tokens that serve as instructions to dictate the decoding layers whether & what modal content to output correspondingly.
  • Multimodal Generation Stage. Receiving the multimodal signals with specific instructions from LLM (if any), the Transformer-based output projection layers map the signal token representations into the ones that are understandable to following multimodal decoders.

For more technical details, kindly refer to the paper.


Getting Started

Table of Contents:


1. Code Structure

β”œβ”€β”€ figures
β”œβ”€β”€ data
β”‚   β”œβ”€β”€ T-X_pair_data  
β”‚   β”‚   β”œβ”€β”€ audiocap                      # text-autio pairs data
β”‚   β”‚   β”‚   β”œβ”€β”€ audios                    # audio files
β”‚   β”‚   β”‚   └── audiocap.json             # the audio captions
β”‚   β”‚   β”œβ”€β”€ cc3m                          # text-image paris data
β”‚   β”‚   β”‚   β”œβ”€β”€ images                    # image files
β”‚   β”‚   β”‚   └── cc3m.json                 # the image captions
β”‚   β”‚   └── webvid                        # text-video pairs data
β”‚   β”‚   β”‚   β”œβ”€β”€ videos                    # video files
β”‚   β”‚   β”‚   └── webvid.json               # the video captions
β”‚   β”œβ”€β”€ IT_data                           # instruction data
β”‚   β”‚   β”œβ”€β”€ T+X-T_data                    # text+[image/audio/video] to text instruction data
β”‚   β”‚   β”‚   β”œβ”€β”€ alpaca                    # textual instruction data
β”‚   β”‚   β”‚   β”œβ”€β”€ llava                     # visual instruction data
β”‚   β”‚   β”œβ”€β”€ T-T+X                         # synthesized text to text+[image/audio/video] instruction data
β”‚   β”‚   └── MosIT                         # Modality-switching Instruction Tuning instruction data
β”œβ”€β”€ code
β”‚   β”œβ”€β”€ config
β”‚   β”‚   β”œβ”€β”€ base.yaml                     # the model configuration 
β”‚   β”‚   β”œβ”€β”€ stage_1.yaml                  # enc-side alignment training configuration
β”‚   β”‚   β”œβ”€β”€ stage_2.yaml                  # dec-side alignment training configuration
β”‚   β”‚   └── stage_3.yaml                  # instruction-tuning configuration
β”‚   β”œβ”€β”€ dsconfig
β”‚   β”‚   β”œβ”€β”€ stage_1.json                  # deepspeed configuration for enc-side alignment training
β”‚   β”‚   β”œβ”€β”€ stage_2.json                  # deepspeed configuration for dec-side alignment training
β”‚   β”‚   └── stage_3.json                  # deepspeed configuration for instruction-tuning training
β”‚   β”œβ”€β”€ datast
β”‚   β”‚   β”œβ”€β”€ base_dataset.py
β”‚   β”‚   β”œβ”€β”€ catalog.py                    # the catalog information of the dataset
β”‚   β”‚   β”œβ”€β”€ cc3m_datast.py                # process and load text-image pair dataset
β”‚   β”‚   β”œβ”€β”€ audiocap_datast.py            # process and load text-audio pair dataset
β”‚   β”‚   β”œβ”€β”€ webvid_dataset.py             # process and load text-video pair dataset
β”‚   β”‚   β”œβ”€β”€ T+X-T_instruction_dataset.py  # process and load text+x-to-text instruction dataset
β”‚   β”‚   β”œβ”€β”€ T-T+X_instruction_dataset.py  # process and load text-to-text+x instruction dataset
β”‚   β”‚   └── concat_dataset.py             # process and load multiple dataset
β”‚   β”œβ”€β”€ model                     
β”‚   β”‚   β”œβ”€β”€ ImageBind                     # the code from ImageBind Model
β”‚   β”‚   β”œβ”€β”€ common
β”‚   β”‚   β”œβ”€β”€ anyToImageVideoAudio.py       # the main model file
β”‚   β”‚   β”œβ”€β”€ agent.py
β”‚   β”‚   β”œβ”€β”€ modeling_llama.py
β”‚   β”‚   β”œβ”€β”€ custom_ad.py                  # the audio diffusion 
β”‚   β”‚   β”œβ”€β”€ custom_sd.py                  # the image diffusion
β”‚   β”‚   β”œβ”€β”€ custom_vd.py                  # the video diffusion
β”‚   β”‚   β”œβ”€β”€ layers.py                     # the output projection layers
β”‚   β”‚   └── ...  
β”‚   β”œβ”€β”€ scripts
β”‚   β”‚   β”œβ”€β”€ train.sh                      # training NExT-GPT script
β”‚   β”‚   └── app.sh                        # deploying demo script
β”‚   β”œβ”€β”€ header.py
β”‚   β”œβ”€β”€ process_embeddings.py             # precompute the captions embeddings
β”‚   β”œβ”€β”€ train.py                          # training
β”‚   β”œβ”€β”€ inference.py                      # inference
β”‚   β”œβ”€β”€ demo_app.py                       # deploy Gradio demonstration 
β”‚   └── ...
β”œβ”€β”€ ckpt                           
β”‚   β”œβ”€β”€ delta_ckpt                        # tunable NExT-GPT params
β”‚   β”‚   β”œβ”€β”€ nextgpt         
β”‚   β”‚   β”‚   β”œβ”€β”€ 7b_tiva_v0                # the directory to save the log file
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ log                   # the logs
β”‚   └── ...       
β”‚   β”œβ”€β”€ pretrained_ckpt                   # frozen params of pretrained modules
β”‚   β”‚   β”œβ”€β”€ imagebind_ckpt
β”‚   β”‚   β”‚   β”œβ”€β”€huge                       # version
β”‚   β”‚   β”‚   β”‚   └──imagebind_huge.pth
β”‚   β”‚   β”œβ”€β”€ vicuna_ckpt
β”‚   β”‚   β”‚   β”œβ”€β”€ 7b_v0                     # version
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ config.json
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ pytorch_model-00001-of-00002.bin
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ tokenizer.model
β”‚   β”‚   β”‚   β”‚   └── ...
β”œβ”€β”€ LICENCE.md
β”œβ”€β”€ README.md
└── requirements.txt

2. Environment Preparation [Back to Top]

Please first clone the repo and install the required environment, which can be done by running the following commands:

conda env create -n nextgpt python=3.8

conda activate nextgpt

# CUDA 11.6
conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.6 -c pytorch -c nvidia

git clone https://github.com/NExT-GPT/NExT-GPT.git
cd NExT-GPT

pip install -r requirements.txt

3. Training/Adapting NExt-GPT on Your Own

3.1. Preparing Pre-trained Checkpoint [Back to Top]

NExT-GPT is trained based on following excellent existing models. Please follow the instructions to prepare the checkpoints.

  • ImageBind is the unified image/video/audio encoder. The pre-trained checkpoint can be downloaded from here with version huge. Afterward, put the imagebind_huge.pth file at [./ckpt/pretrained_ckpt/imagebind_ckpt/huge].
  • Vicuna: first prepare the LLaMA by following the instructions [here]. Then put the pre-trained model at [./ckpt/pretrained_ckpt/vicuna_ckpt/].
  • Image Diffusion is used to generate images. NExT-GPT uses Stable Diffusion with version v1-5. (will be automatically downloaded)
  • Audio Diffusion for producing audio content. NExT-GPT employs AudioLDM with version l-full. (will be automatically downloaded)
  • Video Diffusion for the video generation. We employ ZeroScope with version v2_576w. (will be automatically downloaded)

3.2. Preparing Dataset [Back to Top]

Please download the following datasets used for model training:

A) T-X pairs data

B) Instruction data

3.3. Precomputing Embeddings [Back to Top]

In decoding-side alignment training, we minimize the distance between the representation of signal tokens and captions. To save costs of time and memory, we precompute the text embeddings for image, audio and video captions using the text encoder within the respective diffusion models.

Please run this command before the following training of NExT-GPT, where the produced embedding file will be saved at [./data/embed].

cd ./code/
python process_embeddings.py ../data/T-X_pair_data/cc3m/cc3m.json image ../data/embed/ runwayml/stable-diffusion-v1-5

Note of arguments:

  • args[1]: path of caption file;
  • args[2]: modality, which can be image, video, and audio;
  • args[3]: saving path of embedding file;
  • args[4]: corresponding pre-trained diffusion model name.

3.4. Training NExT-GPT [Back to Top]

First of all, please refer to the base configuration file [./code/config/base.yaml] for the basic system setting of overall modules.

Then, the training of NExT-GPT starts with this script:

cd ./code
bash scripts/train.sh

Specifying the command:

deepspeed --include localhost:0 --master_addr 127.0.0.1 --master_port 28459 train.py \
    --model nextgpt \
    --stage 1\
    --save_path  ../ckpt/delta_ckpt/nextgpt/7b_tiva_v0/\
    --log_path ../ckpt/delta_ckpt/nextgpt/7b_tiva_v0/log/

where the key arguments are:

  • --include: localhost:0 indicating the GPT cuda number 0 of deepspeed.
  • --stage: training stage.
  • --save_path: the directory which saves the trained delta weights. This directory will be automatically created.
  • --log_path: the directory which saves the log file.

The whole NExT-GPT training involves 3 steps:

  • Step-1: Encoding-side LLM-centric Multimodal Alignment. This stage trains the input projection layer while freezing the ImageBind, LLM, output projection layer.

    Just run the above train.sh script by setting: --stage 1

    Also refer to the running config file [./code/config/stage_1.yaml] and deepspeed config file [./code/dsconfig/stage_1.yaml] for more step-wise configurations.

    Note that the dataset used for training in this step is included dataset_name_list and the dataset name must precisely match the definition in [./code/dataset/catalog.py]

  • Step-2: Decoding-side Instruction-following Alignment. This stage trains the output projection layers while freezing the ImageBind, LLM, input projection layers.

    Just run the above train.sh script by setting: --stage 2

    Also refer to the running config file [./code/config/stage_2.yaml] and deepspeed config file [./code/dsconfig/stage_2.yaml] for more step-wise configurations.

  • Step-3: Instruction Tuning. This stage instruction-tune 1) the LLM via LoRA, 2) input projection layer and 3) output projection layer on the instruction dataset.

    Just run the above train.sh script by setting: --stage 3

    Also refer to the running config file [./code/config/stage_3.yaml] and deepspeed config file [./code/dsconfig/stage_3.yaml] for more step-wise configurations.

4. Running NExT-GPT System [Back to Top]

4.1. Preparing Checkpoints

First, loading the pre-trained NExT-GPT system.

4.2. Deploying Gradio Demo

Upon completion of the checkpoint loading, you can run the demo locally via:

cd ./code
bash scripts/app.sh

Specifying the key arguments as:

  • --nextgpt_ckpt_path: the path of pre-trained NExT-GPT params.

Contact

For any questions or feedback, feel free to contact Shengqiong Wu and Hao Fei.

Citation

If you find NextGPT useful in your research or applications, please kindly cite:

@articles{wu2023nextgpt,
  title={NExT-GPT: Any-to-Any Multimodal LLM},
  author={Shengqiong Wu and Hao Fei and Leigang Qu and Wei Ji and Tat-Seng Chua},
  journal = {CoRR},
  volume = {abs/2309.05519},
  year={2023}
}

Acknowledgements

You may refer to related work that serves as foundations for our framework and code repository, Vicuna, ImageBind, Stable Diffusion, AudioLDM, and Zeroscope. We also partially draw inspirations from PandaGPT, VPGTrans, GILL, CoDi, Video-LLaMA, and MiniGPT-4. Thanks for their wonderful works.

License Notices

This repository is under BSD 3-Clause License. NExT-GPT is a research project intended for non-commercial use only. One must NOT use the code of NExT-GPT for any illegal, harmful, violent, racist, or sexual purposes. One is strictly prohibited from engaging in any activity that will potentially violate these guidelines. Any potential commercial use of this code should be approved by the authors.

NExT-GPT's Projects

next-gpt icon next-gpt

Code and models for NExT-GPT: Any-to-Any Multimodal Large Language Model

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.