1 Commits

Author SHA1 Message Date
e217cf9812 可以像 qwen3 那样加上 /no_think 关闭深思考模式吗 2025-07-02 05:41:44 +00:00
6 changed files with 143 additions and 177 deletions

6
.gitattributes vendored
View File

@ -11,7 +11,7 @@
*.model filter=lfs diff=lfs merge=lfs -text *.model filter=lfs diff=lfs merge=lfs -text
*.msgpack filter=lfs diff=lfs merge=lfs -text *.msgpack filter=lfs diff=lfs merge=lfs -text
*.onnx filter=lfs diff=lfs merge=lfs -text *.onnx filter=lfs diff=lfs merge=lfs -text
*.ot filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text *.parquet filter=lfs diff=lfs merge=lfs -text
*.pb filter=lfs diff=lfs merge=lfs -text *.pb filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text *.pt filter=lfs diff=lfs merge=lfs -text
@ -44,6 +44,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text *.tar filter=lfs diff=lfs merge=lfs -text
*.wasm filter=lfs diff=lfs merge=lfs -text *.wasm filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text *.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text *tfevents* filter=lfs diff=lfs merge=lfs -text
notebook.ipynb filter=lfs diff=lfs merge=lfs -text

203
README.md
View File

@ -1,110 +1,93 @@
--- ---
license: mit license: mit
language: ---
- en
- zh # GLM-4.1V-9B-Thinking
base_model:
- zai-org/GLM-4-9B-0414 <div align="center">
pipeline_tag: image-text-to-text <img src=https://raw.githubusercontent.com/THUDM/GLM-4.1V-Thinking/99c5eb6563236f0ff43605d91d107544da9863b2/resources/logo.svg width="40%"/>
library_name: transformers </div>
tags: <p align="center">
- reasoning 📖 查看 GLM-4.1V-9B-Thinking <a href="https://arxiv.org/abs/2507.01006" target="_blank">论文</a>
--- <br>
💡 立即在线体验 <a href="https://huggingface.co/spaces/THUDM/GLM-4.1V-9B-Thinking-Demo" target="_blank">Hugging Face</a><a href="https://modelscope.cn/studios/ZhipuAI/GLM-4.1V-9B-Thinking-Demo" target="_blank">ModelScope</a> 上的 GLM-4.1V-9B-Thinking。
# GLM-4.1V-9B-Thinking <br>
📍 在 <a href="https://www.bigmodel.cn/dev/api/visual-reasoning-model/GLM-4.1V-Thinking">智谱大模型开放平台</a> 使用 GLM-4.1V-9B-Thinking 的API服务。
<div align="center"> </p>
<img src=https://raw.githubusercontent.com/zai-org/GLM-4.1V-Thinking/99c5eb6563236f0ff43605d91d107544da9863b2/resources/logo.svg width="40%"/>
</div> ## 模型介绍
<p align="center">
📖 View the GLM-4.1V-9B-Thinking <a href="https://arxiv.org/abs/2507.01006" target="_blank">paper</a>. 视觉语言大模型VLM已经成为智能系统的关键基石。随着真实世界的智能任务越来越复杂VLM模型也亟需在基本的多模态感知之外
<br> 逐渐增强复杂任务中的推理能力,提升自身的准确性、全面性和智能化程度,使得复杂问题解决、长上下文理解、多模态智能体等智能任务成为可能。
📍 Using GLM-4.1V-9B-Thinking API at <a href="https://www.bigmodel.cn/dev/api/visual-reasoning-model/GLM-4.1V-Thinking">Zhipu Foundation Model Open Platform</a>
</p> 基于 [GLM-4-9B-0414](https://github.com/THUDM/GLM-4) 基座模型我们推出新版VLM开源模型 **GLM-4.1V-9B-Thinking**
,引入思考范式,通过课程采样强化学习 RLCSReinforcement Learning with Curriculum Sampling全面提升模型能力
达到 10B 参数级别的视觉语言模型的最强性能在18个榜单任务中持平甚至超过8倍参数量的 Qwen-2.5-VL-72B。
## Model Introduction 我们同步开源基座模型 **GLM-4.1V-9B-Base**,希望能够帮助更多研究者探索视觉语言模型的能力边界。
Vision-Language Models (VLMs) have become foundational components of intelligent systems. As real-world AI tasks grow ![rl](https://raw.githubusercontent.com/THUDM/GLM-4.1V-Thinking/refs/heads/main/resources/rl.jpeg)
increasingly complex, VLMs must evolve beyond basic multimodal perception to enhance their reasoning capabilities in
complex tasks. This involves improving accuracy, comprehensiveness, and intelligence, enabling applications such as 与上一代的 CogVLM2 及 GLM-4V 系列模型相比,**GLM-4.1V-Thinking** 有如下改进:
complex problem solving, long-context understanding, and multimodal agents.
1. 系列中首个推理模型,不仅仅停留在数学领域,在多个子领域均达到世界前列的水平。
Based on the [GLM-4-9B-0414](https://github.com/zai-org/GLM-4) foundation model, we present the new open-source VLM model 2. 支持 **64k** 上下长度。
**GLM-4.1V-9B-Thinking**, designed to explore the upper limits of reasoning in vision-language models. By introducing 3. 支持**任意长宽比**和高达 **4k** 的图像分辨率。
a "thinking paradigm" and leveraging reinforcement learning, the model significantly enhances its capabilities. It 4. 提供支持**中英文双语**的开源模型版本。
achieves state-of-the-art performance among 10B-parameter VLMs, matching or even surpassing the 72B-parameter
Qwen-2.5-VL-72B on 18 benchmark tasks. We are also open-sourcing the base model GLM-4.1V-9B-Base to ## 榜单信息
support further research into the boundaries of VLM capabilities.
GLM-4.1V-9B-Thinking 通过引入「思维链」Chain-of-Thought推理机制在回答准确性、内容丰富度与可解释性方面
![rl](https://raw.githubusercontent.com/zai-org/GLM-4.1V-Thinking/refs/heads/main/resources/rl.jpeg) 全面超越传统的非推理式视觉模型。在28项评测任务中有23项达到10B级别模型最佳甚至有18项任务超过8倍参数量的Qwen-2.5-VL-72B。
Compared to the previous generation models CogVLM2 and the GLM-4V series, **GLM-4.1V-Thinking** offers the ![bench](https://raw.githubusercontent.com/THUDM/GLM-4.1V-Thinking/refs/heads/main/resources/bench.jpeg)
following improvements:
## 快速推理
1. The first reasoning-focused model in the series, achieving world-leading performance not only in mathematics but also
across various sub-domains. 这里展现了一个使用`transformers`进行单张图片推理的代码。首先,从源代码安装`transformers`库。
2. Supports **64k** context length. ```
3. Handles **arbitrary aspect ratios** and up to **4K** image resolution. pip install git+https://github.com/huggingface/transformers.git
4. Provides an open-source version supporting both **Chinese and English bilingual** usage. ```
## Benchmark Performance 接着按照以下代码运行:
By incorporating the Chain-of-Thought reasoning paradigm, GLM-4.1V-9B-Thinking significantly improves answer accuracy, ```python
richness, and interpretability. It comprehensively surpasses traditional non-reasoning visual models. from transformers import AutoProcessor, Glm4vForConditionalGeneration
Out of 28 benchmark tasks, it achieved the best performance among 10B-level models on 23 tasks, import torch
and even outperformed the 72B-parameter Qwen-2.5-VL-72B on 18 tasks.
MODEL_PATH = "THUDM/GLM-4.1V-9B-Thinking"
![bench](https://raw.githubusercontent.com/zai-org/GLM-4.1V-Thinking/refs/heads/main/resources/bench.jpeg) messages = [
{
## Quick Inference "role": "user",
"content": [
This is a simple example of running single-image inference using the `transformers` library. {
First, install the `transformers` library from source: "type": "image",
"url": "https://upload.wikimedia.org/wikipedia/commons/f/fa/Grayscale_8bits_palette_sample_image.png"
``` },
pip install transformers>=4.57.1 {
``` "type": "text",
"text": "describe this image"
Then, run the following code: }
],
```python }
from transformers import AutoProcessor, Glm4vForConditionalGeneration ]
import torch processor = AutoProcessor.from_pretrained(MODEL_PATH, use_fast=True)
model = Glm4vForConditionalGeneration.from_pretrained(
MODEL_PATH = "zai-org/GLM-4.1V-9B-Thinking" pretrained_model_name_or_path=MODEL_PATH,
messages = [ torch_dtype=torch.bfloat16,
{ device_map="auto",
"role": "user", )
"content": [ inputs = processor.apply_chat_template(
{ messages,
"type": "image", tokenize=True,
"url": "https://upload.wikimedia.org/wikipedia/commons/f/fa/Grayscale_8bits_palette_sample_image.png" add_generation_prompt=True,
}, return_dict=True,
{ return_tensors="pt"
"type": "text", ).to(model.device)
"text": "describe this image" generated_ids = model.generate(**inputs, max_new_tokens=8192)
} output_text = processor.decode(generated_ids[0][inputs["input_ids"].shape[1]:], skip_special_tokens=False)
], print(output_text)
} ```
]
processor = AutoProcessor.from_pretrained(MODEL_PATH, use_fast=True)
model = Glm4vForConditionalGeneration.from_pretrained( 视频推理网页端Demo部署等更代码请查看我们的 [github](https://github.com/THUDM/GLM-4.1V-Thinking)。
pretrained_model_name_or_path=MODEL_PATH,
torch_dtype=torch.bfloat16,
device_map="auto",
)
inputs = processor.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_dict=True,
return_tensors="pt"
).to(model.device)
generated_ids = model.generate(**inputs, max_new_tokens=8192)
output_text = processor.decode(generated_ids[0][inputs["input_ids"].shape[1]:], skip_special_tokens=False)
print(output_text)
```
For video reasoning, web demo deployment, and more code, please check
our [GitHub](https://github.com/zai-org/GLM-V).

View File

@ -3,50 +3,38 @@
"Glm4vForConditionalGeneration" "Glm4vForConditionalGeneration"
], ],
"model_type": "glm4v", "model_type": "glm4v",
"attention_bias": true,
"attention_dropout": 0.0,
"pad_token_id": 151329,
"eos_token_id": [
151329,
151336,
151338,
151348
],
"image_start_token_id": 151339, "image_start_token_id": 151339,
"image_end_token_id": 151340, "image_end_token_id": 151340,
"video_start_token_id": 151341, "video_start_token_id": 151341,
"video_end_token_id": 151342, "video_end_token_id": 151342,
"image_token_id": 151343, "image_token_id": 151343,
"video_token_id": 151344, "video_token_id": 151344,
"hidden_act": "silu",
"hidden_size": 4096,
"initializer_range": 0.02,
"intermediate_size": 13696,
"max_position_embeddings": 32768,
"num_attention_heads": 32,
"num_hidden_layers": 40,
"num_key_value_heads": 2,
"rms_norm_eps": 1e-05,
"rope_theta": 10000.0,
"tie_word_embeddings": false, "tie_word_embeddings": false,
"transformers_version": "4.57.1", "torch_dtype": "bfloat16",
"text_config": { "transformers_version": "4.53.0dev",
"model_type": "glm4v_text", "use_cache": true,
"attention_bias": true, "vocab_size": 151552,
"attention_dropout": 0.0, "partial_rotary_factor": 0.5,
"pad_token_id": 151329,
"eos_token_id": [
151329,
151336,
151338,
151348
],
"hidden_act": "silu",
"hidden_size": 4096,
"initializer_range": 0.02,
"intermediate_size": 13696,
"max_position_embeddings": 65536,
"num_attention_heads": 32,
"num_hidden_layers": 40,
"num_key_value_heads": 2,
"rms_norm_eps": 1e-05,
"dtype": "bfloat16",
"use_cache": true,
"vocab_size": 151552,
"partial_rotary_factor": 0.5,
"rope_theta": 10000,
"rope_scaling": {
"rope_type": "default",
"mrope_section": [
8,
12,
12
]
}
},
"vision_config": { "vision_config": {
"model_type": "glm4v",
"hidden_size": 1536, "hidden_size": 1536,
"depth": 24, "depth": 24,
"num_heads": 12, "num_heads": 12,
@ -61,5 +49,13 @@
"rms_norm_eps": 1e-05, "rms_norm_eps": 1e-05,
"spatial_merge_size": 2, "spatial_merge_size": 2,
"temporal_patch_size": 2 "temporal_patch_size": 2
},
"rope_scaling": {
"type": "default",
"mrope_section": [
8,
12,
12
]
} }
} }

View File

@ -1,15 +0,0 @@
{
"_from_model_config": true,
"do_sample": true,
"eos_token_id": [
151329,
151336,
151338,
151348
],
"pad_token_id": 151329,
"top_p": 0.6,
"temperature": 0.8,
"top_k": 2,
"transformers_version": "4.57.1"
}

BIN
notebook.ipynb (Stored with Git LFS)

Binary file not shown.

View File

@ -134,7 +134,7 @@
"normalized": false, "normalized": false,
"rstrip": false, "rstrip": false,
"single_word": false, "single_word": false,
"special": false "special": true
}, },
"151346": { "151346": {
"content": "</think>", "content": "</think>",
@ -142,7 +142,7 @@
"normalized": false, "normalized": false,
"rstrip": false, "rstrip": false,
"single_word": false, "single_word": false,
"special": false "special": true
}, },
"151347": { "151347": {
"content": "<answer>", "content": "<answer>",
@ -150,7 +150,7 @@
"normalized": false, "normalized": false,
"rstrip": false, "rstrip": false,
"single_word": false, "single_word": false,
"special": false "special": true
}, },
"151348": { "151348": {
"content": "</answer>", "content": "</answer>",
@ -158,7 +158,7 @@
"normalized": false, "normalized": false,
"rstrip": false, "rstrip": false,
"single_word": false, "single_word": false,
"special": false "special": true
}, },
"151349": { "151349": {
"content": "<|begin_of_box|>", "content": "<|begin_of_box|>",
@ -166,7 +166,7 @@
"normalized": false, "normalized": false,
"rstrip": false, "rstrip": false,
"single_word": false, "single_word": false,
"special": false "special": true
}, },
"151350": { "151350": {
"content": "<|end_of_box|>", "content": "<|end_of_box|>",
@ -174,7 +174,7 @@
"normalized": false, "normalized": false,
"rstrip": false, "rstrip": false,
"single_word": false, "single_word": false,
"special": false "special": true
}, },
"151351": { "151351": {
"content": "<|sep|>", "content": "<|sep|>",
@ -182,7 +182,7 @@
"normalized": false, "normalized": false,
"rstrip": false, "rstrip": false,
"single_word": false, "single_word": false,
"special": false "special": true
} }
}, },
"additional_special_tokens": [ "additional_special_tokens": [
@ -200,8 +200,15 @@
"<|end_of_image|>", "<|end_of_image|>",
"<|begin_of_video|>", "<|begin_of_video|>",
"<|end_of_video|>", "<|end_of_video|>",
"<|begin_of_box|>",
"<|end_of_box|>",
"<|sep|>",
"<|image|>", "<|image|>",
"<|video|>" "<|video|>",
"<think>",
"</think>",
"<answer>",
"</answer>"
], ],
"clean_up_tokenization_spaces": false, "clean_up_tokenization_spaces": false,
"do_lower_case": false, "do_lower_case": false,
@ -211,7 +218,7 @@
"input_ids", "input_ids",
"attention_mask" "attention_mask"
], ],
"model_max_length": 65536, "model_max_length": 64000,
"padding_side": "left", "padding_side": "left",
"remove_space": false, "remove_space": false,
"tokenizer_class": "PreTrainedTokenizer" "tokenizer_class": "PreTrainedTokenizer"