Open-Source LLM Deployment Guide: From GLM Architecture to Deployment Validation
This article provides a practical framework for adopting open-source large language models, using the GLM technical line as a reference. It covers license, memory, and data-location constraints; the autoregressive blank infilling architecture; engineering practices for hundred-billion-parameter training; GLM-130B and ChatGLM-6B; quantization and memory estimates; and the boundaries of reasoning and function-calling capabilities.
1. Introduction: Start with Three Conditions
When enterprises use closed-source APIs, they often face issues such as data leaving their environment, unpredictable call costs, and limited customization. Open-source models publish weights and inference code, so teams can deploy, evaluate, and fine-tune them on their own machines. Even with limited compute, small and mid-sized teams can build industry-focused applications.
When choosing an open-source model, three conditions should be checked first: whether the license permits the intended use, whether VRAM can support the target concurrency and context length, and whether data needs to stay inside the intranet. If any of these conditions is not met, later comparisons of model quality are meaningless.
The Knowledge Engineering Group (KEG) at Tsinghua University proposed the GLM general language model architecture and has open-sourced the hundred-billion-parameter bilingual model GLM-130B (2022) and the lightweight dialogue model ChatGLM-6B (2023). This article uses this technical line as a reference to explain the architecture, capability building, and engineering considerations.
2. Architecture Foundation: Autoregressive Blank Infilling
2.1 Three Main Pretraining Paradigms
Large language model pretraining objectives fall roughly into three categories, with different attention patterns and strengths.
| Paradigm | Representative Models | Attention Pattern | Strengths | Open-Ended Generation |
|---|---|---|---|---|
| Encoder | BERT | Bidirectional | Classification, information extraction | Relatively weak |
| Autoregressive | GPT series | Left-to-right | Open-ended generation | Strong |
| Encoder-decoder | T5 | Bidirectional encoder, unidirectional decoder | Translation, summarization | Usable, suited to sequence-to-sequence tasks |
When a single model is expected to handle multiple task types, a single paradigm often has limitations. GLM was designed to address this problem.
2.2 Training Method: Blank Infilling
GLM uses autoregressive blank infilling as a unified pretraining objective. The steps are as follows.
First, randomly sample several contiguous spans in the input text. According to the original GLM paper, about 15% of tokens are selected, and span lengths follow a Poisson distribution with a mean of 3.
Second, replace each span with a mask token to form a corrupted context. This part is called Part A, and the model uses bidirectional attention over it.
Third, shuffle the masked spans and append them in order to the end of the input to form Part B. The model generates Part B autoregressively, so each token can see Part A and previously generated content.
Fourth, the training loss is computed only as the negative log-likelihood of all tokens in Part B. Part A is not included in the loss.
| Part | Content | Attention Pattern | Included in Loss |
|---|---|---|---|
| Part A | Context with spans replaced by mask tokens | Bidirectional | No |
| Part B | Masked spans, shuffled and appended | Autoregressive | Yes |
By changing the number and length of spans, the same architecture can adapt to natural language understanding, conditional generation, and unconditional generation. The cost is that Part B is appended after the input, so the training sequence is longer than with a pure autoregressive objective, increasing compute overhead. The original paper also uses two-dimensional positional encoding to distinguish the positions of the two parts.
2.3 Engineering Points for Hundred-Billion-Parameter Training
Training at the hundred-billion-parameter scale depends on several engineering techniques.
- Mixed precision training: matrix operations use FP16 or BF16, while master weights and optimizer states remain in FP32. This reduces memory usage while lowering the risk of numerical overflow.
- 3D parallelism: data parallelism replicates the model and splits data batches; tensor parallelism splits a single layer’s matrices across multiple GPUs; pipeline parallelism places different layers on different devices. When choosing split ratios, tensor parallelism is usually limited within a single node because intra-node GPU bandwidth is high and communication overhead is low; pipeline parallelism is placed across nodes, and data parallelism is used to scale throughput. The optimal ratio varies with GPU count and bandwidth and requires measurement.
- Memory optimization: activation recomputation trades additional computation for memory space, while optimizer state sharding distributes states across GPUs.
- Long-context extension: rotary position embedding (RoPE) represents relative positions using rotation angles. Position interpolation and other extrapolation methods can extend the usable context from thousands of tokens to tens of thousands of tokens. After extrapolation, the model needs continued training on long-document data and evaluation on long-document tasks. Short-text capability should also be checked for degradation; otherwise long-text results may be unstable.
A common training failure is a loss value of NaN, usually caused by an excessively large learning rate, numerical overflow under low precision, or anomalous data. When troubleshooting, first roll back to more stable precision settings and a smaller learning rate, then check data quality.
3. From Hundred-Billion Base to Dialogue Models
3.1 The Significance of GLM-130B
GLM-130B was released in 2022 with about 130 billion parameters and supports Chinese and English. Its weights were made available for research use through an application process; commercial use must follow the official license terms, as specified on the release page and in the license text.
This model has two notable aspects. First, it showed that teams in China could independently complete the training and tuning of a hundred-billion-scale model. Second, after the weights were public, universities and enterprises could reproduce results and run comparative experiments on the same base, reducing the cost of duplicate training. The paper reports results on multiple Chinese and English benchmarks; refer to the original paper for specific numbers.
3.2 ChatGLM-6B and VRAM Estimates After Quantization
ChatGLM-6B was released in 2023 with about 6.2 billion parameters. Its VRAM requirements can be roughly estimated from weight usage: weight bytes are approximately the number of parameters multiplied by the bytes per parameter.
| Precision | Weight Usage (about 6.2B parameters) | Notes |
|---|---|---|
| FP16 | About 12GB | 2 bytes per parameter |
| INT8 | About 6GB | 1 byte per parameter |
| INT4 | About 3GB | 0.5 bytes per parameter, weights only |
Actual inference also includes KV cache, activations, and framework overhead. The official INT4 inference estimate is about 6GB of VRAM, corresponding to a shorter context and a single request. With longer contexts, higher concurrency, or other GPUs, VRAM requirements will change and cannot be directly applied.
Quantization allows individual developers and small teams to experience and develop dialogue applications on consumer-grade GPUs. Before launch, however, VRAM should still be measured on the target hardware with the target context length and concurrency.
4. Boundaries of Reasoning and Agent Capabilities
Open-source models have clear boundaries in reasoning and agent capabilities, and these should be evaluated separately during model selection.
4.1 Reasoning Capabilities
Multi-step reasoning, such as step-by-step calculation and step-by-step argumentation, depends on training data and model scale. On complex math, code, and long-chain logic tasks, the gap between different open-source models can be large. Leaderboard scores in marketing materials can only serve as an initial screening reference; the final test should use task samples from your own use case.
4.2 Function Calling
Function calling is the most common form of agents. The model outputs a structured call request, usually containing a function name and JSON-formatted arguments. The model itself does not execute tools; the host program validates the request, executes the function, and returns the result to the model.
