Autoregressive Blank Infilling: A Technical Breakdown of the GLM Model Line
This article explains autoregressive blank infilling, the pretraining approach used by the GLM model line to unify language understanding and generation. It covers how input spans are masked and generated, attention and position encoding rules, document-level and sentence-level objectives, the path from base model to chat model, representative GLM releases, and practical guidance on evaluation, ecosystem signals, accelerator compatibility, deployment workflow, hallucination control, and cost control.
1. Why a Pretraining Approach That Unifies Understanding and Generation Is Needed
GPT-style pure autoregressive models are good at generating text from left to right. BERT-style pure autoencoding models are good at understanding text within a complete context. Each type has its strengths, and a single paradigm often covers only part of the business requirements.
Autoregressive blank infilling is the pretraining idea used by the GLM series. It first masks contiguous spans in the input text, then autoregressively generates the masked content token by token. As a result, the same model can perform classification and information extraction as well as summarization and continuation.
This route also has clear boundaries. The model needs to generate output token by token, so single-response latency is higher than that of small pure discriminative models, making it unsuitable for millisecond-level response scenarios. For tasks whose output must strictly comply with business rules, the model should be combined with a rules engine, retrieval-augmented generation (RAG), and human review rather than relied on alone.
2. How Autoregressive Blank Infilling Works
2.1 How the Input Is Split
During training, the system randomly samples several contiguous spans from the input text. In the original paper’s setup, masked tokens account for about 15% of the original text, and span lengths are sampled from a Poisson distribution with an average of about 3 tokens. Each sampled span is replaced in the first part by a special mask token ([MASK]), so the first part retains the full context.
2.2 Generation Order and Attention
The masked spans are moved to the end of the sequence to form the second part. The order of these spans is shuffled, and each span begins with a start marker and ends with an end marker. When generating span content, the model predicts the next token one by one until it generates the end marker. Therefore, the model does not need to predict the blank length in advance; the span length is determined by the end marker that appears during generation.
The attention rules are as follows:
- Tokens in the first part can attend bidirectionally to each other, but cannot see the second part.
- Tokens in the second part can attend to the entire first part, as well as to tokens in the same span and in previously generated spans, but cannot see content that has not yet been generated.
Position encoding is two-dimensional. The first dimension marks the token’s position in the original text, and the second marks its position within the span to which it belongs. This lets the model perceive both the span’s location in the original text and the order inside the span.
Compared with a BERT-style objective, this design has two direct effects. First, later tokens in the same span can see previously generated content, so dependencies between tokens are modeled. Second, dependencies across different spans are also included in training.
2.3 Two Types of Blank Sampling Objectives
Pretraining usually uses two types of sampling objectives at the same time:
- Document-level objective: samples longer spans to train the model to generate longer coherent text.
- Sentence-level objective: samples multiple spans that cover complete sentences to train the model to understand sentences and complete missing content.
The two objectives share the same model structure and change only the sampling method, so the pretraining stage does not require a separate model for each task.
2.4 From Base Model to Chat Model
The pretrained base itself is not good at multi-turn dialogue. Dialogue ability is usually acquired in two steps:
- Supervised fine-tuning: build high-quality instruction data covering multi-turn dialogue, tool calls, and code generation, and use dialogue templates to concatenate multi-turn history into a unified input format.
- Reinforcement learning from human feedback (RLHF): train a reward model to rank candidate responses, then optimize the model accordingly so that answers are more helpful and safer.
Data quality usually affects the final result more than data quantity. Engineering teams should prioritize checking the correctness and diversity of instruction data.
3. Model Evolution: Checking Against Public Release Records
The table below lists several representative models. Parameter scale, context length, and release dates are taken from public information; before use, refer to the official release pages.
| Model | Publisher | Release date | Parameter scale | Context length | Open-source status |
|---|---|---|---|---|---|
| GLM-130B | Tsinghua University and Zhipu AI | August 2022 | 130B | 2048 | Open source |
| ChatGLM-6B | Zhipu AI | March 2023 | 6.2B | 2K | Open source |
| GLM-4 | Zhipu AI | January 2024 | Undisclosed | 128K | Commercial API |
| GLM-4-9B | Zhipu AI | June 2024 | 9B | 128K | Open source |
| GLM-4V-9B | Zhipu AI | June 2024 | 9B (vision-language) | Per official documentation | Open source |
| GLM-4.5 | Zhipu AI | July 2025 | 355B total parameters, 32B activated | 128K | Open source |
This table can be read by stage.
The scale validation stage is represented by GLM-130B. The focus was on validating the stability of training a model at the hundred-billion-parameter scale, including detection of training collapse, numerical stability under mixed precision, and data mixture. Its main value was providing validated training experience for later models.
The dialogue and tooling stage is represented by the ChatGLM series and GLM-4. These models add dialogue alignment on top of the base and support tool-use capabilities such as function calling, code execution, and web retrieval. Small-parameter models such as ChatGLM-6B can be deployed on consumer-grade GPUs after quantization, lowering the barrier to local deployment.
The reasoning enhancement and agent stage is represented by GLM-4.5. This stage introduces long chain-of-thought training and reinforcement learning, and the model shows clear improvements on math, code, and complex planning tasks. It can also perform planning, tool orchestration, and multi-turn correction, making it suitable for executing longer task flows under human supervision.
Multimodal expansion is represented by GLM-4V-9B. After the visual encoder is aligned with the language model, the model can understand images, charts, and document layouts. Support for other modalities such as speech should follow the official documentation available at the time.
When selecting a model, note that large-model versions iterate quickly and the information in the table may become outdated soon. Before each selection, recheck the official model list, license, and context-length documentation.
4. How to Read Evaluations, Ecosystem, and Accelerator Compatibility
To judge whether a model system is mature, three aspects are usually examined. When reading data on these aspects, first clarify the definitions.
Authoritative evaluations. Scores on agent evaluations, reasoning benchmarks, and code benchmarks can be compared horizontally only under the same evaluation set, the same version, and the same settings. Leaderboard rankings change over time and are also affected by submission methods. Teams should reproduce evaluations close to their own business scenarios rather than directly trusting a ranking on a leaderboard.
Open-source ecosystem. Download counts and community activity are useful references, but definitions vary by platform and may include duplicate downloads and automated pulls. When citing such numbers, note the platform, date, and definition.
AI accelerator compatibility. Compatibility needs to be verified item by item by chip model, driver version, and inference framework version. The official support list is a starting point; broad statements such as “fully adapted” cannot replace specific verification. After choosing a solution, test throughput, latency, and whether numerical results match the reference environment on the target hardware.
5. Deployment Process and Acceptance
Large-model applications usually proceed in the following order:
Business scenario analysis → Model selection → Prompt engineering/fine-tuning → Knowledge base integration (RAG)→ Agent orchestration → Evaluation and security hardening → Canary release → Continuous monitoring and iteration
Typical uses by industry are as follows. In government affairs, the model is often used for consultation Q&A, ticket dispatch, and policy summarization. In industrial scenarios, it is often used for equipment fault diagnosis assistants, process knowledge retrieval, and quality inspection report generation. In finance, it is often used for research report parsing, compliance review assistance, and intelligent customer service. In education, it is often used for personalized tutoring, essay grading, and learning analytics.
Three types of issues need separate handling during deployment.
Hallucination control. Hallucinations cannot be fully eliminated, only reduced. A common practice is to use retrieval-augmented generation to anchor answers in a trusted knowledge base and require the model to provide citation sources. Whether the citations are correct needs to be confirmed through sampling checks.
Cost control. Tasks can be routed by difficulty, with simple tasks sent to small models and complex tasks sent to flagship models. For system prompts that recur, reuse is a practical option.
