Release Attention back to Transformer: Disablement, Normalization and Location

One down the length shape. Decoder block , the manual is coding for the unicoded and rotated position and checking for alignment of the position deviation with the cache.

System Chapter . StepCollate in 2 Graphics6 self-measurement4 First-hand sources
Start Body
Learning objectives and first steps3 objectives • 3 first fixes

Try to do it after reading

  • Explain the division of labour between Attention, FFN and residues along the length shape
  • Handheld LayerNorm, RMSNorm and 2D RoPE
  • Check pre-norm, position index and cache boundaries

Suggested first

  • Attention and mask
  • Matrix Multiplication and Element-by-Element Non-linear
  • Mean to Variable

Why are you looking at Attention and you can't read the model code

Assuming that the two lines Q, K, V have been calculated as output, then the model definition is opened, but the homogenization, remnants, door controls and multiple projections are seen. They solve different problems: Attention allows for information exchange between locations; (b) The forward feed network undergoes non-linear transformations at each location; The disability retains an indication and provides a direct gradient path; Qualitative scale of the controlled entry into the sublayer. Delete one of them and get the original block.

Use one in this chapter decoder teaching structure for pre-norm Not all models are claimed to follow it. There are differences in the location used by the original Transformer, the order of standardization and some common variants in modern models. When reading is done, you draw the actual call order and then name it. No specific details can be extrapolated from the name " Transformer " .Original paper To be used to reconcile infrastructure; The synthesis here is constructed by this chapter itself.

A path that checks shapes

The shape of X is B x T x d, representing batches, sequence length and hidden dimensions, respectively. Normalize the last dimension, then focus on the cause-and-effect mask, project back to d and get X added to H. The second sub-layer normalizes H and then adds H to FFN by location. The additions require a strict parallel shape and cannot be relied on for the broadcasting of a false hit.

H=X+Attention(Norm(X))Y=H+FFN(Norm(H))

The normal two-storey version of FFN was first expanded from d to dff, then returned to d after being non-linear. It shares parameters between locations, but not directly mixes time positions; The handler FFN increases the branch and changes the parameter. The multidirectional focus divides the post-projected channel into several headlines, allowing each head to have a separate match and finally to collide. The increase in the number of headlines does not necessarily represent an increase in the amount of information, but is also limited by the overall dimensions and training results.

Pre-norm block Main Dry and Fragmentation PathThe horizontal backbone is down to two levels of homogenization and sublayers; Each of the two above-side paths returns the input to the attention output and the forward feed output, all of which remain hidden in dimension four.NormAttentionNormFFN++Keep input XRetain Centered Expression HB × T × 44 → 8 → 4
The disability is a definite value added; The bypass road is not a direct copy of historical features to the final answer.

Two-dimensionally looking at the difference of unicoded

Take a location for x = [1,3]. LayerNorm calculates the mean value along feature dimensions 2 and the overall variance 1; The output is about [-0.999995, 0.999955] when learning scaling and bias is not considered. The overall variance of the denominator is not an unbiased sample deviation divided by d−1 in the statistical extrapolation.

RMSNorm does not subtract the mean. Here ε=0 and scale=1; mean square is 5, giving [0.447214,1.341641]. It retains the overall positive shift's influence.RMSNorm dissertation explains this rescaling design. Sharing the name Norm does not imply numerical equivalence. Real models learn scaling parameters, with ε and precision read from configuration.

How do you get your position into the matching score

mask without a location signal or a location-specific location is subject to the same variability as a reordering of positions from its own. It is difficult to identify “who is in front” by content alone. Absolute position embedds the position vector into the expression; RoPE rotates the Q and K pairing channels by position, so that the matching fractions bring relative position information. Here, the two-dimensional space is derived and the high-dimensional realization is a two-dimensional rotation block with multiple frequencies.

(Rmq)T(Rnk)=qTRn−mk

Makes each position rotate 90 degrees, q = [10] in position 1, k = [0,1] in position 0. Both are [0,1] and the inner volume is 1. Move them together to one position, which is two and one, both of which are close to [-10], with an inner mass of one. This is an example of how the relative difference between the time of common migration is constant Any long text that doesn't prove beyond the length of training can be reasoned; Frequency, training distribution and numerical accuracy continue to limit extrapolation.

2-D common migration of RoPEThe left circle will be marked with a combination of query and key rotated upwards and a single position added to the right and a combination of both internal volumes to the left.m = 1, n = 0. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . m = 2, n = 1 . Under 1Move Together+1 PositionQ′ / K′Q′ / K′
The angle is 90 degrees easy to calculate and the true frequency requires reading specific model configurations.

Minimum recovery and parameter book

import math
x = [1., 3.]
mu = sum(x) / len(x)
var = sum((v - mu)**2 for v in x) / len(x)
print([(v - mu) / math.sqrt(var + 1e-5) for v in x])
def rot(v, pos):
a = pos * math.pi / 2
return [math.cos(a)*v[0]-math.sin(a)*v[1],
math.sin(a)*v[0]+math.cos(a)*v[1]]
for m, n in [(1, 0), (2, 1)]:
q, k = rot([1, 0], m), rot([0, 1], n)
print(sum(a*b for a, b in zip(q, k)))

The standard Python algorithm has been implemented. Decimal error within float-point tolerance; No real Transformer running. If d = 4, dff = 8, ordinary attention four 4x4 projectors total 64 weights and normal FFN two matrices total 64 weights; The two aggregate 128, which do not take into account bias, standardization, embedding or output headers. This small account could have been suitable for missing calculations, but could not directly predict the speed of operation because of the sequence length impact on activation and attention costs.

(a) Project error is prioritized to check whether the homogenization axis is miswritten as a time dimension; Whether or not to broadcast unexpectedly before the difference is added; Whether the new token absolute position at the time of the incremental decoding is consistent with the existing KV cache. If a new token is numbered zero each time, even if it is in the right shape, it changes the position relationship that the model has read. Further screening also makes a distinction between pre-norm and post-norm, which does not allow for a direct exchange of the calculation of pre-training weights.

Check incremental paths using the equivalent test

If you want to check your block implementation without training a large model, you can first close dropout with a fixed parameter and a very short input. The complete sequence is preceded by a forward direction, and the path of the cache is called on a location-by-place basis, comparing the logits corresponding to the consistency within the tolerance. This check covers both position numbers, cache collage, cause-and-effect visible range and output projection; If you fail, first locate the first layer and position where the difference occurs, and not just compare the final generation text.

It can also set the output of a sub-stratum to zero, confirming that the residue path does keep input; Replace all positions with the same content and observe changes before and after the introduction of the location code. The expected results of the synthesis input are easily derived and suitable for the detection of axle and broadcast errors. They test the realization contract without proving the broad capability of the model in real tasks.

Check understanding

The hidden dimensions of FFN are larger. Why do you still have to add to the gaps?

The extended dimension occurs inside the sub-layer. The second linear layer maps dff back to d so that the external output shape is consistent with the input; If the results of the expansion are directly added, they are usually structural errors.

The input of LayerNorm has changed from [1,3] to [11,13], with the ideal for uniformity?

The same margin shall be applied to the average value [-1,1] and the difference shall remain one, irrespective of the floating point error and the zooming bias. RMSNorm does not have an equal value, so there is no change in the equation.

Do both layers of Norm mean that the whole sequence shares a mean value?

No, it's not. This chapter is calculated separately for each sample, for each time location along the hidden channel; The assimilation of different positions can be mixed with different semantics and length information.

RoPE Why didn't you rotate Value?

RoPE, as explained in this chapter, uses the position to match Q/ K, and the Value is handled according to the specific structure. It is not possible to deduce from the name that all three matrices achieved are rotated the same way.

Add all the positions together. Why can you keep the inner build-up?

(a) The rotation matrix is rounded and the common rotation on the left is offset in the internal volume, leaving a difference in position; This conclusion relies on the use of compatible rotation rules, and not the random repositioning of indexes does not affect output.

The number of layers, the number of parameters, must it be the same?

Not necessarily. The focus configuration, activation length, arithmetic integration, memory reading and writing and hardware parallel efficiency all change the running time. The parameter book answers different questions from the performance test.

Source reconciliation dates are 2026-10-29; RoFormer Corresponding arXiv v5 , RMSNorm Corresponds to 2019 original papers. The structure is relatively stable and the configuration of the model ' s normalized, door controlled, scaled and cache interfaces should be checked. Keep reading Splitting and Language Model Objectives, get block output to trainable predictions.

Sources and reconciliations

Definitions, methods and interfaces are available.

  1. Attention Is All You Need
  2. RoFormer — Enhanced Transformer with Rotary Position Embedding
  3. Root Mean Square Layer Normalization
  4. Stanford CS336 Spring 2025

Figures and calculations are reorganized according to this chapter. Mathematical measurements, framework operations and real business effects are described separately in the body of the text.

← Back to the knowledge directory
Ask Max Ask about this site
Ask Max ↗

Opening the assistant…

Paper figure

Photo comments

LEAVE A NOTE

About this photograph

Connecting to the discussion board…

    Comments become public after moderation. You can delete your own comments from this browser.
    No email is required. Clearing cookies prevents this browser from claiming earlier comments.

    MAX WANG / INDEX

    Find something

    Enter a keyword, or explore the directory below.