---
title: GLM-Z1-Rumination-32B-0414-Int4-W4A16
canonical_url: "https://www.modelscope.cn/models/okwinds/GLM-Z1-Rumination-32B-0414-Int4-W4A16"
md_url: "https://www.modelscope.cn/models/okwinds/GLM-Z1-Rumination-32B-0414-Int4-W4A16.md"
repository: okwinds/GLM-Z1-Rumination-32B-0414-Int4-W4A16
last_updated: 2025-04-17
license: "MIT License"
pipeline_tag: text-generation
tasks:
  - text-generation
model_type:
  - glm4
architectures:
  - Glm4ForCausalLM
base_model:
  - ZhipuAI/GLM-Z1-Rumination-32B-0414
base_model_relation: quantized
parameters: 6.0B
tensor_type:
  - I32
  - BF16
  - I64
library_name:
  - transformer
  - safetensors
  - pytorch
frameworks:
  - Pytorch
language:
  - en
  - cn
inference_backends:
  - "deploy_task text/emb"
  - "sglang 0.5.2"
  - "vllm 0.9.2"
downloads: 113
stars: 1
tags:
  - Chat
  - Instruct
  - Quantization
---

# GLM-Z1-Rumination-32B-0414-Int4-W4A16

> GLM-Z1-Rumination-32B-0414-Int4-W4A16 - okwinds 在 ModelScope 开源的模型。GLM-Z1-Rumination-32B-0414-Int4-W4A16 量化高精校准

okwinds/GLM-Z1-Rumination-32B-0414-Int4-W4A16 是 ModelScope 魔搭社区上的 6.0B 参数text-generation模型，采用 MIT License 许可，基于 ZhipuAI/GLM-Z1-Rumination-32B-0414 构建，可用 deploy_task text/emb、sglang 0.5.2、vllm 0.9.2 部署。

- **Repository**: okwinds/GLM-Z1-Rumination-32B-0414-Int4-W4A16
- **License**: MIT License
- **Tasks**: text-generation
- **Parameters**: 6.0B
- **Base model**: ZhipuAI/GLM-Z1-Rumination-32B-0414
- **Inference backends**: deploy_task text/emb, sglang 0.5.2, vllm 0.9.2
- **Tags**: Chat, Instruct, Quantization
- **Downloads**: 113
- **Stars**: 1
- **Last updated**: 2025-04-17

Source: https://www.modelscope.cn/models/okwinds/GLM-Z1-Rumination-32B-0414-Int4-W4A16

---

# GLM-Z1-Rumination-32B-0414-Int4-W4A16 量化高精校准

### <span style="color:red">友情提醒，推理本模型时，请按照如下官方指引：</span>

> 注意：建议在运行这些模型时设置适当的温度（0.5 到 0.7 之间），否则您可能会遇到无休止的重复或不连贯的输出问题。

### 📖 关于量化损失方面的研究，可阅读公众号“觉察流”文章👇</br>

#### 《[Reason Model 的“瘦身计划”：量化技术的得与失](https://mp.weixin.qq.com/s/NMGq4UUkfo8GMix5LHnWCg)》

#### _仓库作者在此 👇🏻 扫一扫_

<img src="https://www.modelscope.cn/models/okwinds/GPT-2/resolve/master/qrcode_for_jcl_258.jpg" />

_______________________________

SDK下载
```bash
#安装ModelScope
pip install modelscope
```
```python
#SDK模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('okwinds/GLM-Z1-Rumination-32B-0414-Int4-W4A16')
```
Git下载
```
#Git模型下载
git clone https://www.modelscope.cn/okwinds/GLM-Z1-Rumination-32B-0414-Int4-W4A16.git
```

# 模型概述

GLM-Z1-Rumination-32B-0414-Int4-W4A16 是一个基于 [ZhipuAI/GLM-Z1-Rumination-32B-0414](https://www.modelscope.cn/models/ZhipuAI/GLM-Z1-Rumination-32B-0414) 的 Int4 量化的模型。

- **模型名称:** GLM-Z1-Rumination-32B-0414-Int4-W4A16
- **模型架构:** Glm4ForCausalLM
- **权重量化:** Int4

## 量化模型

该模型通过将 [ZhipuAI/GLM-Z1-Rumination-32B-0414](https://www.modelscope.cn/models/ZhipuAI/GLM-Z1-Rumination-32B-0414) 的权重量化为 Int4 数据类型而实现。

量化过程将每个参数从 16bit 减少到 4bit，将模型占用磁盘空间大小，以及推理时加载模型需要的GPU显存空间，减少到了大约为原模型的1/4。只有 transformer 中的 Linear 层权重是量化的，其他层均保持为原模型数据类型，采用了混合精度的计算方式，尽可能减少模型量化后所带来的精度损失。

量化本模型，使用了[AutoGPTQ](https://github.com/AutoGPTQ/AutoGPTQ)，采用 Symmetric group-wise 方式量化（group size : 128）。并在量化过程中，进行了数据校准，以提升模型生成精度。

> <span style="color: red;">注意：本模型需要 compute capability > 8.0（Ampere、Ada Lovelace、Hopper 架构）的 Nvidia GPU 来支持 INT4 **混合精度**计算。</span>

# 部署推理

### 推荐使用 vLLM （ <span style="color: red;">version >= 0.8.3，transformers >= 4.51.3</span> ）

Openai api 兼容模式

```bash
>>> vllm serve "/home/gavin/llm/GLM-Z1-Rumination-32B-0414-Int4-W4A16" --host 0.0.0.0 --port 8000 --gpu-memory-utilization 0.9 --served-model-name "GLM-Z1-Rumination-32B-0414-Int4-W4A16" 
```

---

以下引自原模型的Model Card

# GLM-Z1-Rumination-32B-0414

## 模型介绍

GLM 家族迎来新一代开源模型 **GLM-4-32B-0414** 系列，320 亿参数，效果比肩 OpenAI 的 GPT 系列和 DeepSeek 的 V3/R1 系列，且支持非常友好的本地部署特性。GLM-4-32B-Base-0414 经过 15T 高质量数据的预训练，其中包含大量推理类的合成数据，这为后续的强化学习扩展打下了基础。在后训练阶段，除了针对对话场景进行了人类偏好对齐外，我们还通过拒绝采样和强化学习等技术强化了模型在指令遵循、工程代码、函数调用方面的效果，加强了智能体任务所需的原子能力。GLM-4-32B-0414 在工程代码、Artifacts 生成、函数调用、搜索问答及报告等方面都取得了不错的效果，部分 Benchmark 甚至可以媲美更大规模的 GPT-4o、DeepSeek-V3-0324（671B）等模型。

**GLM-Z1-32B-0414** 是具有深度思考能力的推理模型，这是在 GLM-4-32B-0414 的基础上，通过冷启动和扩展强化学习，以及在数学、代码和逻辑等任务上对模型的进一步训练得到的。相对于基础模型，GLM-4-Z1-32B-0414显著提升了数理能力和解决复杂任务的能力。在训练的过程中，我们还引入了基于对战排序反馈的通用强化学习，进一步增强了模型的通用能力。

**GLM-Z1-Rumination-32B-0414** 是具有沉思能力的深度推理模型（对标Open AI的Deep Research）。不同于一般的深度思考模型，沉思模型通过更长时间的深度思考来解决更开放和更复杂的问题（例如：撰写两个城市AI发展对比情况，以及未来的发展规划），沉思模型还能在深度思考过程中结合搜索工具处理复杂任务，并利用多种规则型奖励来指导和扩展端到端强化学习训练。GLM-4-Z1-Rumination 在研究型写作和复杂检索任务上的能力得到了显著提升。

最后，**GLM-Z1-9B-0414** 是一个惊喜。我们沿用上述一系列技术，训练了一个保持开源传统的 9B 小尺寸模型。尽管规模更小，GLM-4-Z1-9B-0414 在数学推理和通用任务中依然展现出极为优秀的能力，其整体表现已处于同尺寸开源模型中的领先水平。特别是在资源受限的场景下，该模型在效率与效果之间实现了出色的平衡，为追求轻量化部署的用户提供了强有力的选择。


## 推理代码

确保 `transforemrs>=4.51.3`

```python
from transformers import AutoModelForCausalLM, AutoTokenizer

MODEL_PATH = "THUDM/GLM-Z1-Rumination-32B-0414"

tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
model = AutoModelForCausalLM.from_pretrained(MODEL_PATH, device_map="auto")

message = [{"role": "user", "content": "Let a, b be positive real numbers such that ab = a + b + 3. Determine the range of possible values for a + b."}]

inputs = tokenizer.apply_chat_template(
    message,
    return_tensors="pt",
    add_generation_prompt=True,
    return_dict=True,
).to(model.device)

generate_kwargs = {
    "input_ids": inputs["input_ids"],
    "attention_mask": inputs["attention_mask"],
    "temperature": 0.95,
    "top_p": 0.7,
    "do_sample": True,
}
out = model.generate(**generate_kwargs)
print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
```

## 工具调用

该模型当前默认情况下主要支持下面的`function`调用:

- `search`: 根据搜索关键词获取搜索结果
- `click`: 点击搜索结果中的特定网页，查看详细内容
- `open`: 打开固定url，查看其中详细内容
- `finsih`: 信息收集完成，开始写作

下面我们提供一个简单的流程来帮你快速串通pipeline。

```python
from transformers import AutoModelForCausalLM, AutoTokenizer
import re
import json

MODEL_PATH = "THUDM/GLM-Z1-Rumination-32B-0414"

tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
model = AutoModelForCausalLM.from_pretrained(MODEL_PATH, device_map="auto")

messages = [{"role": "user", "content": "Let a, b be positive real numbers such that ab = a + b + 3. Determine the range of possible values for a + b."}]

generate_kwargs = {
    "temperature": 0.95,
    "top_p": 0.7,
    "do_sample": True,
    "stop": ["<|user|>", "<|endoftext|>", "<|observation|>", "<|assistant|>"],
    "max_new_tokens": 16384
}

def get_assistant():
    inputs = tokenizer.apply_chat_template(
        messages,
        return_tensors="pt",
        add_generation_prompt=True,
        return_dict=True,
    ).to(model.device)
    out = model.generate(input_ids=inputs["input_ids"], **generate_kwargs)
    return tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True).strip()

def get_observation(function_name, args):
    content = None
    if function_name == "search":
        mock_search_res = [
            {"title": "t1", "url":"url1", "snippet": "snippet_content_1"},
            {"title": "t2", "url":"url2", "snippet": "snippet_content_2"}
        ]
        content = "\n\n".join([f"【{i}†{res['title']}†{res['url']}\n{res['snippet']}】"] for i, res in enumerate(mock_search_res))
    elif function_name == "click":
        mock_click_res = "main content"
        content = mock_click_res
    elif function_name == "open":
        mock_open_res = "main_content"
        content = mock_open_res
    else:
        raise ValueError("unspport function name!")
    return content
        
def get_func_name_args(llm_text):
    function_call = re.sub(r'.*?</think>', '', llm_text, flags=re.DOTALL)
    function_call = json.loads(function_call)
    action = function_call['name']
    params = function_call['arguments']
    return action, params

def pipeline():
    end_str = "{\"name\": \"finish\", \"arguments\": {}}"
    response = get_assistant()
    messages.append({"role": "assistant", "content": response})
    max_turns, turns = 35, 1
    while not response.endswith(end_str) and turns < max_turns:
        action, params = get_func_name_args(response)
        observation = get_observation(action, params)
        messages.append({"role": "observation", "content": observation})
        response = get_assistant()
        messages.append({"role": "assistant", "content": response})
        turns += 1
        
    if response.endswith(end_str):
        final_answer = get_assistant()
    else:
        final_answer = None
    return final_answer

pipeline()   
```
