nGPT: Normalized Transformer with Representation Learning on the Hypersphere

## Abstract

Abstract We propose a novel neural network architecture, the normalized Transformer (nGPT) with representation learning on the hypersphere. In nGPT, all vectors forming the embeddings, MLP, attention matrices and hidden states are unit norm normalized. The input stream of tokens travels on the surface of a hypersphere, with each layer contributing a displacement towards the target output predictions. These displacements are defined by the MLP and attention blocks, whose vector components also reside on the same hypersphere. Experiments show that nGPT learns much faster, reducing the number of training steps required to achieve the same accuracy by a factor of 4 to 20, depending on the sequence length.

## 1 Introduction

The Transformer architecture (Vaswani et al., ) is the foundation for most of modern language models. An enormous number of modifications to this architecture have been proposed to improve training stability, inference costs, context length, robustness, etc. It has been noted that the application of various normalization techniques is beneficial (Salimans & Kingma, ), leading to experiments with adding normalization layers such as LayerNorm and RMSNorm in nearly every possible position within the network (Xiong et al., ). Another approach to the model normalization is through controlling the norm of weights using weight decay (Loshchilov & Hutter, ). Recent studies (Andriushchenko et al., ) suggest reevaluating the role of weight decay and taking a closer look at rotations rather than focusing solely on vector norms (Kodryan et al., ; Kosson et al., ). Franke et al. () suggested to enforce an upper bound on $L_{2}$ norm of parameter groups. There is growing evidence that representation learning on the hypersphere is associated with more stable training, greater embedding space separability, and better performance on downstream tasks (Wang & Isola, ). Recent studies also suggest that transformers implicitly perform gradient descent as meta-optimizers (Von Oswald et al., ; Dai et al., ).

We propose to unify various findings and observations made in the field under a new perspective of the normalized Transformer. Our key contributions are as follows:

Optimization of network parameters on the hypersphere We propose to normalize all vectors forming the embedding dimensions of network matrices to lie on a unit norm hypersphere. This allows us to view matrix-vector multiplications as dot products representing cosine similarities bounded in [-1,1]. The normalization renders weight decay unnecessary.

Normalized Transformer as a variable-metric optimizer on the hypersphere The normalized Transformer itself performs a multi-step optimization (two steps per layer) on a hypersphere, where each step of the attention and MLP updates is controlled by eigen learning rates—the diagonal elements of a learnable variable-metric matrix. For each token $t_{i}$ in the input sequence, the optimization path of the normalized Transformer begins at a point on the hypersphere corresponding to its input embedding vector and moves to a point on the hypersphere that best predicts the embedding vector of the next token $t_{i+1}$.

Faster convergence We demonstrate that the normalized Transformer reduces the number of training steps required to achieve the same accuracy by a factor of 4 to 20.

**Table 1: Transformer vs. Normalized Transformer.**
| Transformer | Normalized Transformer |
| --- | --- |
| ${\bm{h}}_{\text{A}}\leftarrow\text{ATTN}(\text{RMSNorm}({\bm{h}}))$ | ${\bm{h}}_{\text{A}}\leftarrow\text{Norm}(\text{ATTN}({\bm{h}}))$ |
| ${\bm{h}}\leftarrow{\bm{h}}+{\bm{h}}_{\text{A}}$ | ${\bm{h}}\leftarrow\text{Norm}({\bm{h}}+\bm{\alpha}_{\text{A}}({\bm{h}}_{\text{A}}-{\bm{h}}))$ |
| ${\bm{h}}_{\text{M}}\leftarrow\text{MLP}(\text{RMSNorm}({\bm{h}}))$ | ${\bm{h}}_{\text{M}}\leftarrow\text{Norm}(\text{MLP}({\bm{h}}))$ |
| ${\bm{h}}\leftarrow{\bm{h}}+{\bm{h}}_{\text{M}}$ | ${\bm{h}}\leftarrow\text{Norm}({\bm{h}}+\bm{\alpha}_{\text{M}}({\bm{h}}_{\text{M}}-{\bm{h}}))$ |
| Final: ${\bm{h}}\leftarrow\text{RMSNorm}({\bm{h}})$ |  |
| All parameters of matrices and embeddings are unconstrained. | After each batch pass, all matrices and embeddings are normalized along their embedding dimension. The hidden state updates are controlled by learnable vectors of eigen learning rates $\bm{\alpha}_{\text{A}}$ and $\bm{\alpha}_{\text{M}}$. |

## 2 Evolution of the Transformer: From GPT to nGPT

This section outlines the baseline Transformer and the modifications necessary to derive its normalized version. We illustrate these changes for Transformer decoder with self-attention only. The extension to encoder-decoder and cross-attention is straightforward. A summary of these changes is given in Table 1, with details in Section 2.6.

### 2.1 Token Embeddings and Output Logits

The decoder-only Transformer is
trained to predict
token $t_{i}$ using previous tokens
input sequence ${\bm{x}}=(t_{1},t_{2},\dots,t_{i-1})$.
For each input token $t_{i}$, we retrieve its corresponding embedding in $\mathbb{R}^{d_{\text{model}}}$ from a learnable embedding matrix ${\bm{E}}_{\text{input}}\in\mathbb{R}^{V\times d_{\text{model}}}$ with vocabulary of size $V$. Similarly, the target output sequence ${\bm{y}}$ is represented using a learnable embedding matrix ${\bm{E}}_{\text{output}}\in\mathbb{R}^{V\times d_{\text{model}}}$. Notably, since both ${\bm{E}}_{\text{input}}$ and ${\bm{E}}_{\text{output}}$ are learnable (unless they are tied to be equivalent), any token $t_{i}$ can have different embeddings in the input and output sequences.
To measure token similarity during model training, the dot product between the corresponding embedding vectors is used. However, the norms of embedding vectors in the original Transformer are unconstrained, which can lead to inaccurate similarity estimation.
To improve the accuracy of similarity estimation, we propose to normalize the embedding vectors stored in ${\bm{E}}_{\text{input}}$ and ${\bm{E}}_{\text{output}}$ after each step of the training algorithm.

The next token prediction
is enforced by causal masking (see Section 2.3) to ensure that no future tokens are considered. This allows the model to compute the prediction error for all $T$ tokens in parallel during training, while preserving the autoregressive nature of the task.
After the Transformer processes the sequence $({\bm{x}}_{1},\dots,{\bm{x}}_{i-1})$, it produces an output vector ${\bm{h}}_{i}\in\mathbb{R}^{d_{\text{model}}}$ for each $i$-th position in the predicted sequence. The logits ${\bm{z}}_{i}\in\mathbb{R}^{V}$, representing the unnormalized probabilities for each token in the vocabulary, are computed using the output embedding matrix ${\bm{E}}_{\text{output}}$:

$$ ${\bm{z}}_{i}={\bm{E}}_{\text{output}}{\bm{h}}_{i}$ (1) $$

The logits ${\bm{z}}_{i}$ are passed through a softmax function to convert them into probabilities:

$$ $P(y_{i}|{\bm{x}}_{1},\dots,{\bm{x}}_{i-1})=\frac{\exp(z_{i,y_{i}})}{\sum_{v=1}^{V}\exp(z_{i,v})}$ (2) $$

Here, $z_{i,y_{i}}$ is the logit corresponding to the correct token $y_{i}$, and the denominator normalizes the logits into a probability distribution over the vocabulary. During inference, the prediction $\hat{{\bm{y}}}_{i}$ is obtained by selecting the token with the highest probability.
Since all nGPT embeddings are normalized, the logits ${\bm{z}}\in\mathbb{R}^{V}$ in equation 1 represent dot products bounded in the range $[-1,1]$. This limits the confidence (temperature) of the probability distribution generated by the softmax in equation 2.
To adjust this during training, we introduce a trainable scaling parameter ${\bm{s}}_{z}\in\mathbb{R}^{V}$ that scales the logits element-wise:

$$ $\displaystyle{\bm{z}}\leftarrow{\bm{z}}{\bm{s}}_{z}$ (3) $$

### 2.2 Layers and Blocks

#### 2.2.1 Baseline Transformer

$L$ layers of transformations are applied to the hidden state ${\bm{h}}$, consisting of alternating the self-attention (ATTN) and multi-layer perceptron (MLP) blocks:

$$ $\displaystyle{\bm{h}}$ $\displaystyle\leftarrow{\bm{h}}+\text{ATTN}(\text{RMSNorm}({\bm{h}}))$ (4) $\displaystyle{\bm{h}}$ $\displaystyle\leftarrow{\bm{h}}+\text{MLP}(\text{RMSNorm}({\bm{h}})),$ (5) $$

where RMSNorm(${\bm{h}}$) is one of several possible normalizations. It is used first to normalize each embedding to a norm of $\sqrt{d_{\text{model}}}$, then scales each dimension by a learnable vector of $d_{\text{model}}$ factors, typically initialized to 1.
Since the transformation block outputs are added to ${\bm{h}}$, the token embedding norms can vary significantly. To address this, normalization is also applied after the final layer.

#### 2.2.2 Normalized Transformer

For any points ${\bm{a}}$ and ${\bm{b}}$ on the surface of a hypersphere in $\mathbb{R}^{d_{\text{model}}}$, SLERP (Spherical Linear Interpolation) by Shoemake () computes an interpolation along the geodesic (shortest path):

$$ $\displaystyle\text{SLERP}({\bm{a}},{\bm{b}};\alpha)=\frac{\sin((1-\alpha)\theta)}{\sin(\theta)}{\bm{a}}+\frac{\sin(\alpha\theta)}{\sin(\theta)}{\bm{b}}$ (6) $$

where $\theta=\arccos({\bm{a}}\cdot{\bm{b}})$ is the angle between the points ${\bm{a}}$ and ${\bm{b}}$, and $\alpha\in[0,1]$ is the interpolation parameter, with $\alpha=0$ returning ${\bm{a}}$ and $\alpha=1$ returning ${\bm{b}}$. Our experiments suggest that SLERP can be approximated by simple linear interpolation (LERP):

$$ $\displaystyle\text{LERP}({\bm{a}},{\bm{b}};w)=(1-\alpha){\bm{a}}+\alpha{\bm{b}}$ (7) $$

Let us rewrite this equation as an update equation in nGPT:

$$ $\displaystyle{\bm{a}}\leftarrow{\bm{a}}+{\alpha}({\bm{b}}-{\bm{a}})$ (8) $$

where ${\bm{a}}$ is ${\bm{h}}$, and, ${\bm{b}}$ is the point suggested by the attention or MLP block. Then, for the gradient ${\bm{g}}={\bm{a}}-{\bm{b}}$, a more general form involving a variable matrix ${\bm{B}}\in\mathbb{R}^{d_{\text{model}}\times d_{\text{model}}}$ becomes:

$$ $\displaystyle{\bm{a}}\leftarrow{\bm{a}}-\bm{\alpha}{\bm{B}}{\bm{g}}$ (9) $$

In quasi-Newton methods, ${\bm{B}}$ approximates the inverse Hessian matrix ${\bm{H}}^{-1}$.When ${\bm{B}}$ is diagonal with non-negative elements, $\alpha{\bm{B}}$ becomes a vector $\bm{\alpha}\in\mathbb{R}_{\geq 0}^{d_{\text{model}}}$
whose elements correspond to the diagonal of ${\bm{B}}$ times the learning rate $\alpha$. We denote $\bm{\alpha}$ as eigen learning rates (from the German word eigen, meaning ”own,” referring to the internal structure of the Transformer). We provide some notes in Appendix A.2.
Following equation 8, the update equations for the attention and MLP blocks are as follows:

$$ $\displaystyle{\bm{h}}$ $\displaystyle\leftarrow\text{Norm}(\,{\bm{h}}+\bm{\alpha_{\text{A}}}({\bm{h}}_{\text{A}}-{\bm{h}})\,)$ (10) $\displaystyle{\bm{h}}$ $\displaystyle\leftarrow\text{Norm}(\,{\bm{h}}+\bm{\alpha_{\text{M}}}({\bm{h}}_{\text{M}}-{\bm{h}})\,),$ (11) $$

where $\bm{\alpha_{\text{A}}}\in\mathbb{R}_{\geq 0}^{d_{\text{model}}}$ and $\bm{\alpha_{\text{M}}}\in\mathbb{R}_{\geq 0}^{d_{\text{model}}}$ are learnable parameters applied to the normalized outputs of the attention and MLP blocks ${\bm{h}}_{\text{A}}=\text{Norm}(\text{ATTN}({\bm{h}}))$ and ${\bm{h}}_{\text{M}}=\text{Norm}(\text{MLP}({\bm{h}}))$, respectively. The function $\text{Norm}({\bm{x}})$ normalizes any vector ${\bm{x}}$ to have unit norm, and, unlike RMSNorm or LayerNorm, does not introduce any element-wise scaling factors. The normalization can be viewed as the retraction step in Riemannian optimization, mapping the updated solution back to the manifold. Appendix A.3 discusses the extension of our update equations in the context Riemannian optimization.
In contrast to the baseline Transformer, no additional normalization is required after the final layer, as the embeddings are already normalized by the proposed scheme.

### 2.3 Self-Attention Block

#### 2.3.1 Baseline Transformer

The attention mechanism is a key component of the Transformer. It allows each token to attend to every other token in the sequence, enabling the model to capture long-range dependencies. The block typically starts with a normalization of the input hidden state ${\bm{h}}$ using RMSNorm to deal with fluctuating norms of embeddings. Then, the normalized ${\bm{h}}$ is projected into three separate vectors - the query ${\bm{q}}$, the key ${\bm{k}}$, and the value ${\bm{v}}$:

$$ $\displaystyle{\bm{q}}\leftarrow{\bm{h}}{\bm{W}}_{q},{\bm{k}}\leftarrow{\bm{h}}{\bm{W}}_{k},{\bm{v}}\leftarrow{\bm{h}}{\bm{W}}_{v}$ (12) $$

where ${\bm{W}}_{q},{\bm{W}}_{k},{\bm{W}}_{v}\in\mathbb{R}^{d_{\text{model}}\times d_{k}}$ are learned projection matrices, and $d_{k}$ is the dimensionality of the query/key vectors. To incorporate positional information, we apply Rotary Position Embeddings (RoPE) by Su et al. () to both the query and key vectors. The attention scores are computed by taking the dot product of the query and key vectors, scaling them by $\frac{1}{\sqrt{d_{k}}}$, then applying a softmax function to obtain attention weights, and finally computing a weighted sum of the value vectors ${\bm{v}}$:

$$ $\displaystyle\text{Attention}({\bm{q}},{\bm{k}},{\bm{v}})\leftarrow\text{softmax}\left(\frac{{\bm{q}}{\bm{k}}^{\top}}{\sqrt{d_{k}}}+{\bm{M}}\right){\bm{v}},$ (13) $$

where ${\bm{M}}$ is a matrix that prevents attending to future tokens by setting the corresponding entries to $-\infty$. Specifically, $\text{M}_{i,j}=0$ if $j\leq i$ and $\text{M}_{i,j}=-\infty$ if $j>i$.

In practice, $n_{\text{heads}}$ attention heads are used where for each $i$-th head, separate linear projections ${\bm{W}}_{q}^{i},{\bm{W}}_{k}^{i},{\bm{W}}_{v}^{i}$ are applied, and the attention mechanism is computed independently for each head:

$$ $\displaystyle{\bm{h}}_{\text{A}}\leftarrow\text{Concat}(\text{head}_{1},\dots,\text{head}_{n_{\text{heads}}}){\bm{W}}_{o}$ (14) $$

where $\text{head}_{i}=\text{Attention}({\bm{q}}^{i},{\bm{k}}^{i},{\bm{v}}^{i})$ and ${\bm{W}}_{O}\in\mathbb{R}^{n_{\text{heads}}\times d_{k}\times d_{\text{model}}}$ is a learned projection matrix, where $d_{k}$ is typically set to $d_{\text{model}}/n_{\text{heads}}$.

#### 2.3.2 Normalized Transformer

The matrix-vector multiplication of ${\bm{W}}_{q}\in\mathbb{R}^{d_{\text{model}}\times d_{k}}$ of the $i$-th head(^1^11All the following equations are defined per head but we omit $i$-th head index for the sake of readability.) and ${\bm{h}}\in\mathbb{R}^{d_{\text{model}}}$ can be viewed as a dot product between the columns of ${\bm{W}}_{q}$ and ${\bm{h}}$. In the baseline Transformer, all matrices, including ${\bm{W}}_{q}$ are unconstrained, leading to unbounded values in ${\bm{q}}$. We propose to normalize ${\bm{W}}_{q}$, ${\bm{W}}_{k}$, ${\bm{W}}_{v}$ and ${\bm{W}}_{o}$ along their embedding dimension so that the computed dot products with ${\bm{h}}$ can be interpreted as cosine similarity between unit norm vectors bounded in $[-1,1]$. Thus, all attention matrices can be viewed as collections of normalized embedding vectors to be compared with.

While each element of ${\bm{q}}$ and ${\bm{k}}$ is now bounded, the norms of these two vectors can still vary. Moreover, injection of positional information by RoPE further distorts ${\bm{q}}$ and ${\bm{k}}$. We propose to additionally normalize ${\bm{q}}$ and ${\bm{k}}$, ensuring that the dot product of every query and key is under control:

$$ $\displaystyle{\bm{q}}$ $\displaystyle\leftarrow\text{Norm}({\bm{q}}){\bm{s}}_{qk}$ (15) $\displaystyle{\bm{k}}$ $\displaystyle\leftarrow\text{Norm}({\bm{k}}){\bm{s}}_{qk},$ (16) $$

where ${\bm{s}}_{qk}\in\mathbb{R}^{d_{\text{k}}}$ is a vector(^2^22There is no need for separate scaling factors for ${\bm{q}}$ and ${\bm{k}}$ as the scaling would simply be applied element-wise when computing the dot product between ${\bm{q}}$ and ${\bm{k}}$.) of trainable scaling factors for the $i$-th head.

In the original Transformer, the softmax scaling factor $1/\sqrt{d_{k}}$ in equation 13 is introduced to account for the expected variance of $d_{k}$ in the dot product of non-normalized query and key vectors. In the normalized Transformer, the expected variance of the dot product between normalized query and key vectors is $1/d_{k}$. To restore a variance of 1, the softmax scaling factor should instead be $\sqrt{d_{k}}$. If the softmax scaling factor is set to 1, this is equivalent to initializing the scaling factors ${\bm{s}}_{qk}$ at $d^{1/4}_{k}$.

### 2.4 MLP Block

#### 2.4.1 Baseline Transformer

The input hidden state ${\bm{h}}$ of the MLP block is first normalized using RMSNorm and then passed through two separate linear projections, producing two intermediate vectors (we omit bias terms):

$$ $\displaystyle{\bm{u}}\leftarrow{\bm{h}}{\bm{W}}_{u},\quad\bm{\nu}\leftarrow{\bm{h}}{\bm{W}}_{\nu}$ (17) $$

where ${\bm{W}}_{u},{\bm{W}}_{\nu}\in\mathbb{R}^{d_{\text{model}}\times d_{\text{MLP}}}$ are the learned weight matrices. The intermediate vectors ${\bm{u}}$ and $\bm{\nu}$ are combined using a gated activation function called SwiGLU defined by Shazeer () as:

$$ $\displaystyle\text{SwiGLU}({\bm{u}},\bm{\nu})\leftarrow{\bm{u}}\cdot\text{SiLU}(\bm{\nu})$ (18) $$

where $\text{SiLU}(\bm{\nu})=\bm{\nu}\cdot\sigma(\bm{\nu})$, and $\sigma(\bm{\nu})$ is the sigmoid function. The result of the gated activation is then passed through a final linear transformation ${\bm{W}}_{o\text{MLP}}\in\mathbb{R}^{d_{\text{MLP}}\times d_{\text{model}}}$:

$$ $\displaystyle{\bm{h}}_{\text{M}}\leftarrow\text{SwiGLU}({\bm{u}},\bm{\nu}){\bm{W}}_{o\text{MLP}}$ (19) $$

#### 2.4.2 Normalized Transformer

We propose to normalize matrices ${\bm{W}}_{u}$ and ${\bm{W}}_{\nu}$ along the embedding dimension so that the ${\bm{u}}$ and $\bm{\nu}$ vectors represent the cosine similarity between ${\bm{h}}$ and vectors stored in ${\bm{W}}_{u}$ and ${\bm{W}}_{\nu}$, respectively.
To control their impact, we introduce scaling factors ${\bm{s}}_{u}\in\mathbb{R}^{d_{\text{MLP}}}$ and ${\bm{s}}_{\nu}\in\mathbb{R}^{d_{\text{MLP}}}$:

$$ $\displaystyle{\bm{u}}$ $\displaystyle\leftarrow{\bm{u}}{\bm{s}}_{u},$ (20) $\displaystyle\bm{\nu}$ $\displaystyle\leftarrow\bm{\nu}{\bm{s}}_{\nu}\sqrt{d_{model}},$ (21) $$

where the rescaling of $\bm{\nu}$ by $\sqrt{d_{model}}$ is needed to benefit from the non-linearity of SiLU (see the Appendix A.1). The output of the MLP block is invariant to rescaling of ${\bm{u}}$ by a scalar.

### 2.5 Effective learning rates in Adam

The core of the Adam algorithm by Kingma () is as follows:

$$ $\displaystyle{\bm{m}}$ $\displaystyle\leftarrow\beta_{1}{\bm{m}}+(1-\beta_{1}){\bm{g}}$ $\displaystyle{\bm{v}}$ $\displaystyle\leftarrow\beta_{2}{\bm{v}}+(1-\beta_{2}){\bm{g}}^{2}$ $\displaystyle\bm{\theta}$ $\displaystyle\leftarrow\bm{\theta}-\alpha{\bm{m}}/(\sqrt{{\bm{v}}}+\epsilon),$ (22) $$

where $\bm{\theta}$ is the parameter vector, ${\bm{g}}$ is the batch gradient, ${\bm{m}}$ is the momentum, ${\bm{v}}$ is the estimate of the per-element gradient amplitudes, $\alpha$ is the scheduled learning rate, $\epsilon$ is a small constant, and $\beta_{1}<\beta_{2}$ are momentum factors close to 1. We cite the text of the original Adam paper using our notation: In more common scenarios, we will have that $\frac{m}{\sqrt{v}}\approx\pm 1$ since $\left|{\mathbb{E}[g]}/{\sqrt{\mathbb{E}[g^{2}]}}\right|\leq 1$. The effective magnitude of the steps taken in parameter space at each timestep is approximately bounded by the stepsize setting $\alpha$. Thus, $\alpha$ controls the effective step-size in the search space, while the ratio $\frac{m}{\sqrt{v}}$ can temporarily increase (respectively, decrease) the step-size if the current amplitude of per-parameter momentum is greater (respectively, smaller) than its estimated value over longer time horizon.
Consider an example where $\theta_{i}=0.01$ and the global learning rate is 0.001. If the gradient amplitude remains stable (i.e., $\frac{m_{i}}{\sqrt{v_{i}}}\approx 1$), it would take $\frac{0.02-0.01}{0.001}=10$ steps to double $\theta_{i}$. However, if $\theta_{i}=1.0$, it would take $\frac{2.0-1.0}{0.001}=1000$ steps to double. Even if the gradient’s amplitude is larger in the second case, the number of steps would only decrease if ${m_{i}}>\sqrt{v}$.

In nGPT, for any trainable vector of scaling parameters such as ${\bm{s}}_{a}$, we use two scalars ${\bm{s}}_{a,init}$ and ${\bm{s}}_{a,scale}$. When initializing ${\bm{s}}_{a}$ as a trainable parameter, its initial value is set to ${\bm{s}}_{a,scale}$. However, during the forward pass we restore its actual value by multiplying $s_{a,init}/s_{a,scale}$. This allows us to control the effective learning rate for ${\bm{s}}_{a}$ by adjusting ${\bm{s}}_{a,scale}$, while keeping the global learning rate unchanged. For example, setting ${\bm{s}}_{a,init}=1$ and ${\bm{s}}_{a,scale}=1/\sqrt{d_{model}}$ ensures that this parameter is updated with the same effective learning rate as other normalized parameters in the network.

### 2.6 Summary of modifications

The recipe to convert the baseline Transformer into the normalized Transformer is as follows:

- 1.
Remove all normalization layers such as RMSNorm or LayerNorm.
- 2.
After each training step, normalize all matrices (${\bm{E}}_{\text{input}}$, ${\bm{E}}_{\text{output}}$, ${\bm{W}}_{q}$, ${\bm{W}}_{k}$, ${\bm{W}}_{v}$, ${\bm{W}}_{o}$, ${\bm{W}}_{u}$, ${\bm{W}}_{\nu}$ and ${\bm{W}}_{o\text{MLP}}$) along their embedding dimension.
- 3.
Replace the update equations 4 and 5 by equations 10 and 11, where $\bm{\alpha}_{\text{A}}$ (and also $\bm{\alpha}_{\text{M}}$) is treated with $\bm{\alpha}_{\text{A},init}=0.05$ (in order of $1/n_{layers}$) and $\bm{\alpha}_{\text{A},scale}=1/\sqrt{d_{model}}$.
- 4.
Change the softmax scaling factor in attention from $1/\sqrt{d_{k}}$ to $\sqrt{d_{k}}$. Implement the rescaling and normalization (normalization here is optional) of ${\bm{q}}$ and ${\bm{k}}$ as in equations 15 and 16, where ${\bm{s}}_{qk}$ is treated with ${\bm{s}}_{qk,init}=1$ and ${\bm{s}}_{qk,scale}=1/\sqrt{d_{model}}$.
- 5.
Implement the rescaling of the intermediate state of the MLP block using equations 20 and 21, where ${\bm{s}}_{u}$ (and also ${\bm{s}}_{\nu}$) is treated with ${\bm{s}}_{u,init}=1$ and ${\bm{s}}_{u,scale}=1$
- 6.
Implement the rescaling of logits using equation 3, where ${\bm{s}}_{z}$ is treated with ${\bm{s}}_{z,init}=1$ and ${\bm{s}}_{z,scale}=1/\sqrt{d_{model}}$.
- 7.
Remove weight decay and learning rate warmup.

## 3 Experiments

We train both the baseline Transformer (GPT) and the normalized Transformer (nGPT) on the OpenWebText dataset (Gokaslan & Cohen, ) and evaluate them on a set of standard downstream tasks. We experiment with models containing 0.5B and 1B parameters, including the embeddings. For both GPT and nGPT, we report results using the best initial learning rate settings (see Appendix A.6). A detailed description of the setup and hyperparameters is in Appendix A.5.

### 3.1 Acceleration of training

Figure: Figure 1: Validation loss during training of 1B GPT and nGPT with 4k context length.
Refer to caption: x1.png

Figure 1 presents the validation loss during the training of GPT and nGPT models with 1 billion parameters and a sample length of 4k tokens. After 20k iterations, nGPT achieves the same validation loss that GPT reaches only after 200k iterations (approximately 400 billion tokens), demonstrating a 10x speedup in terms of iterations and tokens used.(^3^33While the time per step of nGPT is higher (80% - for 4k, and 60% - for 8k context respectively), it can be reduced after code optimization. Also the overhead is less significant for larger networks (see Appendix A.4).)

Figure: Figure 2: Final validation loss (y-axis) for training runs with different computation budgets in tokens (x-axis). The training of 0.5B and 1B nGPT models is about 4x, 10x and 20x faster (in terms of tokens) on 1k, 4k and 8k context lengths, respectively.
Refer to caption: x2.png

Figure 2 illustrates how the performance gap between nGPT and GPT scales across three axes: total token budget, context length, and network size. Training the 0.5B and 1B nGPT models is approximately 4x, 10x, and 20x faster at context lengths of 1k, 4k, and 8k tokens, respectively.

Figure 3 shows a similar pattern across downstream tasks, confirming that the acceleration is not only reflected in perplexity but also in task performance. Figures 8 and 9 in the Appendix provide results for 1k and 8k context lengths. We observe some saturation for the longest runs of nGPT, suggesting that the model capacity is nearly reached for this number of trainable model parameters.

Figure: Figure 3: Models trained with 4k context length. Final performance (y-axis) on a set of downstream tasks and their average value (Bottom-Right) for different computation budgets in tokens (x-axis).
Refer to caption: x3.png

Figure: Figure 4: Left: Distribution of norms of vectors from input (Top line) and output (Bottom line) embedding matrices. Middle: Distribution of eigenvalues divided by its median value. Right: Pairwise distribution of dot products between embeddings. Models are trained for 100k iterations.
Refer to caption: x4.png

Figure: Figure 5: Median condition numbers for attention and MLP matrices at different layer depth (24 and 36 layers for 0.5B and 1B models, respectively). Models are trained for 100k iterations.
Refer to caption: x5.png

Figure: Figure 6: (Left): Eigen learning rates of Attention and MLP blocks. (Middle): Scaling factors applied to the intermediate states of MLP. (Right): Scaling factors applied before the QK dot product; distribution of per-vector scalings applied to logits. Models are trained for 100k iterations.
Refer to caption: x6.png

### 3.2 Inspection of network parameters

Figure 4 shows that, while nGPT maintains a fixed norm for embeddings (by design), GPT exhibits significant variation. The distribution of eigenvalues, computed from the covariance matrix of embeddings and normalized by their median, reveals that GPT’s input embeddings have a higher condition number, especially in the 1B model. The distribution of pairwise dot products between embeddings indicates that even in nGPT, embeddings are not uniformly distributed across the hypersphere (where the dot product would approach 0), but instead form clusters—possibly reflecting natural patterns in language data. Dot products in GPT tend to have higher values due to its embeddings forming a hyper-ellipsoid, as suggested by the spread of vector norms. The ill-conditioned nature of GPT’s input embeddings could lead to computational issues involving these embeddings.

Figure 5 shows the median condition numbers (across heads) for attention and MLP matrices at different layer depths—24 layers for the 0.5B model and 36 layers for the 1B model. GPT models exhibit significantly higher condition numbers in their attention matrices compared to nGPT.
A closer inspection of these matrices (the 3rd and 4th layers are in Figure 11 and Figure 12 of Appendix) suggests that they degenerate into lower-rank matrices, potentially reducing the learning capacity of these blocks. One could argue that the elevated condition numbers are influenced by the norms of the vectors in these matrices. Our post-training normalization of these matrices is depicted by the dotted lines in Figure 10 of the Appendix. While the adjusted condition numbers are reduced, they remain higher than those for nGPT, indicating potential rank deficiency. The need for such normalization highlights one of the issues that nGPT is specifically designed to address.

An important contribution of this work is the decoupling of predictions made by the Attention and MLP blocks from their impact on the hidden state ${\bm{h}}$. These contributions are controlled by the eigen learning rates $\bm{\alpha}_{\text{A}}$ and $\bm{\alpha}_{\text{M}}$. Their interpretation is straightforward: if $\bm{\alpha}_{\text{A},i}$ for an embedding dimension $i\in\mathbb{R}^{d_{\text{model}}}$ is 0.2, then the update follows $h_{i}\leftarrow(1-0.2)h_{i}+0.2h_{\text{A},i}$. Thus, they directly quantify the contribution of $h_{\text{A},i}$ into ${\bm{h}}$. Figure 6 shows the average absolute values of ${\bm{h}}_{\text{A}}$ and ${\bm{h}}_{\text{M}}$ at each layer. Notably, the network learns to take only modest steps (20%-30%) in the direction suggested by ${\bm{h}}_{\text{A}}$ and ${\bm{h}}_{\text{M}}$. The average magnitude of $\bm{\alpha}_{\text{A}}$ decreases from 0.25 in the 0.5B network (24 layers) to 0.20 in the 1B network (36 layers). Meanwhile, $\bm{\alpha}_{\text{M}}$ decreases from 0.37 to 0.32, possibly because MLP blocks have more parameters, making their suggestions more precise.

The scaling factors ${\bm{s}}_{u}$, ${\bm{s}}_{\nu}$ and ${\bm{s}}_{qk}$ remain relatively stable across layers. The value of ${\bm{s}}_{\nu}$ can be interpreted as a measure of the non-linearity of the SiLU function, which behaves like ReLU for large ${\bm{s}}_{\nu}$ and approximates a linear unit for values near 0 (see also Appendix A.1). The distribution of ${\bm{s}}_{z}$ is primarily characterized by its mean, which influences the temperature of the softmax during cross-entropy calculations. The introduced scaling factors ${\bm{s}}_{qk},{\bm{s}}_{u},{\bm{s}}_{\nu}$ and ${\bm{s}}_{z}$ seem to compensate for the removal of magnitude information when normalizing matrices and embeddings.

### 3.3 Ablation studies

Appendix A.8 summarizes numerous ablation experiments. An important finding is that having fixed (non-learnable) values for ${\bm{s}}_{qk},{\bm{s}}_{u},{\bm{s}}_{\nu}$ and a single global learnable value for ${\bm{s}}_{z}$ leads to only a slight degradation in accuracy. Therefore, our presented general case can be simplified and become easier to interpret. Appendix A.7 demonstrates that nGPT can handle longer contexts
without requiring any modifications to RoPE.

## 4 Related Work

Wang & Isola () provides a comprehensive overview of the arguments for representation learning on the hypersphere. Spherical representations are associated with more stable training in the latent space of variational autoencoders (Xu & Durrett, ) and in embeddings used for face verification (Wang et al., ). Notably, when embeddings are well clustered, they tend to be linearly separable from the rest of the embedding space (Wang & Isola, ). Mettes et al. () demonstrated that classification and regression can be unified by placing prototype embeddings uniformly on a hypersphere, allowing for separation with large margins a priori. Wang & Isola () found a strong empirical correlation between downstream task performance and both the alignment (closeness) and uniformity of embeddings on the hypersphere.

Since all embeddings in nGPT lie on the hypersphere, any update that causes the hidden state ${\bm{h}}$ to deviate from the manifold is followed by a normalization step. This normalization can be interpreted as a retraction in the context of Riemannian optimization. One might attempt to approximate nGPT’s update in GPT by applying RMSNorm both at the beginning and end of the block (Xiong et al., ). However, this approach does not guarantee a fixed norm for the hidden state, nor does it ensure that the recombination approximates SLERP or LERP.

The normalization in equations 15 and 16 closely resembles the QK normalization by Henry et al. (). In nGPT, this process can be viewed as restoring ${\bm{q}}$ and ${\bm{k}}$ of the $i$-th head to a $(d_{\text{model}}/n_{\text{heads}})$-dimensional hypersphere after the projection of ${\bm{h}}$ by ${\bm{W}}_{q}$ and ${\bm{W}}_{k}$, respectively. Since ${\bm{h}}$ and the embedding dimensions of ${\bm{W}}_{q}$ and ${\bm{W}}_{k}$ are already normalized, the norms of ${\bm{q}}$ and ${\bm{k}}$ are also comparable, making their normalization potentially unnecessary. We explored this scenario (i.e., omitting the normalization of ${\bm{q}}$ and ${\bm{k}}$) in our ablation studies (see Appendix A.8), where the results showed only a slight degradation. The performance drop was comparable to the computational time savings per step. Therefore, removing the normalization of ${\bm{q}}$ and ${\bm{k}}$ in nGPT is a viable option.

## 5 Discussion and Conclusion

This work builds on numerous key findings and observations made in the field which directly (Wang & Isola, ; Xu & Durrett, ; Wang et al., ) and indirectly (Salimans & Kingma, ; Franke et al., ; Kodryan et al., ; Kosson et al., ) support representation learning on the hypersphere. One of our main contributions is the normalization of the embedding dimensions of all matrices, ensuring they reside on the same hypersphere. Crucially, we observed that such normalization alone would constrain the inputs of non-linear units, and, thus, the scaling factors for these units should be introduced.

In line with recent studies suggesting that transformers implicitly perform gradient descent as meta-optimizers (Von Oswald et al., ; Dai et al., ), we explicitly demonstrate how this process occurs in the normalized Transformer: i) the transformation blocks provide gradient information, ii) this information is multiplied by eigen learning rates to adjust the hidden state, and iii) the commonly used normalization can be interpreted as a retraction step in Riemannian optimization, projecting the point back onto the hypersphere. We believe we are the first to decouple the eigen learning rates from the rest of the network, recognizing them as trainable parameters that can be interpreted as the diagonal elements of a variable-metric matrix. In other words, the normalized Transformer functions as a variable-metric optimizer, searching for output solutions using data-driven gradient information estimated in its attention and MLP blocks.

The spherical representation provides valuable insights into the internals of nGPT, enabling the collection and analysis of statistics about its normalized components. Most importantly, it allows for the application of mathematical techniques specifically designed for dealing with hyperspheres. We believe that the reported acceleration, by a factor from 4 to 20, is only the first step towards uncovering new algorithms and architectures that could emerge from nGPT. Future work should explore scaling nGPT to larger network sizes, real-world datasets, and a broader range of tasks.
For instance, the extension of nGPT to encoder-decoder and hybrid architectures (Dao & Gu, ; De et al., ) is straightforward.

## Appendix A Appendix

### A.1 Rescaling in the MLP block of the normalized Transformer

When computing SwiGLU using equation 18, each element $x$ of the vector ${\bm{v}}$ is an input to SiLU:

$$ $\displaystyle\text{SiLU}(x)=x\cdot\sigma(x)=x\cdot\frac{1}{1+e^{-x}},$ (23) $$

where $\sigma(x)$ is sigmoid. For $x$ with large magnitude, $\text{SiLU}(x)$ approximates $\text{ReLU}(x)$: when $x\to-\infty$, $\text{SiLU}(x)\to 0$, and when $x\to\infty$, $\text{SiLU}(x)\approx x$. The minimum of $\text{SiLU}(x_{min})\approx-0.278$ is located at $x_{min}\approx-1.278$. While the elements of ${\bm{v}}$ represent dot products of $d_{model}$-dimensional vectors and are bounded in $[-1,1]$, their expected absolute value (when they are random) is $\mathbb{E}[|\cos(\theta)|]=\frac{2}{\pi}\cdot\frac{1}{\sqrt{d_{model}}}\approx\frac{0.7979}{\sqrt{d_{model}}}$. Thus, we should rescale $x$ by ${\sqrt{d_{model}}}$, otherwise, for very small $x$, we end up with $\text{SiLU}(x)\approx x/2$. An alternative view is to note that since the variance of each of the normalized vectors (${\bm{h}}$ and a vector from ${\bm{W}}_{v}$) is ${1/d_{model}}$, the variance of 1 (suitable for the sigmoid part of SiLU) can be restored by rescaling of $x$ by ${\sqrt{d_{model}}}$. Based on these two views, we rescale ${\bm{v}}$ by $\sqrt{d_{model}}$ to benefit from the non-linearity of SiLU.

### A.2 Eigen learning rates

In the main text of the paper, we defined eigen learning rates as positive ($\bm{\alpha}\leftarrow|\bm{\alpha}|$ is used during the forward pass). However, when they are not constrained to be positive, we obtain experimental results which are the same (up to numerical difference). This surprising observation can be explained as follows. Both the attention and MLP blocks have transformation matrices at their outputs. When the search is unconstrained, it is sufficient for Adam to flip (select) the sign of the $i$-th row of the output transformation matrix ${\bm{W}}_{o}$ to change the sign of the corresponding $i$-th coordinate in ${\bm{h}}_{\text{A}}$. Thus, the transformation calculated as $\bm{\alpha_{\text{A}}}{\bm{W}}_{o}$ is the same as $\bm{\alpha^{\prime}_{\text{A}}}{\bm{W}}^{\prime}_{o}$, where
$\bm{\alpha}^{\prime}_{\text{A},i}=-\bm{\alpha}_{\text{A},i}$
and ${\bm{W}}^{\prime}_{o,(i,:)}=-{\bm{W}}_{o,(i,:)}$. In other words, when unconstrained, we can arrive at exactly the same transformation by flipping the signs in both $\bm{\alpha}$ and ${\bm{W}}_{o}$, which cancel each other. For simplicity and clearer interpretation, we suggest constraining $\bm{\alpha}$ to be positive in the main paper.

There is, however, another interesting scenario when eigen learning rate could become negative.
In quasi-Newton methods, ${\bm{B}}$ approximates the inverse Hessian matrix ${\bm{H}}^{-1}$ whose diagonal elements are positive values if the function is locally convex which is the assumption of the Newton method (${\bm{H}}$ needs to be positive definite). However, the diagonal of ${\bm{H}}^{-1}$ can have negative values if the objective function is non-convex and has saddle points. While quasi-Newton methods like BFGS aim to ensure (e.g., via regularization) that ${\bm{B}}$ is positive-definite even on non-convex problem, some Riemannian optimization methods can exploit negative curvature of ${\bm{H}}^{-1}$ (Agarwal et al., ). When the diagonal of ${\bm{B}}$ is unconstrained, we perform a variable-metric step, acknowledging that the function may be non-convex locally. We did not mention this in the main paper because, as noted earlier, the results with both constrained and unconstrained $\bm{\alpha}$ are essentially the same.

### A.3 Riemannian optimization

If ${\bm{h}}-{\bm{h}}_{\text{A}}$ is viewed as the gradient ${\bm{g}}$ in the Euclidean space, then, aligning with the requirements of Riemannian optimization, the projection of ${\bm{g}}$ onto the tangent space of the hypersphere is

$$ $\displaystyle{\bm{g}}_{\text{proj}}$ $\displaystyle\leftarrow{\bm{h}}({\bm{h}}^{T}{\bm{h}}_{\text{A}})-{\bm{h}}_{\text{A}}$ (24) $$

The projection is equivalent to ${\bm{g}}$ when the dot product ${\bm{h}}^{T}{\bm{h}}_{\text{A}}$ is 1. Depending on the alignment between ${\bm{h}}$ and ${\bm{h}}_{\text{A}}$, the projected gradient varies between ${\bm{h}}-{\bm{h}}_{\text{A}}$ (when the vectors are aligned) and $-{\bm{h}}_{\text{A}}$ (when the vectors are orthogonal). The Riemannian variable-metric update then reads as:

$$ $\displaystyle{\bm{h}}$ $\displaystyle\leftarrow\text{Norm}(\,{\bm{h}}-{\bm{B}}_{\text{A}}({\bm{h}}({\bm{h}}^{T}{\bm{h}}_{\text{A}})-{\bm{h}}_{\text{A}})\,)$ (25) $\displaystyle{\bm{h}}$ $\displaystyle\leftarrow\text{Norm}(\,{\bm{h}}-{\bm{B}}_{\text{M}}({\bm{h}}({\bm{h}}^{T}{\bm{h}}_{\text{M}})-{\bm{h}}_{\text{M}})\,)$ (26) $$

The normalization by Norm can be viewed as the retraction step in Riemannian optimization, mapping the updated solution back to the manifold.

Our experimental results suggest that the impact of ${\bm{h}}^{T}{\bm{h}}_{\text{M}}$ is negligible. Therefore, all experiments in the paper are based on equations 10 and 11.

### A.4 Time cost per step

The time cost per step for nGPT is approximately 80% higher with 4k context length, and 60% higher with 8k context length.
This overhead is not only due to nGPT having 6 normalization steps (2 of them are applied for ${\bm{q}}$ and ${\bm{k}}$) per layer instead of 2, but also because nGPT’s normalizations are not yet fully optimized, unlike GPT, where normalization layers are fused with other operations. Training on larger networks is expected to further reduce this performance gap, as the number of layers (and thus the number of normalizations) increases only modestly with the number of network parameters.
Appendix A.8 shows that we can remove the normalization of ${\bm{q}}$ and ${\bm{k}}$ with a minor negative impact on results.

### A.5 Experimental setup

In all experiments, we use OpenWebText (Gokaslan & Cohen, ) dataset which, according to experiments of Karpathy (), represents a good approximation of the OpenAI’s internal dataset used to train GPT-2 models. We are well aware that this dataset is not of the highest quality. However, we believe that it is suitable for academic research, and, should improve the comparability of our findings with other research papers.

We trained our models using 64 A100 GPUs distributed across 8 nodes (8 GPUs per node). Global batch size is 512. We use the LLaMA-2 tokenizer with 32k tokens. We use the same setup for the 0.5B and 1.0B parameter models.

**Table 2: Model Parameters for GPT and nGPT**
| Model Parameter | 0.5B Models | 1.0B Models |
| --- | --- | --- |
| Number of Layers ($n_{\text{layers}}$) | 24 | 36 |
| Model Dimension ($d_{\text{model}}$) | 1024 | 1280 |
| Number of Attention Heads ($n_{\text{heads}}$) | 16 | 20 |
| Key Dimension ($d_{k}$) | $d_{\text{model}}/n_{\text{heads}}$ | $d_{\text{model}}/n_{\text{heads}}$ |
| MLP Dimension ($d_{\text{MLP}}$) | $4d_{\text{model}}$ | $4d_{\text{model}}$ |
| Parameters in GPT | 468.2M | 1025.7M |
| Parameters in nGPT | 468.4M | 1026.1M |

**Table 3: Optimization Parameters for GPT and nGPT**
| Optimization Parameter | GPT | nGPT |
| --- | --- | --- |
| Optimizer | AdamW | Adam (AdamW with weight decay 0.0) |
| Weight Decay | 0.1 | 0.0 |
| Number of Warmup Steps | 2000 | 0 |
| Learning Rate Schedule | Cosine Annealing | Cosine Annealing |
| Initial Learning Rate | problem-specific | problem-specific |
| Final Learning Rate | 0 | 0 |

All matrix parameters are initialized by sampling from a zero-mean normal distribution with a standard deviation of $0.02$ for GPT and $1/\sqrt{d_{\text{model}}}$ for nGPT. The standard deviation for the output matrices was scaled by a factor of $\sqrt{2\times n_{\text{layer}}}$, as suggested by Radford et al. (). The initialization of matrix parameters is not important for nGPT because they are normalized afterwards. The base of RoPE is 10000. The initialization of the additional parameters introduced in nGPT is described in Section 2.6.

### A.6 Selection of the initial learning

The initial learning rate is the only hyperparameter we tune for both GPT and nGPT. Figure 7 demonstrates our trials to select the most suitable initial learning rate for GPT and nGPT. Our first experiments started with the 0.5B model and 1k context length. After observing the general trend of these curves, we reduced the number of experiments and followed the trends to minimize the total compute used. Apart from estimating the optimal settings for the initial learning rate, our general observation is that the optimal learning rates for GPT and nGPT tend to be similar for the same values of the validation loss. Longer runs are usually associated with the possibility of achieving lower values of the validation loss, and this typically requires lower initial learning rates.

One artifact we observed is the increasing sensitivity of the 1B nGPT model on 8k context length. We found that the smoothness of the hyperparameter curves can be restored (see the dotted lines with squares) by increasing $\bm{\alpha}_{\text{A,init}}$ and $\bm{\alpha}_{\text{M,init}}$ from their default value of
$1/\sqrt{d_{model}}$ to 0.1. This change decreases the effective learning rate of Adam on these variables by a factor of $(1/\sqrt{d_{model}})/0.1\approx 3$. As a result, the eigen learning rates are learned by Adam at a slower rate.

Figure: Figure 7: Final validation loss values for different initial learning rates for the 0.5B models (Top) and 1B models (Bottom). GPT is denoted by solid lines with circles, while nGPT is represented by the dotted lines with stars. A specific case with a different setup, denoted by the dotted lines with squares (Bottom Right), is discussed in the text.
Refer to caption: x7.png

Figure: Figure 8: Models trained with 1k context length. Final performance (y-axis) on a set of downstream tasks and their average value (Bottom-Right) for different computation budgets in tokens (x-axis).
Refer to caption: x8.png

Figure: Figure 9: Models trained with 8k context length. Final performance (y-axis) on a set of downstream tasks and their average value (Bottom-Right) for different computation budgets in tokens (x-axis).
Refer to caption: x9.png

Figure: Figure 10: Median condition numbers measured for attention and MLP matrices at different layer depth (24 and 36 layers for 0.5B and 1B networks, respectively). The dotted lines are for the case when GPT’s matrices are renormalized after training. Models are trained for 100k iterations.
Refer to caption: x10.png

Figure: Figure 11: Left: Distribution of the norms of vectors forming the complete attention matrices (not per head). Right: Distribution of singular values for all heads. The results are shown for the 3rd layer.
Refer to caption: x11.png

Figure: Figure 12: Left: Distribution of the norms of vectors forming the complete attention matrices (not per head). Right: Distribution of singular values for all heads. The results are shown for the 4th layer.
Refer to caption: x12.png

### A.7 Length Extrapolation Ability

We investigate the length extrapolation ability of nGPT by evaluating its perplexity on the PG19 dataset, as shown in Figure 13. In standard GPTs, perplexity tends to increase dramatically when tested on sequences longer than pre-training length. In contrast, nGPT maintains a stable perplexity range even at extrapolated lengths. This result demonstrates that nGPT can handle longer contexts without requiring any modifications to RoPE, providing a clear advantage over standard GPTs in terms of length extrapolation.

Figure: Figure 13: PG19 perplexity from 1K to 32K.
Refer to caption: x13.png

### A.8 Ablation studies

We perform a series of ablations in nGPT, focusing on the selection of scaling factors ${\bm{s}}_{qk}$, ${\bm{s}}_{u}$ (${\bm{s}}_{v}$), ${\bm{s}}_{z}$, as well as evaluating the necessity of normalization. For the scaling factors, we first examine the impact of different initializations of these parameters. Additionally, we explore whether these factors can be simplified to a learnable scalar or a fixed value. For normalization, we analyze whether the removal of QK-normalization is a feasible alternative. To ensure a fair comparison, all our ablation models have size 0.5B and context length 1k and are trained with learning rate $1\times 10^{-3}$ for 100k iterations ($\sim$52B tokens).

Table 4 presents various combinations of ${\bm{s}}_{init}$ and ${\bm{s}}_{scale}$ for each scaling factor, as well as the downstream task accuracy and validation loss. Additionally, we report the mean value of each scaling factor distribution to show the final converged scaling value after training. For ${\bm{s}}_{qk}$, we observe that the mean value (Mean(${\bm{s}}$)) is relatievly stable with value around 1 across most initialization settings, except when using smaller ${\bm{s}}_{init}$ and larger ${\bm{s}}_{scale}$, which results in a Mean(${\bm{s}}$) value less than 1. For ${\bm{s}}_{u}$ and ${\bm{s}}_{v}$, changes in initialization lead to significant shifts in Mean(${\bm{s}}$), accompanied by increases in final validation loss. For ${\bm{s}}_{z}$, we see a substantial degradation in both accuracy and loss under certain initializations. Overall, these results suggest that the baseline hyperparameter settings are robust but additional tuning of ${\bm{s}}_{u}$, ${\bm{s}}_{v}$, and ${\bm{s}}_{z}$ could potentially further improve performance.

In Table 5, we modify each learnable per-element vector of the scaling factors ${\bm{s}}_{qk}$, ${\bm{s}}_{u}$ (${\bm{s}}_{v}$), ${\bm{s}}_{z}$, and the eigen learning rates $\bm{\alpha}_{A}$, $\bm{\alpha}_{M}$ to a single learned scalar or a fixed value. This ablation helps us determine whether these tuning parameters can be simplified in nGPT. From the table, we observe that most changes result in only negligible degradation ($\leq 0.3\%$) in validation loss, and some even lead to slight improvements in accuracy. Notably, replacing the per-element vector ${\bm{s}}_{qk}$ with a single scalar has minimal impact on the mean value, while the mean value of ${\bm{s}}_{u}$, ${\bm{s}}_{v}$, ${\bm{s}}_{z}$, $\alpha_{A}$, and $\alpha_{M}$ show a slight increase. Furthermore, even when fixing ${\bm{s}}_{qk}$, ${\bm{s}}_{u}$, and ${\bm{s}}_{v}$, the model still achieves comparable accuracy and validation loss to the baseline using the per-element vectors.

In Table 6, we investigate the impact of removing certain normalization operations in nGPT to potentially reduce training time per step. We remove QK normalization by eliminating the normalization terms Norm in equations 15 and 16. The results show that this modification lead to similar accuracy and loss compared to the baseline, indicating that they are effective options for reducing computational overhead without compromising performance.

**Table 4: Ablations of ${\bm{s}}_{init}$ and ${\bm{s}}_{scale}$. Our default setup is the first row of each section. Mean(${\bm{s}}$) is the mean value of the learned distribution after training. Avg. Acc is the average accuracy of our selected five downstream tasks, Valid. Loss is the final validation loss, and we use $d_{model}=1024$.**
|  | ${\bm{s}}_{init}$ | ${\bm{s}}_{scale}$ | Mean(${\bm{s}}$) | Avg. Acc (%) $\uparrow$ | Valid. Loss $\downarrow$ |
| --- | --- | --- | --- | --- | --- |
| ${\bm{s}}_{qk}$ | 1 | $1/\sqrt{d_{model}}$ | 1.51 | 54.44 | 2.252 |
| ${\bm{s}}_{qk}$ | 0.33 | $1/\sqrt{d_{model}}$ | 1.36 | 54.67 | -0.33% |
| ${\bm{s}}_{qk}$ | 0.05 | $1/\sqrt{d_{model}}$ | 1.01 | 53.69 | -0.09% |
| ${\bm{s}}_{qk}$ | 1 | 1 | 1.38 | 54.19 | -0.09% |
| ${\bm{s}}_{qk}$ | 0.33 | 1 | 1.11 | 54.89 | -0.08% |
| ${\bm{s}}_{qk}$ | 0.05 | 1 | 0.29 | 52.41 | +1.94% |
| ${\bm{s}}_{u}$ & ${\bm{s}}_{v}$ | 1 | 1 | 1.24 & 1.12 | 54.44 | 2.252 |
| ${\bm{s}}_{u}$ & ${\bm{s}}_{v}$ | $1/\sqrt{d_{model}}$ | 1 | 0.03 & 0.03 | 53.51 | +0.92% |
| ${\bm{s}}_{u}$ & ${\bm{s}}_{v}$ | 1 | $1/\sqrt{d_{model}}$ | 2.75 & 11.2 | 53.90 | +0.05% |
| ${\bm{s}}_{u}$ & ${\bm{s}}_{v}$ | $1/\sqrt{d_{model}}$ | $1/\sqrt{d_{model}}$ | 0.40 & 0.25 | 54.39 | +0.48% |
| ${\bm{s}}_{z}$ | 1 | $1/\sqrt{d_{model}}$ | 60.8 | 54.44 | 2.252 |
| ${\bm{s}}_{z}$ | $\sqrt{d_{model}}$ | $1/\sqrt{d_{model}}$ | 106.1 | 52.60 | +1.06% |
| ${\bm{s}}_{z}$ | 1 | 1 | 23.6 | 52.71 | +3.12% |
| ${\bm{s}}_{z}$ | $\sqrt{d_{model}}$ | 1 | 63.6 | 51.84 | +1.66% |

**Table 5: Ablations of replacing learnable per-element vector (scaling factors and eigen learning rate) with a single learned scalar or a fixed value. The number of the learned vector, learned scalar and fixed value are the mean values across all layers.**
| ${\bm{s}}_{qk}$ | ${\bm{s}}_{u}$ & ${\bm{s}}_{v}$ | ${\bm{s}}_{z}$ | $\alpha_{A}$ & $\alpha_{M}$ | Avg. Acc (%) $\uparrow$ | Valid. Loss $\downarrow$ |
| --- | --- | --- | --- | --- | --- |
| vector = 1.47 | vector = 1.12 & 1.24 | vector = 60.80 | vector = 0.22 & 0.33 | 54.44 | 2.252 |
| scalar = 1.49 | vector = 1.13 & 1.23 | vector = 62.11 | vector = 0.22 & 0.33 | 54.05 | +0.22% |
| vector = 1.46 | scalar = 1.46 | vector = 60.70 | vector = 0.22 & 0.33 | 54.23 | +0.07% |
| vector = 1.47 | vector = 1.12 & 1.24 | scalar = 95.65 | vector = 0.22 & 0.33 | 53.69 | +0.20% |
| vector = 1.40 | vector = 1.13 & 1.13 | vector = 60.90 | scalar = 0.30 & 0.36 | 54.86 | +0.22% |
| scalar = 1.51 | scalar = 1.47 | vector = 61.18 | vector = 0.22 & 0.32 | 54.52 | +0.17% |
| scalar = 1.52 | scalar = 1.68 | scalar = 96.65 | vector = 0.22 & 0.30 | 52.59 | +0.30% |
| scalar = 1.49 | scalar = 1.17 | scalar = 88.64 | scalar = 0.30 & 0.37 | 53.61 | +0.62% |
| value = 1.00 | vector = 1.12 & 1.15 | vector = 60.69 | vector = 0.24 & 0.35 | 54.17 | +0.11% |
| vector = 1.45 | value = 1.00 | vector = 61.53 | vector = 0.23 & 0.35 | 55.51 | +0.05% |
| value = 1.00 | value = 1.00 | vector = 61.26 | vector = 0.24 & 0.36 | 53.63 | +0.20% |
| value = 1.00 | value = 1.00 | scalar = 96.15 | vector = 0.22 & 0.35 | 53.37 | +0.40% |

**Table 6: Ablations on the removal of QK normalization in nGPT which involves taking out the normalization terms Norm in equations 15 and 16.**
|  | ARC-E | HellaSwag | WinoGrande | WSC273 | LAMBADA | Avg. Acc (%) $\uparrow$ | Valid. Loss $\downarrow$ |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Baseline nGPT | 53.07 | 46.03 | 55.96 | 67.03 | 50.13 | 54.44 | 2.252 |
| Baseline nGPT - QK norm | 52.65 | 46.07 | 56.27 | 68.86 | 49.68 | 54.71 | +0.12% |

### A.9 Analysis of scaling parameters

In nGPT, we introduce a total six trainable parameters: the eigen learning rates $\bm{\alpha}_{A}$ and $\bm{\alpha}_{M}$, along with the scaling factors ${\bm{s}}_{qk}$, ${\bm{s}}_{u}$, ${\bm{s}}_{v}$ and ${\bm{s}}_{z}$. Since these parameters are updated using gradients, we are interested in understanding their learned distributions after training. In Figure 14, we present the histograms of these saved weights combining across layers and analyze their distributions under different context lengths, model sizes, learning rates, and numbers of training tokens.

For $\bm{\alpha}_{A}$ and $\bm{\alpha}_{M}$, we observe that their distributions remain stable across various learning rates. However, increasing the context length or the number of training tokens tends to shift the distributions to the right, indicating that the hidden state ${\bm{h}}$ requires more transformation from the Attention and MLP blocks to handle the larger inputs. Additionally, the mean values for these parameters tend to be smaller in larger models because we have more layers to update the hidden state.

Regarding the scaling factors, ${\bm{s}}_{qk}$ is quite stable under all the conditions, suggesting that a fixed value, similar to the softmax scaling factor in original transformer, may be sufficient. Interestingly, we find that ${\bm{s}}_{qk}$ has a high density close to zero, indicating the sparsity of attention in nGPT. For ${\bm{s}}_{u}$ and ${\bm{s}}_{v}$, their distributions shift left as the context length increases, but shift right as the model size or the number of training tokens increases. Furthermore, these two factors become flatter when using larger learning rate. Lastly, for ${\bm{s}}_{z}$, we see higher mean values for longer context lengths, larger model sizes, and more training tokens, suggesting that the model may learn to use a lower temperature to make the final word distribution sharper.

Figure: Figure 14: The distribution of trainable eigen learning rates and scaling factors varies under different context lengths, model sizes, learning rates, and number of training tokens. If not specified, we use context length 1K, model size 0.5B, learning rate $2.0\times 10^{-3}$, and training tokens 52B as default.
Refer to caption: x14.png

## Peer Reviews

confidence: 3
contribution: 4
initial_rating: 8
presentation: 4
questions: **Q1:** The authors comment on the average magnitudes of $\alpha_A$ and $\alpha_M$, noting that $\alpha_M$ has a higher average magnitude than $\alpha_A$, implying their suggestions more precise. could the authors the authors elaborate on this point in more detail?

**Q2:** Previous research has demonstrated that representation learning on a hypersphere enhances training stability, with experiments and ablations confirming stable activations, gradients, and weights, as well as showing gradient descent acting as a meta-optimizer. The 4-20x speedup achieved by the normalized Transformer is impressive, and further intuition or analysis on the factors contributing to this acceleration would be valuable.
soundness: 3
strengths: The paper is well-written and well-structured. The pair-wise comparisons in Section 2 make it easy to understand the architectural modifications, with clear motivation and explanations for each change.

The comprehensive experiments and ablation studies effectively demonstrate the method's effectiveness. The experimental results are impressive.
summary: Motivated by previous findings on the advantages of representation learning on a hypersphere, the authors propose a novel neural network architecture called the normalized Transformer (nGPT). In nGPT, all vectors—including embeddings, MLP outputs, attention matrices, and hidden states—are normalized to ensure they reside on the same hypersphere. This setup ensures that each token in the input sequence, during optimization, starts at a position on the hypersphere defined by its input embedding and moves on the surface of the hypersphere to a point that best predicts the embedding of the next token. Experiments on the OpenWebText dataset demonstrate that nGPT learns significantly faster, reducing the number of training steps needed to achieve performance comparable to baseline models.
weaknesses: Minor: The per-step time of nGPT is approximately 80% higher for a 4k context and 60% higher for an 8k context, primarily due to additional normalization steps. However, Table 6 shows that removing the normalization for q and k only slightly affects performance, suggesting a potential way to reduce overhead.

---

confidence: 3
contribution: 3
initial_rating: 6
presentation: 3
questions: I have no question.
soundness: 3
strengths: - The paper is well-written, and the related work section is presented clearly.

- The experimental results are solid and convincing.
summary: The paper introduces a novel neural network architecture, the normalized Transformer (nGPT) with representation learning on the hypersphere, and empirically shows that nGPT learns significantly faster, cutting down the training steps needed to reach comparable accuracy levels.
weaknesses: - I do not find any major weaknesses. My only concern is that, in essence, the method involves normalizing everything to unit, functioning as an embedding layer within architectures, with empirical results demonstrating its effectiveness. Although hypersphere normalization in representation learning is introduced and applied, the paper provides a clear discussion of related papers.

---

confidence: 4
contribution: 3
initial_rating: 6
presentation: 4
questions: - There are existing studies, such as Bachlechner et al. (2021), that demonstrate fast convergence speeds in Transformer. It would be helpful to see how nGPT compares with these previous studies.
  - Bachlechner et al., “ReZero is All You Need: Fast Convergence at Large Depth”, UAI 2021
- An interesting aspect of nGPT is the linear interpolation between the output of the attention and MLP blocks and the hidden state $h$ in Section 2.2.2. The authors used linear interpolation as shown in Equation (7), but I am curious why they did not consider directly using geodesic interpolation from Equation (6).
- It seems that the bold $\alpha$ in Equation (9) should be corrected as $\alpha$.
soundness: 3
strengths: - Fast convergence in training is practically important for saving computational power, and this paper aims to offer a meaningful solution through the proposed architecture, nGPT.
- The model is carefully designed to prevent loss of expressiveness by introducing appropriate scaling parameters when applying existing results on the effectiveness of representation learning on the hypersphere on Transformers.
- Detailed ablation studies are conducted on the newly introduced learnable parameters, $\mathbf{s}_{qk}$, $\mathbf{s}_u$, $\mathbf{s}_v$, and $\mathbf{s}_z$, demonstrating that nGPT is robust to the introduced scale parameters.
summary: This paper proposes a novel architecture called the normalized Transformer (nGPT), which performs learning on a hypersphere. By normalizing parameters and output features, such as embeddings, MLPs, and attention layers, and introducing learnable scale parameters, the model enables effective representation learning on the hypersphere. The model demonstrates faster convergence compared to GPT, even without using conventional techniques like weight decay and learning rate warmup, in models with 0.5B and 1B parameters.
weaknesses: - Many variations of the Transformer architecture have been proposed, but they have generally failed to successfully replace the original Transformer. This is because they have not demonstrated the scalability inherent in the original Transformer. In this paper, scalability also cannot be verified as performance has not been tested on models widely used at the 7B parameter scale or above.
- As the authors mentioned, nGPT requires an additional computation time of 80% for 4k and 60% for 8k context in a single iteration. While the authors argue that this can be reduced through code optimization, such as fused ops, the normalization of all matrices and embeddings at the beginning of each step would not benefit from fused ops, and GPU communication costs would arise with larger models. Verification of actual wall-clock time on larger models is necessary.
- The authors experimentally show that nGPT has length extrapolation ability in addition to fast convergence, but there is no discussion as to why nGPT possesses this property. Adding insights into this aspect could greatly benefit future research.

---

confidence: 3
contribution: 3
initial_rating: 6
presentation: 3
questions: **Question 1.** Why nGPT converges faster than the original Transformer? Experimentally, the faster convergence of the normalized Transformer was confirmed, but it was not clearly explained why

**Question 2.** The rationale behind the approximation of the SLERP by LERP needs to be clarified. While the motivation and theoretical background are well explained, the purpose and reason behind this approximation still need to be clarified. Is there any reason not to use SLERP with normalization? Or, is there any benefit to using LERP instead of SLERP?

**Question 3.** The benchmarks used in the experiments solely encompass common sense reasoning and word/sentence prediction. Are the authors convinced that the experimental results are enough to indicate the versatility of the normalized Transformer in other NLP tasks? If so, I would like to know the rationale behind this conclusion.

---

**Things to improve the paper that did not impact the score**:

* [line 88] nGPT appeared before defining what it is

* This paper explained how to build it, summarized the modifications, and described hyperparameter settings in detail. Also, the normalized Transformer is easy to be implemented. However, it is recommended to publicly open the code for reproducing the paper's results.

* The structure of the paper -- which divides the proposed method into its constituent components and presents these as separate sections, and then introduces and compares the proposed method in a sequential manner -- is not a common one. This structure facilitates the reader's comprehension of the proposed method as comparing it with the baseline. However, this structure may be perceived as somewhat akin to that of a technical report. It would be advisable to restructure the paper.

* In [4], the use of a single trainable scale parameter on normalized vectors within a matrix has potential to facilitate an examination of the training behavior exhibited by the model. It may be advantageous to consider the implementation of a single trainable scale parameter for each layer or attention within the normalized Transformer. Could this method result in the generation of superior outcomes compared to those observed previously?

---

[1] Salimans, T., & Kingma, D. P. (2016). Weight normalization: A simple reparameterization to accelerate training of deep neural networks. _Advances in neural information processing systems_, _29_.

[2] Yaras, C., Wang, P., Zhu, Z., Balzano, L., & Qu, Q. (2022). Neural collapse with normalized features: A geometric analysis over the riemannian manifold. _Advances in neural information processing systems_, _35_, 11547-11560.

[3] Shleifer, S., Weston, J., & Ott, M. (2021). Normformer: Improved transformer pretraining with extra normalization. _arXiv preprint arXiv:2110.09456_

[4] Hoffer, E., Hubara, I., & Soudry, D. (2018). Fix your classifier: the marginal value of training the last weight layer. _arXiv preprint arXiv:1801.04540_.
soundness: 3
strengths: * The proposed method was well explained, and it is clear how to convert the original Transformer to the normalized Transformer.

* The correctness of each component of the proposed methods was validated through the comparison of experimental results with the original method.

* This paper proposed a variable-metric optimizer that employs LERP and eigen learning rates. This method allows the optimizer to identify an effective learning rate and discard the weight decay.

* This paper identified the appropriate scaling factor to mitigate potential risks associated with applying diverse normalization in Transformer. The proposed approach appears to improve the convergence rate of normalized Transformer.
summary: This paper proposed the normalized Transformer (nGPT), which normalizes all vectors forming the embeddings, MLP, attention matrices, and hidden states into unit norm to travel the tokens on the surface of a hypersphere via optimal scaling factors, trainable scaling parameters, and a variable-metric optimizer, resulting in faster convergence.
weaknesses: **Weakness 1.** *Section 1. Introduction* provided a general overview of normalization and representation learning on the hypersphere within the context of Transformer. However, the research problem that this paper addresses and the rationale behind its significance are not sufficiently highlighted. It should be considered to emphasize these aspects before introducing the paper's contributions.

**Weakness 2.** This paper presents two novel components: one is LERP and eigen learning rates, and the other is the identification of an appropriate scaling factor. The other components, such as the normalization of all matrices and the trainable scaling factor, could be regarded as an integration of diverse normalization techniques (Weight Normalization [1], Feature Normalization [2], NormFormer [3]) and scaling parameter tuning on normalized vectors [1,4]. To further enhance the novelty of this paper, it is recommended that the novel components be validated theoretically or experimentally (e.g., experimentally validate how much the LERP approximates the SLERP after training) and that the normalized Transformer be compared with previous normalization methods, (i.e., describes the difference with other normalization techniques)

**Weakness 3.** This paper proposed numerous ablation experiments to investigate the impact of scaling factors and learnable scaling parameters on model performance. However, it seems essential to conduct an ablation study of the components of the normalized Transformer to gain a comprehensive understanding of the influence of each component on model performance.

Meta-review: This work proposes modifying the standard transformer architecture to normalize various aspects of the architecture (weight vectors, embeddings, etc) to lie on the unit sphere.  The authors note that this allows for the matrix-vector multiplications to be interpreted as cosine-similarity dot products and show empirically that the resulting architecture trains in significantly fewer optimization iterations than standard transformers.

The reviewers are somewhat borderline to positive. One primary concern raised by the reviewers is the scalability of the proposed method, as the computation per iteration is significantly larger than that of a standard transformer.  The authors note that this increased computation per iteration is offset by the smaller number of iterations needed to train the network and the potential for further optimizations in the implementation of the approach.

Overall, the idea is fairly straight-forward and borrows from similar ideas in other (i.e., non-transformer) architectures.  Nevertheless, while a relatively simple idea, I believe the experimental results will be of interest to the community both for practitioners as well as theoreticians exploring topics such as optimization dynamics.

Decision: Accept (Poster)