---
title: 'SiameseNorm: Dual-Stream Norm for Transformers'
url: https://www.emergentmind.com/topics/siamesenorm
type: topic
---

# SiameseNorm: Dual-Stream Norm for Transformers

SiameseNorm is a two-stream residual architecture for Transformer models that addresses the long-standing incompatibility between Pre-Norm and Post-Norm normalization schemes. By explicitly decoupling gradient flow and representational boundedness via parallel streams with shared transformation parameters, SiameseNorm achieves both optimization stability and high expressive capacity. Empirical results on 1.3B-parameter language models demonstrate that SiameseNorm remains robust at aggressive learning rates and outperforms established baselines in both perplexity and downstream task scores, with nearly negligible parameter overhead [2602.08064].

## 1. Structural Incompatibility of Pre-Norm and Post-Norm

Transformer architectures traditionally use either Pre-Norm or Post-Norm residual blocks. In the Pre-Norm scheme, LayerNorm (LN) is applied before the residual transformation:
\[
X_{i+1} = X_i + F_i(\mathrm{LN}(X_i))
\]
This structure guarantees that the “skip” path from $X_i$ to $X_{i+1}$ yields an exact identity Jacobian ($\frac{\partial X_{i+1}}{\partial X_i}=I$) during backpropagation, enabling robust optimization by preventing vanishing or exploding gradients. However, as $X_i$ is never renormalized, its norm typically grows with depth, requiring deeper blocks to contribute inflated residuals—resulting in the dilution problem, where later layers’ influence on representations is diminished.

Conversely, in the Post-Norm setup, LN follows the residual addition:
\[
X_{i+1} = \mathrm{LN}(X_i + F_i(X_i))
\]
This placement stabilizes the hidden state scale, keeping $\|X_i\|$ approximately constant across depth and preserving deep sequence dynamics (signal expressivity). However, gradients then traverse the LN Jacobian repeatedly, which skews the spectral norm away from 1 and amplifies vanishing (or exploding) dynamics with depth—the distortion problem.

Single-stream hybrid approaches attempting to combine these paradigms are forced to compromise: applying LN after the main path eliminates the identity gradient, while omitting normalization allows uncontrolled growth. SiameseNorm directly addresses this incompatibility by deploying two explicitly coupled streams.

## 2. Canonical Pre-Norm and Post-Norm Residual Block Formulations

The difference between Pre-Norm and Post-Norm can be succinctly captured by their forward equations:
- **Pre-Norm residual block:**
  \[
  Y = x + \mathrm{Module}(\mathrm{LN}(x))
  \]
- **Post-Norm residual block:**
  \[
  Y = \mathrm{LN}(x + \mathrm{Module}(x))
  \]
The choice directly determines the propagation and stability of both activations and gradients. Pre-Norm preserves the gradient highway at the expense of unbounded activity scale. Post-Norm enforces boundedness while distorting gradients through repeated LN applications.

## 3. SiameseNorm Two-Stream Architecture

SiameseNorm introduces two interdependent streams within each Transformer block:
- $X_i$: the “bounded” (Post-Norm–like) stream
- $Y_i$: the “unbounded” (Pre-Norm–like) stream

Both streams share residual transformation weights $F_i(\cdot)$ (for attention/MLP). The forward computations are as follows:
\[
\begin{aligned}
Y_i'   &= \mathrm{LN}^Y_i(Y_i) \\
A_i    &= X_i + Y_i' \\
A_i^*  &= \mathrm{LN}^{\mathrm{agg}}_i(A_i) \\
O_i    &= F_i(A_i^*) \\
X_{i+1} &= \mathrm{LN}^X_i(X_i + \alpha_i O_i) \\
Y_{i+1} &= Y_i + O_i
\end{aligned}
\]
where $\alpha_i=1/\sqrt{i+1}$ is depth-wise scaling to maintain X-stream stability.

After $N$ layers, the final model output fuses both:
\[
\text{Output} = X_N + \mathrm{LN}_{\mathrm{final}}(Y_N)
\]
The two additional per-layer LNs (LN$^X$, LN$^Y$), plus a single fuse LN (LN$^{\text{agg}}$), introduce negligible parameter increase.

During gradient backpropagation, the parameter update at layer $i$ is influenced by both Pre-Norm and Post-Norm pathways, as captured by the block Jacobian:
\[
\frac{\partial S_{j+1}}{\partial S_j}
=
\begin{pmatrix}
\mathbf{J}_{\mathrm{LN}_j^X}(\mathbf{I} + \mathbf{J}_{F_j})
& \mathbf{J}_{\mathrm{LN}_j^X}\mathbf{J}_{F_j}\mathbf{J}_{\mathrm{LN}^Y_j} \\
\mathbf{J}_{F_j}
& \mathbf{I} + \mathbf{J}_{F_j}\mathbf{J}_{\mathrm{LN}^Y_j}
\end{pmatrix}
\]
This construction ensures that every $\theta_i$ receives both stable and expressive gradient signals.

## 4. Resolution of the Stability–Performance Trade-Off

SiameseNorm’s two-stream design stabilizes gradient flow and deepens effective network capacity without requiring compromise:
- The $Y$-stream delivers an unbroken identity gradient (as in Pre-Norm), thereby governing training stability and preventing gradient vanishing/explosion.
- The $X$-stream enforces bounded, normalized representations at each layer (as in Post-Norm), preserving expressivity and favorable signal propagation dynamics.
- The shared residual transformation $F$ is updated by gradients influenced by both streams, avoiding performance trade-offs imposed by single-stream hybrids.

The block Jacobian’s structure guarantees one eigen-block with identity elements (for stable gradients) and another bounded in spectral norm by LN. Empirical findings support this—gradient norm plots indicate that both Pre-Norm and SiameseNorm maintain $\|\nabla_\theta\| \approx 0.1$–$0.5$ during training, even as Post-Norm-based variants often exceed $100$ and diverge. The $X$-stream’s hidden state norms are stable, while growth in the $Y$-stream asserts deep sequential reasoning capacity lost in standard Pre-Norm.

Notably, arithmetic evaluation accuracy increases from $28.1\%$ (Pre-Norm) to $39.6\%$ (SiameseNorm), demonstrating the restoration of deep reasoning capabilities.

## 5. Experimental Configuration and Benchmark Results

SiameseNorm was benchmarked in large-scale pre-training experiments with an OLMo-style Transformer featuring:
- 16 layers, hidden size $2048$, 16 attention heads, MLP size $8192$, RoPE positional encoding, SwiGLU, and RMSNorm ($\epsilon=1e^{-5}$).
- Training conducted on $100$B tokens (with $350$B tokens for extended evaluation) of FineWeb-Edu data.
- Learning rate settings:
  - A: $\eta=4 \times 10^{-4}$ (conservative)
  - B: $\eta=1 \times 10^{-3}$ (moderate)
  - C: $\eta=2 \times 10^{-3}$ (aggressive)
  - D: $\eta=2 \times 10^{-3}$, $350$B tokens

Baselines included Pre-Norm, Post-Norm, DeepNorm, ResiDual, HybridNorm, and Hyper-Connections.

Key performance metrics are provided below:

| Setting | Learning Rate | SiameseNorm (PPL) | Pre-Norm (PPL) | Arithmetic Accuracy (%) | Avg. Downstream Score | Notes                        |
|---------|---------------|-------------------|----------------|------------------------|----------------------|------------------------------|
|   A     | $4$e$-4$      | 10.57             | 11.21          | –                      | –                    | HybridNorm: 10.91            |
|   B     | $1$e$-3$      | 10.43             | 10.84          | –                      | 53.5 vs. 51.9        | Post/HybridNorm diverge      |
|   C     | $2$e$-3$      | 10.48             | 10.89          | 39.6 (vs. 28.1)        | –                    | All Post-Norms highly unstable|
|   D     | $2$e$-3$      | 9.42              | 9.67           | –                      | 58.7 vs. 57.2        | 350B tokens                  |

SiameseNorm is the only scheme to maintain stability at aggressive learning rates, consistently reducing perplexity by $0.3$–$0.5$ and improving downstream scores by $1$–$2$ points compared to Pre-Norm.

## 6. Implementation Considerations and Pseudocode

SiameseNorm does not require significant changes to the computational backbone of self-attention or MLP blocks. Its primary architectural modification is the inclusion of two additional per-layer LNs and explicit management of two parallel streams, with an extra normalization on fused inputs before the residual transformation—found to be critical for stability.

Example PyTorch-style pseudocode (layer level):

```python
class SiameseLayer(nn.Module):
    def __init__(self, hidden_dim, layer_idx):
        super().__init__()
        self.lnY   = RMSNorm(hidden_dim)
        self.lnX   = RMSNorm(hidden_dim)
        self.lnAgg = RMSNorm(hidden_dim)
        self.attn  = SelfAttention(hidden_dim)
        self.mlp   = MLP(hidden_dim)
        self.scale = 1.0 / math.sqrt(layer_idx+1)  # depth-wise scaling

    def forward(self, X, Y):
        Yp = self.lnY(Y)
        A  = self.lnAgg(X + Yp)
        O1 = self.attn(A)
        O2 = self.mlp(self.lnAgg(A + O1))
        O  = O1 + O2
        Xn = self.lnX(X + self.scale * O)
        Yn = Y + O
        return Xn, Yn

# Usage in transformer:
X, Y = embedding(input_ids), embedding(input_ids)
for i, layer in enumerate(layers):
    X, Y = layer(X, Y)
output = X + final_ln(Y)   # final fusion
```

Two “small” LNs ($\lnY, \lnX$) and a critical additional LN ($\lnAgg$) are introduced per layer. The layer-wise scaling $1/\sqrt{l+1}$ in the X-stream is required for stability at depth. No duplication of self-attention or MLP weights is required, ensuring parameter efficiency.

In summary, SiameseNorm runs Pre-Norm and Post-Norm paradigms in parallel on two coupled streams with shared residual weights. This duality preserves both the identity-gradient highway of Pre-Norm and the bounded dynamics of Post-Norm, enabling robust and performant deep Transformer training with marginal computational overhead [2602.08064].

Source: https://www.emergentmind.com/topics/siamesenorm