HuggingFace镜像/glm-4v-9b
模型介绍文件和版本分析
下载使用量0

glm-4v-9b

英文版本

GLM-4-9B 是智谱 AI 推出的最新一代预训练模型 GLM-4 系列中的开源版本。 在语义、数学、推理、代码和知识等多方面的数据集测评中,GLM-4-9B 及其人类偏好对齐的版本 GLM-4-9B-Chat 均表现出较高的性能。 除了能进行多轮对话,GLM-4-9B-Chat 还具备网页浏览、代码执行、自定义工具调用(Function Call)和长文本推理(支持最大 128K 上下文)等高级功能。 本代模型增加了多语言支持,支持包括日语,韩语,德语在内的 26 种语言。我们还推出了支持 1M 上下文长度(约 200 万中文字符)的模型。

多模态能力

GLM-4V-9B 是一个多模态语言模型,具备视觉理解能力,其相关经典任务的评测结果如下:

MMBench-EN-TestMMBench-CN-TestSEEDBench_IMGMMStarMMMUMMEHallusionBenchAI2DOCRBench
英文综合中文综合综合能力综合能力学科综合感知推理幻觉性图表理解文字识别
GPT-4o, 2024051383.482.177.163.969.22310.35584.6736
GPT-4v, 202404098180.2735661.72070.243.978.6656
GPT-4v, 202311067774.472.349.753.81771.546.575.9516
InternVL-Chat-V1.582.380.775.257.146.82189.647.480.6720
LlaVA-Next-Yi-34B81.17975.751.648.82050.234.878.9574
Step-1V80.779.970.35049.92206.448.479.2625
MiniCPM-Llama3-V2.577.673.872.351.845.82024.642.478.4725
Qwen-VL-Max77.675.772.749.5522281.741.275.7684
GeminiProVision73.674.370.738.6492148.945.772.9680
Claude-3V Opus63.359.26445.754.91586.837.870.6694
GLM-4v-9B81.179.476.858.747.22163.846.681.1786

本仓库是 GLM-4V-9B 的模型仓库,支持8K上下文长度。

运行模型

更多推理代码和依赖信息,请访问我们的 github。

请严格按照依赖安装,否则无法正常运行。

import torch
from PIL import Image
from openmind import AutoModelForCausalLM, AutoTokenizer

device = "npu"

tokenizer = AutoTokenizer.from_pretrained("AI-Research/glm-4v-9b", trust_remote_code=True)

query = '描述这张图片'
image = Image.open("your image").convert('RGB')
inputs = tokenizer.apply_chat_template([{"role": "user", "image": image, "content": query}],
                                       add_generation_prompt=True, tokenize=True, return_tensors="pt",
                                       return_dict=True)  # chat mode

inputs = inputs.to(device)
model = AutoModelForCausalLM.from_pretrained(
    "AI-Research/glm-4v-9b",
    torch_dtype=torch.bfloat16,
    low_cpu_mem_usage=True,
    trust_remote_code=True
).to(device).eval()

gen_kwargs = {"max_length": 2500, "do_sample": True, "top_k": 1}
with torch.no_grad():
    outputs = model.generate(**inputs, **gen_kwargs)
    outputs = outputs[:, inputs['input_ids'].shape[1]:]
    print(tokenizer.decode(outputs[0]))

协议 (License)

GLM-4 模型的权重的使用则需要遵循 LICENSE。

引用

如果你觉得我们的工作有帮助的话,请考虑引用下列论文。

@article{zeng2022glm,
  title={Glm-130b: An open bilingual pre-trained model},
  author={Zeng, Aohan and Liu, Xiao and Du, Zhengxiao and Wang, Zihan and Lai, Hanyu and Ding, Ming and Yang, Zhuoyi and Xu, Yifan and Zheng, Wendi and Xia, Xiao and others},
  journal={arXiv preprint arXiv:2210.02414},
  year={2022}
}
@inproceedings{du2022glm,
  title={GLM: General Language Model Pretraining with Autoregressive Blank Infilling},
  author={Du, Zhengxiao and Qian, Yujie and Liu, Xiao and Ding, Ming and Qiu, Jiezhong and Yang, Zhilin and Tang, Jie},
  booktitle={Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)},
  pages={320--335},
  year={2022}
}