🚀 AnyGPT:统一多模态大语言模型基础模型
AnyGPT是一个支持任意模态转换的多模态语言模型,它利用离散表示统一处理语音、文本、图像和音乐等多种模态数据。其基础模型实现了四种模态的对齐,支持不同模态与文本之间的相互转换。此外,基于多种生成模型构建的AnyInstruct数据集,包含了任意模态转换的指令。在该数据集上训练的聊天模型能够进行自由的多模态对话,用户可以随意插入多模态数据。
🚀 快速开始
AnyGPT提出了一种生成式训练方案,将所有模态的数据转换为统一的离散表示,并使用Next Token Prediction任务在大语言模型(LLM)上进行统一训练。从“压缩即智能”的角度来看:当分词器(Tokenizer)的质量足够高,且大语言模型的困惑度(PPL)足够低时,就有可能将互联网上大量的多模态数据压缩到同一个模型中,从而涌现出纯文本大语言模型所不具备的能力。
项目演示请见项目页面。
✨ 主要特性
- 多模态统一处理:支持语音、文本、图像和音乐等多种模态的统一处理和相互转换。
- 自由对话:聊天模型可进行自由的多模态对话,允许随意插入多模态数据。
- 生成式训练:采用生成式训练方案,将多模态数据转换为统一离散表示进行训练。
📦 安装指南
git clone https://github.com/OpenMOSS/AnyGPT.git
cd AnyGPT
conda create --name AnyGPT python=3.9
conda activate AnyGPT
pip install -r requirements.txt
💻 使用示例
基础用法
python anygpt/src/infer/cli_infer_base_model.py \
--model-name-or-path "path/to/AnyGPT-7B-base" \
--image-tokenizer-path models/seed-tokenizer-2/seed_quantizer.pt \
--speech-tokenizer-path "path/to/model" \
--speech-tokenizer-config "path/to/config" \
--soundstorm-path "path/to/model" \
--output-dir "infer_output/base"
例如:
python anygpt/src/infer/cli_infer_base_model.py \
--model-name-or-path models/anygpt/base \
--image-tokenizer-path models/seed-tokenizer-2/seed_quantizer.pt \
--speech-tokenizer-path models/speechtokenizer/ckpt.dev \
--speech-tokenizer-config models/speechtokenizer/config.json \
--soundstorm-path models/soundstorm/speechtokenizer_soundstorm_mls.pt \
--output-dir "infer_output/base"
高级用法
基础模型可以执行多种任务,包括文本到图像、图像描述、自动语音识别(ASR)、零样本文本到语音(TTS)、文本到音乐以及音乐描述等。
我们可以按照特定的指令格式进行推理:
- 文本到图像
text|image|{caption}
- 示例:
text|image|A bustling medieval market scene with vendors selling exotic goods under colorful tents
- 图像描述
image|text|{caption}
- 示例:
image|text|static/infer/image/cat.jpg
- TTS(随机语音)
text|speech|{speech content}
- 示例:
text|speech|I could be bounded in a nutshell and count myself a king of infinite space.
- 零样本TTS
text|speech|{speech content}|{voice prompt}
- 示例:
text|speech|I could be bounded in a nutshell and count myself a king of infinite space.|static/infer/speech/voice_prompt1.wav/voice_prompt3.wav
- ASR
speech|text|{speech file path}
- 示例:
speech|text|AnyGPT/static/infer/speech/voice_prompt2.wav
- 文本到音乐
text|music|{caption}
- 示例:
text|music|features an indie rock sound with distinct elements that evoke a dreamy, soothing atmosphere
- 音乐描述
music|text|{music file path}
- 示例:
music|text|static/infer/music/features an indie rock sound with distinct element.wav
📚 详细文档
模型权重
SpeechTokenizer用于语音的分词和重建,Soundstorm负责完成副语言信息,SEED-tokenizer用于图像的分词。
用于重建图像的unCLIP SD-UNet模型权重和用于音乐分词和重建的Encodec-32k模型权重将自动下载。
注意事项
对于不同的任务,我们使用了不同的语言模型解码策略。图像、语音和音乐生成的解码配置文件分别位于config/image_generate_config.json
、config/speech_generate_config.json
和config/music_generate_config.json
中。其他模态到文本的解码配置文件位于config/text_generate_config.json
中。您可以直接修改或添加参数来更改解码策略。
由于数据和训练资源的限制,模型的生成可能仍然不稳定。您可以多次生成或尝试不同的解码策略。
语音和音乐响应将保存为.wav
文件,图像响应将保存为jpg
文件。文件名将是提示词和时间的组合。这些文件的路径将在响应中显示。
训练
预训练
- 安装依赖
cd FastChat
pip3 install -e ".[train]"
- 运行
srun --partition=llm_h --job-name=pretrain --gres=gpu:8 --quotatype=spot --ntasks=1 --ntasks-per-node=1 --cpus-per-task 100 --kill-on-bad-exit=1 bash scripts/stage1_pretrain.sh
我们在"data"文件夹中提供了一些示例数据。要下载完整的数据集,请参考以下内容:
- 图像数据:https://huggingface.co/datasets/zhanjun/AnyGPT-data-image
- t2i文件夹中的两个数据集是高质量图像数据集,用于微调文本到图像的生成。
- 语音数据:https://huggingface.co/datasets/zhanjun/AnyGPT-data-speech
- 音乐数据:无
- 指令数据:https://huggingface.co/datasets/zhanjun/Anygpt_data_instruction
这些数据已通过多模态分词器进行了预处理。
🔧 技术细节
AnyGPT提出的生成式训练方案,核心在于将所有模态的数据转换为统一的离散表示,然后使用Next Token Prediction任务在大语言模型上进行统一训练。从“压缩即智能”的理论出发,当分词器能够高效地将多模态数据进行离散化,且大语言模型能够以低困惑度处理这些离散表示时,就有可能将海量的多模态数据压缩到同一个模型中,从而使模型具备处理多种模态数据和进行模态转换的能力。
📄 许可证
AnyGPT
遵循LLaMA2的原始许可证发布。
引用
如果您在研究或应用中发现AnyGPT和AnyInstruct很有用,请引用以下文献:
@article{zhan2024anygpt,
title={AnyGPT: Unified Multimodal LLM with Discrete Sequence Modeling},
author={Zhan, Jun and Dai, Junqi and Ye, Jiasheng and Zhou, Yunhua and Zhang, Dong and Liu, Zhigeng and Zhang, Xin and Yuan, Ruibin and Zhang, Ge and Li, Linyang and others},
journal={arXiv preprint arXiv:2402.12226},
year={2024}
}
致谢