license: other
pipeline_tag: text-generation
书生·浦语2-大模型
书生·浦语2是基于InternLM2的视觉语言大模型(VLLM),具备先进的图文理解与创作能力。
我们发布的书生·浦语2系列包含两个版本:
- 书生·浦语2-VL:以InternLM2作为大语言模型初始化的预训练VLLM模型,在多项多模态基准测试中表现优异。
- 书生·浦语2:专为自由式图文交错创作任务微调的VLLM模型。
本仓库提供4位量化版本的书生·浦语2模型,使用前请安装最新版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>请根据图片写一篇文章。题目:我最喜欢的动物。'
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。