LLM Architecture Evolution and Optimization: A Component-by-Component Breakdown
This article reviews major architectural and deployment choices in large language models, including normalization, activation functions, positional encoding, low-bit quantization, and width-depth trade-offs. It explains what each change addresses, what costs it introduces, and how practitioners can evaluate these choices for real deployments.
Introduction: Why Look at Architecture Details Component by Component
Much of the capability improvement in large language models comes from architecture details and engineering optimizations, not just parameter scale. Early generative pretrained models established the basic Transformer Decoder framework. Since then, the open-source community has made adjustments in normalization, activation functions, positional encoding, quantization deployment, width-to-depth allocation, and attention mechanisms. This article explains, item by item, what problem each change solves, what cost it introduces, and how readers should judge it in practical work.
1. Evolution of Architecture Components
Normalization: Early models placed LayerNorm after the residual block (Post-LN), and training could become unstable when the network was deep. Modern models mostly use Pre-LN, which places normalization before the sublayer, so gradients propagate more smoothly in deep networks. RMSNorm removes the mean-subtraction step and scales only by the root mean square, which reduces computation; in practice, its effect is close to that of LayerNorm.
Activation functions: Feed-forward networks evolved from ReLU to GELU and then to SwiGLU. SwiGLU uses a gated branch to modulate information flow, so the feed-forward layer gains an additional projection matrix. To keep the total parameter count comparable to the original, implementations usually reduce the intermediate dimension to about two-thirds. Its benefit comes from greater expressiveness, not simply from adding more network layers.
Positional encoding: Absolute positional encodings adapt poorly to sequences beyond the training length. Rotary Position Embedding (RoPE) encodes positional information as rotation angles of query and key vectors, so attention scores naturally depend on relative distance. Most modern open-source models use RoPE, combined with position interpolation or frequency-based scaling methods to extend context length.
2. Low-Bit Quantization: Principles, Memory Estimation, and Configuration
Block-wise scaling: If INT8 or FP8 uses the same scaling factor for an entire tensor, a small number of outliers can widen the dynamic range and reduce precision for most ordinary values. Microscaling formats divide a consecutive group of elements into a block; a common definition shares one scaling factor across every 32 elements and represents elements with 4 bits. In the OCP MX specification, MXFP4 uses the E2M1 element format, and the shared scaling factor uses the 8-bit E8M0 format. Blocks are usually partitioned along the reduction dimension of the matrix multiplication.
Memory estimation: Weight memory is approximately equal to the parameter count multiplied by bits per parameter, divided by 8. For a 70B-parameter model, FP16 requires about 140 GB. With 4 bits plus 8-bit scaling overhead per 32 elements, this is about 4.25 bits per parameter, giving weights of about 37 GB. This estimate excludes the KV cache, activations, and runtime buffers; actual memory requirements are higher, so reserve headroom during deployment.
Hardware and precision: The benefits of MX formats depend on hardware or kernel support. Without native support, inference requires dequantization to higher precision before computation; memory is saved, but throughput may not improve. After quantization, evaluate accuracy on the target tasks, especially error-sensitive tasks such as mathematical reasoning and code generation.
Configuration example: The following code uses bitsandbytes NF4 4-bit quantization. NF4 is another format with a default block size of 64, which differs from MXFP4. Running it requires a CUDA GPU. The dependency installation command is
pip install transformers accelerate bitsandbytes.
import torchfrom transformers import AutoModelForCausalLM, BitsAndBytesConfigmodel_id = "YOUR_MODEL_NAME_OR_LOCAL_PATH"bnb_config = BitsAndBytesConfig(load_in_4bit=True,bnb_4bit_quant_type="nf4",bnb_4bit_compute_dtype=torch.bfloat16,bnb_4bit_use_double_quant=True,llm_int8_skip_modules=["lm_head"], # Keep the output layer at original precision)model = AutoModelForCausalLM.from_pretrained(model_id,quantization_config=bnb_config,device_map="auto",)
Here, llm_int8_skip_modules is used to skip quantization of the output layer, because errors in the output layer directly affect the vocabulary probability distribution.
3. Width and Depth: Trade-offs under a Fixed Parameter Count
The parameter count of each Transformer layer is approximately proportional to the square of the hidden dimension, while the total number of layers adds parameters linearly. Therefore, under a fixed parameter budget, widening means reducing the number of layers, and deepening means narrowing the hidden dimension.
| Adjustment direction | Impact on parameter count | Impact on inference | Better-suited scenarios |
|---|---|---|---|
| Widening (larger hidden dimension) | Per-layer parameters grow quadratically with dimension | Matrix multiplication compute increases; single-layer representation capacity becomes stronger | Knowledge-intensive tasks; batch throughput priority |
| Deepening (more layers) | Parameters grow linearly with layers | KV cache scales with layers; serial computation steps increase | Multi-step reasoning, code, and math tasks that require complex composition |
When selecting a configuration, consider the following order:
- First determine the deployment hardware’s memory limit and target latency.
- If the main bottleneck is memory usage for long contexts, prioritize approaches that reduce the number of KV heads (such as GQA), then decide on the number of layers.
