Glm 4 9b Chat Hf
GLM-4-9B是智譜AI推出的GLM-4系列最新一代預訓練模型的開源版本,具備卓越的語義、數學、推理、代碼和知識能力。
下載量 7,919
發布時間 : 10/23/2024
模型概述
GLM-4-9B-Chat是GLM-4-9B的人類偏好對齊版本,支持多輪對話、網頁瀏覽、代碼執行、自定義工具調用和長上下文推理(128K上下文)。
模型特點
多語言支持
支持26種語言,包括中文、英文、日語、韓語、德語等。
長上下文推理
支持128K上下文長度,具備強大的長文本處理能力。
工具調用
支持自定義工具調用(Function Call),可執行代碼和網頁瀏覽等高級功能。
卓越性能
在語義、數學、推理、代碼和知識等數據集評測中超越Llama-3-8B。
模型能力
文本生成
多輪對話
代碼執行
網頁瀏覽
工具調用
長上下文推理
使用案例
自然語言處理
多語言對話
支持26種語言的對話交流。
在多語言數據集上表現優異。
代碼生成與執行
生成並執行代碼片段。
在HumanEval評測中得分71.8。
知識問答
複雜問題解答
回答涉及多領域知識的複雜問題。
在MMLU和C-Eval等評測中表現優異。
🚀 GLM-4-9B-Chat
GLM-4-9B-Chat 是智譜 AI 推出的 GLM-4 系列預訓練模型的開源版本。它在語義、數學、推理、代碼和知識等數據集評估中表現出色,超越了 Llama-3-8B。除多輪對話外,還具備網頁瀏覽、代碼執行、自定義工具調用和長上下文推理等高級功能。
🚀 快速開始
如需更多推理代碼和要求,請訪問我們的 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": "Answer the following question."
},
{
"role": "user",
"content": "How many legs does a cat have?"
}
]
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
# GLM-4-9B-Chat-1M
# max_model_len, tp_size = 1048576, 4
# If you encounter OOM phenomenon, it is recommended to reduce max_model_len or increase tp_size
max_model_len, tp_size = 131072, 1
model_name = "THUDM/glm-4-9b-chat-hf"
prompt = [{"role": "user", "content": "what is your name?"}]
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-HF If you encounter OOM phenomenon, it is recommended to enable the following parameters
# 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-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 在 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 | 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 上進行測試,結果如下:
模型 | 總體準確率 | 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
上下文長度。
📄 許可證
GLM-4 模型的權重可在 許可證 的條款下使用。
🔖 引用
如果您認為我們的工作有用,請考慮引用以下論文:
@misc{glm2024chatglm,
title={ChatGLM: A Family of Large Language Models from GLM-130B to GLM-4 All Tools},
author={Team GLM and Aohan Zeng and Bin Xu and Bowen Wang and Chenhui Zhang and Da Yin and Diego Rojas and Guanyu Feng and Hanlin Zhao and Hanyu Lai and Hao Yu and Hongning Wang and Jiadai Sun and Jiajie Zhang and Jiale Cheng and Jiayi Gui and Jie Tang and Jing Zhang and Juanzi Li and Lei Zhao and Lindong Wu and Lucen Zhong and Mingdao Liu and Minlie Huang and Peng Zhang and Qinkai Zheng and Rui Lu and Shuaiqi Duan and Shudan Zhang and Shulin Cao and Shuxun Yang and Weng Lam Tam and Wenyi Zhao and Xiao Liu and Xiao Xia and Xiaohan Zhang and Xiaotao Gu and Xin Lv and Xinghan Liu and Xinyi Liu and Xinyue Yang and Xixuan Song and Xunkai Zhang and Yifan An and Yifan Xu and Yilin Niu and Yuantao Yang and Yueyan Li and Yushi Bai and Yuxiao Dong and Zehan Qi and Zhaoyu Wang and Zhen Yang and Zhengxiao Du and Zhenyu Hou and Zihan Wang},
year={2024},
eprint={2406.12793},
archivePrefix={arXiv},
primaryClass={id='cs.CL' full_name='Computation and Language' is_active=True alt_name='cmp-lg' in_archive='cs' is_general=False description='Covers natural language processing. Roughly includes material in ACM Subject Class I.2.7. Note that work on artificial languages (programming languages, logics, formal systems) that does not explicitly address natural-language issues broadly construed (natural-language processing, computational linguistics, speech, text retrieval, etc.) is not appropriate for this area.'}
}
⚠️ 重要提示
如果您使用此倉庫中的權重,請更新到 transformers>=4.46.0 ,這些權重與舊版本的 transformers 庫 不兼容。
💡 使用建議
請嚴格按照 依賴項 進行安裝,否則模型將無法正常運行。在使用 vLLM 庫進行推理時,如果遇到 OOM 現象,建議降低
max_model_len
或增加tp_size
;對於 GLM-4-9B-Chat-1M-HF,若遇到 OOM 現象,建議啟用enable_chunked_prefill=True
和max_num_batched_tokens=8192
等參數。
Phi 2 GGUF
其他
Phi-2是微軟開發的一個小型但強大的語言模型,具有27億參數,專注於高效推理和高質量文本生成。
大型語言模型 支持多種語言
P
TheBloke
41.5M
205
Roberta Large
MIT
基於掩碼語言建模目標預訓練的大型英語語言模型,採用改進的BERT訓練方法
大型語言模型 英語
R
FacebookAI
19.4M
212
Distilbert Base Uncased
Apache-2.0
DistilBERT是BERT基礎模型的蒸餾版本,在保持相近性能的同時更輕量高效,適用於序列分類、標記分類等自然語言處理任務。
大型語言模型 英語
D
distilbert
11.1M
669
Llama 3.1 8B Instruct GGUF
Meta Llama 3.1 8B Instruct 是一個多語言大語言模型,針對多語言對話用例進行了優化,在常見的行業基準測試中表現優異。
大型語言模型 英語
L
modularai
9.7M
4
Xlm Roberta Base
MIT
XLM-RoBERTa是基於100種語言的2.5TB過濾CommonCrawl數據預訓練的多語言模型,採用掩碼語言建模目標進行訓練。
大型語言模型 支持多種語言
X
FacebookAI
9.6M
664
Roberta Base
MIT
基於Transformer架構的英語預訓練模型,通過掩碼語言建模目標在海量文本上訓練,支持文本特徵提取和下游任務微調
大型語言模型 英語
R
FacebookAI
9.3M
488
Opt 125m
其他
OPT是由Meta AI發佈的開放預訓練Transformer語言模型套件,參數量從1.25億到1750億,旨在對標GPT-3系列性能,同時促進大規模語言模型的開放研究。
大型語言模型 英語
O
facebook
6.3M
198
1
基於transformers庫的預訓練模型,適用於多種NLP任務
大型語言模型
Transformers

1
unslothai
6.2M
1
Llama 3.1 8B Instruct
Llama 3.1是Meta推出的多語言大語言模型系列,包含8B、70B和405B參數規模,支持8種語言和代碼生成,優化了多語言對話場景。
大型語言模型
Transformers 支持多種語言

L
meta-llama
5.7M
3,898
T5 Base
Apache-2.0
T5基礎版是由Google開發的文本到文本轉換Transformer模型,參數規模2.2億,支持多語言NLP任務。
大型語言模型 支持多種語言
T
google-t5
5.4M
702
精選推薦AI模型
Llama 3 Typhoon V1.5x 8b Instruct
專為泰語設計的80億參數指令模型,性能媲美GPT-3.5-turbo,優化了應用場景、檢索增強生成、受限生成和推理任務
大型語言模型
Transformers 支持多種語言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一個基於SODA數據集訓練的超小型對話模型,專為邊緣設備推理設計,體積僅為Cosmo-3B模型的2%左右。
對話系統
Transformers 英語

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基於RoBERTa架構的中文抽取式問答模型,適用於從給定文本中提取答案的任務。
問答系統 中文
R
uer
2,694
98