liveBook · Manning

Routing

As explained in Transformers in Action

A gating network is a lightweight neural component that scores experts and selects or weights them for each input token.

Routing is the lightweight gating mechanism in a mixture-of-experts layer. It scores each token’s hidden representation, selects a small set of expert networks, and assigns their contribution. Replacing a transformer feed-forward network with sparsely activated experts enables conditional computation: total parameters can grow without activating them all for every token. section 3.5.1

A practical router typically performs these steps:

  • Apply a lightweight linear layer to each token representation to produce expert scores. section 3.5.1
  • Select the top-k experts, commonly one or two, rather than activating every expert. section 3.5.1

Top-2 gating

A NativeGate applies a linear projection, selects the two highest-scoring experts with topk, reshapes the selected scores, and applies softmax to obtain routing weights. A GshardGate builds on this pattern with capacity settings and optional random routing.

How Transformers in Action covers it

How deep it goes
Explains scoring, top-k selection, softmax weighting, and GShard extensions, but does not detail the complete dispatch computation.
Examples
Demonstrates NativeGate top-k routing and GshardGate capacity-aware routing with optional random assignment.
What it assumes
Assumes transformer and feed-forward-layer terminology while introducing router behavior through progressively concrete architecture and code.
What you can do after
Build it from scratch using a linear scorer, top-k selection, and softmax-normalized expert weights.
How it connects
Connects conditional computation, mixture-of-experts layers, transformer feed-forward networks, softmax, load balancing, and sparse activation.

Also explained in

Compare how 22 books explain routing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Transformers in Action. The section links point to the parts of the book it draws on.