cuuupid/glm-4v-9b

Replicate Explore 模型

摘要

GLM-4V-9B 是Zhipu AI开发的一款开源视觉语言模型,据称在多模态评估中性能优于GPT-4-turbo和Gemini 1.0 Pro等模型。

cuuupid / glm-4v-9b
查看原文
查看缓存全文

缓存时间: 2026/08/30 11:20

# cuuupid/glm-4v-9b – Replicate 来源:https://replicate.com/cuuupid/glm-4v-9b 这是一款在视觉能力方面可与GPT-4的视觉能力相媲美的视觉语言模型。感谢智谱AI(THUDM),原始README如下。 ## 模型简介 GLM-4-9B是智谱AI发布的最新一代GLM-4系列预训练模型的开源版本。在语义、数学、推理、代码和知识等数据集的评估中,**GLM-4-9B**及其经过人类偏好对齐的版本**GLM-4-9B-Chat**均展现出超越Llama-3-8B的卓越性能。除了多轮对话功能外,GLM-4-9B-Chat还具备网页浏览、代码执行、自定义函数调用和长文本推理(支持最长128K上下文)等高级功能。本代模型新增了多语言支持,包括日语、韩语和德语在内的26种语言。我们还推出了支持1M上下文长度(约200万汉字)的**GLM-4-9B-Chat-1M**模型,以及基于GLM-4-9B的多模态模型GLM-4V-9B。**GLM-4V-9B**具备中英双语对话能力,分辨率达1120*1120。在多项多模态评估中(包括中英综合能力、感知与推理、文本识别和图表理解),GLM-4V-9B的表现优于GPT-4-turbo-2024-04-09、Gemini 1.0 Pro、Qwen-VL-Max和Claude 3 Opus。 ## 模型列表 | 模型 | 类型 | 序列长度 | 下载 | 在线演示 | | :--- | :--- | :--- | :--- | :--- | | GLM-4-9B | 基础模型 | 8K | 🤗 Huggingface (https://huggingface.co/THUDM/glm-4-9b) 🤖 ModelScope (https://modelscope.cn/models/ZhipuAI/glm-4-9b) 🟣 WiseModel (https://wisemodel.cn/models/ZhipuAI/GLM-4-9B) | / | | GLM-4-9B-Chat | 对话模型 | 128K | 🤗 Huggingface (https://huggingface.co/THUDM/glm-4-9b-chat) 🤖 ModelScope (https://modelscope.cn/models/ZhipuAI/glm-4-9b-chat) 🟣 WiseModel (https://wisemodel.cn/models/ZhipuAI/GLM-4-9B-Chat) | 🤖 ModelScope CPU (https://modelscope.cn/studios/dash-infer/GLM-4-Chat-DashInfer-Demo/summary) 🤖 ModelScope vLLM (https://modelscope.cn/studios/ZhipuAI/glm-4-9b-chat-vllm/summary) | | GLM-4-9B-Chat-1M | 对话模型 | 1M | 🤗 Huggingface (https://huggingface.co/THUDM/glm-4-9b-chat-1m) 🤖 ModelScope (https://modelscope.cn/models/ZhipuAI/glm-4-9b-chat-1m) 🟣 WiseModel (https://wisemodel.cn/models/ZhipuAI/GLM-4-9B-Chat-1M) | / | | GLM-4V-9B | 对话模型 | 8K | 🤗 Huggingface (https://huggingface.co/THUDM/glm-4v-9b) 🤖 ModelScope (https://modelscope.cn/models/ZhipuAI/glm-4v-9b) 🟣 WiseModel (https://wisemodel.cn/models/ZhipuAI/GLM-4V-9B) | 🤖 ModelScope (https://modelscope.cn/studios/ZhipuAI/glm-4v-9b-Demo/summary) | ## 项目 以下优秀的开源仓库已对GLM-4-9B模型进行了深入支持,欢迎各位扩展学习。 推理加速: - chatglm.cpp (https://github.com/li-plus/chatglm.cpp):通过量化在您的笔记本电脑上实现实时推理,类似于llama.cpp。 ## 基准测试 ### 典型任务 | 模型 | AlignBench | MT-Bench | IFEval | MMLU | C-Eval | GSM8K | MATH | HumanEval | NaturalCodeBench | | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | | Llama-3-8B-Instruct | 6.40 | 8.00 | 68.58 | 68.4 | 51.3 | 79.6 | 30.0 | 62.2 | 24.7 | | ChatGLM3-6B | 5.18 | 5.50 | 28.1 | 66.4 | 69.0 | 72.3 | 25.7 | 58.5 | 11.3 | | GLM-4-9B-Chat | 7.01 | 8.35 | 69.0 | 72.4 | 75.6 | 79.6 | 50.6 | 71.8 | 32.2 | ### 基础模型 | 模型 | MMLU | C-Eval | GPQA | GSM8K | MATH | HumanEval | | :--- | :--- | :--- | :--- | :--- | :--- | :--- | | Llama-3-8B | 66.6 | 51.2 | - | 45.8 | - | 33.5 | | Llama-3-8B-Instruct | 68.4 | 51.3 | 34.2 | 79.6 | 30.0 | 62.2 | | ChatGLM3-6B-Base | 61.4 | 69.0 | 26.8 | 72.3 | 25.7 | 58.5 | | GLM-4-9B | 74.7 | 77.1 | 34.3 | 84.0 | 30.4 | 70.1 | > 由于`GLM-4-9B`在预训练阶段加入了一些数学、推理和代码相关的指令数据,因此也将Llama-3-8B-Instruct纳入对比范围。 ### 长上下文 在上下文长度为1M的条件下进行了大海捞针(needle-in-the-haystack)实验 (https://github.com/LargeWorldModel/LWM/blob/main/scripts/eval_needle.py),结果如下: ### 多语言 对GLM-4-9B-Chat和Llama-3-8B-Instruct在六个多语言数据集上进行了测试。测试结果及各数据集所选语言如下表所示: | 数据集 | Llama-3-8B-Instruct | GLM-4-9B-Chat | 语言 | | :--- | :--- | :--- | :--- | | M-MMLU | 49.6 | 56.6 | 全部 | | FLORES | 25.0 | 28.8 | ru, es, de, fr, it, pt, pl, ja, nl, ar, tr, cs, vi, fa, hu, el, ro, sv, uk, fi, ko, da, bg, no | | MGSM | 54.0 | 65.3 | zh, en, bn, de, es, fr, ja, ru, sw, te, th | | XWinograd | 61.7 | 73.1 | zh, en, fr, jp, ru, pt | | XStoryCloze | 84.7 | 90.7 | zh, en, ar, es, eu, hi, id, my, ru, sw, te | | XCOPA | 73.3 | 80.1 | zh, et, ht, id, it, qu, sw, ta, th, tr, vi | ### 函数调用 在Berkeley Function Calling Leaderboard (https://github.com/ShishirPatil/gorilla/tree/main/berkeley-function-call-leaderboard) 上进行了测试。 | 模型 | 总体准确率 | AST摘要 | 执行摘要 | 相关性 | | :--- | :--- | :--- | :--- | :--- | | Llama-3-8B-Instruct | 58.88 | 59.25 | 70.01 | 45.83 | | gpt-4-turbo-2024-04-09 | 81.24 | 82.14 | 78.61 | 88.75 | | ChatGLM3-6B | 57.88 | 62.18 | 69.7 | 85.42 | | GLM-4-9B-Chat | 81.00 | 80.26 | 84.40 | 87.92 | ### 多模态 GLM-4V-9B是一款具备视觉理解能力的多模态语言模型。其相关经典任务的评估结果如下: | 模型 | MMBench-EN-Test | MMBench-CN-Test | SEEDBench_IMG | MMStar | MMMU | MME | HallusionBench | AI2D | OCRBench | | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | :--- | | gpt-4o-2024-05-13 | 83.4 | 82.1 | 77.1 | 63.9 | 69.2 | 2310.3 | 55 | 84.6 | 736 | | gpt-4-turbo-2024-04-09 | 81.0 | 80.2 | 73.0 | 56.0 | 61.7 | 2070.2 | 43.9 | 78.6 | 656 | | gpt-4-1106-preview | 77.0 | 74.4 | 72.3 | 49.7 | 53.8 | 1771.5 | 46.5 | 75.9 | 516 | | InternVL-Chat-V1.5 | 82.3 | 80.7 | 75.2 | 57.1 | 46.8 | 2189.6 | 47.4 | 80.6 | 720 | | LLaVA-Next-Yi-34B | 81.1 | 79 | 75.7 | 51.6 | 48.8 | 2050.2 | 34.8 | 78.9 | 574 | | Step-1V | 80.7 | 79.9 | 70.3 | 50.0 | 49.9 | 2206.4 | 48.4 | 79.2 | 625 | | MiniCPM-Llama3-V2.5 | 77.6 | 73.8 | 72.3 | 51.8 | 45.8 | 2024.6 | 42.4 | 78.4 | 725 | | Qwen-VL-Max | 77.6 | 75.7 | 72.7 | 49.5 | 52 | 2281.7 | 41.2 | 75.7 | 684 | | Gemini 1.0 Pro | 73.6 | 74.3 | 70.7 | 38.6 | 49 | 2148.9 | 45.7 | 72.9 | 680 | | Claude 3 Opus | 63.3 | 59.2 | 64 | 45.7 | 54.9 | 1586.8 | 37.8 | 70.6 | 694 | | GLM-4V-9B | 81.1 | 79.4 | 76.8 | 58.7 | 47.2 | 2163.8 | 46.6 | 81.1 | 786 | ## 快速调用 **有关硬件配置和系统要求,请查看此处 (https://replicate.com/cuuupid/basic_demo/README_en.md)。** ### 使用以下方法快速调用 GLM-4-9B-Chat 语言模型 使用 transformers 后端进行推理: ```python import torch from transformers import AutoModelForCausalLM, AutoTokenizer device = "cuda" tokenizer = AutoTokenizer.from_pretrained("THUDM/glm-4-9b-chat", trust_remote_code=True) query = "你好" inputs = tokenizer.apply_chat_template([{"role": "user", "content": query}], add_generation_prompt=True, tokenize=True, return_tensors="pt", return_dict=True ) inputs = inputs.to(device) model = AutoModelForCausalLM.from_pretrained( "THUDM/glm-4-9b-chat", 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], skip_special_tokens=True)) ``` 使用 vLLM 后端进行推理: ```python from transformers import AutoTokenizer from vllm import LLM, SamplingParams # GLM-4-9B-Chat # 如果遇到OOM,可以尝试减小 max_model_len 或增大 tp_size max_model_len, tp_size = 131072, 1 model_name = "THUDM/glm-4-9b-chat" prompt = [{"role": "user", "content": "你好"}] tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True) llm = LLM( model=model_name, tensor_parallel_size=tp_size, max_model_len=max_model_len, trust_remote_code=True, enforce_eager=True, # 如果在GLM-4-9B-Chat-1M上遇到OOM,可以尝试启用以下参数 # enable_chunked_prefill=True, # max_num_batched_tokens=8192 ) stop_token_ids = [151329, 151336, 151338] sampling_params = SamplingParams(temperature=0.95, max_tokens=1024, stop_token_ids=stop_token_ids) inputs = tokenizer.apply_chat_template(prompt, tokenize=False, add_generation_prompt=True) outputs = llm.generate(prompts=inputs, sampling_params=sampling_params) print(outputs[0].outputs[0].text) ``` ### 使用以下方法快速调用 GLM-4V-9B 多模态模型 使用 transformers 后端进行推理: ```python import torch from PIL import Image from transformers import AutoModelForCausalLM, AutoTokenizer device = "cuda" tokenizer = AutoTokenizer.from_pretrained("THUDM/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) # 对话模式 inputs = inputs.to(device) model = AutoModelForCausalLM.from_pretrained( "THUDM/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])) ``` 注意:GLM-4V-9B 尚不支持使用 vLLM 方式调用。 ## 完整项目列表 如果您想了解更多关于 GLM-4-9B 系列开源模型的信息,这个开源仓库通过以下内容为开发者提供基础的 GLM-4-9B 使用和开发代码: - basic\_demo (https://replicate.com/cuuupid/basic_demo/README.md):包含 - 使用 transformers 和 vLLM 后端的交互代码 - OpenAI API 后端交互代码 - 批量推理代码 - composite\_demo (https://replicate.com/cuuupid/composite_demo/README.md):包含 - GLM-4-9B 和 GLM-4V-9B 开源模型的全功能演示代码,涵盖 All Tools 能力、长文档解读和多模态能力。 - fintune\_demo (https://replicate.com/cuuupid/finetune_demo/README.md):包含 - PEFT(LORA, P-Tuning)微调代码 - SFT 微调代码 ## 友情链接 - LLaMA-Factory (https://github.com/hiyouga/LLaMA-Factory):高效的开源微调框架,已支持 GLM-4-9B-Chat 语言模型微调。 - SWIFT (https://github.com/modelscope/swift):ModelScope 的 LLM/VLM 训练框架,支持 GLM4-9B-Chat/GLM4v-9b-chat 微调。 - Xorbits Inference (https://github.com/xorbitsai/inference):性能增强且功能全面的全球推理框架,可轻松部署您自己的模型或一键导入前沿开源模型。 - self-llm (https://github.com/datawhalechina/self-llm/tree/master/GLM-4):Datawhale 的 self-llm 项目,包含 GLM-4-9B 开源模型手册。 ## 许可协议 - 使用 GLM-4 模型权重必须遵循模型许可协议 (https://huggingface.co/THUDM/glm-4-9b/blob/main/LICENSE)。 - 此开源仓库中的代码遵循 Apache 2.0 (https://replicate.com/cuuupid/LICENSE) 许可证。 请严格遵守开源许可协议。 ## 引用 如果您发现我们的工作有帮助,请考虑引用以下论文。 ```bibtex @inproceedings{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}, booktitle={The Eleventh International Conference on Learning Representations, {ICLR} 2023, Kigali, Rwanda, May 1-5, 2023}, year= {2023}, } ``` ```bibtex @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} } ``` ```bibtex @misc{wang2023cogvlm, title={CogVLM: Visual Expert for Pretrained Language Models}, author={Weihan Wang and Qingsong Lv and Wenmeng Yu and Wenyi Hong and Ji Qi and Yan Wang and Junhui Ji and Zhuoyi Yang and Lei Zhao and Xixuan Song and Jiazheng Xu and Bin Xu and Juanzi Li and Yuxiao Dong and Ming Ding and Jie Tang}, year={2023}, eprint={2311.03079}, archivePrefix={arXiv}, primaryClass={cs.CV} } ```

相似文章

baseten/GLM-5.2-Vision-NVFP4

Hugging Face Models Trending

Baseten 发布了 GLM-5.2-Vision,这是一个视觉语言模型,通过训练好的 PatchMerger 投影器将 MoonViT 视觉编码器添加到 GLM-5.2,同时保持文本主干和视觉塔冻结。该模型被量化到 NVFP4,以在 Blackwell 硬件上进行高效推理。

google/gemma-4-31B-it-assistant

Hugging Face Models Trending

Google DeepMind 发布了 Gemma 4,这是一个开源权重的多模态模型家族,支持文本、图像、视频和音频,具备增强的推理和编码能力,并通过多令牌预测(MTP)实现高达 2 倍的解码速度提升。

GLM-5.2: 专为长程任务打造

Hugging Face Blog

Z.AI推出GLM-5.2,这是一款专为长程任务设计的旗舰模型,拥有稳定的100万token上下文、改进的编码能力以及MIT开源许可证,在与Opus 4.8和GPT-5.5等领先模型的对比中展现了竞争力。