license: apache-2.0
language:
论文《AnyGPT:基于离散序列建模的统一多模态大语言模型》基础模型
简介
我们推出AnyGPT,这是一款支持任意模态转换的多模态语言模型,通过离散表征统一处理语音、文本、图像和音乐等多元模态。基础模型实现了四种模态的对齐,支持不同模态与文本间的相互转换。此外,我们基于多种生成模型构建了AnyInstruct指令数据集,包含任意模态转换的指令。在该数据集上训练的对话模型可实现自由的多模态对话,可随意插入多模态数据。
AnyGPT提出了一种生成式训练方案,将所有模态数据转化为统一的离散表征,通过Next Token Prediction任务在大型语言模型(LLM)上进行统一训练。从"压缩即智能"的角度来看:当Tokenizer质量足够高,且LLM的困惑度(PPL)足够低时,就有可能将互联网上的海量多模态数据压缩到同一模型中,从而涌现出纯文本LLM所不具备的能力。
演示效果详见项目主页。
示例演示

推理
安装
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
模型权重
SpeechTokenizer用于语音分词与重建,Soundstorm负责副语言信息补全,SEED-tokenizer用于图像分词。
用于图像重建的unCLIP SD-UNet模型权重,以及用于音乐分词与重建的Encodec-32k权重将自动下载。
基础模型命令行推理
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|{描述文本}
- 示例:
text|image|一个热闹的中世纪集市场景,商贩们在彩色帐篷下售卖异域商品
- 图生文
image|text|{图像路径}
- 示例:
image|text|static/infer/image/cat.jpg
- 语音合成(随机音色)
text|speech|{语音内容}
- 示例:
text|speech|即使被关在果壳之中,我仍自以为是无限宇宙之王
- 零样本语音合成
text|speech|{语音内容}|{音色提示}
- 示例:
text|speech|即使被关在果壳之中,我仍自以为是无限宇宙之王|static/infer/speech/voice_prompt1.wav/voice_prompt3.wav
- 语音识别
speech|text|{语音文件路径}
- 示例:
speech|text|AnyGPT/static/infer/speech/voice_prompt2.wav
- 文生乐
text|music|{描述文本}
- 示例:
text|music|具有独立摇滚风格,包含营造梦幻舒缓氛围的独特元素
- 乐生文
music|text|{音乐文件路径}
- 示例:
music|text|static/infer/music/具有独立摇滚风格.wav
注意事项
针对不同任务,我们采用了不同的语言模型解码策略。图像、语音和音乐生成的解码配置文件分别位于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
沿用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}
}