Kolibri Pre-Training from Scratch: UniBPE, Hybrid Attention and Exact Quantile Balancing
Building Aleph Alpha's Kolibri base model from the ground up: the Unigram-loss merge score of UniBPE and why it is pointwise mutual information in disguise, the KV-cache arithmetic of 40 sliding-window and 10 NoPE blocks, sigmoid MoE routing with Exact Quantile Balancing and Load-Error Injection, the 1 − K/E signature of a router the bias has overridden, and the cumulative-learning-rate law behind hyperparameter transfer. Every step is derived on one German sentence and four tokens.
Aleph Alpha’s Kolibri (Aleph Alpha, 2026; weights at Aleph-Alpha/kolibri-1) is an English–German Mixture-of-Experts model with 78.1B total and 3.46B active parameters per token. That is 4.4% of the weights per token. It was trained on 24T tokens, more than a fifth of them German, and released under Apache 2.0. Among the open models the report compares, it sits on the Pareto frontier of quality against serving cost in both languages.
The report runs to 189 pages and covers every stage, from Common Crawl to RL. This post follows one thread: the base model. Four design choices make it cheap per token and strong in German. Each is derived here from scratch:
- UniBPE, a tokeniser that builds merges bottom-up like BPE but ranks them by the Unigram loss.
- Hybrid attention: 40 sliding-window blocks with RoPE and 10 full-attention blocks with no positional encoding.
- Sigmoid MoE routing, balanced by Exact Quantile Balancing (EQB) across the whole batch and Load-Error Injection (LEI) inside each microbatch.
- Hyperparameter transfer by loss extrapolation in the cumulative-learning-rate coordinate.
The companion post, Kolibri Post-Training from Scratch, covers SFT and RL.
The Running Example
We follow one German sentence through the model:
Die Zeitung erscheint täglich. (“The newspaper appears daily.”)
The tokeniser has to decide how to cut Zeitung. German forms thousands of nouns with the suffix -ung (Zeitung, Ordnung, Wohnung, Rechnung), so a good tokeniser should learn ung as a unit. We will watch UniBPE choose ung where plain BPE chooses something else.
The first four tokens of the sentence are then
In the MoE sections these four tokens meet a toy MoE layer with routed experts and top- routing. Kolibri itself has and . The router has collapsed onto two experts, and we will watch EQB repair it in one update.
1. Mathematical Setup
Earlier posts in this series derive most of the tools we need:
- Logarithm rules, the softmax, and entropy are built in Mathematical Prerequisites for Mixture of Experts.
- Top- routing, sigmoid routing scores, and expert-bias load balancing are built in MoE Load Balancing from Scratch.
- Sliding-window attention and grouped-query attention (GQA) are built in Sliding-Window Attention and Grouped-Query Attention.
We also need two small definitions.
The function . Write with . This is the continuous extension, since as . Its derivative, by the product rule, is
Quantiles. For a list of numbers, denotes its -th largest entry. For example, : sorted descending, the list is , and the third entry is .
2. Kolibri at a Glance
| Kolibri Origin | Kolibri | |
|---|---|---|
| Blocks | 50 | 50 |
| Full-attention / SWA blocks | 50 / 0 | 10 / 40 |
| SWA window | — | 512 preceding tokens |
| Width | 2048 | 2560 |
| Query / KV heads (dim 128) | 32 / 4 | 48 / 4 |
| Leading dense blocks | 2 | 0 |
| Routed experts, top- | 128, 8 | 384, 6 |
| Shared experts | 1 | 1 |
| Routed-expert hidden dim | 768 | 512 |
| Total / active parameters | 30.6B / 3.27B | 78.1B / 3.46B |
| Pre-training tokens | 8T | 24T |
| Context | 64k | 256k trained, 1M usable |
Kolibri Origin was an internal model that validated the whole pipeline at scale. In the three months between the two, almost every stage changed. Each block uses sandwich normalisation: an RMSNorm before and after both the attention and the MoE sublayers. Training ran on 768 B200 GPUs: 20T tokens of pre-training at 16k context, 3.44T of mid-training at 64k, and 200B of long-context extension at 256k.
The sparsity is , or 4.4%. Origin activated .
3. UniBPE: Choosing Merges by the Unigram Loss
3.1 Two ways to build a vocabulary
Byte Pair Encoding (BPE) builds a vocabulary bottom-up. It starts from bytes and repeatedly merges the adjacent pair that occurs most often, times, into a new token . Unigram tokenisers work top-down. They start from a huge vocabulary and prune the tokens whose removal hurts a likelihood the least. UniBPE keeps BPE’s procedure but swaps its ranking criterion for Unigram’s likelihood.
3.2 The Unigram loss of a tokeniser state
A tokeniser state gives every token a count over the training corpus, with tokens in total. The Unigram model assigns token the probability . The negative log-likelihood of the corpus under this model is the sum, over every token occurrence, of . Token occurs times, so
Split the logarithm with the logarithm quotient rule, :
The second sum is , so the last term is :
is times the entropy of the unigram distribution. Lower means a shorter, more predictable token stream. Unigram tokenisers minimise it top-down by pruning tokens. UniBPE minimises it bottom-up, by merging.
3.3 The change of the loss under one merge
Merge the pair , with , which occurs times. Exactly four counts change:
- loses occurrences: .
- loses occurrences: .
- The new token appears with count (from ).
- The corpus gets shorter by tokens: , because two tokens become one each time.
Every other count is untouched, so its term cancels in the difference. Substitute into the boxed and subtract. Each term flips sign when it moves to the other side:
BPE ranks candidates by alone. UniBPE ranks them by , most negative first. Both need only the pair count and the two parent counts, so UniBPE costs nothing extra over BPE.
3.4 Numerical check: ung against en
Suppose our tokeniser has already merged n + g into ng. The state now holds the counts , , , , and tokens in total. Two candidate merges compete:
- (e, n), the very frequent German ending -en, occurs times.
- (u, ng), the suffix -ung, occurs times. Every u in this corpus is followed by ng.
BPE takes , since .
UniBPE on (e, n). The values of we need are , , , , , , and . Then
The merge raises the loss.
UniBPE on (u, ng). Here and , so the first bracket is , which cancels exactly against the new-token term :
The merge lowers the loss by 18.2. UniBPE merges ung, and Zeitung becomes Zeit + ung.
3.5 What really measures: pointwise mutual information
Why does the rarer pair win? When is small compared with , and , each difference is well approximated by . This is a first-order Taylor approximation. Applying it to the three differences:
The terms give . Collecting the logarithms with the logarithm product and quotient rules:
where is the pointwise mutual information of the pair. It is large when and co-occur far more often than independent tokens would.
So BPE ranks by frequency alone, while UniBPE ranks by frequency × (PMI − 1). A merge lowers the loss only if the pair is more associated than chance by a factor of more than .
Check on our pairs. For , . The two letters co-occur exactly as often as chance predicts. The approximation gives , and the exact value is ; both are positive. For , . The approximation gives , and the exact value is ; both are negative. The magnitudes differ because is not small here (all six u are consumed), but the sign and the ranking agree.
This is why UniBPE lands on morphemes. A suffix like -ung or a prefix like ver- is a highly associated unit, while -en is a frequent but weakly associated letter pair. In the first 60 merges on the pre-training data, UniBPE produces und, ung, ver and the characters ü, ä, ö, ß. BPE has no German units at all by merge 60.
3.6 The production tokeniser
Pure UniBPE was used for Kolibri Origin and hurt compression, because some useful merges are hard for it. One example is joining .. into .... Kolibri’s tokeniser is therefore a hybrid. Starting from 256 byte tokens, it performs UniBPE merges, then 7,900 standard BPE merges, then adds 100 reserved and special tokens. That makes 128,000 tokens. Digits are split one per token, and the tokeniser was trained on a 100 GB slice of the pre-training data.
| Kolibri | GPT-5 | Plain BPE (same data) | |
|---|---|---|---|
| Vocabulary | 128,000 | 200,019 | 128,000 |
| German bytes/token | 4.90 | 4.35 | 4.89 |
| English bytes/token | 4.58 | 4.67 | 4.59 |
| German morpheme precision | 65.2% | 47.3% | 60.2% |
| English morpheme precision | 50.0% | 40.1% | 36.4% |
Morpheme precision is the share of word-internal token boundaries that fall on a true morpheme boundary. Kolibri compresses German best of the twelve tokenisers tested, needing 11.2% fewer tokens than GPT-5, and stays close on English. In a matched ablation at proxy scale, it reaches the same bits per byte as plain BPE but higher recall on long-context variable tracking and key-value retrieval at every length.
4. Hybrid Attention: 40 Windows and 10 Global Blocks
Kolibri uses full attention in every fifth block (10 of 50). The other 40 blocks use sliding-window attention (SWA) over the 512 preceding tokens. All blocks use GQA with 48 query heads and 4 KV heads of dimension 128.
4.1 KV-cache arithmetic
The KV cache stores each layer’s keys and values for past tokens. Per token and per layer, it holds
where the factor 2 counts keys and values. A full-attention block keeps this for all tokens of the context. A SWA block keeps it for at most , since older tokens are never attended again. The cache of one request is therefore
At :
That is 2.705 GB per 256k-token request with an FP8 cache (one byte per number). All-full attention would need GB, which is more. The 40 SWA blocks contribute of the cache.
Numerical check against the report. The report’s Table 31 estimates how many concurrent 256k-token FP8 requests fit on two H100s, for three model sizes from its sparsity sweep. It assumes a 10% fragmentation margin and 6 GB of activation workspace per GPU. Rebuilding the estimate:
where the billion parameters occupy GB in FP8. For : . For : . For : . All three match the report (33, 18 and 3). Applying the same formula to Kolibri’s 78.1B gives , so 19 concurrent 256k-token requests.
4.2 Choosing
The window was swept from 128 to 4096 at proxy scale M (7.8B total, 0.6B active). FLOPs, KV cache and parameters were matched by adapting the SWA heads and expert widths. Pre-training scores barely moved. On the pooled long-context score, led up to 64k but degraded at 128k. Validated at the larger scale L, and scored 48.0% and 47.8% on pre-training benchmarks, but led by 6.7 points at 256k. Kolibri takes , at a cost of 0.2 points of short-context accuracy.
4.3 RoPE only in the window, nothing in the global blocks
The SWA blocks use RoPE with . The full-attention blocks use no positional encoding (NoPE). A SWA block only ever sees relative offsets in , all of which it saw during training. A NoPE block has no notion of position at all. So the model never meets a relative position larger than any it was trained on, and it runs beyond its 256k training length without positional rescaling. At 1M tokens on RULER, Kolibri Base scores 63.2, above Nemotron 3 Nano Base (58.5) and Qwen3.5 Base with static YaRN (57.5).
4.4 QK normalisation also makes FP8 safe
Every block RMS-normalises queries and keys per head before RoPE: with . That bounds every element. Ignoring ,
because a single coordinate can never exceed the vector’s length, . With , every normalised element is at most times its gain. RoPE is a rotation and preserves the bound. So as long as the gains stay below , no query or key can exceed 448, the largest FP8 E4M3 value, and the FP8 KV cache used in RL cannot overflow. At proxy scale, removing QK normalisation made training diverge at the baseline learning rates. Keeping it only in the SWA blocks still produced gradient-norm spikes of several orders of magnitude.
5. How Sparse? The 80B Decision
At fixed expert width and top-, adding experts raises the total parameter count but leaves FLOPs per token almost unchanged. The sweep held 3.4B active parameters and tried 128, 256 and 384 routed experts, giving 42.1B, 82.3B and 122.6B total. Going from 42.1B to 82.3B clearly improved loss and accuracy. Going to 122.6B helped only slightly.
Total size is not free at inference. Decode is memory-bound, so every expert weight that has to be read costs time. At 4k context, the 82.3B and 122.6B models decode 13% and 32% slower than the 42.1B one. At 256k, where KV reads dominate, the gaps shrink to 4% and 12%. The deployment footprint is the Section 4.1 calculation: 18 long requests for 82.3B on two H100s, against 3 for 122.6B. Kolibri targets about 80B total.
With the size fixed, two ablations set the shape. For expert granularity at roughly 80B, 6-of-384 experts of width 512 (loss 1.847) beat 12-of-512 (1.848) and 6-of-256 of width 1024 (1.860). For residual width at matched FLOPs, wider was better: width 1600 reached loss 2.109, against 2.132 for width 1024.
6. Routing and the Two Kinds of Balance
6.1 The routing equations
For tokens and routed experts, the router produces logits . A bias vector is added for selection only:
Two details matter. The mixture weights are the unbiased sigmoid scores, so decides who is chosen but not how much they contribute. And the selected scores are not renormalised to sum to one.
The running example. Our four tokens produce these logits:
| Top-2 | |||||
|---|---|---|---|---|---|
| “Die” | 2.0 | 0.5 | −2.0 | −1.0 | |
| ” Zeit” | 2.0 | 3.0 | 0.5 | −1.0 | |
| “ung” | 0.0 | 2.0 | −0.5 | −1.0 | |
| ” erscheint” | 2.0 | 0.0 | −1.5 | −1.0 |
With , every token picks . The loads are , and experts 3 and 4 receive no tokens and no gradient.
6.2 Measuring imbalance: MaxVio
The target load is : each of tokens makes choices, spread evenly over experts. Here it is . The maximum violation is
The busiest expert carries twice its share. There are two distinct requirements. Global balance, over the whole optimiser-step batch, ensures every expert gets learning signal. Local balance, within each microbatch, keeps expert-parallel GPUs equally busy. Over the Kolibri pre-training run, the global MaxVio averaged 0.31 across layers.
7. Exact Quantile Balancing (EQB)
7.1 Quantile Balancing
Quantile Balancing computes a token bias and an expert bias by alternating quantile updates:
Why the minus sign. Subtracting the -th largest entry of a list from every entry leaves exactly entries positive, assuming no ties. So adding to row leaves exactly positive entries, one per selection. Adding to column leaves exactly positive entries, which is that expert’s fair share. Each training step performs one token update and then one expert update. The expert biases are centred (their mean is subtracted), and routing uses the top- of . The token biases are discarded; per-token top- approximates them.
7.2 Numerical check: one update repairs the collapse
Here , , , so . Starting from :
Token biases. of each row is its third-largest logit:
- : sorted , third , so .
- : sorted , third , so .
- : sorted , third , so .
- : sorted , third , so .
Expert biases. Add down each column, then take the third largest:
- : , sorted , so .
- : , sorted , so .
- : , sorted , so .
- : , sorted , so .
Check: each column of now has exactly two positive entries. For the column becomes , with two positives.
Centre. The mean of is , so .
Route with :
| Top-2 | |||||
|---|---|---|---|---|---|
| 1.0 | −0.5 | −1.0 | 0.0 | ||
| 1.0 | 2.0 | 1.5 | 0.0 | ||
| −1.0 | 1.0 | 0.5 | 0.0 | ||
| 1.0 | −1.0 | −0.5 | 0.0 |
The loads are now , and MaxVio drops from 1.0 to 0.
The mixture weights still use the unbiased scores. Token goes to with weight and to with weight . The two weights sum to , not 1, because nothing renormalises them. The bias moved to , but the model still sees that the router itself thinks little of for this token.
7.3 Why “exact”: the quantile of a distributed batch
In real training, the global batch is split across data-parallel ranks and gradient-accumulation microbatches. The token bias needs only the token’s own row, so it is local. The expert bias needs a quantile of a column across every token in the global batch.
Suppose live on rank A and on rank B. Column is on A and on B. One published approach averages per-rank quantiles. Each rank has 2 tokens and a local share , so each takes its second largest: on A and on B. The average is . The true global quantile is , so averaging gives instead of . The average of quantiles is not the quantile of the union. Another approach sums 1000-bin histograms across ranks, which represents the union but is only accurate to the bin width.
EQB computes the global quantile exactly with two-pass radix selection. Every bfloat16 value is encoded as an order-preserving 16-bit integer key. In pass one, each rank builds a 256-bin histogram of the high byte of its keys, and the histograms are summed with one all-reduce. Scanning bins from the top shows which bin contains the target rank. In pass two, the ranks histogram the low byte of only the keys inside that bin, all-reduce again, and read off the exact value.
A two-digit analogue. Scale our column by 10 to get keys , and treat the tens digit as the high byte. Pass one counts tens digits: bin 3 holds 2 keys, bin 1 holds 1, bin 0 holds 1. We want the 3rd largest. Bin 3 covers ranks 1–2 and bin 1 covers rank 3, so the answer lies in bin 1. Pass two looks at the units digits inside bin 1, which is just , giving key , or . That is exact, with no bin-width error.
The cost does not depend on : two all-reduces of int32 counts per layer per step. For that is bytes per all-reduce. EQB has no balancing hyperparameter at all.
8. Load-Error Injection (LEI): Balance Inside Each Microbatch
One global cannot balance every microbatch individually. The usual fix is a GShard-style auxiliary loss, but that loss was derived for softmax probabilities that sum to one, and Kolibri’s sigmoid scores do not. LEI instead writes each expert’s load error directly into the gradient of the scores. For a microbatch :
where is the incoming gradient with respect to . The scaling factor is defined as 1 at by continuity. Kolibri uses and . The report’s companion paper derives this update as the straight-through estimator for unnormalised sigmoid scores. The GShard loss is the corresponding estimator for normalised softmax probabilities.
Numerical check. Treat our four tokens as one microbatch, before EQB has acted. The loads are against a target of , so
Every token’s score gradient receives . Gradient descent subtracts the gradient, so the scores of the overloaded are pushed down and those of the idle are pushed up, for every token in the microbatch.
The push reaches the router logits through the chain rule, . For and , , so the logit receives .
Why : a bounded injection. Each entry obeys , so
since . However lopsided a microbatch is, the injection never exceeds . The report found this bound helps training stability. When imbalance is small, and the injection is simply , proportional to the error.
The two mechanisms split the work. EQB holds global balance with no tunable knob. LEI’s single coefficient then governs local balance and throughput, which gives fewer and less sensitive hyperparameters than Origin’s mix of bias updates and an auxiliary loss. Pre-training throughput stayed flat at about 16,500 tokens/s/GPU across the run, with no expert-parallel degradation.
9. When the Bias Wins: The Signature
Balance metrics can look perfect while the router has been silently overruled. Kolibri drops Origin’s two leading dense blocks. An ablation at 327.6B tokens favoured all-MoE (loss 1.847 against 1.850). The full run then revealed a problem. To see it, compare the router’s own choice with the routed choice :
In the running example. Token ‘s own top-2 is and it was routed to , an overlap of 1, so . Every token has overlap 1, so .
What a fully overruled router looks like. Suppose the bias dominates so completely that the routed set is a uniformly random -subset, unrelated to the router’s preference. Each of the router’s preferred experts then lands in the routed set with probability . By linearity of expectation, the expected overlap is , so
In our toy, , the same value we computed. With only 4 experts and , one EQB step is indistinguishable from random routing by this metric alone. For Kolibri, .
What happened. In Kolibri’s first two MoE layers, the intervention rate climbed to 98.5% by the end of pre-training, which is the random-routing value. Their intrinsic top- mass was the highest of all layers: the router had strong preferences. But the mass on the actually selected experts fell to near . To confirm, one layer at a time was perturbed at step 225,000, either replacing routed experts with random ones or silencing them entirely while keeping the shared expert. Only for layers 0 and 1 did the loss change by nothing measurable. Their routed experts are effectively unused. An attempt to densify these layers during SFT gave no clear gain, and fixing them is left to future work. A high intervention rate alone is not damning, though: layer 48 also has one, yet perturbing it clearly raises the loss.
10. Optimisation and Hyperparameter Transfer
Kolibri trains with Warmup-Stable-Merge. The learning rate warms up linearly over the first 100B tokens and then stays constant through all three stages. The base model is the average of the last 20 long-context checkpoints, taken 10B tokens apart. Attention and expert weights use Muon in the spectral convention, scaling each orthogonalised update by , which makes its learning rate width-independent. Embeddings and norm scales use Adam, and the LM head and router use AdamW with . The attention output and expert down-projections start at zero, so every block starts as the identity.
Width transfer uses P on 50-layer proxies of width 1024 and 2048. Their optimal learning rates differed by one grid step, and losses within one step of the optimum differed by less than 0.1%.
Horizon transfer uses loss extrapolation with a power law in the cumulative learning rate:
Deriving . During warmup over tokens, the learning rate rises linearly from to , so its integral over warmup is the area of a triangle, . After warmup it stays at for tokens. The total is
So the cumulative learning rate is proportional to . With B and T, the coordinate is T.
Sweeping Muon learning rates from to and two batch sizes on a half-width proxy for 500B tokens, the observed optimum sat at the largest learning rate. The fitted laws extrapolated to 20T moved it to with batch 4,608 sequences of 16k tokens: M tokens per step. Weight decay beat and at every forecast horizon.
11. Data and Stages, Briefly
Pre-training (20T at 16k). The pool holds 78 datasets and 29.3T tokens. Aleph Alpha’s own Common Crawl pipeline extracts over 308B documents. Exact deduplication across snapshots leaves 21.16B; fuzzy MinHash deduplication removes a further 25.9%; substring deduplication removes 21.3% of the remaining bytes. German makes up 21.3% of training tokens. About 0.8T of it is organic web text, and about 1.1T comes from rephrasing German documents, which keeps German subject matter and register in a way translation would not. English quality scores blend five classifier heads on the probability simplex. The source mix is fit by a log-linear law over 3,354 proxy runs.
Mid-training (3.44T at 64k). Mid-training shifts the mix towards English instruction and reasoning, STEM QA and code, which together hold 73% of the budget. The pool is decontaminated against all 226 evaluation tasks. The switch from the pre-training mix is a linear blend over the first B tokens. If the pre-training share decays as , the cumulative pre-training tokens by position are
To place a pre-training bulk whose token midpoint is , solve . This is , and the quadratic formula, taking the root inside , gives
At , the total is B pre-training tokens in the window, as the report states.
Long-context extension (200B at 256k). One third of the data comes from naturally long documents, one third () from the mid-training pool reweighted towards long documents, and the rest from the natural mid-training mix. The reweighting gives length band (0 for up to 8k tokens, up to 5 for 128k–256k) the weight . That is for the 64k–128k band and for the longest. Checkpoint merging recovered the small loss of short-context ability that long-context training caused.
12. Results
Pre-training benchmark averages, Overall English / German:
| Model | Active | EN | DE |
|---|---|---|---|
| Kolibri Base | 3.46B | 81.1 | 81.5 |
| Kolibri Origin Base | 3.27B | 58.4 | 61.1 |
| Nemotron 3 Nano Base | 3B | 77.5 | 76.0 |
| Qwen3.5 35B-A3B Base | 3B | 73.8 | 76.6 |
| Gemma 4 26B-A4B Base | 4B | 58.1 | 61.1 |
| GLM-4.5 Air Base | 12B | 77.1 | 79.4 |
| Nemotron 3 Super Base | 12B | 83.1 | 85.0 |
| OLMo 3 32B | 32B | 67.9 | 65.2 |
Kolibri Base leads every model up to 5B active parameters and is second only to Nemotron 3 Super, which activates more than three times as many parameters. It is first on the English math average (84.9). Code is its relative weak spot against the 12B-active models.
The report flags one caveat itself. HumanEval completions during pre-training recite the reference solution 22% to 95% of the time, and pass@1 tracks the recited share with Pearson . The pre-training pool is not decontaminated, so the HumanEval numbers are inflated.
On “I don’t know” variants of seven multiple-choice tasks, Kolibri Base has the second-best distributional correctness score. It moves more probability onto abstention or the right answer than any similar-sized model.
Summary
UniBPE ranks merges by the change in Unigram loss, , which to first order is . It therefore prefers associated units like -ung over merely frequent pairs like -en, and gives German its best compression and morphology among the tokenisers tested. Ten NoPE global blocks and forty 512-token RoPE windows cut the KV cache to about 20% of full attention, numbers per request, and let the model run past 256k without rescaling. In the sparse MoE behind them, Exact Quantile Balancing finds the exact global quantile of each expert’s column, repairing our collapsed router to in one step. Load-Error Injection adds a gradient bounded by to balance each microbatch. An intervention rate near exposed Kolibri’s first two layers as routing effectively at random.
Enjoyed this post?
Subscribe to get notified when I publish new posts. No spam, unsubscribe anytime.