Open-Source LLM Architecture: From Normalization to Activation Functions
This article examines the architectural choices shared by many mainstream open-source large language models, including pre-layer normalization, RMSNorm, the SwiGLU activation function, and Rotary Position Embedding (RoPE). It explains how these components improve training stability, computational efficiency, nonlinear representation, and long-sequence extrapolation, and briefly discusses the infrastructure considerations for fine-tuning and serving such models.
As AI technology advances rapidly, many excellent open-source large models have emerged. Although these models differ in parameter scale, pretraining data, and alignment strategies, if we look beneath the surface and examine the underlying network structure, most adopt a unified architecture evolved from the Transformer decoder. This architecture makes several key improvements to basic components such as multi-head self-attention layers and feed-forward neural networks, substantially improving training stability and inference performance. This article systematically analyzes the core architectural innovations shared by these mainstream open-source large models, covering pre-layer normalization, RMSNorm, the SwiGLU activation function, and Rotary Position Embedding (RoPE).
Pre-Layer Normalization and RMSNorm
Early Transformer architectures usually used post-layer normalization, where normalization is performed after the residual connection. However, as model depth increases, post-normalization can make it difficult for gradients to propagate effectively through shallow layers, affecting convergence speed. To address this, open-source large models generally introduce pre-layer normalization.
Pre-layer normalization moves the first normalization operation before the multi-head self-attention layer and the second before the feed-forward neural network, while residual connections remain after each sublayer. This structural adjustment effectively ensures direct gradient propagation in the backbone network and greatly enhances the stability of deep model training.
For the specific normalization function, mainstream solutions abandon traditional LayerNorm and use RMSNorm (Root Mean Square Normalization). The core idea of RMSNorm is that it removes the mean-subtraction operation in LayerNorm and performs scaling normalization only by computing the root mean square of the input vector. For an input vector $a$, the formula is:
$ \bar{a} = \frac{a}{\sqrt{\frac{1}{n}\sum_{i=1}^{n}a_i^2}} $
In addition, RMSNorm can also introduce a learnable scaling factor $g_i$ and offset parameter $b_i$, yielding the final output: $y_i = g_i \bar{a}_i + b_i$. Compared with LayerNorm, RMSNorm maintains the normalization effect while reducing the computational overhead of mean subtraction, improving computational efficiency.
In mainstream deep learning frameworks, a common implementation of RMSNorm is as follows:
import torchimport torch.nn as nnclass RMSNorm(nn.Module):def __init__(self, hidden_size, eps=1e-6):super().__init__()self.weight = nn.Parameter(torch.ones(hidden_size))self.variance_epsilon = eps # Prevent division by zero after reciprocaldef forward(self, hidden_states):input_dtype = hidden_states.dtypevariance = hidden_states.to(torch.float32).pow(2).mean(-1, keepdim=True)hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)# weight is the trainable parameter multiplied at the endreturn (self.weight * hidden_states).to(input_dtype)
SwiGLU Activation Function
In the design of feed-forward neural networks (FFN), mainstream open-source large models often abandon traditional ReLU or GELU activation functions and instead use SwiGLU (Swish-Gated Linear Unit). The basic idea of GLU (Gated Linear Unit) is to filter information through a gating mechanism, with the structure: $(W_1 x + b_1) \otimes \sigma(W_2 x + b_2)$, where $\sigma$ is usually the Sigmoid function.
SwiGLU replaces the Sigmoid gate in GLU with the Swish activation function. The Swish function is expressed as $Swish_\beta(x) = x \cdot \sigma(\beta x)$, where $\beta$ is an adjustable parameter. When $\beta$ approaches 0, Swish approximates a linear function; when $\beta$ approaches infinity, Swish approximates ReLU.
Combining Swish and GLU, the computation formula for a fully connected layer with SwiGLU activation can be written as:
$ FFN_{SwiGLU}(x) = (Swish(x W_1) \otimes x W_2) W_3 $
Here, $W_1, W_2, W_3$ are weight matrices. SwiGLU introduces a nonlinear gating mechanism, which not only enhances the model’s representational capacity but also demonstrates performance superior to traditional activation functions on multiple natural language processing benchmarks. This gating mechanism can dynamically regulate information flow in the network, making the model more efficient when processing complex semantic features.
Rotary Position Embedding
Position encoding is an indispensable part of the Transformer architecture, used to compensate for the self-attention mechanism’s inability to perceive sequence order. Traditional absolute position encoding (such as sine/cosine position encoding) is usually added directly to word embeddings, but this approach has poor extrapolation ability when processing text beyond the pretraining length. Relative position encoding introduces position information by computing the relative distance between Query and Key, offering better generalization.
Rotary Position Embedding cleverly combines the advantages of absolute and relative position encoding. The core idea of RoPE is to inject absolute position information by rotating Query and Key vectors in the complex domain, while making the inner product of two vectors naturally reflect their relative position.
Specifically, for a feature vector of dimension $d$, RoPE treats it as a combination of $d/2$ two-dimensional vectors. For the $m$-th absolute position, RoPE transforms it through a rotation matrix. When computing the inner product between the Query at position $m$ and the Key at position $n$, due to the orthogonality of the rotation matrix, the result depends only on the relative position $m-n$. This design not only supports variable-length sequences but also greatly improves the model’s performance on long-text extrapolation tasks.
Infrastructure and Engineering Practice
After understanding these underlying architectural innovations, in practical engineering, enterprises or developers who want to perform secondary development or fine-tuning based on these open-source large models often need strong compute infrastructure as support. Whether it is the thousand-GPU parallel computing required for large-scale pretraining or the high throughput required for daily inference services, these needs can be met through compute platforms, container services, and distributed storage provided by general cloud providers. With a standardized cloud-native architecture, developers can focus more on optimizing the model algorithms themselves rather than spending excessive effort on setting up the underlying environment.
Conclusion
Current mainstream open-source large models show a high degree of convergence and scientific design in their architecture. Pre-layer normalization and RMSNorm improve training stability and computational efficiency; the SwiGLU activation function strengthens nonlinear representational capacity through a gating mechanism; and RoPE gives the model excellent long-sequence processing and extrapolation capabilities while maintaining computational efficiency. The integration of these core technologies together forms the foundation of the excellent performance of current open-source large models. For developers, a deep understanding of these underlying mechanisms not only helps them better use and fine-tune large models but also provides an important reference for exploring next-generation model architectures.
