LLM直接生成权重代码:无需梯度下降构建语言模型
I built an LLM where Gemini 4 wrote the initial weights as code (97% of bytes)
这是一篇极具启发性的架构创新论文,展示了利用 LLM 直接生成模型权重的全新范式,突破了传统依赖梯度下降的训练路径,值得研究模型底层机制的同学深入阅读。
An LLM writes the program that fills 97% of a language model's stored weights with corpus statistics, with no gradient step. Gradient descent trains only a 103M-parameter network on top, and the model supports continual knowledge updates without training.
一个大型语言模型(LLM)编写了一个程序,该程序将语料库统计信息填充到语言模型存储权重的97%中,无需梯度步骤。梯度下降仅在其顶部训练一个拥有1.03亿参数的网络,且该模型支持无需训练的持续知识更新。
An LLM writes a program P that compiles a text corpus D into frozen sparse tables T = P(D). The Transformer reads the tables at every position, through an Engram block after its fourth layer and through gated fusion with its output logits, and only the network is trained. After pretraining, an external edit layer (dashed) adds facts without any training.
一个LLM编写了一个程序P,将文本语料库D编译为冻结的稀疏表T = P(D)。Transformer在每个位置读取这些表,通过其第四层之后的Engram块以及与其输出logits的门控融合来读取,仅对该网络进行训练。预训练完成后,外部编辑层(虚线所示)可在无需任何训练的情况下添加事实。
Abstract
摘要
Weight-space programming (WSP) is the idea that a frontier LLM can read and write the weights of a neural network directly, without gradient descent. So far, however, WSP has been limited to small networks or to sparse edits of existing models, and it has not been used to build a language model from scratch. We instead have an LLM write a compiler that builds the model's initial weights. The compiler turns 31.8B tokens of corpus statistics into a 7.96 GiB bank of sparse tables, over 97% of the model's stored bytes, without a single gradient step. Gradient descent then trains a 103M-parameter network on top of the frozen tables. After pretraining, an external edit layer adds new facts without any training, enabling continual knowledge updates. Trained on 10B tokens on a single GPU, the table model reaches a word-level perplexity of 46.4 on held-out FineWeb-Edu documents, 11% lower than a parameter-matched model without tables (52.1), comparable under standard parameter scaling laws to making the network about 1.5 times larger, and raises mean zero-shot accuracy on ten tasks by 1.2 points. Over 10,000 sequential WikiBigEdit edits, the edit layer answers 99.9% of the edited questions and 97.4% of their paraphrases, leaves 98.2% of unrelated answers unchanged, and changes perplexity by only 0.003%, at 12 ms per fact with no gradient step. Fine-tuning and LoRA, by comparison, recall at most 36.3% of the edits and push perplexity above 1,000. Code and results are available at github.com/Kim-Ai-gpu/wtable-lm.
权重空间编程(WSP)的理念是,前沿的大型语言模型可以直接读取和写入神经网络的权重,而无需梯度下降。然而迄今为止,WSP仅限于小型网络或对现有模型的稀疏编辑,尚未用于从头构建语言模型。我们转而让LLM编写一个编译器来构建模型的初始权重。该编译器将318亿个token的语料库统计信息转化为一个7.96 GiB的稀疏表库,占模型存储字节的97%以上,且无需任何梯度步骤。随后,梯度下降在冻结的表格顶部训练一个拥有1.03亿参数的网络。预训练完成后,外部编辑层可在无需任何训练的情况下添加新事实,从而实现持续的知識更新。在单个GPU上使用100亿个token进行训练后,该表格模型在未见的FineWeb-Edu文档上达到了46.4的词级困惑度,比没有表格的参数匹配模型(52.1)低11%,在标准参数缩放定律下与使网络增大1.5倍相当,并将十个任务的平均零样本准确率提高了1.2分。在超过10,000次连续的WikiBigEdit编辑中,编辑层回答了99.9%的被编辑问题和97.4%的改写问题,保持98.2%的不相关问题答案不变,且困惑度仅变化0.003%,每个事实的处理时间为12毫秒,无需梯度步骤。相比之下,微调(Fine-tuning)和LoRA最多只能回忆出36.3%的编辑内容,并使困惑度升至1,000以上。代码和结果可在github.com/Kim-Ai-gpu/wtable-lm获取。
Results
结果
Hover over any bar or point for exact values.
悬停在任意条形或点上可查看精确数值。
Same network, lower perplexity
相同的网络,更低的困惑度
Both models have the same backbone, about 103M trained parameters, and the same 10B training tokens. The only difference is the frozen tables.
两个模型具有相同的主干结构、约1.03亿个可训练参数以及相同的100亿训练token。唯一的区别在于冻结的表格。
Word-level perplexity on 2,000 held-out FineWeb-Edu test documents, context 1,024. The 1.5× estimate uses the parameter scaling law of Kaplan et al. (2020), loss ∝ N−0.076.
在2,000份保留的FineWeb-Edu测试文档上的词级困惑度,上下文长度为1,024。1.5×估计值采用Kaplan等人(2020)的参数缩放定律,损失∝ N^−0.076。
Bigger tables keep helping
更大的表格持续带来帮助
Keep only the most frequent fraction F of table entries in the trained model, without retraining. Perplexity improves with every doubling and shows no sign of saturating.
仅在训练后的模型中保留出现频率最高的F比例的表格条目,无需重新训练。随着条目数量每翻倍一次,困惑度都会改善,且未见饱和迹象。
Show
显示
Validation perplexitydev-9 accuracy
验证集困惑度 dev-9 准确率
Zero-shot accuracy
零样本准确率
Accuracy of the table model minus the baseline on ten tasks. The largest gains come on tasks that reward common associations between words and events.
表格模型相对于基线在十个任务上的准确率提升。最大的增益出现在那些奖励词语与事件之间常见关联的任务上。
lm-eval 0.4.13, zero-shot, length-normalized accuracy where available. Results on all 21 evaluated tasks are in the paper's appendix.
lm-eval 0.4.13,零样本模式,在可用情况下使用长度归一化准确率。所有21个评估任务的结果见论文附录。
Adding 10,000 facts after pretraining
预训练后添加10,000条事实
WikiBigEdit facts are applied one batch after another and never undone. The edit layer stores each fact as a record and trains nothing. Weight editing keeps learning the new facts but forgets the old ones and damages the model.
WikiBigEdit 事实按批次依次应用,且永不撤销。编辑层将每条事实存储为一条记录,不进行任何训练。权重编辑虽然能继续学习新事实,但会遗忘旧事实并损害模型性能。
Metric
指标
UpdateRephrase PersonaLoc keep Perplexity
更新 改写 人格保持 困惑度
Show results after 10,000 edits
显示经过10,000次编辑后的结果
EM is SQuAD-normalized exact match (%). Loc keep is the share of unrelated questions whose answer did not change. Perplexity is word-level on 2,000 validation documents. Time is the editing cost per fact on one T4 GPU.
EM是SQuAD标准化的精确匹配率(%)。Loc keep是指答案未发生变化的无关问题的比例。困惑度基于2,000份验证文档的词级计算。时间是单张T4 GPU上每条事实的编辑成本。
How the edit layer adds a fact
编辑层如何添加事实
Writing facts into the tables fails, because the last few tokens before an answer are almost always the same question template. The edit layer keeps facts outside the tables instead.
将事实写入表格会失败,因为答案前的最后几个令牌几乎总是相同的问题模板。因此,编辑层将事实存储在表格之外。
1
Store a record
存储一条记录
Subject tokens, a key (the hidden state where the answer should be given) and the answer tokens. One forward pass, about 12 ms, no gradient step.
主体令牌、一个键(应给出答案的隐藏状态位置)以及答案令牌。只需一次前向传播,耗时约12毫秒,无需梯度步骤。
2
Fire only when it should
仅在必要时触发
The subject must appear verbatim in the last 64 tokens (stored with and without a leading space, never inside a longer word), and the raw hidden state must match the key, cos(ht, ki) ≥ 0.93. No statistics of the prompt template are needed.
主体必须以前64个令牌中的字面形式出现(存储时包含和不包含前导空格,绝不出现在更长单词的内部),且原始隐藏状态必须与键匹配,cos(ht, ki) ≥ 0.93。无需提示模板的任何统计信息。
3
Push the answer
推高答案
The stored answer token is raised 1.5 above the current top logit, one token after another, until the answer ends.
存储的答案令牌被逐个提升,使其比当前最高logit高出1.5,直到答案结束。
Records are plain data, so a person or an LLM can write, inspect or delete them. A new edit for the same subject and relation replaces the old one.
记录是纯数据,因此人或大语言模型都可以写入、检查或删除它们。针对同一主体和关系的新编辑将替换旧编辑。
Eighteen channels, one interface
十八个通道,一个接口
Every channel answers in the same form, a short list of next-token candidates with scores, so the network only learns how much to trust each one at each position.
每个通道都以相同的形式回答,即一个带有分数的下一个 token 候选者短列表,因此网络只学习在每个位置上对每个通道的信任程度。
| Group | Predicts the next token from | Channels |
|---|---|---|
| n-gram | the last 1 to 5 tokens | 5 |
| Skip-gram | earlier tokens, with gaps | 3 |
| Synonym | synonym clusters of recent tokens | 2 |
| Concept | associations between concepts | 2 |
| Rule | explicit phrase and fact rules | 2 |
| In-context | the current document | 4 |
| 组别 | 从...预测下一个 token | 通道数 |
|---|---|---|
| n-gram | 最后 1 到 5 个 token | 5 |
| Skip-gram | 较早的 token,存在间隔 | 3 |
| 同义词 | 近期 token 的同义词簇 | 2 |
| 概念 | 概念之间的关联 | 2 |
| 规则 | 显式短语和事实规则 | 2 |
| 上下文内 | 当前文档 | 4 |
The first five groups are counted from 31.8B FineWeb-Edu tokens, disjoint from the network's training data. The compiler was designed by Gemini 4 Neon.
前五个组的计数基于 31.8B FineWeb-Edu token,与网络的训练数据不重叠。编译器由 Gemini 4 Neon 设计。
Citation
引用
Copy
复制
@article{202611.3172,
doi = {10.20944/preprints202611.3172.v1},
url = {https://doi.org/10.20944/preprints202611.3172.v1},
year = 2026,
month = {November},
publisher = {Preprints},
author = {Youngseong Kim},
title = {A Language Model Architecture Whose Initial Weights an LLM Can Write as Code},
journal = {Preprints}
}更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力