AlgoViz

Experts, distillation and multimodal inputs

hard 6 min

Architecture determines where work happens.

Video lesson · Chapter 1 of 4

Only two experts light up

0:00 / 3:35

Theory

Read or listen first. About 2 min.

What it is

Architecture determines where work happens. An expert router selects only part of a network for each token, a student can learn from a larger teacher, and a multimodal front end translates images into representations the language model can use. These mechanisms solve different bottlenecks.

Why it exists

A small stored artifact, a small active computation and faithful reading of an image are separate properties. Define the deployment limit and the task failure, then measure the corresponding mechanism rather than ranking models by parameter count alone.

Why eight experts do not imply eight active experts

Image patches → Expert router (encode observations). Expert router → Digit accuracy (test routed output)
Image patches → Expert router (encode observations). Expert router → Digit accuracy (test routed output)

Inside this chapter

Chapter sources
Mixture of Experts (MoE)
A mixture-of-experts layer routes a token to a subset of feed-forward experts. Total parameters measure storage while activated parameters better describe part of the per-token work. Skewed routing can overload one expert and add communication overhead even when average compute looks low.

An MoE layer replaces one large feed-forward block with several experts and a small router that scores them per token. Only the top few run, and their outputs are combined using the router's weights, so per-token compute tracks activated parameters while memory tracks total parameters. Training adds a load-balancing term because routers tend to favour a few experts. In serving, a popular expert on one device becomes a hot spot, and moving tokens between devices adds latency that average FLOP counts hide.

Example. Eight equally sized experts are available but two process this token. Count two expert computations while budgeting storage for all eight.

Another example. A model with 8 experts per layer and top-2 routing runs roughly a quarter of the expert compute per token, yet a single GPU still needs room for all 8 experts unless they are spread across devices.

Router picks 2 of 8 experts for this token

Compute: 2 expert passes. Memory: all 8 experts must be loaded somewhere.
Knowledge Distillation
Distillation trains a smaller student using a teacher’s outputs or probability distribution. Soft targets can encode similarities between alternatives. Test the student independently on rare inputs and on tasks where the teacher was weak. Matching a teacher faithfully can also reproduce its mistakes.

A hard label says only which answer is right. A teacher's full distribution also says how wrong each alternative is, which carries information about how classes relate and gives the student a richer signal per example. Students are usually trained on a mix of teacher targets and ground-truth labels. The catch is that faithful imitation copies the teacher's blind spots too, so test the student on rare cases and on slices where the teacher was weak.

Example. Two incorrect labels can receive teacher probabilities 0.09 and 0.001. A student can learn their relative plausibility from soft targets.

Hard label versus soft teacher targets

ClassHard labelTeacher probabilityWhat the student learns
refund (correct)10.909the right answer
billing (wrong)00.090a plausible near miss
shipping (wrong)00.001clearly unrelated
Illustrative probabilities. The hard label treats both wrong classes the same; the soft target ranks them.
Multimodal Internals
A multimodal model maps nontext inputs into representations the language model can consume, for example image patches projected into its embedding space. Resolution and preprocessing determine which details survive. Test reading tiny table cells separately from summarizing a page’s overall subject.

The language model never sees pixels. A vision encoder turns each patch into a vector, a small projection maps those vectors into the language model's embedding space, and they sit in the sequence like extra tokens. Everything depends on what survived preprocessing: downscaling a long receipt can merge digits, and cropping can remove the header that says which column is which. Evaluate small-text reading, layout understanding and overall gist as separate tests.

Example. Crop a receipt to retain its total but remove the column header. A correct digit read can still become an incorrect field assignment.

Another example. An expense app reads totals correctly from phone photos but fails on scanned A4 statements, because the resize step shrinks the scan until each digit spans less than one patch.

From receipt pixels to language-model positions
  1. 1Resize and cropfixes which details survive
  2. 2Cut into patchese.g. 14 x 14 pixel squares
  3. 3Vision encoderone vector per patch
  4. 4Projectormaps into text embedding space
  5. 5Language modelreads image and text positions together

A digit smaller than a patch can be blurred away before the language model ever sees it.

Distillation temperature
Dividing logits by a temperature above 1 before the softmax spreads probability onto the alternatives, so the teacher's ranking of wrong answers becomes visible enough to learn from.

Raising T flattens the distribution without changing the order of the classes. Both teacher and student are softened with the same T during training; the student is used at T = 1 afterwards. Too high a temperature makes every class look alike and washes out the signal.

Example. At temperature 1 a teacher gives a near miss 0.001; at a higher temperature the same logits give it a few per cent, and the student can learn the ordering.

Softened targets and the distillation loss

pi(T)=ezi/T∑jezj/T,LKD=T2 KL(pteacher(T) ∥ pstudent(T))p_i^{(T)}=\frac{e^{z_i/T}}{\sum_j e^{z_j/T}},\qquad \mathcal L_{\rm KD}=T^2\,\mathrm{KL}\big(p^{(T)}_{\rm teacher}\,\|\,p^{(T)}_{\rm student}\big)
z are logits and T the temperature. The T squared factor keeps gradient size comparable as T changes.
Image token budget
A vision front end turns an image into a number of positions that grows with resolution, roughly the image area divided by the patch area. Those positions consume context and compute like text tokens.

Doubling each side quadruples the positions, so higher resolution buys detail at a steep price in context and attention cost. Many systems therefore tile large images or compress patch vectors before they reach the language model. Measure accuracy on your smallest critical text at each setting before choosing one.

Example. A 224 by 224 image in 14-pixel patches gives 16 x 16 = 256 positions. At 448 by 448 it gives 1,024, four times as many.

Resolution against positions at 14-pixel patches

Input sizePatches per sidePositionsRelative cost
224 x 224162561x
336 x 336245762.25x
448 x 448321,0244x
Illustrative patch size. Many models also pool or tile, so check the real count for the deployed model.

How it works

Step through the idea, or press Play.

Step 1 of 3

Image patches. Receipt and text question

Understand it

Worked example

Why eight experts do not imply eight active experts

  1. 1

    Receipt and text question

    The multimodal front end produces representations for image regions and text positions. Resolution affects whether a tiny digit survives.

  2. 2

    Select 2 of 8 experts

    In this illustrative MoE layer the router assigns each token to two feed-forward experts. Shared parts of the network still run.

  3. 3

    Verify totals on held-out scans

    Stored parameters include all eight experts. Neither that count nor agreement with a teacher proves the system reads small digits correctly.

Follow the handoffs

A small stored artifact, a small active computation and faithful reading of an image are separate properties. Define the deployment limit and the task failure, then measure the corresponding mechanism rather than ranking models by parameter count alone.

What each count tells you for the receipt model

QuantityIllustrative MoE layerAnswers which question
Experts stored8How much device memory is needed
Experts run per token2Roughly how much expert compute per token
Shared layersattention and embeddings always runWork that sparsity does not remove
Held-out digit accuracymeasured on scansWhether the system actually reads totals
Neither parameter count says anything about reading small digits; only the evaluation does.

Summary

The whole topic in one minute.

Activation sparsity changes parts of compute. The deployment must still make the weights available, locally or through sharding.

A small stored artifact, a small active computation and faithful reading of an image are separate properties. Define the deployment limit and the task failure, then measure the corresponding mechanism rather than ranking models by parameter count alone.

Sources