Qwe-VL
?
?&bsp; |
Qwe-VL-Chat
?
?&bsp;
(It4:
?
?&bsp;) |
Qwe-VL-Plus
?
?&bsp; |
Qwe-VL-Max
?
?&bsp;
Web&bsp;&bsp; | &bsp;&bsp;
API&bsp;&bsp; | &bsp;&bsp;
WeChat&bsp;&bsp; | &bsp;&bsp;
Discord&bsp;&bsp; | &bsp;&bsp;
Paper&bsp;&bsp; | &bsp;&bsp;
Tutorial
Qwe-VL 是阿里云研发的大规模视觉语言模型(Large Visio Laguage Model, LVLM)。Qwe-VL 可以以图像、文本、检测框作为输入,并以文本和检测框作为输出。Qwe-VL 系列模型的特点包括:
- 强大的性能:在四大类多模态任务的标准英文测评中(Zero-shot Captio/VQA/DocVQA/Groudig)上,均取得同等通用模型大小下最好效果;
- 多语言对话模型:天然支持多语言对话,端到端支持图片里中英双语的长文本识别;
- 多图交错对话:支持多图输入和比较,指定图片问答,多图文学创作等;
- 首个支持中文开放域定位的通用模型:通过中文开放域语言表达进行检测框标注;
- 细粒度识别和理解:相比于目前其它开源LVLM使用的224分辨率,Qwe-VL是首个开源的448分辨率的LVLM模型。更高分辨率可以提升细粒度的文字识别、文档问答和检测框标注。
Qwe-VL (Qwe Large Visio Laguage Model) is the visual multimodal versio of the large model series, Qwe (abbr. Togyi Qiawe), proposed by Alibaba Cloud. Qwe-VL accepts image, text, ad boudig box as iputs, outputs text ad boudig box. The features of Qwe-VL iclude:
- Strog performace: It sigificatly surpasses existig ope-source Large Visio Laguage Models (LVLM) uder similar scale settigs o multiple Eglish evaluatio bechmarks (icludig Zero-shot captio, VQA, DocVQA, ad Groudig).
- Multi-ligual LVLM support text recogizatio: Qwe-VL aturally supports multi-ligual coversatio, ad it promotes ed-to-ed recogitio of Chiese ad Eglish bi-ligual text i images.
- Multi-image iterleaved coversatios: This feature allows for the iput ad compariso of multiple images, as well as the ability to specify questios related to the images ad egage i multi-image storytellig.
- First geeralist model support groudig i Chiese: Detectig boudig boxes through ope-domai laguage expressio i both Chiese ad Eglish.
- Fie-graied recogizatio ad uderstadig: Compared to the 224 resolutio curretly used by other ope-source LVLM, the 448 resolutio promotes fie-graied text recogitio, documet QA, ad boudig box aotatio.
目前,我们提供了 Qwe-VL 系列的两个模型:
- Qwe-VL: Qwe-VL 以 Qwe-7B 的预训练模型作为语言模型的初始化,并以 Opeclip ViT-bigG 作为视觉编码器的初始化,中间加入单层随机初始化的 cross-attetio,经过约1.5B的图文数据训练得到。最终图像输入分辨率为448。
- Qwe-VL-Chat: 在 Qwe-VL 的基础上,我们使用对齐机制打造了基于大语言模型的视觉AI助手Qwe-VL-Chat,其训练数据涵盖了 QWe-7B 的纯文本 SFT 数据、开源 LVLM 的 SFT 数据、数据合成和人工标注的图文对齐数据。
如果想了解更多关于模型的信息,请点击链接查看我们的技术备忘录。
We release two models of the Qwe-VL series:
- Qwe-VL: The pre-traied LVLM model uses Qwe-7B as the iitializatio of the LLM, ad Opeclip ViT-bigG as the iitializatio of the visual ecoder. Ad coects them with a radomly iitialized cross-attetio layer. Qwe-VL was traied o about 1.5B image-text paired data. The fial image iput resolutio is 448.
- Qwe-VL-Chat: A multimodal LLM-based AI assistat, which is traied with aligmet techiques.
For more details about Qwe-VL, please refer to our techical memo.
依赖项 (Depedecy)
- pytho 3.8及以上版本
- pytorch 1.12及以上版本,推荐2.0及以上版本
- 建议使用CUDA 11.4及以上(GPU用户需考虑此选项)
pip istall modelscope -U
pip istall trasformers accelerate tiktoke -U
pip istall eiops trasformers_stream_geerator -U
pip istall "pillow==9.*" -U
pip istall torchvisio
pip istall matplotlib -U
快速使用(Quickstart)
您可以通过以下代码轻松调用:
You ca easily call the model with the followig code:
from modelscope import (
sapshot_dowload, AutoModelForCausalLM, AutoTokeizer, GeeratioCofig
)
import torch
model_id = 'qwe/Qwe-VL-Chat'
revisio = 'v1.1.0'
model_dir = sapshot_dowload(model_id, revisio=revisio)
torch.maual_seed(1234)
# 请注意:分词器默认行为已更改为默认关闭特殊toke攻击防护。
tokeizer = AutoTokeizer.from_pretraied(model_dir, trust_remote_code=True)
# 打开bf16精度,A100、H100、RTX3060、RTX3070等显卡建议启用以节省显存
# model = AutoModelForCausalLM.from_pretraied(model_dir, device_map="auto", trust_remote_code=True, bf16=True).eval()
# 打开fp16精度,V100、P100、T4等显卡建议启用以节省显存
model = AutoModelForCausalLM.from_pretraied(model_dir, device_map="auto", trust_remote_code=True, fp16=True).eval()
# 使用CPU进行推理,需要约32GB内存
# model = AutoModelForCausalLM.from_pretraied(model_dir, device_map="cpu", trust_remote_code=True).eval()
# 默认使用自动模式,根据设备自动选择精度
# model = AutoModelForCausalLM.from_pretraied(model_dir, device_map="auto", trust_remote_code=True).eval()
# 可指定不同的生成长度、top_p等相关超参
model.geeratio_cofig = GeeratioCofig.from_pretraied(model_dir, trust_remote_code=True)
# 第一轮对话 1st dialogue tur
query = tokeizer.from_list_format([
{'image': 'https://qiawe-res.oss-c-beijig.aliyucs.com/Qwe-VL/assets/demo.jpeg'},
{'text': '这是什么'},
])
respose, history = model.chat(tokeizer, query=query, history=Noe)
prit(respose)
# 图中是一名年轻女子在沙滩上和她的狗玩耍,狗的品种是拉布拉多。她们坐在沙滩上,狗的前腿抬起来,与人互动。
# 第二轮对话 2st dialogue tur
respose, history = model.chat(tokeizer, '输出击掌的检测框', history=history)
prit(respose)
# <ref>"击掌"</ref><box>(211,412),(577,891)</box>
image = tokeizer.draw_bbox_o_latest_picture(respose, history)
image.save('output_chat.jpg')
使用量化
import os
os.eviro['CUDA_VISIBLE_DEVICES'] = '0'
from modelscope import (
sapshot_dowload, AutoModelForCausalLM, AutoTokeizer, GeeratioCofig,
)
from trasformers import BitsAdBytesCofig
import torch
model_id = 'qwe/Qwe-VL-Chat'
revisio = 'v1.1.0'
model_dir = sapshot_dowload(model_id, revisio=revisio)
torch.maual_seed(1234)
quatizatio_cofig = BitsAdBytesCofig(
load_i_4bit=True,
bb_4bit_compute_dtype=torch.float16,
bb_4bit_quat_type='f4',
bb_4bit_use_double_quat=True,
llm_it8_skip_modules=['lm_head', 'att_pool.att'])
tokeizer = AutoTokeizer.from_pretraied(model_dir, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretraied(model_dir, device_map="auto",
trust_remote_code=True, fp16=True,
quatizatio_cofig=quatizatio_cofig).eval()
model.geeratio_cofig = GeeratioCofig.from_pretraied(model_dir, trust_remote_code=True)
query = tokeizer.from_list_format([
{'image': 'https://qiawe-res.oss-c-beijig.aliyucs.com/Qwe-VL/assets/demo.jpeg'},
{'text': '这是什么'},
])
respose, history = model.chat(tokeizer, query=query, history=Noe)
prit(respose)
respose, history = model.chat(tokeizer, '输出狗的检测框', history=history)
prit(respose)
image = tokeizer.draw_bbox_o_latest_picture(respose, history)
image.save('output_chat2.jpg')
微调(SFT)
代码链接: https://github.com/modelscope/swift/tree/mai/examples/pytorch/llm
- 支持的sft方法: lora, qlora, 全参数微调, …
- 支持的模型: qwe系列, qwe-vl系列, baichua系列, chatglm2系列, llama系列, opebuddy-llama系列, iterlm系列, xverse系列, …
- 支持的特性: 模型量化, DDP, 模型并行, gradiet checkpoitig, 梯度累加, 支持推送ModelScope Hub, 自定义数据集, 多模态和Aget SFT, 多轮对话, …
使用qlora SFT qwe-vl-chat的脚本 (需要10GB显存)
# https://github.com/modelscope/swift/blob/mai/examples/pytorch/llm/scripts/qwe_vl_chat/qlora/sft.sh
# Experimetal eviromet: A10
# 10GB GPU memory (ot use flash_att)
PYTHONPATH=../../.. \
CUDA_VISIBLE_DEVICES=0 \
pytho llm_sft.py \
--model_type qwe-vl-chat \
--sft_type lora \
--template_type chatml \
--dtype bf16 \
--output_dir output \
--dataset coco-e \
--trai_dataset_sample 20000 \
--um_trai_epochs 1 \
--max_legth 2048 \
--quatizatio_bit 4 \
--bb_4bit_comp_dtype bf16 \
--lora_rak 8 \
--lora_alpha 32 \
--lora_dropout_p 0. \
--lora_target_modules c_att att.c_proj \
--gradiet_checkpoitig true \
--batch_size 1 \
--weight_decay 0. \
--learig_rate 1e-4 \
--gradiet_accumulatio_steps 16 \
--max_grad_orm 0.5 \
--warmup_ratio 0.03 \
--eval_steps 100 \
--save_steps 100 \
--save_total_limit 2 \
--loggig_steps 10 \
--use_flash_att false \
--push_to_hub false \
--hub_model_id qwe-vl-chat-qlora \
--hub_private_repo true \
--hub_toke 'your-sdk-toke' \
评测
我们从两个角度评测了两个模型的能力:
在英文标准 Bechmark 上评测模型的基础任务能力。目前评测了四大类多模态任务:
- Zero-shot Captio: 评测模型在未见过数据集上的零样本图片描述能力;
- Geeral VQA: 评测模型的通用问答能力,例如判断题、颜色、个数、类目等问答能力;
- Text-based VQA:评测模型对于图片中文字相关的识别/问答能力,例如文档问答、图表问答、文字问答等;
- Referrig Expressio Compressio:评测模型给定物体描述画检测框的能力;
试金石 (TouchStoe):为了评测模型整体的图文对话能力和人类对齐水平。我们为此构建了一个基于 GPT4 打分来评测 LVLM 模型的 Bechmark:TouchStoe。在 TouchStoe-v0.1 中:
- 评测基准总计涵盖 300+张图片、800+道题目、27个类别。包括基础属性问答、人物地标问答、影视作品问答、视觉推理、反事实推理、诗歌创作、故事写作,商品比较、图片解题等尽可能广泛的类别。
- 为了弥补目前 GPT4 无法直接读取图片的缺陷,我们给所有的带评测图片提供了人工标注的充分详细描述,并且将图片的详细描述、问题和模型的输出结果一起交给 GPT4 打分。
- 评测同时包含英文版本和中文版本。
评测结果如下:
We evaluated the model's ability from two perspectives:
- Stadard Bechmarks: We evaluate the model's basic task capabilities o four major categories of multimodal tasks:
- Zero-shot Captio: Evaluate model's zero-shot image captioig ability o usee datasets;
- Geeral VQA: Evaluate the geeral questio-aswerig ability of pictures, such as the judgmet, color, umber, category, etc;
- Text-based VQA: Evaluate the model's ability to recogize text i pictures, such as documet QA, chart QA, etc;
- Referrig Expressio Comprehesio: Evaluate the ability to localize a target object i a image described by a referrig expressio.
- TouchStoe: To evaluate the overall text-image dialogue capability ad aligmet level with humas, we have costructed a bechmark called TouchStoe, which is based o scorig with GPT4 to evaluate the LVLM model.
- The TouchStoe bechmark covers a total of 300+ images, 800+ questios, ad 27 categories. Such as attribute-based Q&A, celebrity recogitio, writig poetry, summarizig multiple images, product compariso, math problem solvig, etc;
- I order to break the curret limitatio of GPT4 i terms of direct image iput, TouchStoe provides fie-graied image aotatios by huma labelig. These detailed aotatios, alog with the questios ad the model's output, are the preseted to GPT4 for scorig.
- The bechmark icludes both Eglish ad Chiese versios.
Zero-shot Captioig & Geeral VQA
Model type |
Model |
Zero-shot Captioig |
Geeral VQA |
NoCaps |
Flickr30K |
VQAv2dev |
OK-VQA |
GQA |
SciQA-Img (0-shot) |
VizWiz (0-shot) |
Geeralist Models |
Flamigo-9B |
- |
61.5 |
51.8 |
44.7 |
- |
- |
28.8 |
Flamigo-80B |
- |
67.2 |
56.3 |
50.6 |
- |
- |
31.6 |
Uified-IO-XL |
100.0 |
- |
77.9 |
54.0 |
- |
- |
- |
Kosmos-1 |
- |
67.1 |
51.0 |
- |
- |
- |
29.2 |
Kosmos-2 |
- |
66.7 |
45.6 |
- |
- |
- |
- |
BLIP-2 (Vicua-13B) |
103.9 |
71.6 |
65.0 |
45.9 |
32.3 |
61.0 |
19.6 |
IstructBLIP (Vicua-13B) |
121.9 |
82.8 |
- |
- |
49.5 |
63.1 |
33.4 |
Shikra (Vicua-13B) |
- |
73.9 |
77.36 |
47.16 |
- |
- |
- |
Qwe-VL (Qwe-7B) |
121.4 |
85.8 |
78.8 |
58.6 |
59.3 |
67.1 |
35.2 |
Qwe-VL-Chat |
120.2 |
81.0 |
78.2 |
56.6 |
57.5 |
68.2 |
38.9 |
Previous SOTA (Per Task Fie-tuig) |
- |
127.0 (PALI-17B) |
84.5 (IstructBLIP -FlaT5-XL) |
86.1 (PALI-X -55B) |
66.1 (PALI-X -55B) |
72.1 (CFR) |
92.53 (LLaVa+ GPT-4) |
70.9 (PALI-X -55B) |
在 Zero-shot Captio 中,Qwe-VL 在 Flickr30K 数据集上取得了 SOTA 的结果,并在 Nocaps 数据集上取得了和 IstructBlip 可竞争的结果。
在 Geeral VQA 中,Qwe-VL 取得了 LVLM 模型同等量级和设定下 SOTA 的结果。
For zero-shot image captioig, Qwe-VL achieves the SOTA o Flickr30K ad competitive results o Nocaps with IstructBlip.
For geeral VQA, Qwe-VL achieves the SOTA uder the same geeralist LVLM scale settigs.
Text-orieted VQA (focuse o text uderstadig capabilities i images)
Model type |
Model |
TextVQA |
DocVQA |
ChartQA |
AI2D |
OCR-VQA |
Geeralist Models |
BLIP-2 (Vicua-13B) |
42.4 |
- |
- |
- |
- |
IstructBLIP (Vicua-13B) |
50.7 |
- |
- |
- |
- |
mPLUG-DocOwl (LLaMA-7B) |
52.6 |
62.2 |
57.4 |
- |
- |
Pic2Struct-Large (1.3B) |
- |
76.6 |
58.6 |
42.1 |
71.3 |
Qwe-VL (Qwe-7B) |
63.8 |
65.1 |
65.7 |
62.3 |
75.7 |
Specialist SOTAs (Specialist/Fietued) |
PALI-X-55B (Sigle-task FT) (Without OCR Pipelie) |
71.44 |
80.0 |
70.0 |
81.2 |
75.0 |
在文字相关的识别/问答评测上,取得了当前规模下通用 LVLM 达到的最好结果。
分辨率对上述某几个评测非常重要,大部分 224 分辨率的开源 LVLM 模型无法完成以上评测,或只能通过切图的方式解决。Qwe-VL 将分辨率提升到 448,可以直接以端到端的方式进行以上评测。Qwe-VL 在很多任务上甚至超过了 1024 分辨率的 Pic2Struct-Large 模型。
I text-related recogitio/QA evaluatio, Qwe-VL achieves the SOTA uder the geeralist LVLM scale settigs.
Resolutio is importat for several above evaluatios. While most ope-source LVLM models with 224 resolutio are icapable of these evaluatios or ca oly solve these by cuttig images, Qwe-VL scales the resolutio to 448 so that it ca be evaluated ed-to-ed. Qwe-VL eve outperforms Pic2Struct-Large models of 1024 resolutio o some tasks.
Referrig Expressio Comprehesio
Model type |
Model |
RefCOCO |
RefCOCO+ |
RefCOCOg |
GRIT |
val |
test-A |
test-B |
val |
test-A |
test-B |
val-u |
test-u |
refexp |
Geeralist Models |
GPV-2 |
- |
- |
- |
- |
- |
- |
- |
- |
51.50 |
OFA-L* |
79.96 |
83.67 |
76.39 |
68.29 |
76.00 |
61.75 |
67.57 |
67.58 |
61.70 |
Uified-IO |
- |
- |
- |
- |
- |
- |
- |
- |
78.61 |
VisioLLM-H |
|
86.70 |
- |
- |
- |
- |
- |
- |
- |
Shikra-7B |
87.01 |
90.61 |
80.24 |
81.60 |
87.36 |
72.12 |
82.27 |
82.19 |
69.34 |
Shikra-13B |
87.83 |
91.11 |
81.81 |
82.89 |
87.79 |
74.41 |
82.64 |
83.16 |
69.03 |
Qwe-VL-7B |
89.36 |
92.26 |
85.34 |
83.12 |
88.25 |
77.21 |
85.58 |
85.48 |
78.22 |
Qwe-VL-7B-Chat |
88.55 |
92.27 |
84.51 |
82.82 |
88.59 |
76.79 |
85.96 |
86.32 |
- |
Specialist SOTAs (Specialist/Fietued) |
G-DINO-L |
90.56&bsp;&bsp; |
93.19 |
88.24 |
82.75 |
88.95 |
75.92 |
86.13 |
87.02 |
- |
UNINEXT-H |
92.64 |
94.33 |
91.46 |
85.24 |
89.63 |
79.79 |
88.73 |
89.37 |
- |
ONE-PEACE |
92.58 |
94.18 |
89.26 |
88.77 |
92.21 |
83.23 |
89.22 |
89.27 |
- |
在定位任务上,Qwe-VL 全面超过 Shikra-13B,取得了目前 Geeralist LVLM 模型上在 Refcoco 上的 SOTA。
Qwe-VL 并没有在任何中文定位数据上训练过,但通过中文 Captio 数据和 英文 Groudig 数据的训练,可以 Zero-shot 泛化出中文 Groudig 能力。
Qwe-VL achieves the SOTA i all above referrig expressio comprehesio bechmarks.
Qwe-VL has ot bee traied o ay Chiese groudig data, but it ca still geeralize to the Chiese Groudig tasks i a zero-shot way by traiig Chiese Captio data ad Eglish Groudig data.
我们提供了以上所有评测脚本以供复现我们的实验结果。请阅读 eval/EVALUATION.md 了解更多信息。
We provide all of the above evaluatio scripts for reproducig our experimetal results. Please read eval/EVALUATION.md for more iformatio.
Chat 能力测评
TouchStoe 是一个基于 GPT4 打分来评测 LVLM 模型的图文对话能力和人类对齐水平的基准。它涵盖了 300+张图片、800+道题目、27个类别,包括基础属性、人物地标、视觉推理、诗歌创作、故事写作、商品比较、图片解题等尽可能广泛的类别。关于 TouchStoe 的详细介绍,请参考这里(TODO: Lik)。
TouchStoe is a bechmark based o scorig with GPT4 to evaluate the abilities of the LVLM model o text-image dialogue ad aligmet levels with humas. It covers a total of 300+ images, 800+ questios, ad 27 categories, such as attribute-based Q&A, celebrity recogitio, writig poetry, summarizig multiple images, product compariso, math problem solvig, etc. Please read eval/EVALUATION.md for more iformatio.
英文版本测评
Model |
Score |
PadaGPT |
488.5 |
MiiGPT4 |
531.7 |
IstructBLIP |
552.4 |
LLaMA-AdapterV2 |
590.1 |
mPLUG-Owl |
605.4 |
LLaVA |
602.7 |
Qwe-VL-Chat |
645.2 |
中文版本测评
Model |
Score |
VisualGLM |
247.1 |
Qwe-VL-Chat |
401.2 |
Qwe-VL-Chat 模型在中英文的对齐评测中均取得当前 LVLM 模型下的最好结果。
The Qwe-VL-Chat model has achieved the best results i both Chiese ad Eglish aligmet evaluatio.
FAQ
如遇到问题,敬请查阅FAQ以及issue区,如仍无法解决再提交issue。
使用协议
研究人员与开发者可使用Qwe-VL和Qwe-VL-Chat或进行二次开发。我们同样允许商业使用,具体细节请查看LICENSE。如需商用,请填写问卷申请。
联系我们
如果你想给我们的研发团队和产品团队留言,请通过邮件(qiawe_opesource@alibabacloud.com)联系我们。
评论