🚀 InternLM-XComposer2
InternLM-XComposer2 是一款基于 InternLM2 的视觉语言大模型(VLLM),具备先进的图文理解与组合能力。
InternLM-XComposer2
[💻Github 仓库](https://github.com/InternLM/InternLM-XComposer)
[论文](https://arxiv.org/abs/2401.16420)
我们发布了两个版本的 InternLM-XComposer2 系列模型:
- InternLM-XComposer2-VL:以 InternLM2 作为大语言模型(LLM)初始化的预训练 VLLM 模型,在各种多模态基准测试中表现出色。
- InternLM-XComposer2:针对 自由交错图文组合 进行微调的 VLLM 模型。
这是 InternLM-XComposer2 的 4 位版本,使用前请安装最新版本的 auto_gptq。
🚀 快速开始
这是 InternLM-XComposer2 的 4 位版本,使用前请安装最新版本的 auto_gptq。
💻 使用示例
基础用法
import torch, auto_gptq
from PIL import Image
from transformers import AutoModel, AutoTokenizer
from auto_gptq.modeling import BaseGPTQForCausalLM
auto_gptq.modeling._base.SUPPORTED_MODELS = ["internlm"]
torch.set_grad_enabled(False)
class InternLMXComposer2QForCausalLM(BaseGPTQForCausalLM):
layers_block_name = "model.layers"
outside_layer_modules = [
'vit', 'vision_proj', 'model.tok_embeddings', 'model.norm', 'output',
]
inside_layer_modules = [
["attention.wqkv.linear"],
["attention.wo.linear"],
["feed_forward.w1.linear", "feed_forward.w3.linear"],
["feed_forward.w2.linear"],
]
model = InternLMXComposer2QForCausalLM.from_quantized(
'internlm/internlm-xcomposer2-7b-4bit', trust_remote_code=True, device="cuda:0").eval()
tokenizer = AutoTokenizer.from_pretrained(
'internlm/internlm-xcomposer2-7b-4bit', trust_remote_code=True)
img_path_list = [
'panda.jpg',
'bamboo.jpeg',
]
images = []
for img_path in img_path_list:
image = Image.open(img_path).convert("RGB")
image = model.vis_processor(image)
images.append(image)
image = torch.stack(images)
query = '<ImageHere> <ImageHere>please write an article based on the images. Title: my favorite animal.'
with torch.cuda.amp.autocast():
response, history = model.chat(tokenizer, query=query, image=image, history=[], do_sample=False)
print(response)
📄 许可证
代码遵循 Apache 2.0 许可证,而模型权重完全开放用于学术研究,也允许免费商业使用。如需申请商业许可证,请填写申请表(英文)/申请表(中文)。如有其他问题或合作需求,请联系 internlm@pjlab.org.cn。