Ubuntu
commited on
Commit
•
368f865
1
Parent(s):
269b8ba
english readme
Browse files- README.md +12 -12
- README_en.md +182 -0
- generation_config.json +13 -0
README.md
CHANGED
@@ -15,11 +15,15 @@ inference: false
|
|
15 |
|
16 |
# GLM-4-9B-Chat
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
23 |
|
24 |
## 评测结果
|
25 |
|
@@ -31,7 +35,6 @@ GLM-4-9B 是智谱 AI 推出的最新一代预训练模型 GLM-4 系列中的开
|
|
31 |
| ChatGLM3-6B | 3.97 | 5.50 | 28.1 | 66.4 | 69.0 | 72.3 | 25.7 | 58.5 | 11.3 |
|
32 |
| GLM-4-9B-Chat | 6.61 | 8.35 | 69.0 | 72.4 | 75.6 | 79.6 | 50.6 | 71.8 | 32.2 |
|
33 |
|
34 |
-
|
35 |
### 长文本
|
36 |
|
37 |
在 1M 的上下文长度下进行[大海捞针实验](https://github.com/LargeWorldModel/LWM/blob/main/scripts/eval_needle.py),结果如下:
|
@@ -55,11 +58,10 @@ GLM-4-9B 是智谱 AI 推出的最新一代预训练模型 GLM-4 系列中的开
|
|
55 |
| XStoryCloze | 84.7 | 90.7 | zh, en, ar, es, eu, hi, id, my, ru, sw, te
|
56 |
| XCOPA | 73.3 | 80.1 | zh, et, ht, id, it, qu, sw, ta, th, tr, vi
|
57 |
|
58 |
-
|
59 |
-
|
60 |
### 工具调用能力
|
61 |
|
62 |
-
我们在 [Berkeley Function Calling Leaderboard](https://github.com/ShishirPatil/gorilla/tree/main/berkeley-function-call-leaderboard)
|
|
|
63 |
|
64 |
| Model | Overall Acc. | AST Summary | Exec Summary | Relevance |
|
65 |
|:-----------------------|:------------:|:-----------:|:------------:|:---------:|
|
@@ -80,7 +82,7 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
80 |
|
81 |
device = "cuda"
|
82 |
|
83 |
-
tokenizer = AutoTokenizer.from_pretrained("THUDM/glm-4-9b-chat",trust_remote_code=True)
|
84 |
|
85 |
query = "你好"
|
86 |
|
@@ -145,8 +147,6 @@ print(outputs[0].outputs[0].text)
|
|
145 |
|
146 |
GLM-4 模型的权重的使用则需要遵循 [LICENSE](LICENSE)。
|
147 |
|
148 |
-
Rhe use of the GLM-4 model weights needs to comply with the [LICENSE](LICENSE).
|
149 |
-
|
150 |
## 引用
|
151 |
|
152 |
如果你觉得我们的工作有帮助的话,请考虑引用下列论文。
|
|
|
15 |
|
16 |
# GLM-4-9B-Chat
|
17 |
|
18 |
+
Read this in [English](README_en.md)
|
19 |
+
|
20 |
+
GLM-4-9B 是智谱 AI 推出的最新一代预训练模型 GLM-4 系列中的开源版本。 在语义、数学、推理、代码和知识等多方面的数据集测评中,
|
21 |
+
**GLM-4-9B** 及其人类偏好对齐的版本 **GLM-4-9B-Chat** 均表现出超越 Llama-3-8B 的卓越性能。除了能进行多轮对话,GLM-4-9B-Chat
|
22 |
+
还具备网页浏览、代码执行、自定义工具调用(Function Call)和长文本推理(支持最大 128K 上下文)等高级功能。本代模型增加了多语言支持,支持包括日语,韩语,德语在内的
|
23 |
+
26 种语言。我们还推出了支持 1M 上下文长度(约 200 万中文字符)的 **GLM-4-9B-Chat-1M** 模型和基于 GLM-4-9B 的多模态模型
|
24 |
+
GLM-4V-9B。**GLM-4V-9B** 具备 1120 * 1120 高分辨率下的中英双语多轮对话能力,在中英文综合能力、感知推理、文字识别、图表理解等多方面多模态评测中,GLM-4V-9B
|
25 |
+
表现出超越 GPT-4-turbo-2024-04-09、Gemini
|
26 |
+
1.0 Pro、Qwen-VL-Max 和 Claude 3 Opus 的卓越性能。
|
27 |
|
28 |
## 评测结果
|
29 |
|
|
|
35 |
| ChatGLM3-6B | 3.97 | 5.50 | 28.1 | 66.4 | 69.0 | 72.3 | 25.7 | 58.5 | 11.3 |
|
36 |
| GLM-4-9B-Chat | 6.61 | 8.35 | 69.0 | 72.4 | 75.6 | 79.6 | 50.6 | 71.8 | 32.2 |
|
37 |
|
|
|
38 |
### 长文本
|
39 |
|
40 |
在 1M 的上下文长度下进行[大海捞针实验](https://github.com/LargeWorldModel/LWM/blob/main/scripts/eval_needle.py),结果如下:
|
|
|
58 |
| XStoryCloze | 84.7 | 90.7 | zh, en, ar, es, eu, hi, id, my, ru, sw, te
|
59 |
| XCOPA | 73.3 | 80.1 | zh, et, ht, id, it, qu, sw, ta, th, tr, vi
|
60 |
|
|
|
|
|
61 |
### 工具调用能力
|
62 |
|
63 |
+
我们在 [Berkeley Function Calling Leaderboard](https://github.com/ShishirPatil/gorilla/tree/main/berkeley-function-call-leaderboard)
|
64 |
+
上进行了测试并得到了以下结果:
|
65 |
|
66 |
| Model | Overall Acc. | AST Summary | Exec Summary | Relevance |
|
67 |
|:-----------------------|:------------:|:-----------:|:------------:|:---------:|
|
|
|
82 |
|
83 |
device = "cuda"
|
84 |
|
85 |
+
tokenizer = AutoTokenizer.from_pretrained("THUDM/glm-4-9b-chat", trust_remote_code=True)
|
86 |
|
87 |
query = "你好"
|
88 |
|
|
|
147 |
|
148 |
GLM-4 模型的权重的使用则需要遵循 [LICENSE](LICENSE)。
|
149 |
|
|
|
|
|
150 |
## 引用
|
151 |
|
152 |
如果你觉得我们的工作有帮助的话,请考虑引用下列论文。
|
README_en.md
ADDED
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: other
|
3 |
+
license_name: glm-4
|
4 |
+
license_link: https://huggingface.co/THUDM/glm-4-9b-chat/blob/main/LICENSE
|
5 |
+
|
6 |
+
language:
|
7 |
+
- zh
|
8 |
+
- en
|
9 |
+
tags:
|
10 |
+
- glm
|
11 |
+
- chatglm
|
12 |
+
- thudm
|
13 |
+
inference: false
|
14 |
+
---
|
15 |
+
|
16 |
+
# GLM-4-9B-Chat
|
17 |
+
|
18 |
+
## Model Introduction
|
19 |
+
|
20 |
+
GLM-4-9B is the open-source version of the latest generation of pre-trained models in the GLM-4 series launched by Zhipu
|
21 |
+
AI. In the evaluation of data sets in semantics, mathematics, reasoning, code, and knowledge, **GLM-4-9B**
|
22 |
+
and its human preference-aligned version **GLM-4-9B-Chat** have shown superior performance beyond Llama-3-8B. In
|
23 |
+
addition to multi-round conversations, GLM-4-9B-Chat also has advanced features such as web browsing, code execution,
|
24 |
+
custom tool calls (Function Call), and long text
|
25 |
+
reasoning (supporting up to 128K context). This generation of models has added multi-language support, supporting 26
|
26 |
+
languages including Japanese, Korean, and German. We have also launched the **GLM-4-9B-Chat-1M** model that supports 1M
|
27 |
+
context length (about 2 million Chinese characters) and the multimodal model GLM-4V-9B based on GLM-4-9B.
|
28 |
+
**GLM-4V-9B** possesses dialogue capabilities in both Chinese and English at a high resolution of 1120*1120.
|
29 |
+
In various multimodal evaluations, including comprehensive abilities in Chinese and English, perception & reasoning,
|
30 |
+
text recognition, and chart understanding, GLM-4V-9B demonstrates superior performance compared to
|
31 |
+
GPT-4-turbo-2024-04-09, Gemini 1.0 Pro, Qwen-VL-Max, and Claude 3 Opus.
|
32 |
+
|
33 |
+
## Benchmark
|
34 |
+
|
35 |
+
We evaluated the GLM-4-9B-Chat model on some classic tasks and obtained the following results:
|
36 |
+
|
37 |
+
| Model | AlignBench-v2 | MT-Bench | IFEval | MMLU | C-Eval | GSM8K | MATH | HumanEval | NCB |
|
38 |
+
|:--------------------|:-------------:|:--------:|:------:|:----:|:------:|:-----:|:----:|:---------:|:----:|
|
39 |
+
| Llama-3-8B-Instruct | 5.12 | 8.00 | 68.58 | 68.4 | 51.3 | 79.6 | 30.0 | 62.2 | 24.7 |
|
40 |
+
| ChatGLM3-6B | 3.97 | 5.50 | 28.1 | 66.4 | 69.0 | 72.3 | 25.7 | 58.5 | 11.3 |
|
41 |
+
| GLM-4-9B-Chat | 6.61 | 8.35 | 69.0 | 72.4 | 75.6 | 79.6 | 50.6 | 71.8 | 32.2 |
|
42 |
+
|
43 |
+
### Long Context
|
44 |
+
|
45 |
+
The [eval_needle experiment](https://github.com/LargeWorldModel/LWM/blob/main/scripts/eval_needle.py) was conducted with
|
46 |
+
a context length of 1M, and the results are as follows:
|
47 |
+
|
48 |
+
![needle](https://raw.githubusercontent.com/THUDM/GLM-4/main/resources/eval_needle.jpeg)
|
49 |
+
|
50 |
+
The long text capability was further evaluated on LongBench, and the results are as follows:
|
51 |
+
|
52 |
+
![leaderboard](https://raw.githubusercontent.com/THUDM/GLM-4/main/resources/longbench.png)
|
53 |
+
|
54 |
+
### Multi Language
|
55 |
+
|
56 |
+
The tests for GLM-4-9B-Chat and Llama-3-8B-Instruct are conducted on six multilingual datasets. The test results and the
|
57 |
+
corresponding languages selected for each dataset are shown in the table below:
|
58 |
+
|
59 |
+
| Dataset | Llama-3-8B-Instruct | GLM-4-9B-Chat | Languages |
|
60 |
+
|:------------|:-------------------:|:-------------:|:----------------------------------------------------------------------------------------------:|
|
61 |
+
| M-MMLU | 49.6 | 56.6 | all |
|
62 |
+
| 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 |
|
63 |
+
| MGSM | 54.0 | 65.3 | zh, en, bn, de, es, fr, ja, ru, sw, te, th |
|
64 |
+
| XWinograd | 61.7 | 73.1 | zh, en, fr, jp, ru, pt |
|
65 |
+
| XStoryCloze | 84.7 | 90.7 | zh, en, ar, es, eu, hi, id, my, ru, sw, te |
|
66 |
+
| XCOPA | 73.3 | 80.1 | zh, et, ht, id, it, qu, sw, ta, th, tr, vi |
|
67 |
+
|
68 |
+
### Function Call
|
69 |
+
|
70 |
+
Tested
|
71 |
+
on [Berkeley Function Calling Leaderboard](https://github.com/ShishirPatil/gorilla/tree/main/berkeley-function-call-leaderboard).
|
72 |
+
|
73 |
+
| Model | Overall Acc. | AST Summary | Exec Summary | Relevance |
|
74 |
+
|:-----------------------|:------------:|:-----------:|:------------:|:---------:|
|
75 |
+
| Llama-3-8B-Instruct | 58.88 | 59.25 | 70.01 | 45.83 |
|
76 |
+
| gpt-4-turbo-2024-04-09 | 81.24 | 82.14 | 78.61 | 88.75 |
|
77 |
+
| ChatGLM3-6B | 57.88 | 62.18 | 69.78 | 5.42 |
|
78 |
+
| GLM-4-9B-Chat | 81.00 | 80.26 | 84.40 | 87.92 |
|
79 |
+
|
80 |
+
**This repository is the model repository of GLM-4-9B-Chat, supporting `128K` context length.**
|
81 |
+
|
82 |
+
## Quick call
|
83 |
+
|
84 |
+
**For hardware configuration and system requirements, please check [here](basic_demo/README_en.md).**
|
85 |
+
|
86 |
+
### Use the following method to quickly call the GLM-4-9B-Chat language model
|
87 |
+
|
88 |
+
Use the transformers backend for inference:
|
89 |
+
|
90 |
+
```python
|
91 |
+
import torch
|
92 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
93 |
+
|
94 |
+
device = "cuda"
|
95 |
+
|
96 |
+
tokenizer = AutoTokenizer.from_pretrained("THUDM/glm-4-9b-chat", trust_remote_code=True)
|
97 |
+
|
98 |
+
query = "Hello"
|
99 |
+
|
100 |
+
inputs = tokenizer.apply_chat_template([{"role": "user", "content": query}],
|
101 |
+
add_generation_prompt=True,
|
102 |
+
tokenize=True,
|
103 |
+
return_tensors="pt",
|
104 |
+
return_dict=True
|
105 |
+
)
|
106 |
+
|
107 |
+
inputs = inputs.to(device)
|
108 |
+
model = AutoModelForCausalLM.from_pretrained(
|
109 |
+
"THUDM/glm-4-9b-chat",
|
110 |
+
torch_dtype=torch.bfloat16,
|
111 |
+
low_cpu_mem_usage=True,
|
112 |
+
trust_remote_code=True
|
113 |
+
).to(device).eval()
|
114 |
+
|
115 |
+
gen_kwargs = {"max_length": 2500, "do_sample": True, "top_k": 1}
|
116 |
+
with torch.no_grad():
|
117 |
+
outputs = model.generate(**inputs, **gen_kwargs)
|
118 |
+
outputs = outputs[:, inputs['input_ids'].shape[1]:]
|
119 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
120 |
+
```
|
121 |
+
|
122 |
+
Use the vLLM backend for inference:
|
123 |
+
|
124 |
+
```python
|
125 |
+
from transformers import AutoTokenizer
|
126 |
+
from vllm import LLM, SamplingParams
|
127 |
+
|
128 |
+
# GLM-4-9B-Chat-1M
|
129 |
+
# max_model_len, tp_size = 1048576, 4
|
130 |
+
|
131 |
+
# GLM-4-9B-Chat
|
132 |
+
# If you encounter OOM, it is recommended to reduce max_model_len or increase tp_size
|
133 |
+
max_model_len, tp_size = 131072, 1
|
134 |
+
model_name = "THUDM/glm-4-9b-chat"
|
135 |
+
prompt = [{"role": "user", "content": "你好"}]
|
136 |
+
|
137 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
138 |
+
llm = LLM(
|
139 |
+
model=model_name,
|
140 |
+
tensor_parallel_size=tp_size,
|
141 |
+
max_model_len=max_model_len,
|
142 |
+
trust_remote_code=True,
|
143 |
+
enforce_eager=True,
|
144 |
+
# GLM-4-9B-Chat-1M If you encounter OOM phenomenon, it is recommended to enable the following parameters
|
145 |
+
# enable_chunked_prefill=True,
|
146 |
+
# max_num_batched_tokens=8192
|
147 |
+
)
|
148 |
+
stop_token_ids = [151329, 151336, 151338]
|
149 |
+
sampling_params = SamplingParams(temperature=0.95, max_tokens=1024, stop_token_ids=stop_token_ids)
|
150 |
+
|
151 |
+
inputs = tokenizer.apply_chat_template(prompt, tokenize=False, add_generation_prompt=True)
|
152 |
+
outputs = llm.generate(prompts=inputs, sampling_params=sampling_params)
|
153 |
+
|
154 |
+
print(outputs[0].outputs[0].text)
|
155 |
+
```
|
156 |
+
|
157 |
+
## LICENSE
|
158 |
+
|
159 |
+
The weights of the GLM-4 model are available under the terms of [LICENSE](LICENSE).
|
160 |
+
|
161 |
+
## Citations
|
162 |
+
|
163 |
+
If you find our work useful, please consider citing the following paper.
|
164 |
+
|
165 |
+
```
|
166 |
+
@article{zeng2022glm,
|
167 |
+
title={Glm-130b: An open bilingual pre-trained model},
|
168 |
+
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},
|
169 |
+
journal={arXiv preprint arXiv:2210.02414},
|
170 |
+
year={2022}
|
171 |
+
}
|
172 |
+
```
|
173 |
+
|
174 |
+
```
|
175 |
+
@inproceedings{du2022glm,
|
176 |
+
title={GLM: General Language Model Pretraining with Autoregressive Blank Infilling},
|
177 |
+
author={Du, Zhengxiao and Qian, Yujie and Liu, Xiao and Ding, Ming and Qiu, Jiezhong and Yang, Zhilin and Tang, Jie},
|
178 |
+
booktitle={Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)},
|
179 |
+
pages={320--335},
|
180 |
+
year={2022}
|
181 |
+
}
|
182 |
+
```
|
generation_config.json
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"eos_token_id": [
|
3 |
+
151329,
|
4 |
+
151336,
|
5 |
+
151338
|
6 |
+
],
|
7 |
+
"pad_token_id": 151329,
|
8 |
+
"do_sample": true,
|
9 |
+
"temperature": 0.8,
|
10 |
+
"max_length": 128000,
|
11 |
+
"top_p": 0.8,
|
12 |
+
"transformers_version": "4.38.2"
|
13 |
+
}
|