Autoregressive Blank Infilling: How This Pretraining Objective Works and Why It Matters

    Autoregressive blank infilling is the pretraining objective behind the GLM family of models. This article explains how it combines bidirectional understanding with autoregressive generation, how to read model benchmark results critically, how to trade off inference latency and throughput, how to design long-context tests, and how to implement reliable tool calling in AI agents. It is a practical guide for developers evaluating and deploying large language models.

    1. Blank Infilling as a Pretraining Objective

    A pretraining objective determines what a model learns during training. Autoregressive blank infilling is one such objective, adopted by the GLM series of models. The idea is straightforward: randomly select several contiguous spans from a text, replace them with placeholder tokens, and train the model to regenerate the masked content token by token, in order.

    This is a training objective, not a complete model architecture. The same objective can be paired with different network designs, so when evaluating a model’s capabilities, you still need to look at its specific architecture, training data, and training configuration.

    2. Why It Combines Understanding and Generation

    Early pretraining approaches fell into two main camps. Left-to-right autoregressive models excel at generation but can only see preceding context at each position. Masked language models leverage both preceding and following context, but are not directly trained for word-by-word generation. Blank infilling attempts to combine the strengths of both.

    Taking GLM’s design as an example, the input is split into two parts. The first part is the masked original text, processed with bidirectional attention, so every position can see the full context. The second part contains the masked spans, generated left to right, where each position only sees previously generated content. Understanding capabilities come from the bidirectional attention; generation capabilities come from the autoregressive decoding.

    At larger training scales, stability depends on data mixture, optimizer choice, and parallelism strategy. Throughout training, you need to continuously monitor gradient norms, loss spikes, and convergence curves. The objective itself does not guarantee stable training.

    3. How to Read Model Benchmark Results

    Benchmark results often appear as a single score, but a single number rarely reflects a model’s overall capability. A more complete evaluation typically covers several task categories: commonsense QA tests knowledge utilization, math word problems test multi-step symbolic reasoning, multi-hop QA tests information integration, and coding tasks test generation and bug-fixing ability.

    When reading leaderboards, verify four things: dataset name and version, evaluation date, model version and inference parameters, and metric definitions. Public datasets such as MMLU, GSM8K, HumanEval, and SWE-bench all have different versions and subsets—comparing scores across different versions is meaningless.

    Coding ability in particular requires distinguishing memorized reproduction from genuine understanding and generation. A model may have seen similar code in its training data and thus produce a correct answer. One way to assess generalization is to use problems published after the model’s training cutoff, or to run contamination checks—for example, measuring n-gram overlap between the problems and the training corpus.

    4. Trading Off Inference Latency and Throughput

    Production deployments usually focus on three metrics. The table below lists their definitions, measurement methods, and common optimization techniques.

    Metric Definition Measurement Method Main Optimizations Typical Use Cases
    Time to first token Time from request submission to receiving the first token Record timestamps per request; report P50 and P95 Prefix caching, shorter prefill length Chat assistants
    Generation throughput Number of tokens generated per unit of time Count total output tokens and elapsed time under load testing Batching, continuous batching Batch analysis, data labeling
    End-to-end latency Total time from request to complete response Client-side timing Combine the above, plus output length control Report generation, workflows

    Each common optimization comes with trade-offs:

    • Quantization compresses weights from 16-bit to 8-bit or 4-bit. It reduces memory usage, but the accuracy loss depends on the quantization method, the model, and the task. Compare results before and after quantization on your own evaluation set.
    • KV cache stores the keys and values of past attention computations to avoid redundant calculation. Cache memory grows with context length, so long-context scenarios need sufficient memory headroom.
    • Prefix sharing is effective for fixed system prompts. When multiple requests share the same prefix, previously computed results can be reused.
    • Speculative decoding uses a small draft model to generate candidate tokens, which the large model then verifies in a single pass. The speedup depends on the acceptance rate of the candidates and the overhead of the draft model. It can deliver significant gains in certain configurations, but must be measured under real traffic.

    Optimization results must always be reported with measurement conditions, including model size, batch size, hardware model, draft model configuration, and precision baseline. Without these, any claimed speedup is hard to reproduce.

    5. How to Design Long-Context Tests

    Long-context capability cannot be judged by window size alone. A model may accept 128k tokens of input yet fail on information located in the middle of the text—the well-known “lost in the middle” problem.

    The “needle in a haystack” test is a common way to check this. It inserts a fact at some position in a long text and asks the model a question about it. The following parameters must be fixed:

    • Context length: e.g., test at 8k, 32k, and 128k separately;
    • Insertion position: e.g., at 0%, 25%, 50%, 75%, and 100% of the text;
    • Number of facts: one or more; with multiple facts, also test whether the model can retrieve all of them;
    • Scoring method: exact match or judge-model evaluation—the report should state which judge model is used;
    • Pass threshold: e.g., accuracy at every insertion position for a given length must be no lower than a set value.

    These parameters determine whether the results can be reproduced by others, and should be listed in the report.

    6. Implementing Tool Calling in AI Agents

    The basic agent loop works like this: the model breaks the user’s goal into subtasks, selects a tool, reads the tool’s returned result, and decides on the next step. The JSON below is an illustration; field names follow the OpenAI-style function calling format, though field names may differ across platforms:

    1. {
    2. "role": "assistant",
    3. "tool_calls": [
    4. {
    5. "id": "call_001",
    6. "type": "function",
    7. "function": {
    8. "name": "run_python",
    9. "arguments": "{\"code\": \"print(sum(range(11)))\", \"timeout_s\": 5}"
    10. }
    11. }
    12. ]
    13. }

    The tool’s execution result is returned as a message with role set to tool, carrying the corresponding tool_call_id. Parameters are typically described with JSON Schema, and the server should validate parameter types and value ranges before execution.

    In production, you need to handle the following issues:

    • Retry limits: set a maximum retry count for failed tool calls, e.g., 3, with exponential backoff to prevent infinite loops and runaway costs.
    • Idempotency: use idempotency keys for write operations such as creating orders or sending emails, so retries do not cause duplicate execution.
    • Permission control: use tool whitelists and grant minimum privileges. Irreversible operations such as deletion, money transfers, and publishing should require human confirmation.
    • State consistency: log the input, output, and decision at every step. If a long-running task is interrupted, it can be resumed from the most recent consistent state.
    • Self-correction: when tool results conflict with the model’s expectations…