ProgramAsWeights:将英文函数描述编译为本地运行的神经程序
ProgramAsWeights: compile English function descriptions into neural programs that run locally [R]
提出了将自然语言规范编译为可复用神经程序的独特架构,小模型本地运行效果超越大模型直接提示,值得 Agent 开发者关注其工程落地潜力。
Given the recent interest in tools like Jev, I wanted to share ProgramAsWeights (PAW), an open-source research project I'm working on at the University of Waterloo.
鉴于近期人们对 Jev 等工具的关注,我想分享 ProgramAsWeights(PAW),这是我在滑铁卢大学从事的一个开源研究项目。
You describe a text function in English, compile it into a reusable neural program, and run it locally, including on a CPU. For example:
你用英文描述一个文本函数,将其编译为可重用的神经程序,并在本地运行,包括在 CPU 上运行。例如:
import programasweights as paw fn = paw.compile_and_load("Classify urgent emails") fn("Need this today") # "urgent" (runs locally)import programasweights as paw fn = paw.compile_and_load("Classify urgent emails") fn("Need this today") # "urgent" (runs locally)This example uses our hosted compiler for compilation (you can host your own compiler if you have a GPU using our released model weights). Once the program and local runtime are downloaded, subsequent calls run on your machine without an external API.
此示例使用我们托管的编译器进行编译(如果你有 GPU,可以使用我们发布的模型权重来托管自己的编译器)。一旦程序和本地运行时下载完成,后续调用将在你的机器上运行,无需外部 API。
The idea: separate compilation from inference
理念:将编译与推理分离
In many applications, the task stays fixed while the inputs keep changing. You define what makes an email urgent once, then apply that definition to thousands of emails.
在许多应用中,任务保持不变,而输入不断变化。你只需定义一次什么是紧急邮件,然后即可将该定义应用于数千封邮件。
There are two jobs here: understanding the function you want, and executing it repeatedly. Our idea is to train a larger model to generate the task-specific weights that let a smaller model do the second job.
这里有两个任务:理解你想要的函数,以及重复执行它。我们的想法是训练一个更大的模型来生成任务特定的权重,从而使较小的模型能够完成第二个任务。
The resulting function can be saved, distributed, and composed with ordinary code.
生成的函数可以被保存、分发,并与普通代码组合使用。
https://preview.redd.it/a5zxim8w8kqh1.png?width=2122&format=png&auto=webp&s=c009655b083bddd316687c2fdef0365c9334c82e
https://preview.redd.it/a5zxim8w8kqh1.png?width=2122&format=png&auto=webp&s=c009655b083bddd316687c2fdef0365c9334c82e
How it works
工作原理
https://preview.redd.it/g47kgyqq8kqh1.png?width=2462&format=png&auto=webp&s=28d0ea86131954e870ed7da8abb006e267b6bce7
https://preview.redd.it/g47kgyqq8kqh1.png?width=2462&format=png&auto=webp&s=28d0ea86131954e870ed7da8abb006e267b6bce7
Our standard compiler uses a finetuned Qwen3-4B model to generate a LoRA adapter for a frozen Qwen3-0.6B model, which we call the interpreter. Different functions use different adapters with the same base interpreter.
我们的标准编译器使用微调后的 Qwen3-4B 模型为冻结的 Qwen3-0.6B 模型生成 LoRA 适配器,我们将后者称为解释器。不同的函数使用不同的适配器,但共享同一个基础解释器。
A neural program contains two components:
神经程序包含两个组件:
- A LoRA adapter that specializes the interpreter for the task.
- A pseudo-program: a cleaned-up task description and a few input/output examples, generated at compile time and included in the interpreter’s prompt.
- 一个 LoRA 适配器,用于针对特定任务定制解释器。
- 伪程序:经过清理的任务描述以及少量输入/输出示例,这些内容在编译时生成并包含在解释器的提示词中。
The adapter-generation mechanism is similar to text-to-LoRA (Charakorn et al., 2025).
适配器生成机制类似于 text-to-LoRA(Charakorn 等人,2025)。
To train the compiler, we use triples of (task description, input, output). The compiler generates an adapter from the task description and pseudo-program. We attach that adapter to the interpreter and maximize the likelihood of the correct output for the given input.
为了训练编译器,我们使用三元组(任务描述、输入、输出)。编译器从任务描述和伪程序中生成适配器。我们将该适配器附加到解释器上,并最大化给定输入下正确输出的似然概率。
Gradients flow through the frozen interpreter into the compiler and its adapter-generating layers. The interpreter's base weights remain unchanged.
梯度通过冻结的解释器反向传播到编译器及其适配器生成层。解释器的基础权重保持不变。
This is one of the parts I still find surprising: the same frozen 0.6B model can become much more useful just by changing the program we load onto it. We're training the compiler to discover how to specialize it.
这是我仍然感到惊讶的部分之一:仅仅通过更改加载到其上的程序,同一个冻结的 0.6B 模型就能变得更有用。我们正在训练编译器去发现如何对其进行专门化。
After training, the standard compiler predicts adapter weights for a new specification directly. Compilation takes seconds, and the larger compiler is no longer needed when processing new inputs.
训练完成后,标准编译器可直接为新规范预测适配器权重。编译仅需数秒,处理新输入时不再需要大型编译器。
Results
结果
We built FuzzyBench, a synthetic dataset of specification/input/output examples covering classification, extraction, parsing, format conversion, and other text functions. The train/validation/test split is by specification, so test specifications are unseen during compiler training.
我们构建了 FuzzyBench,这是一个涵盖分类、提取、解析、格式转换及其他文本功能的规范/输入/输出示例的合成数据集。训练集/验证集/测试集的划分基于规范,因此编译器训练期间未见测试规范。
On FuzzyBench, PAW with the 0.6B interpreter reaches 73.4% exact-match accuracy, compared with 68.7% for direct prompting of Qwen3-32B. Our first paper includes the other benchmarks, baselines, and ablations.
在 FuzzyBench 上,配备 0.6B 解释器的 PAW 达到了 73.4% 的精确匹配准确率,而直接提示 Qwen3-32B 仅为 68.7%。我们的首篇论文包含了其他基准、基线及消融实验。
https://preview.redd.it/eylmemku8kqh1.png?width=1334&format=png&auto=webp&s=528adcbfab287f1f4028380399cfadf41040250f
https://preview.redd.it/eylmemku8kqh1.png?width=1334&format=png&auto=webp&s=528adcbfab287f1f4028380399cfadf41040250f
A higher-accuracy compilation mode
更高精度的编译模式
Because the generated program contains a LoRA adapter, we can also use it as an initialization for further training.
由于生成的程序包含 LoRA 适配器,我们还可以将其作为进一步训练的初始化参数。
Our follow-up, Compile by Training, does this automatically: teacher models synthesize task-specific examples, then we finetune the generated adapter for 100 steps. This takes roughly a minute in our deployment and produces the same reusable program format for the same local interpreter.
我们的后续工作 Compile by Training 实现了这一过程的自动化:教师模型合成特定任务的示例,随后我们对生成的适配器进行 100 步微调。在我们的部署中,这大约耗时一分钟,并为相同的本地解释器生成相同可重用的程序格式。
On FuzzyBench-Hard, a subset selected from specifications where the original PAW evaluation produced no exact matches, this reaches 83.6% semantic accuracy.
在 FuzzyBench-Hard(从原始 PAW 评估未产生任何精确匹配的规范中选取的子集)上,语义准确率达到 83.6%。
The two compilers offer different compile-time/accuracy tradeoffs. Both produce functions that run locally without teacher calls afterward.
两种编译器提供了不同的编译时间与准确率权衡。两者均生成功能函数,且在后续运行时无需调用教师模型即可在本地执行。
Trying it and building on it
尝试与扩展
My recommended workflow is to handwrite a small validation set, compile a specification, and inspect the errors. Then revise the specification or try the Finetune compiler.
我推荐的工作流程是:手写一个小型验证集,编译一个规范,并检查错误。然后修订规范或尝试 Finetune 编译器。
My longer-term hope is that large models can become tool builders: describe the function you need, get back a small neural program, and use it as part of your own software. This is what makes me excited about PAW beyond any individual benchmark.
我更长远的期望是大模型能成为工具构建者:描述你需要的功能,获得一个小型神经程序,并将其作为你自己软件的一部分使用。这正是让我对 PAW 感到兴奋的原因,其意义超越了任何单一基准测试。
I'd love to see people build on this, whether through better compilers, different interpreters, or applications we haven't considered. Happy to answer questions about the architecture, training details, and failure cases.
我很期待人们在此基础上进行构建,无论是通过更好的编译器、不同的解释器,还是我们尚未考虑的应用场景。很乐意回答关于架构、训练细节和失败案例的问题。
Papers
论文
- Program-as-Weights: A Programming Paradigm for Fuzzy Functions
- Compile by Training: Turning Natural-Language Specifications into Local Neural Functions
- Program-as-Weights: A Programming Paradigm for Fuzzy Functions
- Compile by Training: Turning Natural-Language Specifications into Local Neural Functions
Code and models
代码与模型
- Code
- compile-by-training
- Model weights
- 代码
- compile-by-training
- 模型权重
Demo: https://programasweights.com/playground
演示:https://programasweights.com/playground
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力