Table of Contents
Fetching ...

Programming by Backprop: An Instruction is Worth 100 Examples When Finetuning LLMs

Jonathan Cook, Silvia Sapora, Arash Ahmadian, Akbir Khan, Tim Rocktaschel, Jakob Foerster, Laura Ruis

TL;DR

Though execution of instructions in training data remains less reliable than when instructions are given in-context, the results demonstrate that procedural knowledge can be noisily `programmed'into LLMs through PBB, with important implications for data curation and safety.

Abstract

Large language models (LLMs) are typically trained to acquire behaviours from demonstrations or experience, yet much of their training data is declarative: instructions, rules, and descriptions that specify behaviours without showing how to execute them. We introduce Programming by Backprop (PBB): a training regime that enables LLMs to acquire procedural knowledge (i.e., reusable behaviours) from declarative instructions encountered during training. With PBB, instructions in training data provide an opportunity to `program' specific behaviours into model weights. The core principle underpinning PBB is the separation of learning how instructions map to behaviour from internalising new instructions. We devise two distinct PBB curricula that leverage this principle. Through controlled experiments across two domains (algorithmic execution from Python source code and text generation from context-free grammars), we demonstrate the benefit of these curricula over training on a homogeneous data mixture. Crucially, PBB is highly sample efficient, with a single instruction substituting for up to 100 execution examples. Though execution of instructions in training data remains less reliable than when instructions are given in-context, our results demonstrate that procedural knowledge can be noisily `programmed' into LLMs through PBB, with important implications for data curation and safety.

Programming by Backprop: An Instruction is Worth 100 Examples When Finetuning LLMs

TL;DR

Though execution of instructions in training data remains less reliable than when instructions are given in-context, the results demonstrate that procedural knowledge can be noisily `programmed'into LLMs through PBB, with important implications for data curation and safety.

Abstract

Large language models (LLMs) are typically trained to acquire behaviours from demonstrations or experience, yet much of their training data is declarative: instructions, rules, and descriptions that specify behaviours without showing how to execute them. We introduce Programming by Backprop (PBB): a training regime that enables LLMs to acquire procedural knowledge (i.e., reusable behaviours) from declarative instructions encountered during training. With PBB, instructions in training data provide an opportunity to `program' specific behaviours into model weights. The core principle underpinning PBB is the separation of learning how instructions map to behaviour from internalising new instructions. We devise two distinct PBB curricula that leverage this principle. Through controlled experiments across two domains (algorithmic execution from Python source code and text generation from context-free grammars), we demonstrate the benefit of these curricula over training on a homogeneous data mixture. Crucially, PBB is highly sample efficient, with a single instruction substituting for up to 100 execution examples. Though execution of instructions in training data remains less reliable than when instructions are given in-context, our results demonstrate that procedural knowledge can be noisily `programmed' into LLMs through PBB, with important implications for data curation and safety.

Paper Structure

This paper contains 44 sections, 4 equations, 15 figures.

Figures (15)

  • Figure 1: Illustration of Programming by Backprop (PBB) --- the learning of behaviours from instructions. We define train instructions as those for which examples of behaviour are also available. Evaluation instructions (yellow in the figure) correspond to the behaviours being tested, which are never demonstrated in training data. PBB comprises two training curricula: Proactive PBB, where models learn a general correspondence between instructions and behaviours before being exposed to evaluation instructions, and Retroactive PBB, where initial exposure to all instructions is followed by learning how to map those to behaviour using the train set.
  • Figure 2: PBB enables Qwen3-14B to learn an algorithm from a single instruction (piece of code) to similar efficacy as using Algorithm Distillation (AD) --- learning an algorithm from input-specific examples --- on 100 examples.
  • Figure 3: Upper Left: Accuracy when conditionally executing random arithmetic programs of different lengths provided in-context. Upper Middle: Accuracy following proactive PBB on executing unpaired programs. Explicitly computing intermediate operations via CoT is more effective than direct inference, but larger models show some ability to encode entire procedures in their weights via PBB. Upper Right: Accuracy following retroactive PBB throughout stage 2 training. RL is more effective, with SFT initially memorising paired executions before generalising execution ability to unpaired programs. Lower Left: Accuracy following each stage of proactive PBB. The full curriculum has a significant impact on performance. Lower Middle: Accuracy following proactive PBB when programs are represented as natural language or code. The role of prompt augmentations is also ablated. Lower Right: Accuracy following proactive PBB for compositions of two programs that have been trained on independently. Direct inference performance is only shown for GPT-4o as the smaller models fail in this setting.
  • Figure 4: Left: Accuracy following each stage of proactive PBB on Leetcode programs. Despite zero-shot performance being high in this setting, the full curriculum yields the greatest performance, showing that execution performance can be refined by further training on instructions. Right: Accuracy following retroactive PBB (RL) throughout Stage 2 training.
  • Figure 5: Finetuning GPT-4o on custom Ciphers via proactive PBB (Stage 1 Leetcode, Stage 2 Ciphers) yields greater robustness to shift variations than training on imbalanced demonstrations. Mixing Stage 2 training on cipher code with imbalanced demonstrations yields the best results, overcoming biases from demonstrations while grounding execution behaviour.
  • ...and 10 more figures