ChatGLM2-6B is the second-generation version of the open-source bilingual Chinese-English dialogue model ChatGLM-6B, developed and maintained by the THUDM team. While retaining the first-generation model's features such as fluent dialogue and a low deployment threshold, it introduces several improvements.
Purpose: ChatGLM2-6B is mainly used for bilingual Chinese-English dialogue generation and can serve as a base model for applications such as chatbots, question-answering systems, and text generation. It also supports academic research and commercial use (registration required).
Main capabilities:
- Stronger performance: Based on the GLM mixed objective function, it is trained with 1.4T Chinese-English tokens of pretraining and human preference alignment training. Evaluations show that, compared with the first-generation model, its performance is substantially improved on datasets such as MMLU (+23%), CEval (+33%), GSM8K (+571%), and BBH (+60%).
- Longer context: Based on FlashAttention technology, the base model's context length is extended from 2K to 32K, and the dialogue stage is trained with an 8K context. A ChatGLM2-6B-32K model is also released, showing competitive performance in the LongBench evaluation.
- More efficient inference: It adopts Multi-Query Attention technology, improving inference speed by 42% compared with the first generation; under INT4 quantization, the dialogue length supported by 6G of GPU memory increases from 1K to 8K.
- More open license: The weights are fully open for academic research, and free commercial use is permitted after filling out a questionnaire to register.
Usage:
- Environment requirements: transformers library version 4.30.2 and torch 2.0 or above are recommended for the best inference performance.
- Model loading: The model implementation and parameters can be downloaded automatically via transformers, or downloaded from the Hugging Face Hub and loaded locally. Downloading the model requires Git LFS.
- Web demo: Web demos based on Gradio and Streamlit are provided; after running the command to start the Web Server, they can be used in a browser.
- Command-line demo: Run cli_demo.py for interactive dialogue, supporting clear to clear the history and stop to terminate the program.
- API deployment: Run api.py to deploy a local API (default port 8000), or run openai_api.py to deploy an OpenAI-format streaming API as the backend for ChatGPT-like applications.
- Quantized loading: INT4 quantization is supported, and generation remains natural and fluent under 4-bit quantization.
- CPU inference: When no GPU is available, inference can be performed on CPU (requiring about 32GB of memory); quantized models can also be used, requiring gcc and openmp to be installed.
- Mac support: Macs with Apple Silicon or AMD GPUs can use the MPS backend, which currently only supports loading models locally; ChatGLM.cpp can also be used.
- Multiple GPUs: After installing accelerate, the model can be split across multiple GPUs for inference.
Applicable scenarios: Suitable for developers and researchers who need to deploy a bilingual Chinese-English dialogue model locally, and can be used to build applications such as chatbots, intelligent customer service, and text generation. It is also suitable for inference in resource-constrained environments (such as GPUs with 6GB of memory, CPUs, and Macs).
Limitations: The model is small in scale and affected by probabilistic randomness, so the accuracy of output content cannot be guaranteed, and it is easily misled. The project team has not developed any applications based on ChatGLM2-6B (including web, mobile, etc.). Use must comply with the open-source license, and it must not be used for services that harm the country and society or that have not undergone security assessment and filing. Quantization causes some performance loss. On Mac, quantized models only support CPU inference.