AI Logic

Normalization

Dynamic Tanh (DyT)

Updated:

How DyT is used and its shape. Left: a Pre-LN Transformer layer in which the layer normalizations before attention and feed-forward, and the final layer normalization, are replaced with DyT. Right: graphs of tanh(αx), showing the S-shaped curves for α = 4, 1, and 1/4. Bottom: a comparison of the computation of layer normalization (normalizing with per-token mean and variance) and DyT (tanh(αx) element-wise)

What Is DyT?

Dynamic Tanh (DyT) is a method that directly replaces layer normalization in a Transformer with the element-wise function DyT(x)=γtanh⁡(αx)+β\mathrm{DyT}(x) = \gamma \tanh(\alpha x) + \beta. α\alpha is a single learnable scalar. Zhu, Chen, He, LeCun, and Liu (Meta FAIR and others) proposed it in 2025 in the paper "Transformers without Normalization".

Normalization layers compute means and variances to rescale values and have been considered indispensable for training deep networks. Even in new architectures that replace attention or convolution, normalization layers are almost always kept. DyT showed that the role of normalization layers can be fulfilled without computing any mean or variance.

In the paper, normalization layers were replaced with DyT in image classification (ViT, ConvNeXt), self-supervised learning (MAE, DINO), image generation (DiT), large language models (LLaMA with 7 to 70 billion parameters), speech (wav2vec 2.0), and DNA sequence models, achieving equal or better performance, in most cases without changing hyperparameters.

Computation Steps

Place it where the normalization layer was

Let the input xx be a tensor of "batch BB × tokens TT × dimensions CC". A DyT layer computes the following in order (Eq. (2) and Algorithm 1 of the paper).

  1. Multiply each element of the input by α\alpha. α\alpha is a single learnable scalar per layer.
  2. Pass it through tanh⁡\tanh. The output lies in the range −1-1 to 11.
  3. Apply a per-dimension scale γ\gamma and shift β\beta. As in normalization layers, γ\gamma and β\beta are learnable vectors of length CC.

DyT(x)=γ∗tanh⁡(αx)+β\mathrm{DyT}(x) = \gamma * \tanh(\alpha x) + \beta

For comparison, layer normalization is written as follows (Eq. (1) of the paper). μ\mu and σ2\sigma^2 are the mean and variance of the CC values of one token.

LN(x)=γ∗x−μσ2+ϵ+β\mathrm{LN}(x) = \gamma * \frac{x - \mu}{\sqrt{\sigma^2 + \epsilon}} + \beta

DyT swaps the part x−μσ2+ϵ\frac{x - \mu}{\sqrt{\sigma^2 + \epsilon}} for tanh⁡(αx)\tanh(\alpha x). The key difference from normalization layers is that it transforms each element independently, without aggregating over other values (mean and variance). For this reason, the paper does not regard DyT as a new kind of normalization.

Where to replace

Each normalization layer is replaced with one DyT layer. This covers the normalization in the attention block, the normalization in the feed-forward block, and the final normalization before the output (left of the figure at the top of the article). Activation functions such as GELU and ReLU stay as they are. Models that use RMSNorm, such as LLaMA, are converted the same way.

Initial values

γ\gamma is initialized to all 1s and β\beta to all 0s (as in normalization layers). The initial value α0\alpha_0 of α\alpha defaults to 0.5. Only for large language models does tuning α0\alpha_0 improve performance (see "Practical Considerations").

Why tanh Can Replace Normalization

Trained layer normalization has an S shape

The paper took trained ViT, wav2vec 2.0, and DiT models and plotted, for every element, the input of each layer normalization against its output (before applying γ\gamma and β\beta) (Figure 2 of the paper).

  • In shallow layers, the relationship was nearly linear.
  • In deeper layers, it became an S-shaped curve like tanh. Most values (about 99%) lie on the nearly linear central part, but some extreme values (in ViT, those above 50 or below −50, for example) were strongly squashed.

Subtracting the mean and dividing by the standard deviation is a linear function (a straight line) within one token. But because the mean and variance differ from token to token, the slope of the line also differs per token: tokens with small variance get steep slopes, and tokens with large variance get shallow ones. Overlaying all these lines makes the whole look like an S (Figure 4 of the paper). The paper suggests that this nonlinear squashing of extreme values may be exactly why normalization layers matter.

Mimicking this shape with tanh and α

DyT mimics this S shape with tanh⁡(αx)\tanh(\alpha x).

  • tanh⁡\tanh squashes extreme values. Near the center it is almost linear (tanh⁡(αx)≈αx\tanh(\alpha x) \approx \alpha x), and large values approach ±1\pm 1.
  • α\alpha sets the horizontal scaling to match the spread of the input. As shown on the right of the figure at the top of the article, the larger α\alpha is, the steeper the S becomes, and the smaller it is, the closer the curve gets to a straight line.

As an analogy, layer normalization "remakes the ruler for each token before measuring", while DyT "uses a single stretchable ruler for everything (α\alpha) and stops any length that runs off the end at the last mark (±1\pm 1)".

α learns the reciprocal of the input's standard deviation

According to the paper, α\alpha during training behaved much like the reciprocal of the standard deviation of that layer's input (1/std1/\mathrm{std}) (Figure 8 of the paper). The final trained α\alpha was also strongly correlated with 1/std1/\mathrm{std}. In other words, α\alpha takes over part of normalization's "divide by the standard deviation" role. However, while layer normalization divides per token, α\alpha is a single value for the layer's entire input, so α\alpha alone cannot squash extreme values nonlinearly. tanh⁡\tanh fills that gap.

Both tanh and α are essential

Experiments on ViT (Tables 7 and 8 of the paper) confirm the role of each.

ChangeViT-B accuracy
DyT (tanh⁡\tanh and α\alpha)82.5%
Replace tanh⁡\tanh with hardtanh82.2%
Replace tanh⁡\tanh with sigmoid81.6%
Remove tanh⁡\tanh (αx\alpha x only)Rose to 61.0%, then diverged
Remove α\alpha (tanh⁡(x)\tanh(x) only)81.1%

Without a squashing function, training diverged; without α\alpha, accuracy dropped. Among the squashing functions, tanh⁡\tanh worked best, which the paper attributes to its being smooth and symmetric about 0.

Experimental Results

The paper replaced the normalization layers of each model with DyT and trained them with the same hyperparameters as the original models (α0=0.5\alpha_0 = 0.5, except for large language models).

Image classification (ImageNet-1K, top-1 accuracy; Table 1 of the paper):

ModelLayer normalizationDyT
ViT-B82.3%82.5%
ViT-L83.1%83.6%
ConvNeXt-B83.7%83.7%
ConvNeXt-L84.3%84.4%

Other tasks (Tables 2–6 of the paper):

TaskModelNormalization layerDyT
Self-supervised learning (accuracy)MAE ViT-L85.5%85.4%
Self-supervised learning (accuracy)DINO ViT-B (patch 8)84.1%84.5%
Image generation (FID, lower is better)DiT-B64.963.9
Image generation (FID, lower is better)DiT-XL19.920.8
Language modeling (average over 15 zero-shot tasks / training loss)LLaMA 7B0.513 / 1.590.513 / 1.60
Language modeling (same as above)LLaMA 70B0.549 / 1.450.549 / 1.45
Speech pretraining (validation loss)wav2vec 2.0 Large1.921.91

(LLaMA's normalization layers are RMSNorm; the others are layer normalization)

Results were on par or slightly better on many tasks, though some, such as DiT-XL's FID, were slightly worse. The training loss curves of layer normalization and DyT also almost overlapped.

Comparison with other normalization-free methods (Table 9 of the paper): DyT was compared with Fixup and SkipInit, which stabilize training through initialization, and σReparam, which constrains the spectral norm of the weights. For fairness, the learning rate was tuned for every method here.

ModelLayer normalizationFixupSkipInitσReparamDyT
ViT-B82.3%77.2%74.1%82.5%82.8%
ViT-L83.1%78.1%75.6%83.0%83.6%
MAE ViT-B83.2%73.7%73.1%83.2%83.7%
MAE ViT-L85.5%74.1%74.0%85.4%85.8%

Methods that rely on initialization alone needed much lower learning rates to avoid divergence, and their accuracy was also lower.

Practical Considerations

Large language models require tuning the initial value of α. For vision and speech models, varying α0\alpha_0 between 0.5 and 1.2 barely changed performance, but for LLaMA, tuning changed performance substantially. According to the paper, wider models (larger hidden dimension) prefer smaller α0\alpha_0, while depth had almost no effect. In addition, a larger value for the DyT in the attention block and smaller values for the feed-forward and final DyT gave better results (e.g., 0.8 and 0.2 for LLaMA 7B, 0.2 and 0.05 for LLaMA 70B). For LLaMA, a learnable scalar is also added after the initial embedding layer.

It is a poor substitute for batch normalization. In the paper's preliminary experiments, replacing the batch normalization in ResNet-50 with DyT dropped ImageNet accuracy from 76.2% to 68.9% (from 72.7% to 71.0% for VGG19). The paper suggests this may be because CNNs have batch normalization after every weight layer, giving them more normalization layers than Transformers. The paper's evaluation focuses on models that use layer normalization and RMSNorm.

Also keep the following points in mind.

  • Lower the initial α for large models or large learning rates. For supervised ViT-L, training diverged when α0\alpha_0 exceeded 0.6. The paper states that when enlarging the model or raising the learning rate, lowering α0\alpha_0 helps, and conversely when raising α0\alpha_0, lowering the learning rate keeps training stable. With α0=0.5\alpha_0 = 0.5, stability was about the same as with layer normalization.
  • It is not necessarily faster. On LLaMA 7B, with an unoptimized implementation, the DyT layers took about half the time of the RMSNorm layers, but after compiling with torch.compile the two took almost the same time (Appendix C of the paper).
  • The computation is the same during training and inference. DyT does not aggregate means or variances and keeps no running averages, so model.train() and model.eval() give the same output.
  • It is not meant to be used as an activation function. The paper uses DyT only to replace normalization layers and keeps activation functions such as GELU as they are.

Comparison with Other Normalization Methods

AspectDyTLayer normalizationRMSNormBatch normalization
Computationtanh⁡(αx)\tanh(\alpha x) element-wisePer token, subtract the mean and divide by the standard deviationPer token, divide by the root mean squarePer channel, subtract the batch mean and divide by the standard deviation
Aggregates mean/varianceNoYes (within a token)Yes (within a token, mean of squares only)Yes (across the batch)
Learnable parametersα\alpha (scalar), γ\gamma, β\betaγ\gamma, β\betaγ\gammaγ\gamma, β\beta
Training vs. inferenceSame computationSame computationSame computationComputation differs (running averages)
Main usesReplacing LN and RMSNorm in Transformers (in the paper)TransformersLarge language modelsCNNs

Rough guidelines for choosing:

  • You want to train a Transformer with proven, standard settings: layer normalization or RMSNorm. Many implementations and training recipes assume them.
  • You want to eliminate the aggregation (mean and variance) of normalization layers, or to study the role of normalization: DyT. For vision and speech models, it can be swapped in directly with α0=0.5\alpha_0 = 0.5. Large language models require tuning α0\alpha_0.
  • Your CNN uses batch normalization: replacing it with DyT is likely to reduce accuracy, so use batch normalization, Group Normalization, or similar.

For stabilizing the training of deep Transformers, there are also methods that change where normalization is placed (Pre-LN and Post-LN) or how the residual is applied (DeepNorm, LayerScale). These keep the normalization layers in place.

PyTorch example

Show code
python
import torch
import torch.nn as nn

class DyT(nn.Module):
    """Eq. (2) and Algorithm 1 of the paper: DyT(x) = γ * tanh(αx) + β"""
    def __init__(self, dim, alpha_init=0.5):
        super().__init__()
        self.alpha = nn.Parameter(torch.ones(1) * alpha_init)   # one scalar per layer (default initial value 0.5)
        self.gamma = nn.Parameter(torch.ones(dim))               # γ initialized to 1, β to 0 (same as normalization layers)
        self.beta = nn.Parameter(torch.zeros(dim))

    def forward(self, x):                                        # x: [B, T, C]
        x = torch.tanh(self.alpha * x)                           # element-wise; no mean or variance is computed
        return self.gamma * x + self.beta

class Block(nn.Module):
    """Pre-LN Transformer layer with nn.LayerNorm replaced by DyT"""
    def __init__(self, dim, n_heads):
        super().__init__()
        self.norm1 = DyT(dim)                                    # originally nn.LayerNorm(dim)
        self.attn = nn.MultiheadAttention(dim, n_heads, batch_first=True)
        self.norm2 = DyT(dim)                                    # originally nn.LayerNorm(dim)
        self.ffn = nn.Sequential(nn.Linear(dim, 4 * dim), nn.GELU(), nn.Linear(4 * dim, dim))  # GELU stays as is

    def forward(self, x):
        h = self.norm1(x)
        x = x + self.attn(h, h, h, need_weights=False)[0]
        return x + self.ffn(self.norm2(x))

model = nn.Sequential(*[Block(384, 6) for _ in range(12)], DyT(384))   # the final normalization becomes DyT too
x = torch.randn(2, 197, 384)
print(model(x).shape)        # torch.Size([2, 197, 384])

# For large language models, the initial α depends on location (Table 10 of the paper; LLaMA 7B: 0.8 for attention, 0.2 elsewhere)
attn_norm, ffn_norm = DyT(4096, alpha_init=0.8), DyT(4096, alpha_init=0.2)

FAQ

Q. Can the layer normalization in a trained model be swapped for DyT afterward?
A.

All of the paper's experiments train models with DyT from scratch. Swapping the normalization layers of a trained model changes the layers' outputs, so the original performance will not be retained as is. Other studies have explored removing normalization from trained models, but this was not evaluated in the DyT paper.

Q. What should the initial value of α be?
A.

For vision, speech, DNA, and similar models, the paper's default of 0.5 is sufficient; performance barely changed between 0.5 and 1.2. However, if training diverges with a large model or a large learning rate, lower the initial value. Large language models need tuning: use smaller values for wider models, and make the DyT before attention larger than the DyT before the feed-forward network and the final DyT.

Q. Does DyT make training or inference faster?
A.

It depends on the implementation. In the paper's measurements (LLaMA 7B, H100), with an unoptimized implementation the DyT layers took about half the time of the RMSNorm layers, and the whole model was about 8% faster. After compiling with torch.compile, however, the two took almost the same time. The paper notes that because DyT does not aggregate means or variances, it may be faster on hardware where such aggregation is slow.

References

  1. J. Zhu, X. Chen, K. He, Y. LeCun, and Z. Liu, "Transformers without Normalization," CVPR, 2025.
  2. J. L. Ba, J. R. Kiros, and G. E. Hinton, "Layer Normalization," arXiv, 2016.
  3. B. Zhang and R. Sennrich, "Root Mean Square Layer Normalization," NeurIPS, 2019.
  4. DyT project page (code released by the paper's authors)