🚀 InternLM-XComposer2-4KHD
InternLM-XComposer2-4KHD是基于InternLM2的通用视觉语言大模型(VLLM),具备4K分辨率图像理解能力。
InternLM-XComposer2-4KHD
[💻Github Repo](https://github.com/InternLM/InternLM-XComposer)
[Paper](https://arxiv.org/abs/2401.16420)
🚀 快速开始
我们提供一个简单的示例,展示如何使用🤗 Transformers调用InternLM-XComposer。
基础用法
import torch
from transformers import AutoModel, AutoTokenizer
torch.set_grad_enabled(False)
model = AutoModel.from_pretrained('internlm/internlm-xcomposer2-4khd-7b', torch_dtype=torch.bfloat16, trust_remote_code=True).cuda().eval()
tokenizer = AutoTokenizer.from_pretrained('internlm/internlm-xcomposer2-4khd-7b', trust_remote_code=True)
query1 = '<ImageHere>Illustrate the fine details present in the image'
image = './example.webp'
with torch.cuda.amp.autocast():
response, his = model.chat(tokenizer, query=query, image=image, hd_num=55, history=[], do_sample=False, num_beams=3)
print(response)
query1 = 'what is the detailed explanation of the third part.'
with torch.cuda.amp.autocast():
response, _ = model.chat(tokenizer, query=query1, image=image, hd_num=55, history=his, do_sample=False, num_beams=3)
print(response)
📦 安装指南
从Transformers导入模型
要使用Transformers加载InternLM-XComposer2-4KHD模型,请使用以下代码:
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
ckpt_path = "internlm/internlm-xcomposer2-4khd-7b"
tokenizer = AutoTokenizer.from_pretrained(ckpt_path, trust_remote_code=True).cuda()
model = AutoModelForCausalLM.from_pretrained(ckpt_path, torch_dtype=torch.bfloat16, trust_remote_code=True).cuda()
model = model.eval()
📄 许可证
代码采用Apache-2.0许可证,而模型权重完全开放用于学术研究,也允许免费商业使用。如需申请商业许可证,请填写申请表([英文](application form)/中文)。如有其他问题或合作需求,请联系internlm@pjlab.org.cn。