wikillm

Paper · 2024-06-18 · cs.CL

ChatGLM: A Family of Large Language Models from GLM-130B to GLM-4 All Tools

Technical report for the ChatGLM family, centred on GLM-4: pre-training on about ten trillion tokens, grouped-query attention, RMSNorm and SwiGLU, SFT plus RLHF, and GLM-4 All Tools, which picks a browser, Python, image or user-defined tool itself. Author-reported: GLM-4 (0520) scores 83.3 MMLU, 93.3 GSM8K and 78.5 HumanEval.

Language model pretrainingInstruction tuningReinforcement learning from human feedback (RLHF)Tool usellmpretrainingalignmenttool-usetechnical-report

arXivPDFCodeMarkdown14 min read

AI-compiled by claude-haiku-5-5 on 2026-10-24, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.

In plain words

This report describes a family of language models called ChatGLM, made by Team GLM at Zhipu AI and Tsinghua University. It focuses on the newest series, GLM-4. The models first learn from a huge pile of mostly Chinese and English text, then are tuned to follow instructions and to match what people prefer.

One variant, GLM-4 All Tools, is trained to decide on its own when a question needs an outside tool: a web browser, a Python interpreter, an image generator, or a function a developer has defined. It then uses the tool's output to continue.

Most of the report is a list of benchmark results. The authors say GLM-4 is close to the strongest commercial models on common tests and ahead of them on Chinese alignment tests. Those are the authors' own numbers. The report gives few training details, so use it to judge whether the models are relevant, not to rebuild them.

TL;DR

The report describes the ChatGLM family from GLM-130B to GLM-4 and GLM-4 All Tools, by Team GLM at Zhipu AI and Tsinghua University p. 1. GLM-4 is pre-trained on about ten trillion tokens, mostly Chinese and English, and aligned with supervised fine-tuning and RLHF [abstract] §2 Alignment. GLM-4 All Tools is further trained to choose among a web browser, a Python interpreter, a text-to-image model and user-defined functions §2 GLM-4 All Tools. Results are author-reported. Training hyperparameters, the data mixture and the All Tools training method are largely not stated, so this card supports relevance checks, not reproduction.

Problem

The report has no single research question. Its goal is a family of general models that match top commercial systems on English benchmarks and lead on Chinese, with open releases alongside §1. Three concrete pressures shape it:

  • Inference cost: the team switched to grouped-query attention to shrink the key-value cache during inference §2 Architecture.
  • Context length: moving from 2K (ChatGLM-6B) to 32K and then to 128K and 1M needed position-encoding extension, continual training on long text and long-context alignment §2 Architecture.
  • Tool use: the model has to decide when a task needs an external tool and to fold the tool's result back into the answer §2 GLM-4 All Tools.

Assumptions: the models are pre-trained mostly on Chinese and English, and aligned primarily for those two languages [abstract] §2 Pre-Training Data. Other languages get only a small share of the pre-training data and are not the alignment focus [abstract].

Method

The paper has no equations and no algorithm box. The steps below follow its prose.

  1. Pre-training data. Multilingual documents (mostly English and Chinese) from web pages, Wikipedia, books, code and research papers. The pipeline runs deduplication (exact and fuzzy), filtering of noisy web pages, and tokenization §2 Pre-Training Data. Sources are re-weighted to favour books and Wikipedia §2 Pre-Training Data. Mixture ratios are not stated.
  2. Tokenizer. Byte-level BPE learns separate Chinese and multilingual vocabularies, which are merged with the cl100k_base tokenizer of tiktoken into one vocabulary of 150,000 tokens §2 Pre-Training Data.
  3. Architecture changes from GLM-130B to GLM-4 §2 Architecture:
    1. Remove all bias terms except those of the query, key and value projections.
    2. Use RMSNorm instead of LayerNorm, and SwiGLU instead of ReLU in the feed-forward block.
    3. Extend rotary positional embeddings to two dimensions.
    4. Replace multi-head attention with grouped-query attention; set the feed-forward width to 10/3 of the hidden size so the parameter count stays the same.
  4. Context extension §2 Architecture. Position-encoding extension, continual training on long text, and long-context alignment. The paper defers the long-context recipe to LongAlign §2 ChatGLM Techniques.
  5. Alignment §2 Alignment. Supervised fine-tuning on authentic human prompts (the paper says template-based or model-written prompts were worse), then RLHF to reduce refusals, unsafe outputs, mixed-language output and multi-turn drift. Annotators score each response for safety, factuality, relevance, helpfulness and preference. Early models used annotations by the developers; later models used in-house annotation and purchased third-party data under quality control.
  6. All Tools §2 GLM-4 All Tools. The model analyses a request, plans steps, calls one or more tools, and uses their intermediate results. The tools named are a web browser, a Python interpreter and a text-to-image model; the GLMs platform adds user-defined functions, APIs and knowledge bases §2 GLM-4 All Tools.

Sketch of the architecture block as the paper describes it. Norm placement relative to the residual connection is not stated.

Pseudocode
# Transformer block for GLM-4  [§2 Architecture]
# Input and output: hidden (B, T, d); cache holds grouped keys and values
def transformer_block(hidden, positions, cache):
    # RMSNorm replaces LayerNorm  [§2 Architecture]
    normed = rms_norm(hidden)                    # (B, T, d)

    # Only the Q, K and V projections carry a bias  [§2 Architecture]
    # Keys and values use fewer heads than queries (GQA)  [§2 Architecture]
    queries, keys, values = qkv_projection(normed)

    # Two-dimensional rotary positional encoding  [§2 Architecture]
    queries, keys = rope_2d(queries, keys, positions)

    # Keys and values are cached in the grouped (smaller) form  [§2]
    cache.append(keys, values)
    attended = attention(queries, cache.keys, cache.values)
    hidden = hidden + output_projection(attended)

    # SwiGLU feed-forward; width d_ffn = 10/3 * d  [§2 Architecture]
    normed = rms_norm(hidden)
    hidden = hidden + swiglu_ffn(normed)
    return hidden

Sketch of the All Tools loop, written from the prose. The paper gives no algorithm and no step limit §2 GLM-4 All Tools.

Pseudocode
# Tool loop for an All Tools model  [§2 GLM-4 All Tools]
# Tools: browser, Python, text-to-image, user-defined functions
def all_tools_loop(conversation, tools):
    while True:
        # The model plans and may request one tool  [§2 GLM-4 All Tools]
        reply = model.generate(conversation, tools)
        if reply.tool_name is None:
            return reply.text
        # Run the tool, then feed its result back  [§2 GLM-4 All Tools]
        result = dispatch_tool(reply.tool_name, reply.arguments)
        conversation.append(reply)
        conversation.append(result)

Hyperparameters

Values from the paper unless the notes say otherwise. Repository defaults are marked as such, because they are not the paper's training settings.

NameValueWhereNotes
pre-training corpus sizeabout 10 trillion tokens[abstract] §1 §2 Pre-Training Datamostly Chinese and English, plus a small share from 24 languages [abstract]
tokenizer vocabulary150,000§2 Pre-Training DataBPE, merged with cl100k_base
pre-training context length, GLM-4-9B8,192§1GLM-4 (128K) pre-training length: not stated
inference context length128K (GLM-4); 1M (experimental GLM-4-9B-Chat-1M)§1
attentiongrouped-query attention§2 Architecturenumber of key-value groups: not stated
feed-forward width d_ffn10/3 × hidden size§2 Architecturechosen to keep parameter count equal to multi-head attention
feed-forward activationSwiGLU§2 Architecturereplaces ReLU
normalizationRMSNorm§2 Architectureepsilon and norm placement: not stated
bias termsnone except Q, K, V§2 Architecture
positional encodingtwo-dimensional RoPE§2 Architecturerotary base: not stated
evaluation precisionBFloat16§3 intro
prompting, math and reasoning benchmarkschain-of-thought for GSM8K, MATH and BBH§3.1number of shots: not stated
IFEval541 prompts, 25 instruction types, strict and loose scoring§3.2
AlignBenchv1.1; 683 queries in 8 categories; GPT-4-based judge§3.3judge prompt: not stated
LongBench-Chatscored by GPT-4, few-shot, averaged over repeated runs§3.4number of runs and shots: not stated
Berkeley Function Call Leaderboardabout 2k question-function-answer pairs§3.6
AgentBench7 of 8 environments; Digital Card Game excluded§3.7official per-dataset weights
SFT and RLHF learning rate, batch size, steps, optimizernot stated§2 Alignment
RLHF algorithm detailsnot stated here§2 ChatGLM Techniquesdefers to ChatGLM-RLHF
SafetyBench filterChinese subset with highly sensitive questions removed§4
demo decoding (CLI)top_p 0.8, temperature 0.6, repetition_penalty 1.2, max new tokens 8,192trans_cli_demo.py trans_cli_demo.pyrepository demo default, not from the paper
demo decoding (web)top_p 0.8, temperature 0.95, repetition_penalty 1.0, max new tokens 2,048main.pyslider defaults, not from the paper
full SFT configlearning rate 5e-5, 3,000 steps, DeepSpeed ZeRO-3sft.yamlrepository fine-tuning default, not the paper's
LoRA configlearning rate 5e-4, 3,000 steps, rank 8, alpha 32, dropout 0.1, targets q/k/vlora.yaml lora.yamlrepository fine-tuning default, not the paper's

Results

Author-reported throughout. Baselines come from public technical reports or from public APIs, which the paper says are the sources §3 intro. Table numbers follow source order in the LaTeX, because the compiled PDF is not in the repository.

Open models and earlier generations §1

Setup: ChatGLM-6B (2023-03-14), ChatGLM2-6B (2023-06-25), ChatGLM3-6B-Base (2023-10-27) and GLM-4-9B (2024-06-05). Evaluation settings are not stated tab. 1.

DatasetChatGLM-6BChatGLM2-6BChatGLM3-6B-BaseGLM-4-9B
GSM8K1.525.972.384.0
MATH3.16.925.730.4
BBH0.029.266.176.3
MMLU25.245.261.474.7
GPQA--26.834.3
HumanEval0.09.858.570.1
BoolQ51.879.087.989.6
CommonSenseQA20.565.486.590.7
HellaSwag30.457.079.782.6
PIQA65.769.680.179.1
DROP3.925.670.977.2
C-Eval23.751.769.077.1
CMMLU25.350.067.575.1
GAOKAO-Bench26.846.467.374.5
C335.158.673.977.2

Academic benchmarks §3.1 tab. 2

Setup: MMLU, GSM8K, MATH, BBH, GPQA and HumanEval, with chain-of-thought for GSM8K, MATH and BBH §3.1.

ModelMMLUGSM8KMATHBBHGPQAHumanEval
GPT-4 (0314)86.492.052.983.135.767.0
GPT-4 Turbo (1106)84.795.764.388.342.583.7
GPT-4 Turbo (2024-04-09)86.795.673.488.249.388.2
Claude 3 Opus86.895.060.186.850.484.9
Gemini 1.5 Pro85.990.867.789.246.284.1
GLM-4-9B-Chat72.479.650.676.328.871.8
GLM-4-Air (0605)81.990.957.980.438.475.7
GLM-4 (0116)81.587.647.982.335.772.0
GLM-4 (0520)83.393.361.384.739.978.5

Instruction following, IFEval §3.2 tab. 3

Setup: 541 prompts; L = loose, S = strict, P = prompt-level, I = instruction-level. The Chinese columns use a translated set with inapplicable instructions removed §3.2.

ModelEN L-PEN S-PEN L-IEN S-IZH L-PZH S-PZH L-IZH S-I
GPT-4 (0613)79.577.185.583.772.468.980.075.7
GPT-4 Turbo (1106)79.175.485.182.474.369.180.876.5
GPT-4 Turbo (2024-04-09)84.581.288.785.979.372.684.279.1
Claude 275.058.081.767.757.146.564.955.1
Claude 3 Opus90.685.593.790.078.373.384.380.4
GLM-4-9B-Chat73.069.080.377.273.069.080.377.2
GLM-4-Air (0605)80.475.286.182.379.371.284.077.3
GLM-4 (0520)83.779.188.785.079.771.984.278.0

Alignment in Chinese, AlignBench v1.1 §3.3 tab. 4

Setup: 683 queries, 8 categories, GPT-4-based multidimensional scoring §3.3.

ModelMathLogicLanguageChineseQAWritingRole PlayProfessionalOverall
GPT-4 (0613)7.547.177.827.027.397.678.207.297.46
GPT-4 Turbo (1106)7.857.667.907.228.248.538.467.957.90
GPT-4 Turbo (2024-04-09)8.327.677.607.578.377.758.188.598.00
Claude 26.395.856.755.726.685.876.866.566.26
Claude 3 Opus7.277.117.947.718.217.617.738.027.53
Gemini 1.5 Pro7.077.777.317.228.557.837.798.527.47
GLM-4-9B-Chat7.006.016.697.267.977.598.107.527.01
GLM-4-Air (0605)7.696.957.538.007.908.018.358.097.65
GLM-4 (0116)7.207.207.608.198.457.888.058.567.66
GLM-4 (0520)7.897.958.007.868.118.048.068.478.00

Long context, LongBench-Chat §3.4 tab. 5

Setup: context lengths from 10k to 100k (unit not stated); GPT-4 scores, few-shot prompting, averaged over repeated runs §3.4.

ModelEnglishChinese
GPT-4 Turbo (1106)87.271.4
GPT-4 Turbo (2024-04-09)85.082.1
Claude 281.376.2
Claude 3 Opus87.782.7
GLM-4-9B-Chat76.879.0
GLM-4-Air (0605)82.481.0
GLM-4 (0520)87.384.0

Real-world coding, NaturalCodeBench §3.5 tab. 6

Setup: real user prompts in Python and Java, in English and Chinese §3.5.

ModelPython (en)Java (en)Python (zh)Java (zh)Overall
GPT-4 (0613)55.751.153.451.152.8
GPT-4 Turbo (1106)51.955.047.351.951.5
GPT-4 Turbo (2024-04-09)57.552.353.152.353.8
Claude 234.436.633.632.834.4
Claude 3 Opus48.948.945.050.448.3
Gemini 1.5 Pro45.039.741.543.142.3
GLM-4-9B-Chat33.929.830.834.432.2
GLM-4-Air (0605)40.839.743.139.740.8
GLM-4 (0520)51.642.845.448.947.1

Function calling, Berkeley Function Call Leaderboard §3.6 tab. 7

Setup: AST summary, execution summary and relevance detection §3.6.

ModelAST summaryExec summaryRelevanceOverall
Llama-3-8B-Instruct59.2570.0145.8358.88
GPT-4 Turbo (2024-04-09)82.1478.6188.7581.24
GPT-4o (2024-05-13)85.2380.3781.2582.94
ChatGLM3-6B62.1869.785.4257.88
GLM-4-9B-Chat80.2684.4087.9281.00
GLM-4-Air (0605)84.3485.9368.3380.94
GLM-4 (0520)82.5987.7884.1781.76

Agents, AgentBench §3.7 tab. 8

Setup: seven environments; overall score uses AgentBench's per-dataset weights §3.7.

ModelOSDBKGLTPHHWSWBOverall
GPT-4 (0613)42.432.058.816.678.061.129.03.69
GPT-4 Turbo (1106)40.352.754.017.770.052.830.03.77
GPT-4 Turbo (2024-04-09)41.046.753.219.472.055.119.03.68
Claude 218.127.341.38.454.061.40.02.03
Claude 3 Opus23.655.053.420.070.048.528.03.62
GLM-4-Air (0605)31.951.053.812.378.069.230.03.58
GLM-4 (0520)36.852.751.415.382.068.329.03.79

OS = Operating System, DB = Database, KG = Knowledge Graph, LTP = Lateral Thinking Puzzles, HH = House Holding, WS = Web Shopping, WB = Web Browsing.

GLM-4 All Tools §3.8 tab. 9

Setup: the All Tools system on the web, GLM-4 All Tools (Web, 0116), compared with GPT-4 (Web, 0110). Python tasks are GSM8K, MATH and Math23K; the browser task is "Information Seeking", which the paper does not define §3.8.

ToolTaskGLM-4 All Tools (Web, 0116)GPT-4 (Web, 0110)
Python interpreterGSM8K91.5992.72
Python interpreterMATH63.6065.00
Python interpreterMath23K88.5088.40
BrowserInformation Seeking78.0867.12

Safety, SafetyBench (Chinese subset) §4 tab. 10

Setup: seven categories; Chinese subset with highly sensitive questions removed §4.

ModelEthics and MoralityIllegal ActivitiesMental HealthOffensivenessPhysical HealthPrivacy and PropertyUnfairness and BiasOverall
GPT-4 (0613)92.793.393.087.796.791.373.389.7
GPT-4 Turbo (1106)91.092.093.086.092.088.774.388.1
GPT-4 Turbo (2024-04-09)90.391.391.785.392.089.375.087.9
Claude 3 Opus92.791.792.786.394.788.766.087.5
GLM-4 (0520)92.391.393.386.392.388.666.087.2

Paper vs code

Code: github.com/THUDM/GLM-4 at commit 024d8fd, Apache-2.0 LICENSE. The README cites this arXiv id README.md, and the owner is the THUDM organisation of the authors' lab. The clone is the repository's current main branch, which is later than the paper. Its README lists releases after June 2024 README.md. The repository holds no training code, no model architecture code and no benchmark harness. The architecture lives in checkpoint configs loaded with trust_remote_code trans_cli_demo.py. I searched the repository for AlignBench, IFEval, LongBench, NaturalCodeBench and AgentBench and found only README mentions.

  • Checkpoint: the CLI demo loads zai-org/GLM-4-9B-0414, not the GLM-4 (0520) or GLM-4-Air (0605) checkpoints evaluated in the paper trans_cli_demo.py §3 intro. Numbers from the paper cannot be reproduced from this code.
  • Decoding: the paper gives no evaluation decoding settings §3 intro. The repository's two demos disagree: the CLI uses temperature 0.6 and repetition penalty 1.2 trans_cli_demo.py trans_cli_demo.py; the web demo defaults to temperature 0.95 and repetition penalty 1.0 main.py.
  • Precision: the paper says BFloat16 at evaluation §3 intro. The CLI demo also loads in bfloat16 trans_cli_demo.py. These agree.
  • Tool use: the paper says the model chooses tools itself §2 GLM-4 All Tools. The repository only contains the client-side dispatch. ALL_TOOLS maps simple_browser, python and cogview tool_registry.py. dispatch_tool runs a predefined tool or a registered custom tool whose arguments are JSON tool_registry.py. The learned choice of tool is not in the repository.
  • Architecture: grouped-query attention, RMSNorm, SwiGLU and 2D RoPE cannot be checked against the repository. The one architecture log is from an Intel demo README and lists multi_query_group_num = 2 and ffn_hidden_size = 13696 README.md. It gives no hidden size, so the 10/3 width ratio §2 Architecture cannot be checked.
  • Fine-tuning defaults: the repository's SFT and LoRA configs use learning rates of 5e-5 and 5e-4 sft.yaml lora.yaml. The paper gives no SFT learning rate §2 Alignment, so these are user defaults and do not describe the paper's alignment.

Pitfalls

  • Baseline labels disagree. The text compares GLM-4 with GPT-4 (0613) at 86.4 MMLU and Gemini 1.5 Pro at 83.7 §1. Table 2 labels 86.4 as GPT-4 (0314) and lists Gemini 1.5 Pro at 85.9 tab. 2. Use the table values and name the GPT-4 build.
  • Percentage claim. The text says GLM-4 reaches 96.3% of GPT-4's MMLU accuracy §3.1. Dividing the table values 83.3 by 86.4 gives 96.4%. The difference is rounding or a different base.
  • AlignBench wording. The text says GLM-4 outperforms GPT-4 Turbo overall §3.3. The table shows both at 8.00 for GLM-4 (0520) and GPT-4 Turbo (2024-04-09) tab. 4.
  • Suspicious duplicate. The GLM-4-9B-Chat IFEval rows are identical for English and Chinese tab. 3. This looks like a copy error, so do not read it as a cross-language result.
  • All Tools comparison. The text compares with "ChatGPT-4 (Web)" §3.8, but the table column is "GPT-4 (Web, 0110)" tab. 9. The browser benchmark "Information Seeking" is not defined, and no sample size is given. Its numbers cannot be re-run from the paper.
  • Context length. GLM-4 is said to support 128K §1, but the only stated pre-training length is 8,192, for GLM-4-9B §1. The pre-training length for the 128K models is not stated, so long-context ability depends on the long-context alignment step §2 Architecture.
  • Baseline sourcing. Baselines come from technical reports or public APIs, and the paper does not say which for each cell §3 intro. API results depend on each provider's safety policy, which the paper says affected its Chinese SafetyBench subset §4.
  • Judge dependence. AlignBench and LongBench-Chat are scored by a GPT-4-based judge §3.3 §3.4. The judge prompt, judge version and the number of repeated runs are not stated.
  • Benchmark edits. The SafetyBench results use a Chinese subset with highly sensitive questions removed §4, so they are not comparable with the full benchmark.
  • Missing training detail. Learning rates, batch sizes, step counts, optimizer settings and the SFT and RLHF data sizes are not stated §2 Alignment. The RLHF methods are described in other reports the paper cites §2 ChatGLM Techniques.
  • Norm placement and bias details. The paper does not say whether RMSNorm is applied before or after each residual branch, nor the RMSNorm epsilon. The sketch above leaves placement open.
  • Tool loop limits. The paper gives no step limit, stopping rule or error handling for tool calls §2 GLM-4 All Tools. The repository's dispatcher returns a system error when a tool call fails tool_registry.py.
  • Cost hidden in agents. The paper gives no latency or cost figures for the tool calls behind the All Tools results §3.8.

Lineage

  • Builds on: GLM-130B, arXiv:2210.02414. This report keeps the transformer base but changes the normalization, feed-forward activation, bias setup and attention design §2 Architecture.
  • Alignment work used or cited by the authors: ChatGLM-RLHF, arXiv:2404.00934 §2 ChatGLM Techniques; ChatGLM-Math, arXiv:2404.02893 §2 ChatGLM Techniques; Self-Contrast, arXiv:2404.00604 §2 ChatGLM Techniques. AgentTuning and LongAlign are cited in the paper, but their arXiv ids are not checked on this card.
  • Compared against: GPT-4 (0314, 0613, Turbo variants), GPT-4o, Claude 2, Claude 3 Opus, Gemini 1.5 Pro and Llama-3-8B-Instruct tab. 2 to tab. 9.
  • Superseded by: none known from content already in this wiki.

Source and license

Adapted from “ChatGLM: A Family of Large Language Models from GLM-130B to GLM-4 All Tools” by Team GLM, Aohan Zeng, Bin Xu, Bowen Wang, Chenhui Zhang, Da Yin, Dan Zhang, Diego Rojas, Guanyu Feng, Hanlin Zhao, Hanyu Lai, Hao Yu, Hongning Wang, Jiadai Sun, Jiajie Zhang, Jiale Cheng, Jiayi Gui, Jie Tang, Jing Zhang, Jingyu Sun, Juanzi Li, Lei Zhao, Lindong Wu, Lucen Zhong, Mingdao Liu, Minlie Huang, Peng Zhang, Qinkai Zheng, Rui Lu, Shuaiqi Duan, Shudan Zhang, Shulin Cao, Shuxun Yang, Weng Lam Tam, Wenyi Zhao, Xiao Liu, Xiao Xia, Xiaohan Zhang, Xiaotao Gu, Xin Lv, Xinghan Liu, Xinyi Liu, Xinyue Yang, Xixuan Song, Xunkai Zhang, Yifan An, Yifan Xu, Yilin Niu, Yuantao Yang, Yueyan Li, Yushi Bai, Yuxiao Dong, Zehan Qi, Zhaoyu Wang, Zhen Yang, Zhengxiao Du, Zhenyu Hou, Zihan Wang (arXiv:2406.12793), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. Code citations refer to https://github.com/THUDM/GLM-4 at commit 024d8fd48e62 (Apache-2.0). Any quoted code is shown under that license.