license: other
license_name: glm-4
license_link: https://huggingface.co/THUDM/glm-4-9b-chat-hf/blob/main/LICENSE
language:
- en
- zh
base_model:
- THUDM/glm-4-9b-chat
new_version: THUDM/glm-4-9b-chat-hf
pipeline_tag: text-generation
library_name: transformers
tags:
- chatglm
inference: false
GLM-4-9B-Chat
中文说明请参阅此处。
若使用本仓库权重,请确保升级至
transformers>=4.46.0
旧版transformer库与当前权重不兼容。
模型介绍
GLM-4-9B是智谱AI推出的GLM-4系列最新一代开源预训练模型。在语义、数学、推理、代码及知识等数据集评测中,GLM-4-9B及其人类偏好对齐版本GLM-4-9B-Chat均展现出超越Llama-3-8B的卓越性能。除多轮对话外,GLM-4-9B-Chat还具备网页浏览、代码执行、自定义工具调用(Function Call)及长文本推理(支持128K上下文)等进阶特性。本代模型新增多语言支持,涵盖日语、韩语、德语等26种语言。我们还推出了支持1M上下文长度(约200万中文字符)的GLM-4-9B-Chat-1M模型,以及基于GLM-4-9B的多模态模型GLM-4V-9B。GLM-4V-9B在1120*1120高分辨率下具备中英双语对话能力,在中英文综合能力、感知推理、文本识别、图表理解等多模态评测中,其表现均优于GPT-4-turbo-2024-04-09、Gemini 1.0 Pro、Qwen-VL-Max和Claude 3 Opus。
性能基准
我们在经典任务上评估GLM-4-9B-Chat模型,结果如下:
模型 |
AlignBench-v2 |
MT-Bench |
IFEval |
MMLU |
C-Eval |
GSM8K |
MATH |
HumanEval |
NCB |
Llama-3-8B-Instruct |
5.12 |
8.00 |
68.58 |
68.4 |
51.3 |
79.6 |
30.0 |
62.2 |
24.7 |
ChatGLM3-6B |
3.97 |
5.50 |
28.1 |
66.4 |
69.0 |
72.3 |
25.7 |
58.5 |
11.3 |
GLM-4-9B-Chat |
6.61 |
8.35 |
69.0 |
72.4 |
75.6 |
79.6 |
50.6 |
71.8 |
32.2 |
长文本能力
在1M上下文长度的eval_needle实验中结果如下:

在LongBench上的长文本能力评估结果:

多语言能力
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 |
俄语、西班牙语、德语、法语、意大利语、葡萄牙语、波兰语、日语、荷兰语、阿拉伯语、土耳其语、捷克语、越南语、波斯语、匈牙利语、希腊语、罗马尼亚语、瑞典语、乌克兰语、芬兰语、韩语、丹麦语、保加利亚语、挪威语 |
MGSM |
54.0 |
65.3 |
中文、英语、孟加拉语、德语、西班牙语、法语、日语、俄语、斯瓦希里语、泰卢固语、泰语 |
XWinograd |
61.7 |
73.1 |
中文、英语、法语、日语、俄语、葡萄牙语 |
XStoryCloze |
84.7 |
90.7 |
中文、英语、阿拉伯语、西班牙语、巴斯克语、印地语、印尼语、缅甸语、俄语、斯瓦希里语、泰卢固语 |
XCOPA |
73.3 |
80.1 |
中文、爱沙尼亚语、海地克里奥尔语、印尼语、意大利语、克丘亚语、斯瓦希里语、泰米尔语、泰语、土耳其语、越南语 |
工具调用能力
基于伯克利工具调用排行榜测试:
模型 |
综合准确率 |
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.78 |
5.42 |
GLM-4-9B-Chat |
81.00 |
80.26 |
84.40 |
87.92 |
本仓库为GLM-4-9B-Chat模型仓库,支持128K
上下文长度。
快速开始
更多推理代码及环境要求请访问我们的GitHub页面。
请严格按依赖说明安装,否则无法正常运行
Transformers库(4.46.0及以上版本)推理:
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained('THUDM/glm-4-9b-chat-hf')
model = AutoModelForCausalLM.from_pretrained('THUDM/glm-4-9b-chat-hf', device_map="auto")
message = [
{
"role": "system",
"content": "请回答下列问题"
},
{
"role": "user",
"content": "猫有几条腿?"
}
]
inputs = tokenizer.apply_chat_template(
message,
return_tensors='pt',
add_generation_prompt=True,
return_dict=True,
).to(model.device)
input_len = inputs['input_ids'].shape[1]
generate_kwargs = {
"input_ids": inputs['input_ids'],
"attention_mask": inputs['attention_mask'],
"max_new_tokens": 128,
"do_sample": False,
}
out = model.generate(**generate_kwargs)
print(tokenizer.decode(out[0][input_len:], skip_special_tokens=True))
vLLM库(0.6.4及以上版本)推理:
from transformers import AutoTokenizer
from vllm import LLM, SamplingParams
max_model_len, tp_size = 131072, 1
model_name = "THUDM/glm-4-9b-chat-hf"
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,
)
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-4模型权重遵循LICENSE条款授权使用。
引用文献
若您认为我们的工作有价值,请考虑引用以下论文:
@misc{glm2024chatglm,
title={ChatGLM:从GLM-130B到全工具链GLM-4的大模型家族},
author={GLM团队与多位贡献者},
year={2024},
eprint={2406.12793},
archivePrefix={arXiv},
primaryClass={id='cs.CL' full_name='计算与语言' is_active=True alt_name='cmp-lg' in_archive='cs' is_general=False description='涵盖自然语言处理。大致对应ACM主题分类I.2.7。注意:若人工语言(编程语言、逻辑、形式系统)研究未明确涉及广义自然语言问题(自然语言处理、计算语言学、语音、文本检索等),则不属于本领域。'}
}