Architectures

August 2026Vladislav Kruglikov

Neural network architectures are built from components that transform representations and control how information flows through the model. This article collects short explanations of these components, starting with dropout.

Dropout

Dropout randomly sets part of an activation tensor to zero during training. It is a regularizer. The model cannot rely on every feature always being present, so it is pushed to learn less brittle representations.

During training, each value is kept with probability 1p1-p and dropped with probability pp. The kept values are divided by 1p1-p:

y=mx1py = \frac{m \odot x}{1-p}

where mm is a random mask with values 00 or 11.

The scaling keeps the expected value the same. For one activation xx:

E[y]=(1p)x1p+p0=x\mathbb{E}[y] = (1-p)\frac{x}{1-p} + p\cdot 0 = x

That is why in evaluation dropout does nothing but in training samples a mask and rescales the kept activations.

In distributed training, replicated activations that must remain identical need the same dropout mask on every replica. Different shards of one activation instead use independent mask entries, so together they form one independent mask for the full tensor.

Dropout should usually come after the activation because some activations turn an input of zero into a nonzero output. For example, sigmoid(0)=0.5\operatorname{sigmoid}(0)=0.5, so masking a value before sigmoid does not actually remove it. Masking after the activation always makes the dropped feature zero. With ReLU the two placements can be equivalent because ReLU(0)=0\operatorname{ReLU}(0)=0.

Applying dropout after the final logits usually does not make sense. Logits are the direct inputs to the loss. If we randomly zero them, we are corrupting the model's answer right before the objective reads it.

Residual connection

A residual block is a group of layers with a shortcut connection that adds the original input to the layers' output. If the layers compute F(x)F(x), the block returns F(x)+xF(x)+x.

During the backward pass, the gradient can flow through both paths. Let y=F(x)+xy=F(x)+x and let JF(x)J_F(x) be the Jacobian of FF. Then

xL=JF(x)TyL+yL=(JF(x)T+I)yL\nabla_x L = J_F(x)^\mathsf{T}\nabla_y L + \nabla_y L = \left(J_F(x)^\mathsf{T}+I\right)\nabla_y L

The first term is the gradient through FF, and the second is the gradient through the identity shortcut.

A feedforward block compared with a residual block.

Suppose the desired output for input xx is the underlying mapping H(x)H(x). Instead of asking the stacked layers to learn H(x)H(x) directly, a residual block lets them learn a residual function F(x)F(x) relative to the input. The original mapping is then obtained by adding the input back:

H(x)=F(x)+xH(x)=F(x)+x

The idea is that optimizing the residual mapping can be easier than optimizing the original, unreferenced mapping. If the identity mapping is already a good solution, so that H(x)=xH(x)=x, the stacked layers only need to push F(x)F(x) toward zero. This can be easier than learning the identity function from scratch through multiple nonlinear layers. The Deep Residual Learning paper introduced this approach.

Multi-head attention (MHA)

MHA gives every attention head its own query, key, and value projections. The heads can learn different relationships, then their outputs are concatenated and mixed. This is the attention mechanism introduced in Attention Is All You Need.

Grouped-query attention (GQA)

GQA keeps many query heads but groups them so that several query heads share one key and value head. It reduces key/value cache memory and bandwidth while retaining more query-head diversity than MQA. See GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints.

Multi-query attention (MQA)

MQA gives every query head its own projection but shares a single key and value head across all queries. This greatly reduces key/value cache size and decoding bandwidth, at the cost of less independent key/value representations. It was introduced in Fast Transformer Decoding: One Write-Head is All You Need.

Mixture of experts (MoE)

An MoE layer contains several expert networks and a router. For each token, the router selects only a small number of experts, such as the top one or two, and the layer combines their outputs.

This lets the model increase its parameter count without running every parameter for every token. The main challenges are routing tokens evenly across experts and communicating tokens to the workers that own the selected experts.

MoE also creates a smaller effective batch for each expert because every token is sent only to a subset of experts. Each expert therefore performs smaller matrix multiplications, which can be less efficient. A larger global batch is often needed to provide enough tokens to each expert and keep the same computations well saturated.

Some MoE layers also include a shared expert that processes every token alongside the selected routed experts. The shared expert can learn common features, while the routed experts specialize. For example, Qwen3.5-35B-A3B has 256 routed experts, selects 8 of them per token, and adds 1 shared expert. Thus 257 expert modules exist in total if the shared expert is counted, while 9 expert branches are active for each token.

Dropless MoE

Standard MoE implementations often give each expert a fixed token capacity. This bounds memory, but overflow tokens must be dropped, while unused capacity becomes padding. Dropless MoE avoids that trade-off by packing the routed tokens into dynamically sized blocks and applying block-sparse matrices, so every token is processed without padding every expert to its worst case. This idea was developed in MegaBlocks: Efficient Sparse Training with Mixture-of-Experts.

Activation functions

Activation functions add nonlinearity to neural networks. Without them, stacking linear layers would still produce only one linear transformation.

ReLU

ReLU keeps positive values and sets negative values to zero:

ReLU(x)=max(0,x)\operatorname{ReLU}(x)=\max(0,x)

Plot of ReLU.

It is simple and cheap, but neurons that remain negative can stop receiving useful gradients. Near zero, a tiny change in the input can switch ReLU's gradient completely off or on. SiLU changes its gradient gradually instead, which can make optimization less sensitive to crossing this threshold.

Leaky ReLU

Leaky ReLU keeps a small slope for negative values:

LeakyReLU(x)=max(αx,x),0<α1\operatorname{LeakyReLU}(x)=\max(\alpha x,x),\qquad 0<\alpha\ll1

Plot of Leaky ReLU.

This reduces the risk of permanently inactive neurons while keeping ReLU's simplicity.

Sigmoid and tanh

Sigmoid maps values to (0,1)(0,1) and is useful for gates and probabilities:

σ(x)=11+ex\sigma(x)=\frac{1}{1+e^{-x}}

Plot of sigmoid.

Tanh maps values to (1,1)(-1,1) and is zero-centered:

tanh(x)=exexex+ex\tanh(x)=\frac{e^x-e^{-x}}{e^x+e^{-x}}

Plot of tanh.

Both saturate for large positive or negative inputs, which can make their gradients very small.

GELU

GELU smoothly gates values according to their magnitude instead of applying a hard cutoff. It is widely used in transformer models because its smooth behavior works well with gradient-based optimization.

GELU(x)=xΦ(x)\operatorname{GELU}(x)=x\Phi(x)

where Φ\Phi is the standard normal cumulative distribution function.

Plot of GELU.

SiLU / Swish

SiLU, also called Swish, multiplies the input by its sigmoid:

SiLU(x)=xσ(x)\operatorname{SiLU}(x)=x\,\sigma(x)

Plot of SiLU.

It is smooth and is commonly used in modern convolutional and language models.

GLU variants

Gated linear units split a projection into a value and a gate, then multiply them elementwise. For value projection v=xWv+bvv=xW_v+b_v and gate projection g=xWg+bgg=xW_g+b_g:

GLU(x)=vσ(g)GEGLU(x)=vGELU(g)SwiGLU(x)=vSiLU(g)\begin{aligned} \operatorname{GLU}(x) &= v\odot\sigma(g) \\ \operatorname{GEGLU}(x) &= v\odot\operatorname{GELU}(g) \\ \operatorname{SwiGLU}(x) &= v\odot\operatorname{SiLU}(g) \end{aligned}

These are popular in transformers because the gate lets each token control how much of the value is passed through.

Plots of the gates used in GLU variants.