# GLM-4-9B-Chat-1M Read this in [English](README.md). 如果您使用的是这个仓库中的权重,请更新到 transformers>=4.46.0 这些权重 **不兼容** 较早版本的 transformers 库。 ## 模型介绍 GLM-4-9B 是智谱 AI 推出的最新一代预训练模型 GLM-4 系列中的开源版本。 在语义、数学、推理、代码和知识等多方面的数据集测评中,GLM-4-9B 及其人类偏好对齐的版本 GLM-4-9B-Chat 均表现出较高的性能。 除了能进行多轮对话,GLM-4-9B-Chat 还具备网页浏览、代码执行、自定义工具调用(Function Call)和长文本推理(支持最大 128K 上下文)等高级功能。 本代模型增加了多语言支持,支持包括日语,韩语,德语在内的 26 种语言。我们还推出了支持 1M 上下文长度(约 200 万中文字符)的模型。 ## 评测结果 ### 长文本 在 1M 的上下文长度下进行[大海捞针实验](https://github.com/LargeWorldModel/LWM/blob/main/scripts/eval_needle.py),结果如下: ![needle](https://raw.githubusercontent.com/THUDM/GLM-4/main/resources/eval_needle.jpeg) 在 LongBench-Chat 上对长文本能力进行了进一步评测,结果如下: ![leaderboard](https://raw.githubusercontent.com/THUDM/GLM-4/main/resources/longbench.png) **本仓库是 GLM-4-9B-Chat-1M 的模型仓库,支持`1M`上下文长度。** ## 运行模型 **更多推理代码和依赖信息,请访问我们的 [github](https://github.com/THUDM/GLM-4)。** **请严格按照[依赖](https://github.com/THUDM/GLM-4/blob/main/basic_demo/requirements.txt)安装,否则无法正常运行。** 使用 transformers 后端进行推理: ```python from transformers import AutoModelForCausalLM, AutoTokenizer MODEL_PATH = 'ZhipuAI/glm-4-9b-chat-1m-hf' tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH) model = AutoModelForCausalLM.from_pretrained(MODEL_PATH, 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)) ``` ## 协议 GLM-4 模型的权重的使用则需要遵循 [LICENSE](LICENSE)。 ## 引用 如果你觉得我们的工作有帮助的话,请考虑引用下列论文。 ``` @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.'} } ```