ChatGLM3-6B是什么?2026年开源双语对话模型技术解析
ChatGLM3-6B is an open-source bilingual dialogue language model jointly released by Zhipu AI and Tsinghua University KEG Lab, featuring enhanced base model performance, comprehensive function support (including tool calling and code execution), and a full open-source series (including base, 32K, and 128K variants). It is available for academic research and free commercial use after registration.
原文翻译: ChatGLM3-6B是由智谱AI和清华大学KEG实验室联合发布的开源双语对话语言模型,具备更强大的基础模型性能、更完整的功能支持(包括工具调用和代码执行)以及更全面的开源序列(包括基础版、32K和128K变体)。该模型对学术研究完全开放,登记后亦允许免费商业使用。
引言与项目概览
ChatGLM3 是由智谱AI与清华大学知识工程实验室(KEG)联合推出的新一代开源双语对话大语言模型系列。作为该系列的第三代模型,ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。 在继承前两代模型对话流畅、部署门槛低等优秀特性的基础上,在模型能力、功能支持与开源生态方面实现了显著突破。本技术博客旨在为开发者与研究人员提供一份关于 ChatGLM3 的全面技术解析、性能评估及实践部署指南。
ChatGLM3 is a new generation of open-source bilingual dialogue large language model series jointly released by Zhipu AI and the Knowledge Engineering Group (KEG) of Tsinghua University. As the third-generation model in this series, ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。 builds upon the excellent characteristics of its predecessors, such as fluent dialogue and low deployment barriers, while achieving significant breakthroughs in model capabilities, functional support, and open-source ecosystem. This technical blog aims to provide developers and researchers with a comprehensive technical analysis, performance evaluation, and practical deployment guide for ChatGLM3.
核心资源链接:
- 📄 技术报告: arXiv
- 🤗 模型仓库: Hugging Face
- 📔 详细文档: 飞书文档
- 👋 社区交流: Discord | 微信
Core Resource Links:
- 📄 Technical Report: arXiv
- 🤗 Model Hub: Hugging Face
- 📔 Detailed Documentation: Feishu Doc
- 👋 Community: Discord | WeChat
ChatGLM3 核心特性
1. 更强大的基础模型
ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。 的基础模型 ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。-Base 采用了更多样化的训练数据、更充分的训练步数和更优化的训练策略。在涵盖语义理解、数学推理、代码生成、知识问答等多个维度的基准测试集上,其表现均显示出在10B参数量以下的基础模型中具备领先的性能。
The base model of ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。, ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。-Base, employs more diverse training data, more sufficient training steps, and more optimized training strategies. Its performance on benchmark datasets covering multiple dimensions such as semantic understanding, mathematical reasoning, code generation, and knowledge Q&A demonstrates leading capabilities among base models with parameters below 10B.
2. 更完整的功能支持
ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。 引入了全新设计的 Prompt 格式,原生支持复杂场景的应用:
- 工具调用 (Function Call): 模型可以根据用户指令,自主调用外部工具或API来完成任务。
- 代码解释器 (Code Interpreter): 模型可以在安全的沙箱环境中执行代码,并基于执行结果进行推理和回答。
- 智能体 (Agent) 任务: 支持多步骤规划与执行,完成更复杂的交互任务。
ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。 introduces a newly designed Prompt format, natively supporting applications in complex scenarios:
- Function Call: The model can autonomously call external tools or APIs to complete tasks based on user instructions.
- Code Interpreter: The model can execute code in a secure sandbox environment and reason and answer based on the execution results.
- Agent Tasks: Supports multi-step planning and execution to accomplish more complex interactive tasks.
3. 更全面的开源模型序列
除了标准的对话模型外,项目开源了完整的模型家族,以满足不同场景需求:
- ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。: 标准8K上下文长度的对话模型。
- ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。-Base: 未经对话对齐的基础模型,适用于进一步微调与研究。
- ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。-32K: 支持32K长上下文的对话模型。
- ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。-128K: 支持128K超长上下文的对话模型,进一步强化了长文本理解能力。
重要提示: 以上所有权重对学术研究完全开放,在填写登记问卷后亦允许免费商业使用。
In addition to the standard dialogue model, the project has open-sourced a complete model family to meet the needs of different scenarios:
- ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。: Standard dialogue model with an 8K context length.
- ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。-Base: Base model without dialogue alignment, suitable for further fine-tuning and research.
- ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。-32K: Dialogue model supporting a 32K long context.
- ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。-128K: Dialogue model supporting a 128K ultra-long context, further enhancing long-text comprehension capabilities.
Important Note: All the above weights are fully open for academic research and also allow free commercial use after filling out the registration form.
模型性能评测
典型任务性能
在多个权威的中英文评测集上,ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。-Base 相比前代模型和同期同规模基线模型展现出了显著提升。
| 模型 | GSM8K | MATH | BBH | MMLU | C-Eval | CMMLU | MBPP | AGIEval |
|---|---|---|---|---|---|---|---|---|
| ChatGLM2-6B-Base | 32.4 | 6.5 | 33.7 | 47.9 | 51.7 | 50.0 | - | - |
| 最佳基线 (Best Baseline) | 52.1 | 13.1 | 45.0 | 60.1 | 63.5 | 62.2 | 47.5 | 45.8 |
| ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。-Base | 72.3 | 25.7 | 66.1 | 61.4 | 69.0 | 67.5 | 52.4 | 53.7 |
On multiple authoritative Chinese and English evaluation sets, ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。-Base has demonstrated significant improvements compared to its predecessor and contemporary baseline models of similar scale.
Model GSM8K MATH BBH MMLU C-Eval CMMLU MBPP AGIEval ChatGLM2-6B-Base 32.4 6.5 33.7 47.9 51.7 50.0 - - Best Baseline 52.1 13.1 45.0 60.1 63.5 62.2 47.5 45.8 ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。-Base 72.3 25.7 66.1 61.4 69.0 67.5 52.4 53.7
说明:
- 最佳基线 (Best Baseline): 指截至2023年10月27日,参数量在10B以下、在对应数据集上表现最好的通用预训练模型。
- 测试设置: BBH采用3-shot,GSM8K和MATH采用0-shot思维链(CoT),MBPP采用0-shot生成后运行测试用例计算Pass@1,其他选择题数据集采用0-shot。
Notes:
- Best Baseline: Refers to the best-performing general-purpose pre-trained model with parameters below 10B on the corresponding dataset as of October 27, 2023.
- Evaluation Settings: BBH uses 3-shot, GSM8K and MATH use 0-shot Chain-of-Thought (CoT), MBPP uses 0-shot generation followed by test case execution to calculate Pass@1, and other multiple-choice datasets use 0-shot.
长文本理解能力
ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。-32K 在 LongBench 评测集上表现优异,尤其在涉及多文档问答、小样本学习和合成任务方面,相比 ChatGLM2-6B-32K 提升显著。
| 模型 | 平均 | 摘要 | 单文档QA | 多文档QA | 代码 | 小样本 | 合成任务 |
|---|---|---|---|---|---|---|---|
| ChatGLM2-6B-32K | 41.5 | 24.8 | 37.6 | 34.7 | 52.8 | 51.3 | 47.7 |
| ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。-32K | 50.2 | 26.6 | 45.8 | 46.1 | 56.2 | 61.2 | 65.0 |
在实际的长文本应用场景(如论文阅读、文档摘要、财报分析)的人工评估中,其效果平均提升超过50%。
ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。-32K performs excellently on the LongBench evaluation set, showing significant improvements compared to ChatGLM2-6B-32K, especially in multi-document QA, few-shot learning, and synthetic tasks.
Model Avg. Summary Single-Doc QA Multi-Doc QA Code Few-shot Synthetic ChatGLM2-6B-32K 41.5 24.8 37.6 34.7 52.8 51.3 47.7 ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。-32K 50.2 26.6 45.8 46.1 56.2 61.2 65.0 In human evaluations of practical long-text application scenarios (such as paper reading, document summarization, and financial report analysis), its effectiveness has improved by an average of over 50%.
快速开始:环境安装与基础使用
环境安装
首先克隆项目仓库并安装依赖。
git clone https://github.com/THUDM/ChatGLM3
cd ChatGLM3
pip install -r requirements.txt
First, clone the project repository and install the dependencies.
git clone https://github.com/THUDM/ChatGLM3 cd ChatGLM3 pip install -r requirements.txt
注意: 请严格按照 PyTorch 官方文档 安装正确版本的 torch。
Note: Please install the correct version of
torchstrictly according to the PyTorch official documentation.
代码调用示例
通过 transformers 库可以轻松加载模型并进行对话。
from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm3-6b", trust_remote_code=True)
model = AutoModel.from_pretrained("THUDM/chatglm3-6b", trust_remote_code=True, device='cuda')
model = model.eval()
response, history = model.chat(tokenizer, "你好", history=[])
print(response)
# 输出: 你好👋!我是人工智能助手 ChatGLM3-6B...
response, history = model.chat(tokenizer, "晚上睡不着应该怎么办", history=history)
print(response)
# 输出: 晚上睡不着可能会让你感到焦虑或不舒服...
The model can be easily loaded and used for dialogue via the
transformerslibrary.from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm3-6b", trust_remote_code=True) model = AutoModel.from_pretrained("THUDM/chatglm3-6b", trust_remote_code=True, device='cuda') model = model.eval() response, history = model.chat(tokenizer, "Hello", history=[]) print(response) # Output: Hello👋! I am the AI assistant ChatGLM3-6B... response, history = model.chat(tokenizer, "What should I do if I can't sleep at night?", history=history) print(response) # Output: Having trouble sleeping at night can make you feel anxious or uncomfortable...
从本地加载模型
若网络环境不佳,可先手动下载模型至本地,再从本地路径加载。
# 使用 Git LFS 克隆模型仓库(以 Hugging Face 为例)
git clone https://huggingface.co/THUDM/chatglm3-6b /path/to/local/chatglm3-6b
# 代码中指定本地路径
model = AutoModel.from_pretrained("/path/to/local/chatglm3-6b", trust_remote_code=True, device='cuda')
If the network environment is poor, you can manually download the model to your local machine first, then load it from the local path.
# Clone the model repository using Git LFS (using Hugging Face as an example) git clone https://huggingface.co/THUDM/chatglm3-6b /path/to/local/chatglm3-6b# Specify the local path in the code model = AutoModel.from_pretrained("/path/to/local/chatglm3-6b", trust_remote_code=True, device='cuda')
多样化部署与使用方式
1. 综合演示 (Composite Demo)
项目提供了一个集成了三种核心功能的综合演示界面:
- 对话模式 (Chat): 标准的交互式对话。
- 工具模式 (Tool): 展示模型调用外部工具的能力。
- 代码解释器模式 (Code Interpreter): 在 Jupyter 环境中执行代码并返回结果。
运行方法请参考 composite_demo/README.md。
The project provides a comprehensive demo interface integrating three core functions:
- Chat Mode: Standard interactive dialogue.
- Tool Mode: Demonstrates the model's ability to call external tools.
- Code Interpreter Mode: Executes code in a Jupyter environment and returns results.
For running instructions, please refer to composite_demo/README.md.
2. 网页版与命令行 Demo
- Gradio 网页 Demo:
python web_demo_gradio.py - Streamlit 网页 Demo (更流畅):
streamlit run web_demo_streamlit.py - 命令行交互 Demo:
python cli_demo.py(输入clear清空历史,stop退出)
- Gradio Web Demo:
python web_demo_gradio.py- Streamlit Web Demo (Smoother):
streamlit run web_demo_streamlit.py- Command Line Interactive Demo:
python cli_demo.py(Enterclearto clear history,stopto exit)
3. OpenAI/Zhipu API 格式兼容部署
ChatGLM3 提供了与 OpenAI API 格式兼容的部署方案,可轻松集成到现有基于 ChatGPT 生态的应用中。
cd openai_api_demo
python api_server.py
启动后,即可通过 http://127.0.0.1:8000/v1/chat/completions 接口以标准 OpenAI API 格式调用模型。
ChatGLM3 provides a deployment solution compatible with the OpenAI API format, allowing easy integration into existing applications based on the ChatGPT ecosystem.
cd openai_api_demo python api_server.pyOnce started, the model can be called using the standard OpenAI API format via the
http://127.0.0.1:8000/v1/chat/completionsendpoint.
低成本部署方案
模型量化
对于显存有限的 GPU,可以使用 4-bit 量化加载模型,显著降低显存占用(约需 6GB),同时保持可接受的生成质量。
model = AutoModel.from_pretrained("THUDM/chatglm3-6b", trust_remote_code=True).quantize(4).cuda()
For GPUs with limited VRAM, you can load the model using 4-bit quantization, significantly reducing VRAM usage (approximately 6GB required) while maintaining acceptable generation quality.
model = AutoModel.from_pretrained("THUDM/chatglm3-6b", trust_remote_code=True).quantize(4).cuda()
CPU
常见问题(FAQ)
ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。有哪些核心功能?
ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。具备工具调用、代码解释器和智能体任务支持,能自主调用外部API、在沙箱执行代码并完成多步骤复杂交互。
ChatGLM3系列包含哪些模型变体?
开源系列包括标准8K对话模型、基础版、32K长上下文版和128K超长上下文版,满足不同场景需求,均开放学术研究并允许免费商业使用。
ChatGLM3-6B智谱AI和清华大学KEG实验室联合发布的对话预训练模型,是ChatGLM3系列中的开源模型,支持双语对话、工具调用、代码执行等功能。的基础模型性能如何?
采用更优训练策略,在语义理解、数学推理、代码生成等基准测试中,在10B参数以下基础模型中表现领先。
版权与免责声明:本文仅用于信息分享与交流,不构成任何形式的法律、投资、医疗或其他专业建议,也不构成对任何结果的承诺或保证。
文中提及的商标、品牌、Logo、产品名称及相关图片/素材,其权利归各自合法权利人所有。本站内容可能基于公开资料整理,亦可能使用 AI 辅助生成或润色;我们尽力确保准确与合规,但不保证完整性、时效性与适用性,请读者自行甄别并以官方信息为准。
若本文内容或素材涉嫌侵权、隐私不当或存在错误,请相关权利人/当事人联系本站,我们将及时核实并采取删除、修正或下架等处理措施。 也请勿在评论或联系信息中提交身份证号、手机号、住址等个人敏感信息。