Needle 3 runs on watches, Raspberry Pis and phones. Each device has a different memory budget, so each wants a different model size. Training one model per size means several training runs, several files and a separate fine-tune for each. Needle 3 is one set of weights. Every depth from 2 to 20 layers is a trained model, and all of them run on the same engine. We call this an intelligence ladder.
Blocks and the residual stream
A transformer is a stack of blocks. Needle 3 has twenty, . They share one running vector, the residual stream. Block reads the stream, computes an update, and adds it:
Because each block only adds to the stream, skipping a block means adding nothing, the same fact that stochastic depth and LayerDrop use during training. The stream passes through unchanged and the model is simply shallower. Two questions remain: which blocks to skip, and how to make the shallow models good.
Unroll the recursion and the stream at the top of the stack is a sum,
the embedding of the token plus one displacement per block. A token is a word or a piece of one, the unit the model reads and writes. Its embedding is the list of numbers the model looks up for it before any block has run, and a list of numbers can be pictured as a point, one coordinate per number. Each block nudges that point in , the space of all such points with numbers, and the output layer reads wherever the point ends up.
Skipping block sets its term to zero. The point still arrives at the output layer, in the same space and with the same shape, only with one nudge fewer, and every later block still receives a vector it knows how to read. Whether the later blocks can finish the job from that point is not guaranteed by the arithmetic. It is what the training in the next sections has to make true.
Stochastic depth and LayerDrop, the two methods named above, are training tricks that lean on this. Stochastic depth came from residual networks in vision. On each training step it drops each block with some probability and lets the stream pass through unchanged in its place, so the network learns not to depend on any one block being present. LayerDrop does the same for the layers of a transformer, and its authors found that a network trained this way can have layers removed at inference with limited loss.
The ladder keeps that mechanism, a skipped block passes the stream through unchanged, and changes two things. The blocks that are skipped are not random but chosen by a fixed rule, so depth is the same subnetwork at every training step and at inference. And the shallow models are trained as targets in their own right, not only as a way to make the full model robust.
Which blocks make a subnetwork
A subnetwork of depth is a set of blocks, run in their original order. The sets must nest, , so that one set of weights serves all of them. The chosen blocks must also stay spread through the stack, so that a shallow model sees early and late computation rather than only the first few blocks.
Lay the twenty blocks out as twenty marks on a ruler, and call a subnetwork a choice of marks. Nesting means the choices form a chain. Going from depth to depth adds one mark and never moves or removes one, so the whole ladder is a single ordering of the twenty blocks, and depth is its first entries.
Spread means the chosen marks should be about evenly spaced at every , so the longest unchosen stretch of the ruler should be as short as it can be. The two wants pull against each other. The evenly spaced set of five marks is not in general a subset of the evenly spaced set of seven, so a rule that picked the best set at each depth on its own would not nest.
The rule that satisfies both is to never reconsider a choice and to always put the next mark in the middle of the widest gap. After the two ends come the middle, then roughly the quarters, then roughly the eighths. Each level sits inside the next, the way halving an interval and then halving the halves does.
One rule gives both. Start from the two ends, then repeatedly split the widest gap between chosen blocks at its midpoint:
with ties going to the leftmost gap. Each step only adds a block, so the sets nest. Each step halves the largest hole, so the coverage stays balanced.
Twenty blocks give one fixed sequence, . The subnetwork of depth is its first entries.
Running a subnetwork
With equal to 1 when block is in the set and 0 otherwise, the forward pass at depth is
followed by the same final normalisation and the same output layer as the full model.
Three details make this hold in the real architecture:
- Needle's residual stream has four parallel lanes, and blocks read and write them in round-robin order. Inside a subnetwork the order is renumbered over the blocks that remain, so consecutive surviving blocks still alternate lanes.
- The engram memory sites and the global-attention layers belong to specific blocks. They are kept when their block is kept and dropped when it is dropped.
- The KV cache is per block, so a shallower model also has a proportionally smaller cache.
The KV cache needs a word. When the model generates text, every block computes a key and a value for each earlier token so that later tokens can attend to them, and it stores those rather than recompute them at every step. That store is the KV cache. Each block keeps its own, so dropping a block drops its share.
Training every depth at once
Adding one loss term per depth to every training step would cost forward passes per step. Instead, each step samples one path. With probability it is the full model and the step is an ordinary language-modelling step. Otherwise a depth is drawn uniformly from , only the blocks in run, and the loss is scaled by the fraction of the model that took part:
is the next-token distribution at depth , is cross-entropy against the true next token, and is a stop-gradient: the full model's prediction is a fixed target on that step, and no gradient flows into it.
The KL term does most of the work for the shallow depths. Cross-entropy asks a 3-layer subnetwork to predict the next token, which it can barely do, and its gradient is small. The KL term asks it to predict what the whole network predicts. The full model is the teacher, each subnetwork is a student, and because they share every weight, the teacher costs no extra forward pass. This is self-distillation, with .
The KL term needs pinning down, because its gradient is what carries the signal just described. KL is the Kullback-Leibler divergence, a number that says how far one probability distribution is from another. Here both distributions are over the vocabulary, the list of every token the model can output. They are the teacher's and the student's , and the divergence is
the extra nats the student pays per token when the tokens are really drawn from the teacher's distribution but the student's probabilities are used to code them. A nat is a unit of surprise. A model that gives the true token probability is surprised by nats, so a probability of one costs nothing and a probability of 0.37 costs one nat. The divergence is zero only when the two distributions agree and positive otherwise.
Now the gradient, the one derivative I will make you sit through. The student's logits are the raw scores it gives every vocabulary entry before they are turned into probabilities. The softmax is the function that does the turning, , raising to each score and dividing by the total so that the results sum to one. Differentiating the divergence with respect to the scores gives , one number per vocabulary entry. It pushes the student's probability up wherever the teacher's is higher and down wherever it is lower.
Cross-entropy against the true token is minus the log of the probability the student gave that token, the surprise in nats from above. Its gradient is , the same shape but with a target that is one at the single true token and zero at every other. The teacher's target is a whole spread of plausible next tokens, and a shallow student can move toward that spread even when it cannot reach the single true token. This is the knowledge-distillation argument in its original form, where a small model is trained to match the probabilities of a large one, with the full depth of the same network standing in for the separate large model.
Each step trains one depth. Averaged over many steps, this gives the same expected loss as training every depth on every step, and it costs one forward pass instead of eighteen.
Written out, the loss the ladder optimises on average is the expectation over the sampling, meaning the average of the per-step loss over which depth the coin picks,
This is one term per depth with fixed weights, and it is the sum the first paragraph said would cost forward passes, one pass through the network per depth. Sampling one term per step gets the same gradient on average for the price of one pass.
The factor inside the sum scales each sampled step by the fraction of the blocks that ran. A depth-3 step moves the shared weights with of the force of a full step, so a step that trained only a sliver of the network changes it by only a sliver.
The ladder also improves the full model. We trained the same 18-layer architecture twice for 3,000 steps on the same data, once with the ladder and once without. With the ladder the full-depth validation loss was 1.958; without it, 2.037. The ladder model was ahead at every checkpoint, and its 16-layer exit alone matched the control's full 18 layers. Every prefix of the stack has to predict well on its own, so the early blocks cannot leave the work to the later ones, and no single block can become one the model depends on.
Two of the words in the table need defining. Validation loss is the loss on text held back from training, in nats per token. A tokenizer is the rule that cuts text into tokens, and two models with different tokenizers have per-token losses that cannot be compared, so the loss is also given per byte of raw text.
The numbers behind the figure. Bits per byte is the validation text loss in a unit that does not depend on the tokenizer; lower is better.
| run, 18 layers, 3,000 steps | validation loss (nats) | bits per byte at 18L | at 16L | at 12L | at 8L | at 4L | at 2L |
|---|---|---|---|---|---|---|---|
| control, full depth only | 2.037 | 0.686 | |||||
| ladder from step 0 | 1.958 | 0.660 | 0.689 | 0.769 | 0.855 | 0.991 | 1.538 |
| ladder switched on late in training | 2.059 | 0.694 | 0.736 | 0.836 | 0.908 | 0.996 | 1.675 |
Two things follow. The ladder costs the full model nothing and gains it 0.079 nats, 3.9% of the loss. And the ladder has to be there from the start: switching it on late gives worse subnetworks at every depth and a slightly worse full model, 1.1% above the control, because the blocks have already specialised around a fixed depth.
What each depth of the ladder-trained model keeps and what it costs, against its own full depth. The parameters kept are the surviving blocks with the engram sites and the confidence rows that belong to them; the embeddings and the final layers are shared by every depth.
| depth | 18L | 16L | 12L | 8L | 4L | 2L |
|---|---|---|---|---|---|---|
| parameters kept | 100% | 93% | 80% | 55% | 31% | 24% |
| bits per byte | 0.660 | 0.689 | 0.769 | 0.855 | 0.991 | 1.538 |
| loss change | +4.4% | +16.7% | +29.6% | +50.3% | +133% |
Down to 4 layers the loss grows more slowly than the parameters shrink. At 2 layers it more than doubles.
What each depth scores
Every depth from 2 to 20 layers ships in the one Needle 3 file, and needle build
--layers picks any of them. We benchmarked four of them on two tool-calling suites, sliced
from the same checkpoint and run through the same engine with the confidence gate on.
Tool calling means the model answers a request by writing out a function call, the name of a function and its arguments, which the app then runs. The two suites below are collections of such requests with the right call recorded for each, and a call is scored by exact match, so it counts only when it matches the recorded call exactly. Needle also has a confidence head, a small extra output that says how sure the model is that a call is wanted, and the gate withholds the call when it is not sure. The names in the figures, for readers who have not met them.
| name | what it is |
|---|---|
| DroidCall | 200 requests for phone actions, each answered by one or more calls, scored as the exact calls in the right order |
| Mobile Actions | 961 requests for a single phone action, scored as the exact call |
| DeepSeek V4 Flash | a large hosted model from DeepSeek, run through its cloud API, used as the comparison line in the second figure |
The 2-layer subnetwork is absent because at 2 layers the base model's confidence head withholds almost every call, so its gated score is zero, and with calls forced it scores 20.5 on DroidCall. Two layers of a generalist is not a product. Two layers fine-tuned on one product's tools is, which is the next figure.
Fine-tuning lifts every depth by 18 to 36 points on DroidCall, and from 4 layers up the tuned subnetwork passes DeepSeek V4 Flash. The 2-layer model goes from unusable to 56.5. A small network trained on one narrow task reaches frontier accuracy on that task, and the ladder is what lets you choose how small.
Fine-tune once, deploy any depth
Because the subnetworks share weights, one fine-tune is a fine-tune of all of them. The LoRA adapter is trained on the frozen base at the full 20 layers, merged into the weights, then sliced:
where is the low-rank update and keeps the blocks in , the engram tables of their sites, and the rows of the confidence head that belong to them.
LoRA, for readers who have not met it, is a way of fine-tuning a weight matrix by training a small separate update instead of the matrix itself. A matrix is a grid of numbers, and fine-tuning means training an already trained model a little further on one narrow task. For a weight matrix , with rows and columns, the update is written as the product , where and and is small. The product has rank at most , meaning it can only move along independent directions, and only numbers are trained instead of . That is the saving.
itself is frozen. starts at zero so the model is unchanged at the first step, and after training the product is added into , so the deployed weights are one matrix of the original shape and the adapter costs nothing at inference. In the equation above is every weight of the base at all 20 layers, and is the merged update to the matrices the adapter touched. Because the adapter was trained through the full stack on weights the subnetworks share, every subnetwork inherits it when it is sliced out.
A sliced model has its own block numbering, 0 to 15 for a 16-layer slice. Running the bisection rule on that numbering picks a different set of blocks from the parent's, blocks that were never trained together as a subnetwork. Of the 14 depths of a 16-layer slice, 13 differ between the two rules.
So every slice carries its parent's selection order, and slicing a slice equals slicing the original. In the Python package:
needle finetune data.jsonl --epochs 10 --out adapter.safetensors
needle build --lora adapter.safetensors --layers 8 --platform linux-arm64 --out ./piThe same ladder exists along width, where each sampled subnetwork is a depth and a channel prefix of every matrix, as in Matryoshka representations and MatFormer. The shipped Needle 3 exposes depth.
What it costs
At training time, a sampled step is cheaper than a full step, so the ladder adds no wall-clock time per step. The price is that 20% of steps update only part of the model, which the self-distillation term recovers.
At inference time there is no cost. A subnetwork of depth is exactly a -layer model in operations, in cache and in file size. The blocks are the same bytes at every depth, so file size is a straight line in .
A device can hold the full 29 MB file and choose a depth per request, a shallow pass for a simple command and the full stack for a hard one, with no second download. That part is not shipped yet.
The recipe is not specific to tool calling. Whistle, our speech model, is laddered the same
way: its decoder trains every depth at once and picks one at load time with
--audio-depth, on the same engine and out of the same file.
References
- He et al., Deep Residual Learning for Image Recognition, 2015.
- Huang et al., Deep Networks with Stochastic Depth, 2016.
- Fan et al., Reducing Transformer Depth on Demand with Structured Dropout, 2019.
- Hinton et al., Distilling the Knowledge in a Neural Network, 2015.
- Kusupati et al., Matryoshka Representation Learning, 2022.
- Devvrit et al., MatFormer: Nested Transformer for Elastic Inference, 2023.
- Cai et al., Once-for-All: Train One Network and Specialize it for Efficient Deployment, 2019.
- Hu et al., LoRA: Low-Rank Adaptation of Large Language Models, 2021.