SuperAPIAI Directory

ChatGLM2-6B

github.com · AI assistants

ChatGLM2-6B is the second-generation version of the open-source Chinese-English bilingual dialogue model ChatGLM-6B. Based on the GLM hybrid objective function, it has undergone 1.4T Chinese-English token pre-training and human preference alignment training. Compared with the first generation, its performance is substantially improved on datasets such as MMLU, CEval, GSM8K, and BBH, its context length is extended to 32K (8K during the dialogue stage), and it adopts Multi-Query Attention to improve inference speed and reduce GPU memory usage. Under INT4 quantization, 6G of GPU memory can support a dialogue length of 8K. The weights are fully open for academic research and can be used commercially for free after registration.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)
PlatformsmacOS

About this tool

ChatGLM2-6B is the second-generation version of the open-source Chinese-English bilingual dialogue model ChatGLM-6B, maintained by zai-org on GitHub. While retaining the first-generation model's features such as fluent dialogue and a low deployment threshold, it introduces multiple improvements.

Purpose: ChatGLM2-6B is mainly used for Chinese-English bilingual dialogue generation and can serve as a base model for applications such as chatbots, question-answering systems, and text generation. The project team has not developed any applications based on this model (including web and mobile clients, etc.); it only provides the model weights and code for developers to use.

Main capabilities:

  • Stronger performance: Based on the GLM hybrid objective function, it has undergone 1.4T Chinese-English token pre-training 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 has also been 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 is increased 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 4.30.2 and torch 2.0 or above are recommended.
  • Model loading: The model implementation and parameters can be downloaded automatically via transformers, or downloaded from the Hugging Face Hub and loaded locally. If the network is poor, you can download only the model implementation and manually download the parameter files to replace them.
  • Web demo: Web demos based on Gradio and Streamlit are provided. Run the command to start the Web Server, and open the output address in a browser to use it. The Streamlit version is more fluent.
  • Command-line demo: Run cli_demo.py for interactive dialogue; enter clear to clear the history, and enter stop to terminate the program.
  • API deployment: After installing fastapi and uvicorn, runRun api.py, deployed by default on local port 8000, invoked via POST. Additionally, openai_api.py provides an OpenAI-format streaming API that can serve as a backend for ChatGPT applications.
  • Quantized loading: The default FP16 precision requires about 13GB of VRAM; when VRAM is limited, INT4 quantized loading can be used, and it can still generate naturally and fluently under 4-bit quantization.
  • CPU inference: When there is no GPU, inference can be done on the CPU (requires about 32GB of memory), and quantized models can also be used (requires installing gcc and openmp).
  • Mac support: Macs with Apple Silicon or AMD GPUs can use the MPS backend, requiring PyTorch-Nightly; currently only loading models from local storage is supported. ChatGLM.cpp can also be used.
  • Multiple GPUs: After installing accelerate, the model can be split across multiple GPUs for inference.

Use cases: Suitable for developers and researchers conducting research, fine-tuning, and application development of Chinese-English bilingual dialogue models, including chatbots, text generation, question-answering systems, etc. Also suitable for deployment in resource-limited environments (such as 6GB VRAM graphics cards, CPUs, Macs).

Limitations:

  • The model scale is relatively small, and due to probabilistic randomness, the accuracy of the output content cannot be guaranteed, and it is easy to be misled.
  • The project does not assume risks and responsibilities arising from the model being misled, abused, disseminated, or improperly used.
  • The model, code, and derivatives must not be used for purposes that may harm the country and society, or for services without security assessment and filing.
  • The code follows the Apache-2.0 license, and the use of weights must follow the Model License.
  • Quantization will cause a certain performance loss.
  • On Mac, the quantization kernel is based on CUDA, so GPU quantized inference cannot be used on MacOS; only CPU inference is possible.
  • The official project does not provide any applications (web pages, apps, etc.).
Up/Down to navigate · Enter to open · ESC to closeBrowse all tools