Experiments›Sampled Softmax with Over-Tokenized Transformer
Oct 3, 2026

Sampled Softmax with Over-Tokenized Transformer

By Wenhao Chai作者 Wenhao Chai

Setup设置

The baseline is the MuonH Qwen3 recipe of the Marin speedrun, which covers 130m to 1.2B parameters. We replace the softmax of the training loss with a sampled softmax and add the input and output vocabularies of the Over-Tokenized Transformer, or OT. OT adds hashed 2-gram and 3-gram embeddings to each input token, and we test two forms of its output side: OT-H (head), the paper's form, a second head that predicts the token two positions ahead; and OT-2 (2-gram), a real output vocabulary of hashed 2-grams. Each setup is judged by its training speed and by its Paloma loss against backbone compute 6ND, where N counts the parameters of the transformer layers without the embedding and the heads, and D the training tokens. Code

基线是 Marin speedrun 的 MuonH Qwen3 配方,覆盖 130m 到 1.2B 参数。我们把训练损失中的 softmax 换成采样 softmax,并在输入端和输出端加上 Over-Tokenized Transformer 的输入和输出词表,简称 OT。OT 给每个输入词加上 2-gram 和 3-gram 的 hash embedding;输出端我们测试两种形式:OT-H(head),即论文的形式,用第二个头预测往后第二个位置的词;OT-2(2-gram),真正的 hash 2-gram 输出词表。每种做法看训练速度,以及 Paloma 损失随骨干算力 6ND 的变化,其中 N 是 transformer 各层的参数量,不含 embedding 和输出头,D 是训练 token 数。代码

--- baseline loss (simplified)+++ OT-H + sampled softmax (simplified; the Code link has the real code) def loss_fn(model, tokens):     targets = tokens[1:]-    x = model.embed(tokens[:-1])+    # OT, input: add the hashed 2-gram and 3-gram embeddings that end at each token+    x = model.embed(tokens[:-1]) + model.ngram_embed(tokens[:-1], n=2) + model.ngram_embed(tokens[:-1], n=3)     h = model.norm(model.blocks(x))-    logits = h @ model.head.weight.T-    return cross_entropy(logits, targets)+    # sampled softmax: score this GPU's targets plus random negatives, P tokens in all+    cand = targets.unique() + random_tokens(P - len(targets.unique()))+    logits = h @ model.head.weight[cand].T+    loss = cross_entropy(logits, position_in(cand, targets))+    # OT-H, output: a second head predicts the token two positions ahead, at weight 0.1+    loss += 0.1 * cross_entropy(model.head2(h[:-1]), tokens[2:])+    return loss
--- 基线损失(简化)+++ OT-H + 采样 softmax(简化;真实代码见“代码”链接) def loss_fn(model, tokens):     targets = tokens[1:]-    x = model.embed(tokens[:-1])+    # OT 输入端:加上以每个词结尾的 2-gram 和 3-gram 的 hash embedding+    x = model.embed(tokens[:-1]) + model.ngram_embed(tokens[:-1], n=2) + model.ngram_embed(tokens[:-1], n=3)     h = model.norm(model.blocks(x))-    logits = h @ model.head.weight.T-    return cross_entropy(logits, targets)+    # 采样 softmax:只给本 GPU 的目标词和随机负样本打分,共 P 个词+    cand = targets.unique() + random_tokens(P - len(targets.unique()))+    logits = h @ model.head.weight[cand].T+    loss = cross_entropy(logits, position_in(cand, targets))+    # OT-H 输出端:第二个头预测往后第二个位置的词,权重 0.1+    loss += 0.1 * cross_entropy(model.head2(h[:-1]), tokens[2:])+    return loss

Experiments实验

Answered已有结论Do the sampled softmax and OT-H make pretraining cheaper or better?采样 softmax 和 OT-H 能让预训练更省或更好吗?

The sampled softmax trains faster at every size and ends level with the baseline; OT-H lowers the loss up to 520m and raises it at 1.2B, the one size that repeats most of its data.

采样 softmax 在每个规模上都训练得更快,最终损失与基线持平;OT-H 在 520m 及以下降低损失,在 1.2B 上反而升高损失,而 1.2B 是唯一把大部分数据重复使用的规模。

Baseline基线 Baseline基线

The MuonH Qwen3 recipe, unchanged: the softmax scores all 128K tokens.MuonH Qwen3 配方,不做改动:softmax 给全部 128K 个词打分。

Sampled softmax采样 softmax

Training scores a sample of the vocabulary that grows from 19% to 51%, and the last 7% of steps use the full softmax.训练时只给词表的一部分打分,比例从 19% 增加到 51%,最后 7% 的步数用完整 softmax。

OT-HOT-H

Hashed 2-gram and 3-gram embeddings join each input token, and a second head predicts the token two positions ahead.每个输入词加上 2-gram 和 3-gram 的 hash embedding,第二个头预测往后第二个位置的词。

OT-H + sampled softmaxOT-H + 采样 softmax Main主做法

Both changes, with the sampled softmax on both heads.两处改动都用,两个头都用采样 softmax。

Answered已有结论Does a change to the training loss help OT-H further?改训练损失能让 OT-H 更好吗?

Not much: focal loss changes the loss of OT-H little, and the sampled softmax helps OT-H only at 130m, not at the larger sizes.

帮助不大:focal loss 对 OT-H 的损失影响很小;采样 softmax 只在 130m 上让 OT-H 更好,在更大的规模上没有帮助。

OT-H + focal lossOT-H + focal loss

OT-H with each token's loss weighted by how badly the model predicts it, at 130m.在 130m 上给 OT-H 加 focal loss:模型预测得越差的词,损失权重越大。

Answered已有结论Why does OT-H lose at 1.2B?OT-H 为什么在 1.2B 上变差?

Because the data repeats: at 300m with 2.4 passes OT-H falls behind after each new pass, the large n-gram input tables cause it, and tables ten times smaller, or frozen after the first pass, shrink the damage.

因为数据重复:在 300m 上训练 2.4 遍时,每开始新的一遍,OT-H 都会落后;原因是大的 n-gram 输入表;把表缩小 10 倍,或在第一遍后冻结表,都能减轻损失。

OT-H with 1.28M-row tablesOT-H,表 1.28M 行

OT-H with each n-gram embedding table cut from 12.8M to 1.28M rows.OT-H 的每张 n-gram embedding 表从 12.8M 行减到 1.28M 行。

OT-H without the second headOT-H 去掉第二个头

OT-H with only its n-gram input tables: one head predicts the next token.OT-H 只保留输入端的 n-gram 表:只有一个头预测下一个词。

OT-H with tables frozen from pass 2OT-H 从第 2 遍起冻结表

OT-H whose n-gram tables stop updating when the second pass over the data begins.OT-H 的 n-gram 表从第二遍数据开始不再更新。

Answered已有结论Does a real 2-gram output vocabulary beat the head of OT-H?真正的 2-gram 输出词表能胜过 OT-H 的头吗?

Weakly: at 300m OT-2 ends ahead of OT-H with and without the sampled softmax, by a margin close to the noise of single runs; at 130m the four setups end within noise of each other.

证据较弱:在 300m 上,无论是否用采样 softmax,OT-2 最终都领先 OT-H,但领先的幅度接近单个 run 的噪声;在 130m 上,四种做法的最终结果都在噪声范围内。

OT-2OT-2

The second head scores whole 2-grams, hashed into 12.8M classes with their own output embeddings, by a sampled softmax.第二个头直接给整个 2-gram 打分:2-gram hash 到 12.8M 类,每类有自己的输出 embedding,用采样 softmax 训练。

OT-2 + sampled softmaxOT-2 + 采样 softmax

OT-2 with the sampled softmax on its main head as well, as OT-H + sampled softmax has on both of its heads.OT-2 的主头也用采样 softmax,和 OT-H + 采样 softmax 两个头都用采样 softmax 一样。

Takeaways核心结论

A sampled softmax trains the Marin recipe 1.07–1.30× faster from 130m to 1.2B at no cost in loss; the Over-Tokenized Transformer's input tables lower the loss up to 520m but overfit repeated data, which turns the gain into a loss at 1.2B, and a real 2-gram output head adds at most a small gain.

采样 softmax 让 Marin 配方在 130m 到 1.2B 上训练快 1.07–1.30 倍,损失不变;Over-Tokenized Transformer 的输入表在 520m 及以下降低损失,但会在重复数据上过拟合,使 1.2B 上的增益变成损失;真正的 2-gram 输出头最多只带来很小的增益。

Acknowledgements致谢

The author is pleased to acknowledge that the work reported on in this post was substantially performed using the Princeton Research Computing resources at Princeton University. Princeton Research Computing is a consortium of groups including the Princeton Institute for Computational Science and Engineering (PICSciE) and Research Computing at Princeton University.

本文报告的工作主要使用普林斯顿大学 Princeton Research Computing 的计算资源完成。Princeton Research Computing 是由普林斯顿计算科学与工程研究所(PICSciE)和普林斯顿大学 Research Computing 等团队组成的联合体。

Experiment record实验记录

Citation

@misc{chai2026ssov,
  title        = {Sampled Softmax with Over-Tokenized Transformer},
  author       = {Chai, Wenhao},
  year         = {2026},
  howpublished = {Blog post},
  url          = {https://wenhaochai.com/exps/sampled-softmax-ov.html}
}
Experiments Back to top回到顶部