🌐 Blog • 🤗 HF Repo • 🐦 Twitter • 📄 Report
👋 Join our <a href="https://discord.gg/fK2dz4bg" target="_blank">Discord</a> and <a href="https://github.com/zai-org/ChatGLM-6B/raw/main/resources/WECHAT.md" target="_blank">WeChat</a>
📍Experience and use a larger-scale GLM business model on the Zhipu AI Open Platform
We have released the latest GLM-4 model, which has made new breakthroughs in multiple indicators. You can directly experience our latest model in the following two channels.
API platform The new generation of API
platform has been launched. You can directly experience new models such
as GLM-4-0520, GLM-4-air, GLM-4-airx, GLM-4-flash, GLM-4, GLM-3-Turbo, CharacterGLM-3, CogView-3 on
the API platform.
Among them, the two models GLM-4 and GLM-3-Turbo support new functions such
as System Prompt, Function Call, Retrieval, and Web_Search. You are welcome to experience them.
GLM-4 API open source tutorial GLM-4 API tutorial and basic applications, welcome to try. API-related questions can be asked in this open source tutorial, or use GLM-4 API AI Assistant to get help with common problems.
ChatGLM-6B is an open bilingual language model based on General Language Model (GLM) framework, with 6.2 billion parameters. With the quantization technique, users can deploy locally on consumer-grade graphics cards (only 6GB of GPU memory is required at the INT4 quantization level). Welcome to use the larger ChatGLM model on chatglm.cn
ChatGLM-6B uses technology similar to ChatGPT, optimized for Chinese QA and dialogue. The model is trained for about 1T tokens of Chinese and English corpus, supplemented by supervised fine-tuning, feedback bootstrap, and reinforcement learning wit human feedback. With only about 6.2 billion parameters, the model is able to generate answers that are in line with human preference.
In order to facilitate downstream developers to customize the model for their own application scenarios, we also implements an parameter-efficient tuning method based on P-Tuning v2(Guidelines). Tuning requires at least 7GB of GPU memory at INT4 quantization level.
ChatGLM-6B weights are completely open for academic research, and free commercial use is also allowed after completing the questionnaire.
Try the online demo on Huggingface Spaces.
[2023/07/25] Release CodeGeeX2, which is based on ChatGLM2-6B and trained on more code data. It has the following features:
[2023/06/25] Release ChatGLM2-6B, the second-generation version of ChatGLM-6B. It retains the smooth conversation flow and low deployment threshold of the first-generation model, while introducing the following new features:
Fore more information, please refer to ChatGLM2-6B.
[2023/05/17] Release VisualGLM-6B, a multimodal conversational language model supporting image understanding.

You can run the command line and web demo through cli_demo_vision.py and web_demo_vision.py in the repository. Note that VisualGLM-6B requires additional installation of SwissArmyTransformer and torchvision. For more information, please refer to VisualGLM-6B.
[2023/05/15] Update the checkpoint of v1.1 version, add English instruction data for training to balance the proportion of Chinese and English data, which solves the phenomenon of Chinese words mixed in English answers .
The following is a comparison of English questions before and after the update








For more update info, please refer to UPDATE.md.
Open source projects that accelerate ChatGLM: * lyraChatGLM: Inference acceleration for ChatGLM-6B, up to 9000+ tokens/s inference speed. * ChatGLM-MNN: An MNN-based implementation of ChatGLM-6B C++ inference, which supports automatic allocation of computing tasks to GPU and CPU according to the size of GPU memory * JittorLLMs: Running ChatGLM-6B in FP16 with a minimum of 3G GPU memory or no GPU at all, with Linux, windows, and Mac support * InferLLM: Lightweight C++ inference, which can realize real-time chat on local x86 and Arm processors, and can also run in real time on mobile phones. It only requires 4G of running memory.
Open source projects using ChatGLM-6B: * langchain-ChatGLM: ChatGLM application based on langchain, realizing Q&A based on extensible knowledge base * Wenda: Large-scale language model call platform, based on ChatGLM-6B to achieve ChatPDF-like functions * chatgpt_academic: An academic writing and programming toolbox that supports ChatGLM-6B. It has the characteristics of modularization and multi-thread calling LLM, and can call multiple LLMs in parallel. * glm-bot: Connect ChatGLM to Koishi to call ChatGLM on major chat platforms
Example projects supporting online training of ChatGLM-6B and related applications: * ChatGLM-6B deployment and fine-tuning tutorial * ChatGLM-6B combined with langchain to implement local knowledge base QA Bot
Third-party evaluation: * Measuring Massive Multitask Chinese Understanding
For more open source projects, see PROJECT.md.
| Quantization Level | GPU Memory |
|---|---|
| FP16(no quantization) | 13 GB |
| INT8 | 10 GB |
| INT4 | 6 GB |
Install the requirements with pip: pip install -r requirements.txt. transformers library version is recommended to be 4.27.1, but theoretically any version no lower than 4.23.1 is acceptable.
In addition, if you need to run the quantified model on the CPU, you also need to install gcc and openmp. Most Linux distributions are installed by default. For Windows, you can check openmp when installing TDM-GCC. On Windows testing environment, the gcc version is TDM-GCC 10.3.0, and on Linux is gcc 11.3.0.
Generate dialogue with the following code
>>> from transformers import AutoTokenizer, AutoModel
>>> tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True)
>>> model = AutoModel.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True).half().cuda()
>>> model = model.eval()
>>> response, history = model.chat(tokenizer, "你好", history=[])
>>> print(response)
你好👋!我是人工智能助手 ChatGLM-6B,很高兴见到你,欢迎问我任何问题。
>>> response, history = model.chat(tokenizer, "晚上睡不着应该怎么办", history=history)
>>> print(response)
晚上睡不着可能会让你感到焦虑或不舒服,但以下是一些可以帮助你入睡的方法:
1. 制定规律的睡眠时间表:保持规律的睡眠时间表可以帮助你建立健康的睡眠习惯,使你更容易入睡。尽量在每天的相同时间上床,并在同一时间起床。
2. 创造一个舒适的睡眠环境:确保睡眠环境舒适,安静,黑暗且温度适宜。可以使用舒适的床上用品,并保持房间通风。
3. 放松身心:在睡前做些放松的活动,例如泡个热水澡,听些轻柔的音乐,阅读一些有趣的书籍等,有助于缓解紧张和焦虑,使你更容易入睡。
4. 避免饮用含有咖啡因的饮料:咖啡因是一种刺激性物质,会影响你的睡眠质量。尽量避免在睡前饮用含有咖啡因的饮料,例如咖啡,茶和可乐。
5. 避免在床上做与睡眠无关的事情:在床上做些与睡眠无关的事情,例如看电影,玩游戏或工作等,可能会干扰你的睡眠。
6. 尝试呼吸技巧:深呼吸是一种放松技巧,可以帮助你缓解紧张和焦虑,使你更容易入睡。试着慢慢吸气,保持几秒钟,然后缓慢呼气。
如果这些方法无法帮助你入睡,你可以考虑咨询医生或睡眠专家,寻求进一步的建议。
The implementation of the model is still in development. If you want to fix the used model implementation to ensure compatibility, you can add the revision="v1.1.0" parameter in the from_pretrained call. v1.1.0 is the latest version number. For a complete list of versions, see Change Log.
The above code will automatically download the model implementation and checkpoints by transformers. The full model implementation can be found at Hugging Face Hub. If your network environment is poor, downloading model parameters may take a long time or even fail. At this point, you can download the model to the local first, and then load it from the local.
To download models from Hugging Face Hub, you need to install Git LFS , then run
git clone https://huggingface.co/THUDM/chatglm-6b
After downloading the model locally, replace THUDM/chatglm-6b in the above code with the path of your local chatglm-6b folder to load the model lo
$ claude mcp add ChatGLM-6B \
-- python -m otcore.mcp_server <graph>