语言:
- 英文
库名称: transformers
许可证: apache-2.0
标签:
- GPT
- 大语言模型
- 多模态大语言模型
- OCR
缩略图: >-
https://h2o.ai/etc.clientlibs/h2o/clientlibs/clientlib-site/resources/images/favicon.ico
管道标签: 文本生成
模型卡片
[📜 H2OVL-Mississippi 论文]
[🤗 HF 演示]
[🚀 快速开始]
H2OVL-Mississippi-2B 是由 H2O.ai 开发的一款高性能通用视觉语言模型,能够处理广泛的多模态任务。这款拥有 20 亿参数的模型在图像描述、视觉问答(VQA)和文档理解等任务中表现出色,同时保持实际应用中的高效性。
Mississippi-2B 模型基于我们 H2O-Danube 语言模型的坚实基础,现扩展至整合视觉与语言任务。它在多个基准测试中与更大规模的模型竞争,为文档 AI、OCR 和多模态推理提供了多功能且可扩展的解决方案。
主要特点:
- 20 亿参数: 在性能与效率之间取得平衡,适用于文档处理、OCR、VQA 等多种任务。
- 针对视觉语言任务优化: 在文档 AI、OCR 和多模态推理等广泛应用中实现高性能。
- 全面数据集: 基于 1700 万图像-文本对训练,确保广泛覆盖和强大的任务泛化能力。
基准测试
相似规模模型在多个基准测试中的性能对比 - OpenVLM 排行榜
模型 |
参数(十亿) |
平均得分 |
MMBench |
MMStar |
MMMUVAL |
Math Vista |
Hallusion |
AI2DTEST |
OCRBench |
MMVet |
Qwen2-VL-2B |
2.1 |
57.2 |
72.2 |
47.5 |
42.2 |
47.8 |
42.4 |
74.7 |
797 |
51.5 |
H2OVL-Mississippi-2B |
2.1 |
54.4 |
64.8 |
49.6 |
35.2 |
56.8 |
36.4 |
69.9 |
782 |
44.7 |
InternVL2-2B |
2.1 |
53.9 |
69.6 |
49.8 |
36.3 |
46.0 |
38.0 |
74.1 |
781 |
39.7 |
Phi-3-Vision |
4.2 |
53.6 |
65.2 |
47.7 |
46.1 |
44.6 |
39.0 |
78.4 |
637 |
44.1 |
MiniMonkey |
2.2 |
52.7 |
68.9 |
48.1 |
35.7 |
45.3 |
30.9 |
73.7 |
794 |
39.8 |
MiniCPM-V-2 |
2.8 |
47.9 |
65.8 |
39.1 |
38.2 |
39.8 |
36.1 |
62.9 |
605 |
41.0 |
InternVL2-1B |
0.8 |
48.3 |
59.7 |
45.6 |
36.7 |
39.4 |
34.3 |
63.8 |
755 |
31.5 |
PaliGemma-3B-mix-448 |
2.9 |
46.5 |
65.6 |
48.3 |
34.9 |
28.7 |
32.2 |
68.3 |
614 |
33.1 |
H2OVL-Mississippi-0.8B |
0.8 |
43.5 |
47.7 |
39.1 |
34.0 |
39.0 |
29.6 |
53.6 |
751 |
30.0 |
DeepSeek-VL-1.3B |
2.0 |
39.6 |
63.8 |
39.9 |
33.8 |
29.8 |
27.6 |
51.5 |
413 |
29.2 |
快速开始
我们提供一个示例代码,展示如何使用 transformers
运行 h2ovl-mississippi-2b。
安装依赖:
pip install transformers torch torchvision einops timm peft sentencepiece
如果您有安培架构的 GPU,可以安装 flash-attention 以加速推理:
pip install flash_attn
使用 Transformers 进行推理:
import torch
from transformers import AutoModel, AutoTokenizer
model_path = 'h2oai/h2ovl-mississippi-2b'
model = AutoModel.from_pretrained(
model_path,
torch_dtype=torch.bfloat16,
low_cpu_mem_usage=True,
trust_remote_code=True).eval().cuda()
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True, use_fast=False)
generation_config = dict(max_new_tokens=1024, do_sample=True)
question = '你好,你是谁?'
response, history = model.chat(tokenizer, None, question, generation_config, history=None, return_history=True)
print(f'用户: {question}\n助手: {response}')
image_file = './examples/image1.jpg'
question = '<image>\n请详细描述这张图片。'
response, history = model.chat(tokenizer, image_file, question, generation_config, history=None, return_history=True)
print(f'用户: {question}\n助手: {response}')
image_files = ['./examples/image1.jpg', './examples/image2.jpg']
question = '图片1: <image>\n图片2: <image>\n请详细描述图片1和图片2。'
response, history = model.chat(tokenizer, image_files, question, generation_config, history=None, return_history=True)
print(f'用户: {question}\n助手: {response}')
question = '这两张图片有什么相似和不同之处?'
response, history = model.chat(tokenizer, image_files, question, generation_config=generation_config, history=history, return_history=True)
print(f'用户: {question}\n助手: {response}')
使用 vLLM 进行推理
h2ovl-mississippi 模型也支持 vllm v0.6.4 及更高版本。
首先安装 vllm
pip install vllm
离线推理
from vllm import LLM, SamplingParams
from transformers import AutoTokenizer
from PIL import Image
question = "详细描述这张图片"
image = Image.open("assets/a_cat.png")
model_name = "h2oai/h2ovl-mississippi-2b"
llm = LLM(
model=model_name,
)
tokenizer = AutoTokenizer.from_pretrained(model_name,
trust_remote_code=True)
messages = [{'role': 'user', 'content': f"<image>\n{question}"}]
prompt = tokenizer.apply_chat_template(messages,
tokenize=False,
add_generation_prompt=True)
stop_token_ids = [tokenizer.eos_token_id]
sampling_params = SamplingParams(n=1,
temperature=0.8,
top_p=0.8,
seed=777,
max_tokens=1024,
stop_token_ids=stop_token_ids)
outputs = llm.generate({
"prompt": prompt,
"multi_modal_data": {"image": image},
},
sampling_params=sampling_params)
for o in outputs:
generated_text = o.outputs[0].text
print(generated_text)
更多示例请参见 https://docs.vllm.ai/en/latest/models/vlm.html#offline-inference