VisCPM-Chat

作者 openbmb · 下载 1357 · 点赞 15 · 更新 2023-11-02

VisCPM

简体中文 | English

VisCPM-Chat 预览 1 VisCPM-Chat 预览 2

VisCPM is a family of open-source large multimodal models, which support multimodal conversational capabilities (VisCPM-Chat model) and text-to-image generation capabilities (VisCPM-Paint model) in both Chinese and English, achieving state-of-the-art peformance among Chinese open-source multimodal models. VisCPM is trained based on the large language model CPM-Bee with 10B parameters, fusing visual encoder (Q-Former) and visual decoder (Diffusion-UNet) to support visual inputs and outputs. Thanks to the good bilingual capability of CPM-Bee, VisCPM can be pre-trained with English multimodal data only and well generalize to achieve promising Chinese multimodal capabilities.

VisCPM是一个开源的多模态大模型系列,支持中英双语的多模态对话能力(VisCPM-Chat模型)和文到图生成能力(VisCPM-Paint模型),在中文多模态开源模型中达到最佳水平。VisCPM基于百亿参数量语言大模型CPM-Bee(10B)训练,融合视觉编码器(Q-Former)和视觉解码器(Diffusion-UNet)以支持视觉信号的输入和输出。得益于CPM-Bee底座优秀的双语能力,VisCPM可以仅通过英文多模态数据预训练,泛化实现优秀的中文多模态能力。

VisCPM-Chat

VisCPM-Chat支持面向图像进行中英双语多模态对话。该模型使用Q-Former作为视觉编码器,使用CPM-Bee(10B)作为语言交互基底模型,并通过语言建模训练目标融合视觉和语言模型。模型训练包括预训练和指令精调两阶段:

我们在LLaVA英文测试集和翻译的中文测试集对模型进行了评测,该评测基准考察模型在开放域对话、图像细节描述、复杂推理方面的表现,并使用GPT-4进行打分。可以观察到,VisCPM-Chat在中文多模态能力方面取得了最佳的平均性能,在通用域对话和复杂推理表现出色,同时也表现出了不错的英文多模态能力。

模型 英文 中文
多模态对话 细节描述 复杂推理 平均 多模态对话 细节描述 复杂推理 平均
英文模型 MiniGPT4 65 67.3 76.6 69.7 - - - -
InstructBLIP 81.9 68 91.2 80.5 - - - -
LLaVA 89.5 70.4 96.2 85.6 - - - -
中英双语 mPLUG-Owl 64.6 47.7 80.1 64.2 76.3 61.2 77.8 72
VisualGLM 62.4 63 80.6 68.7 76.6 87.8 83.6 82.7
Ziya (LLaMA 13B) 82.7 69.9 92.1 81.7 85 74.7 82.4 80.8
VisCPM-Chat 83.3 68.9 90.5 81.1 92.7 76.1 89.2 86.3

VisCPM-Paint

VisCPM-Paint支持中英双语的文到图生成。该模型使用CPM-Bee(10B)作为文本编码器,使用UNet作为图像解码器,并通过扩散模型训练目标融合语言和视觉模型。在训练过程中,语言模型参数始终保持固定。我们使用Stable Diffusion 2.1的UNet参数初始化视觉解码器,并通过逐步解冻其中关键的桥接参数将其与语言模型融合:首先训练文本表示映射到视觉模型的线性层,然后进一步解冻UNet的交叉注意力层。该模型在LAION 2B英文图文对数据上进行了训练。

与VisCPM-Chat类似,我们发现得益于CPM-Bee的双语能力,VisCPM-Paint可以仅通过英文图文对训练,泛化实现良好的中文文到图生成能力,达到中文开源模型的最佳效果。通过进一步加入20M清洗后的原生中文图文对数据,以及120M翻译到中文的图文对数据,模型的中文文到图生成能力可以获得进一步提升。我们在MSCOCO上采样了3万张图片,计算了FID(Fréchet Inception Distance)和Clip Score,前者用于评估生成图片的质量,后面用于评估生成的图片与输入的匹配程度。

模型 英文 中文
FID↓ CLIP Score↑ FID↓ CLIP Score↑
AltDiffusion 17.16 25.24 16.09 24.05
TaiyiDiffusion - - 15.58 22.69
Stable Diffusion 9.08 26.22 - -
VisCPM-Paint-en 9.51 25.35 10.86 23.38
VisCPM-Paint-zh 9.98 25.04 9.65 24.17

安装

conda create -n viscpm python=3.10 -y
conda activate viscpm
pip install setuptools
pip install diffusers jieba matplotlib numpy opencv_python
pip install pandas Pillow psutil pydantic scipy
pip install torch==1.13.1 torchscale==0.2.0 torchvision==0.14.1 timm
pip install transformers==4.28.0
pip install tqdm typing_extensions
pip install git+https://github.com/thunlp/OpenDelta.git
pip install git+https://github.com/OpenBMB/CPM-Bee.git#egg=cpm-live&subdirectory=src

VisCPM需要单卡40GB以上的GPU运行,我们会在尽快更新更加节省显存的推理方式。

使用

>>> from transformers import AutoModel, AutoTokenizer, AutoImageProcessor
>>> from PIL import Image

>>> tokenizer = AutoTokenizer.from_pretrained('openbmb/VisCPM-Chat', trust_remote_code=True)
>>> processor = AutoImageProcessor.from_pretrained('openbmb/VisCPM-Chat', trust_remote_code=True)
>>> model = AutoModel.from_pretrained('openbmb/VisCPM-Chat', trust_remote_code=True).to('cuda')

>>> data = [{
>>>     'context': '',
>>>     'question': 'describe this image in detail.',
>>>     'image': tokenizer.unk_token * model.query_num,
>>>     '<ans>': ''
>>>     }]
>>> image = Image.open('case.jpg')
>>> result = model.generate(data, tokenizer, processor, image)
>>> print(result[0]['<ans>'])
这幅图片显示了一群热气球在天空中飞行。这些热气球漂浮在不同的地方,包括山脉、城市和乡村地区。