Elamur Research

Learning to Execute Programs with Instruction Pointer Attention Graph Neural Networks

Paper · 2020 · David Bieber, Charles Sutton, Hugo Larochelle et al.

Summary

The order in which a program is written can tell you surprisingly little about the order in which its statements will run. A short loop can account for much of a computation, and a branch can skip a block of code entirely. Given a program’s source code and a graph showing which statements can pass control to which others, can a neural network learn to predict the program’s result? That is the question David Bieber and his colleagues pose. They study this as a static analysis problem. In the main experiments, the predictor receives information that can be obtained from the source before execution. One task supplies the complete program, and the other hides an expression while keeping the original program’s result as the target.

The authors present IPA-GNN, short for Instruction Pointer Attention Graph Neural Network. It takes two ideas from an interpreter: keep track of where execution has reached, and use the current computational state to decide where to go next. The instruction pointer here is a distribution over statements. Each statement also has a vector that represents the state of the computation at that location. A learned recurrent update prepares a new state from the current one and the statement’s text. At a branch, learned weights allocate both the pointer and the state contribution across possible successors. The paper shows how this construction becomes a recurrent network following a single path when the branch choices are fully concentrated. Supplying the correct choices recovers a recurrent network over the actual execution trace.

The experiments use generated programs in a subset of Python, with assignments, arithmetic, conditions and loops. Training uses short programs and testing uses longer ones from the same generator. On the longer-program test split, IPA-GNN reaches 62.1% accuracy on complete programs and 29.1% on programs with a hidden expression. It leads every comparison system that works from static input alone. A recurrent network given the true execution trace reaches 66.4% overall on complete programs, although IPA-GNN does better at some lengths. Replacing parts of IPA-GNN with the corresponding operations of a conventional graph network points to the importance of its learned control flow.

IPA-GNN has a limited step budget. In one example, its pointer attends to a loop body once, while the actual run visits the body seven times. The authors also see branch choices that are frequently close to discrete. These observations help explain what it can mean to learn a program’s result under a computation limit: the learned process can use the program’s structure while taking a shorter route to an answer. The paper proposes partial-program prediction as a possible way to guide synthesis from examples, where a search procedure must judge unfinished code. The experiments test prediction accuracy on generated programs. The proposed application follows from that task and would require a separate evaluation.

Deep dive: Learning to Execute Programs with Instruction Pointer Attention Graph Neural Networks

IPA-GNN uses a soft instruction pointer to predict Python program outputs from code and control flow, including when a statement is hidden. · about 35 minutes to read

The problem and its context

What the source tells you about a run

Static analysis draws conclusions about code and programming languages without running the program under inspection. The paper places its task alongside the analysis used in compilers, debuggers and development environments. A tool might need to know where control can go after a statement, which regions can be skipped, or how a fact established in one part of a program bears on another. An execution result asks for a particular kind of conclusion. The analyzer has to connect what the statements say with the order in which their effects can occur.

The paper uses a statement-level control flow graph. Each node represents a statement, and a directed edge says that the statement at its destination could execute immediately after the statement at its source. A parse tree, which represents the grammatical structure of the source, provides the basis for constructing this graph. A loop produces a route back to an earlier point in the program. An if can give a statement two successors, corresponding to the outcomes of its condition. Several different routes can also lead to the same later statement.

An execution trace records the statements actually visited, in the order in which they run. It can contain repeated visits to the same node. The control flow graph makes those visits possible by encoding the loop, while the condition and current variable values determine how many visits occur. This distinction explains why handing a predictor the graph still leaves a substantial problem to solve. It knows which steps are legal according to the graph. It has to work out which ones matter for this particular result.

The task grants access to the source and information available through ordinary static analysis. The authors allow representations such as the parse tree and control flow graph. The setting excludes consulting an interpreter or compiler to answer the question, as well as obtaining extra evidence from dependencies or a test suite. A separate trace-based comparison deliberately receives more information. Its role is to show how a recurrent network performs when the sequence of statements is supplied by actual execution.

Why sequence and graph representations each help

The paper describes earlier machine learning work on code completion, bug finding and repair as evidence for the usefulness of program graphs. Such graphs expose relationships that may be difficult to infer from the order of source tokens alone. A graph neural network, or GNN, updates vectors at nodes by passing information along edges. That design makes relationships represented in the graph directly available to the computation. The cited work on representing programs with graphs is one example of this direction. Learning to Represent Programs with Graphs

A graph also makes it possible to pass information locally around a branch or loop. The difficulty arises when the answer depends on a long sequence of changes. A loop can have a small footprint in the graph while requiring many applications of its body during a run. The number of propagation rounds in a graph network determines how many successive transfers it can carry out. An architecture that succeeds by collecting information from nearby statements can therefore face a different problem when it has to combine effects in execution order, repeatedly and over a longer horizon.

A recurrent neural network, or RNN, has another useful property. It applies a learned update repeatedly, passing a hidden vector from one step to the next. Sequence processing is the role associated with recurrence in the earlier literature the paper cites. For program execution, this architecture raises a prior question: what sequence should the network read? Source order is available without running the program. Actual execution order would give the recurrent update a much more relevant sequence, but the trace is part of the behavior the task requires the system to infer. Sequence to Sequence Learning with Neural Networks

Earlier learning-to-execute work used recurrence to see whether a network could infer outputs for simple programs. The authors describe results for long short-term memory networks, or LSTMs, on programs with restricted control flow and linear computational complexity. Their own experiments turn the question toward graph architectures. They also draw inspiration from neural algorithm induction, where an architecture is designed to help it learn an algorithm from examples. Systems such as Neural Turing Machines appear in that broader line of work. In learning to execute, the source itself is part of the input. The learned update must respond to what the individual statements mean for the computation at hand. Learning to Execute · Neural Turing Machines

The authors also compare their design with graph attention. In a graph attention network, learned weights determine the contributions passed across graph edges. The relational variant, R-GAT, can distinguish edge types. Attention already provides a way to favor some neighbors over others. IPA-GNN gives those weights a specific operational role. They govern where the next instruction can be, and the weight carried by a statement depends on how much of the preceding computation reached it. That role comes from the design of an interpreter, where the location of the instruction and the state of the program jointly determine what happens next.

Why length and missing code are separate challenges

The paper uses systematic generalization to ask whether familiar kinds of statements can still be handled when they are composed into more complex programs. A test example can be new in the ordinary sense while resembling the training examples in length and structure. Here, the authors impose an explicit boundary on program length. All scored test programs fall beyond the training cutoff. This gives the benchmark a clear interpretation. Success requires some ability to carry what was learned on shorter examples into a longer computation. The paper relates this choice to earlier work asking how architecture and generalization to unfamiliar compositions fit together. Systematic Generalization: What Is Required and Can It Be Learned?

Program length and trace length capture different aspects of that challenge. Length measures the size of the written program. Trace length depends on branches, loop iterations and the values produced along the way. The authors use source length to form the splits and control flow structure to set the graph computation budget. This lets them study the practical question of training with short propagation histories and then asking the same update procedure to run for longer. They motivate this choice in part by the cost of training through very long histories, both in time and memory and in the difficulty of learning across many recurrent steps.

Partial execution changes the information available to the predictor. The intended output is still the one produced by the original program. A missing expression can have little effect on the evidence available for that output, or it can be central to it. The network has to use what remains visible to make a prediction in either case. A search procedure for programming by example faces a related problem when it considers a candidate that still has holes. A guess about the behavior of its possible completions could help decide which candidate to explore. The paper tests the more narrowly specified prediction problem as a step towards that use.

The method, step by step

From source statements to a sequence of learned updates

An interpreter needs a record of variable values and a pointer to the next instruction. Executing a statement can change the record. A condition uses the record to determine where the pointer goes. When the program contains a loop, the same instruction can be visited with different values in the record each time. The sequence matters because every state change can affect the outcome of a later condition or assignment.

IPA-GNN builds an analogous computation out of learned vectors. It associates each source line with a node in the statement-level graph and represents the line with four fields: indentation level, operation, variable and operand. The indentation field describes the position of the line within the program’s blocks. The other fields describe what the line does and the pieces it acts on. The statement receives an embedding, a vector used as input to the recurrent update. The graph provides the allowed successor relationships separately.

At each propagation step, the system forms a proposal for what the state would become at each statement. It then determines where each proposal can go. A statement with a single successor sends its contribution along that edge. A branch has learned weights for both successors. The incoming contributions at each destination are combined, and a separate pointer calculation keeps track of how much weight arrived there. These operations repeat for a budget determined from the program. The prediction is read from the state at the exit.

From source code to an IPA-GNN prediction

The steps in order.

From source code to an IPA-GNN predictionStep 1: Encode statements and build the control flow graph1. Encode statements and build the control flow graphStep 2: Initialize node states and the entry pointer2. Initialize node states and the entry pointerStep 3: Propose updated states with a recurrent cell3. Propose updated states with a recurrent cellStep 4: Assign weights to the possible successors4. Assign weights to the possible successorsStep 5: Aggregate incoming states and pointer mass5. Aggregate incoming states and pointer massStep 6: Repeat within the program’s propagation budget6. Repeat within the program’s propagation budgetStep 7: Predict the target from the exit state7. Predict the target from the exit state

The proposal and routing operations have distinct responsibilities. The proposal represents the effect associated with processing a statement in its current context. Routing determines which statements receive that effect. A branch weight can therefore depend on the state prepared at its source. A decision about a loop may change on a later visit even though the loop statement’s embedding remains the same. The state and the location of the computation provide the time-varying information.

The task and graph in notation

The authors formalize an example as a pair consisting of a program and a target property. In the experiments, that property has a finite set of possible values. The dataset is partitioned by a function measuring complexity.

Dtrain = {(x, y) ∈ D : c(x) ≤ C}

Dtrain is the training partition, D is the dataset, x denotes a program, and y is its target. The symbol ∈ means membership. The function c measures program complexity, and C is the cutoff. The colon inside the braces introduces the condition for admitting a pair.

Dtest = {(x, y) ∈ D : c(x) > C}

Dtest is the test partition. The pair (x, y), dataset D, complexity c(x) and threshold C have the same meanings as in the training definition. The symbol > places the test programs strictly beyond the cutoff. Program length supplies c(x) in the experiments.

The notation xₙ identifies the statement at node n. The entry statement is x₀. For a node n, Nin(n) contains its immediate predecessors, and Nout(n) contains its immediate successors. A branch in these programs has at most two successors. A node can have more incoming edges because routes can converge. The undirected neighborhood used in some comparisons can be expressed as follows.

Nall(n) = Nin(n) ∪ Nout(n)

Nall(n) is the set of all neighbors of node n, Nin(n) is its set of predecessors, and Nout(n) is its set of successors. The union symbol ∪ combines the sets. This distinction matters because an interpreter follows an outgoing edge, while a conventional graph update can also receive messages in the reverse direction.

Starting with a recurrent network on one path

The simplest recurrent architecture in the paper reads the program in source order. It uses a hidden state as a learned counterpart to the interpreter’s record of variables. The update consumes the embedding of the statement chosen by the most recent instruction pointer.

hₜ = RNN(hₜ₋₁, Embed(xₙ₍ₜ₋₁₎))

hₜ is the hidden state after step t, and hₜ₋₁ is the state from the preceding step. RNN is the learned recurrent update, and Embed is the function mapping a statement to its input vector. In xₙ₍ₜ₋₁₎, the subscript identifies the statement indexed by the previous pointer, nₜ₋₁. The hidden vector has dimension H, the width of the recurrent representation.

For the Line-by-Line RNN, nₜ is t. The source supplies the order, so each line contributes at its textual position. This fits a straight-line program naturally. For the Trace RNN, the pointer instead comes from the sequence produced by actually running the program. A line in a loop can then contribute on several recurrent steps, and the network receives only the route that execution followed. The trace establishes the order of visits. The recurrent update still has to learn to use that order to predict the output.

The Hard IP-RNN inserts a learned branch decision between those cases. Given the new hidden state, a dense layer scores the two ways to leave a branch. An argmax picks the successor associated with the larger score.

nₜ = Nout(nₜ₋₁)[argmax Dense(hₜ)]

nₜ is the next pointer, and nₜ₋₁ is the previous pointer. Nout gives the available successors, with brackets selecting an entry in their branch order. Dense is the learned scoring layer applied to the updated state hₜ. The argmax operator returns the index of the highest score. A statement with an unambiguous successor can advance directly.

The Hard IP-RNN is useful for understanding the architecture because it follows the interpreter’s order of decisions. It updates its state, uses that state to choose a branch, and then reads the next instruction. A branch choice can determine every statement read afterwards, including whether the computation exits a loop or goes through its body again. That same feature creates a training problem. The index returned by argmax is a discrete choice. Small score changes can leave it exactly as it was, and crossing a decision boundary can switch the rest of the route. The authors use a continuous relaxation so the final prediction loss can train the routing operation together with the state updates.

Turning the pointer into a distribution

The soft instruction pointer assigns a weight pₜ,ₙ to node n at time t. At the start, the pointer is concentrated at the entry statement. As the network propagates, a branch can send mass to more than one node. With distinct candidate positions for execution, the network keeps a separate hidden vector at every statement and time. hₜ,ₙ is the representation associated with reaching node n at step t. The initial IPA-GNN hidden vectors are zero. The statement embedding then enters as part of the recurrent computation at that node.

A propagation step begins by proposing a new state at each possible current statement.

aₜ,ₙ = RNN(hₜ₋₁,ₙ, Embed(xₙ))

aₜ,ₙ is the state proposal produced at node n during step t. The recurrent cell RNN receives hₜ₋₁,ₙ, the state previously available at that node, and Embed(xₙ), the vector for its statement. This gives the proposal access to the statement itself on each visit. Sharing the update across steps makes the same kind of computation available when a test program calls for a longer propagation history.

The routing operation examines the resulting proposal. If the statement has a single successor, the corresponding branch weight is one. At a binary branch, a dense layer supplies the scores and a softmax turns them into weights over the successors.

(bₜ,ₙ,ₙ₁, bₜ,ₙ,ₙ₂) = softmax(Dense(aₜ,ₙ))

bₜ,ₙ,ₙ₁ and bₜ,ₙ,ₙ₂ are the weights for sending a contribution from node n to its successors n₁ and n₂ at step t. The layer Dense maps the proposal aₜ,ₙ to branch scores. softmax converts the scores to non-negative weights that sum to one. Entries of b for destinations outside the outgoing neighborhood are zero. These weights depend on the state proposal as well as on the graph that identifies their destinations.

Each successor then adds the incoming proposals, with the contribution of each edge scaled by the pointer at its source and by its branch weight.

hₜ,ₙ = ∑ₙ′∈Nin(n) pₜ₋₁,ₙ′ · bₜ,ₙ′,ₙ · aₜ,ₙ′

hₜ,ₙ is the new hidden vector at destination n. The sum ∑ ranges over nodes n′ in Nin(n), the predecessor set of the destination. pₜ₋₁,ₙ′ is the preceding pointer mass at the source. bₜ,ₙ′,ₙ is the branch weight for sending some of that source’s contribution to n, and aₜ,ₙ′ is the vector proposed at the source. The multiplication dots indicate how the two scalar weights scale that vector. The contributing proposal is the one computed at the predecessor because that is the statement processed before the transfer.

The pointer itself follows the same routing weights.

pₜ,ₙ = ∑ₙ′∈Nin(n) pₜ₋₁,ₙ′ · bₜ,ₙ′,ₙ

pₜ,ₙ is the pointer mass at the destination after the step. The sum again ranges over the incoming neighbors n′, and the term for each edge multiplies the preceding mass pₜ₋₁,ₙ′ by the branch weight bₜ,ₙ′,ₙ. The pointer records the amount of mass that reached the destination. The state aggregation additionally records a weighted vector contribution from each incoming edge.

The two quantities help distinguish a choice made at a statement from the network’s current commitment to that statement. A branch can strongly favor one successor while sitting at a node with very little pointer mass. Its effect on the next step will then be small. When routes converge, their mass and state contributions are added at the destination, so the subsequent update uses the combined state. This is how the network can represent uncertainty about routing while keeping a single vector per location at each step.

When the graph computation follows a single trace

The relationship to the Hard IP-RNN can be made explicit by replacing softmax with a hard selection while keeping the graph notation.

(bₜ,ₙ,ₙ₁, bₜ,ₙ,ₙ₂) = hardmax(Dense(aₜ,ₙ))

The symbols b, t, n, n₁, n₂ and a identify the same weights, step, source, successors and proposal as in the soft branch equation. Dense again gives the scores. The operator hardmax returns a vector with a one at the selected highest-scoring position and zero at the other position. A pointer concentrated at entry then stays concentrated along a single route. The active proposal moves to the successor selected by the branch rule.

The Trace RNN has a corresponding expression in terms of the true sequence of statement indices.

bₜ,ₙ,ₙ′ = 𝟙{n*ₜ₋₁ = n ∧ n*ₜ = n′}

n*ₜ₋₁ and n*ₜ are consecutive statements in the actual trace. n is a proposed source node, and n′ is a proposed destination. The symbol ∧ means both equalities must hold. The indicator 𝟙 is one when its condition is true and zero otherwise. bₜ,ₙ,ₙ′ therefore selects the transition made by the oracle trace at step t.

These cases give a precise sequence of relationships. Fully concentrated IPA-GNN branch decisions recover the hard-pointer recurrence. When the hard-pointer network chooses the correct successor at each visited branch, it follows the Trace RNN route. With straight-line code, the trace follows the order of the statements, which aligns the Trace RNN with the Line-by-Line RNN. This is an equivalence between computational forms under stated conditions. Whether learned weights produce those conditions is an empirical matter.

The construction also shows how a recurrent network whose execution path depends on latent branch choices can be represented as a message-passing graph network. A latent choice is one whose value has to be inferred within the predictor. During training, the final answer supplies supervision, and the branch weights are internal quantities that help produce that answer. The oracle gives a separate way to specify the route. This distinction matters when reading the learned pointer as evidence about an execution: the optimization can favor any use of the graph that helps predict the target within the budget.

The comparison with conventional graph propagation

The paper decomposes a graph step into a local proposal, a message sent along an edge, a pooled incoming message, and a new node state. For IPA-GNN, the local proposal is the recurrent update over the statement embedding. The edge message is that proposal scaled by both pointer and branch weight. The pooled message is the sum over allowed predecessors, and it becomes the next state. This decomposition makes it possible to change how the network processes a statement while keeping how it routes, or to change routing while keeping the statement update.

The gated graph neural network, or GGNN, starts each node with its statement embedding as the state. Its local proposal at a step is the previous state, and a learned dense transformation produces a message on each edge. Its graph contains forward and reverse edges, with separate types for the true and false branch directions and their reverses. The dense transformation has parameters that depend on the edge type. The network sums messages from all neighbors and then combines that aggregate with the preceding state by a gated recurrent unit, or GRU.

hₜ,ₙ = GRU(hₜ₋₁,ₙ, h̃ₜ,ₙ)

hₜ,ₙ is the updated state of node n on step t, hₜ₋₁,ₙ is its preceding state, and h̃ₜ,ₙ is the pooled incoming message. GRU is the learned gated update that combines the two. This places recurrence at the destination after pooling. IPA-GNN’s LSTM update over the statement embedding precedes the transfer to destinations.

NoControl keeps the IPA-GNN initialization and statement update. It uses the bidirectional neighborhood and gives each transmitted proposal a unit weight. NoExecute keeps the directed, pointer-weighted routing while adopting the embedding initialization, transformed messages and GRU update of the GGNN side of the comparison. Adopting both groups of GGNN operations recovers GGNN. These names refer to what changes relative to IPA-GNN. NoControl still uses a graph derived from control flow, and NoExecute still carries out learned transformations of its state.

The step budget and the prediction

The graph architectures use the state at the program’s exit after a prescribed number of propagation steps.

hfinal = hT(x),nexit

hfinal is the vector sent to the output layer. hT(x),nexit denotes the state at time T(x) and node nexit. The function T(x) gives the budget for program x, and nexit indexes its exit statement. The graph architectures read out from the same kind of location, so their representations must carry evidence needed for the output to that point.

The budget accounts for statements and loop nesting.

T(x) = ∑₀≤i≤nexit 2^LoopNesting(i) + ∑ᵢ∈Loops(x) 2^LoopNesting(i)

T(x) is the number of graph propagation steps. In the first sum, the statement index i runs from entry through nexit, inclusive. LoopNesting(i) counts the loop bodies that contain statement xᵢ, and 2^ denotes raising the base two to that depth. In the second sum, Loops(x) is the set of while-loop statements in x, and the same depth weight applies to each such statement. The rule reserves repeated propagation through loop structures. The authors design it to allow passage along the paths through those structures twice. Most exact traces require more steps than the rule provides.

The final hidden state is converted into scores, then into a distribution over the possible outputs.

s = softmax(Dense(hfinal))

s is the vector of predicted class probabilities, Dense is the output layer that turns the final state hfinal into class scores, and softmax converts those scores to probabilities. This output layer has a different role from the dense layer that scores branches. It predicts the program’s target from the state produced by the computation as a whole.

L = −∑ᵢ 𝟙{y = i} log(sᵢ)

L is the categorical cross-entropy loss. The sum runs over the K output classes, with i denoting an individual class. y is the true target, and the indicator 𝟙{y = i} is one for its class and zero for the others. sᵢ is the assigned probability, and log is the logarithm. The leading minus sign makes the loss increase when the probability assigned to the correct class decreases.

The authors train from the program and its output label using this loss and Adam. In IPA-GNN, both the recurrent proposals and the routing weights participate in a differentiable computation ending at that label. The training signal can thus change how a statement is represented and how evidence leaves it. A two-layer LSTM supplies the recurrent cell for the recurrent baselines and IPA-GNN. The comparison can therefore examine what happens when a similar kind of recurrent unit is given different statement sequences or put inside a graph propagation step.

Experiments and results

How the programs and their targets are generated

The authors define a probabilistic grammar for a synthetic subset of Python. It lets them produce programs with comparable elementary operations and a wide range of lengths and nesting patterns. The grammar begins by initializing v0 and then generates a block containing statements. A block can contain an expression, an if, an if-else, a repeat construct, or statements corresponding to continue, break and pass. Blocks can occur inside control flow constructs, so the source can require decisions within decisions and loops within other structures.

The main arithmetic expressions add to, subtract from or multiply v0 by a small integer. The grammar permits integer operands from 0 through 9 and initial values for v0 from 0 through 999. Conditions compare the residue of v0 modulo 10 to an integer, using one of the listed comparison operators. This makes it possible for an arithmetic update to affect a later choice of path. A generated repeat is translated into a Python while using a counter chosen uniformly from v1 through v9, excluding variables in use when that repeat is entered. The resulting programs have a bounded vocabulary of variables and statements but can still exhibit complicated patterns of execution.

The target in both tasks is the final value of v0 modulo 1000. For a full program, the source includes the statements that produced the label. For a partial program, the authors uniformly select an expression statement from the eligible non-control flow statements and mask it. The label remains the value from the original program. This asks the predictor to infer the result of the program before masking. The visible branch and loop structure is part of the input, while an omitted expression may change the values that govern those branches and loops.

The categorical target holds the range of possible answers fixed as source length grows. The authors choose it to put the emphasis on generalizing across longer and more complex computations. The generated program may involve arithmetic on larger intermediate values, but credit on the benchmark depends on the specified residue. That choice makes the accuracy measure consistent across program lengths and gives the authors a narrower generalization question than predicting arbitrary high-precision values.

Splits, settings and comparisons

The training partition contains 5M programs, all meeting the length cutoff C = 10. The authors sample 4.5k programs for the test partition. It contains 500 examples at each tested length in the progression written as {20, 30, …, 100}. The progression and the training cutoff give the experiment its systematic length shift, while the same grammar supplies the statements and construction rules in both partitions. The accuracy at any test length therefore describes performance on longer compositions of familiar language constructs.

Each training run lasts three epochs and uses a batch size of 32. The authors sweep hidden sizes {200, 300} and learning rates {0.003, 0.001, 0.0003, 0.0001}. They choose parameters for each architecture by accuracy on withheld examples from the training partition, all at complexity C. Selection at the upper end of the training range gives each candidate a check on the longest programs available there. The reported test split then measures how those selected settings carry over to the longer lengths.

The baselines ask different questions about access to structure. Line-by-Line RNN provides a comparison with simple sequential reading. GGNN tests conventional gated message passing on the graph. NoControl and NoExecute reuse parts of both graph architectures to help isolate the effect of the design changes. R-GAT supplies an attention-based graph comparison. The authors perform additional tuning for R-GAT and report that they were unable to train it to a competitive level. They provide no R-GAT test accuracy in the results table.

The full-program experiment adds the Trace RNN. It receives the order of visited statements from an oracle, meaning a source of privileged information available for the comparison. Given that order, its task is to turn the visited statements into a useful state and predict the output. The trace carries information about the actual branch outcomes, so this comparison helps show what can be gained from knowing the route. It also tests whether that knowledge alone makes a recurrent system consistently stronger across lengths.

Accuracy is the fraction of programs on which the predicted category equals the target. The authors report it over the entire test split and also at individual lengths. Their length plots show one standard error of accuracy. The overall figures give a compact comparison across the chosen mix of lengths. The curves address whether the same ordering holds as the input grows and whether a system that is competitive at short lengths retains that position.

Complete programs

For complete programs on Dtest, IPA-GNN reaches 62.1% accuracy. NoExecute scores 50.7%, the closest result among the systems using only static input. Line-by-Line RNN reaches 32.0%. The tests with GGNN and NoControl further distinguish basic propagation on the graph from propagation whose routing depends on an instruction pointer. The Trace RNN obtains 66.4% with access to the actual route and leads on overall accuracy for complete programs.

Complete programs on Dtest by architecture and accuracy

IPA-GNN leads the systems with static input, while the trace oracle scores highest overall.

Complete programs on Dtest by architecture and accuracyTrace RNN (oracle): 66.4Trace RNN (oracle)66.4IPA-GNN (this paper): 62.1IPA-GNN (this paper)62.1NoExecute: 50.7NoExecute50.7Line-by-Line RNN: 32.0Line-by-Line RNN32.0NoControl: 28.1NoControl28.1GGNN: 16.0GGNN16.0
The numbers
System or settingaccuracy %
Trace RNN (oracle)66.4
IPA-GNN (this paper)62.1
NoExecute50.7
Line-by-Line RNN32.0
NoControl28.1
GGNN16.0

The length curves show why the split matters. At low complexities used in training, the Line-by-Line RNN is close to IPA-GNN. Reading source in order can carry considerable useful information on short examples, where the recurrent network has fewer statements to combine. As length increases, the authors observe faster deterioration in the static baselines than in IPA-GNN. The aggregate comparison therefore reflects performance under the selected length shift. A comparison confined to short programs would give a different impression of the advantage.

The trace comparison has another nuance. The Trace RNN’s aggregate accuracy is higher, but the authors observe lengths at which IPA-GNN leads it. Knowing the true path allows the Trace RNN to see repeated statements in their actual order. That still leaves the burden of carrying and transforming useful information over the trace. IPA-GNN can form an output with fewer propagation steps than the trace would require. The paper shows examples of that behavior in its attention plots. The accuracy curves establish that a privileged trace comparison can lose at particular lengths, while the plots illustrate one way the bounded computation can differ from processing every trace step.

Programs with a masked expression

On Dtest for partial programs, IPA-GNN reaches 29.1% accuracy. NoExecute reaches 20.7%, and Line-by-Line RNN reaches 11.5%. The graph comparisons form the same order as in complete execution. The paper reports the oracle comparison for complete programs only. Here the test is how much a predictor can recover from a representation with a missing expression and a label inherited from the complete source.

Programs with a masked expression on Dtest by architecture and accuracy

IPA-GNN has the highest accuracy, and the closest comparison also uses pointer-based routing.

Programs with a masked expression on Dtest by architecture and accuracyIPA-GNN (this paper): 29.1IPA-GNN (this paper)29.1NoExecute: 20.7NoExecute20.7Line-by-Line RNN: 11.5Line-by-Line RNN11.5NoControl: 8.1NoControl8.1GGNN: 5.7GGNN5.7
The numbers
System or settingaccuracy %
IPA-GNN (this paper)29.1
NoExecute20.7
Line-by-Line RNN11.5
NoControl8.1
GGNN5.7

The lower accuracy across the comparisons is consistent with the missing information in the task. Even an expression outside a branch header can change a later condition through its effect on v0. In a loop, the missing expression can matter each time its position would have been visited. Conversely, some masked statements will be outside the route relevant to the output. A system that can use candidate routes and the visible state to concentrate on relevant code has a way to handle both situations, with success depending on what can be inferred in each example.

The classification result gives a concrete measure of partial-program prediction under this masking procedure. A synthesis search would use a prediction in another way, for instance to rank incomplete candidates against an output requirement. Accuracy here counts an exact class match. A ranking algorithm would also care about relative scores across candidates, how the candidate set is generated, and how the scores influence the search. The experiment supports investigating that connection by showing a consistent advantage on the masked task itself.

What the ablations show

Keeping the routing or keeping the statement update

The controlled comparison comes from exchanging the two groups of graph operations described in the method. NoExecute keeps IPA-GNN’s pointer and branch-weighted transmission and substitutes the GGNN-style state computations. NoControl keeps IPA-GNN’s recurrent computation over statement embeddings and substitutes the GGNN-style neighborhood and transmission rule. GGNN supplies the comparison in which both groups come from conventional gated propagation. This design puts each component group into two different architectural settings.

The contrast between NoExecute and NoControl is the strongest evidence the paper gives about the influence of the routing changes. NoExecute reaches 50.7% versus 28.1% for NoControl on Dtest complete programs. On Dtest partial programs, the corresponding accuracies are 20.7% and 8.1%. Both comparisons favor the system that retains the pointer and its learned allocation over forward control flow edges. The ordering holds even when losing access to an expression makes the final target much harder to infer.

The full architecture also leads NoExecute on both versions of the task. This comparison holds the broad control mechanism in place and changes the way the state is initialized, transformed and updated. Keeping the complete combination gives the strongest static predictor in the paper’s setup. A plausible role for the per-statement recurrence is visible in the design itself. Each time a statement is processed, the update has direct access to its embedding, together with the state available at that location. The ablation measures the contribution of that group of changes within the pointer-based architecture.

These are grouped comparisons. NoControl changes the allowed directions of message passing together with the weights on the messages. NoExecute changes several aspects of hidden-state processing together. Accordingly, the results identify a stronger contribution for the control-flow group in this experiment. The tables do not distinguish how much of that contribution comes from using directed edges, maintaining mass across steps or conditioning branch weights on the current proposal. The comparison with R-GAT adds training evidence about another attention architecture under the benchmark, with the unsuccessful tuning reported in place of a competitive score.

The relative positions also clarify why the graph alone is an incomplete explanation. GGNN receives a structured representation, yet its test accuracy is lower than the source-order recurrent baseline on both tasks. NoExecute uses the directed graph in a more specific way. Its messages travel according to weights connected to the current execution position. Within the experiments, how the graph is used has a larger visible effect than simply including graph connectivity in the input.

What appears in the pointer plots

The authors inspect the weights at individual statements over time. Their plots put program locations and propagation steps on the axes, using intensity to show the value of the soft pointer. A concentration at one location looks like a single active instruction. A split can reveal weight spreading across alternatives, and repeated concentrations at the same position on later steps can reveal a return through a loop. This is an interpretability analysis of where the system directs its computation.

The main examples use two programs and examine each with different initial values for v0. Changing the input value while reusing the program makes the distinction between state and structure concrete. The same graph supplies the available edges. The changing state gives the route a reason to differ. The plots show cases where the pointer is strongly concentrated when it chooses a branch. That is consistent with the hard-pointer special case and shows that a continuously trainable routing rule can behave almost discretely during prediction.

In one program, the authors interpret the pointer as following only the route relevant to the result. In the loop example, it attends to the loop body once, where the ordinary trace visits it seven times. The paper describes this as a shortcut, because the system produces the correct result with a shorter pattern of visits. The plot establishes the difference in visits and the outcome for the example. It leaves open what the hidden vector represents internally and how the arithmetic associated with the skipped visits is reflected in the state.

This behavior is compatible with the supervision and the budget. The learning objective rewards a correct final category. If the network can use information at the loop header and body to prepare a state that suffices for the output, it can do well while using fewer steps than the run itself. A pointer that moves out of the loop early can therefore be consistent with good execution prediction. The possibility is especially relevant here because the authors provide enough steps to traverse loop paths repeatedly only within a fixed structural budget. A network that had to reproduce all exact traces would exceed that budget on many examples.

The supplementary analysis shows four randomly sampled complete programs, then masks a statement in each and runs the partial-program predictor on the corresponding inputs. All four complete examples are answered correctly. The partial predictor answers the first three correctly and the fourth incorrectly. The paired view lets the reader see how the pointer behaves with the same surrounding code and a different information constraint. The incorrect partial example also shows why a trajectory image and an output check serve different purposes: the resulting route can be inspected, while correctness still depends on its relation to the hidden expression and the final label.

What the accuracy and the trajectories establish together

The aggregate ablations and the pointer examples address different questions. Accuracy measures whether predictions are correct under the conditions of the task. The component swaps show how that accuracy changes when the control mechanism or the state computation changes. The trajectories show that the learned control mechanism can concentrate on particular statements and can sometimes reach a correct answer through a shorter route. This combination is what supports the authors’ interpretation that modeling instruction position helps execution prediction.

An individual plot gives direct evidence about the displayed case. The paper supplies no benchmark-wide count of how often the pointer takes an exactly discrete route or how often it uses each kind of shortcut. The length curves quantify generalization across the test groups, while the plots make the computation easier to examine. Keeping those evidentiary roles distinct also helps interpret the comparison with the trace oracle. The observation that bounded IPA-GNN leads at some lengths is a result of the accuracy experiment. The shorter loop route is a concrete example of the behavior available to IPA-GNN under its step budget.

Limitations

Limits the authors identify

The authors emphasize that the programs cover a subset of Python. The generator restricts the variables, value magnitudes and permitted statements. It supports nested control flow, but the arithmetic and condition language are tightly defined. Its vocabulary is shared across training and testing. The experiment is therefore a test of transfer to longer generated programs under the same construction rules. The authors see this constrained setting as a starting point for harder tasks and for the question of whether the architecture can scale to real programs.

They deliberately keep the output format fixed by using v0 modulo 1000. The stated goal is to study more complicated execution paths with limited variation in data types and precision. They identify generalization across numerical values as another direction and leave an evaluation combining those challenges for future work. That distinction matters because a system can improve at deciding which statements affect a result while still struggling to represent the values those statements manipulate.

The authors also discuss the difficulties of working with long traces. More propagation steps require more time and memory, and learning across long sequences can be difficult. The paper demonstrates that the architecture can be run with well over 100 propagation steps at evaluation after training usually used 16 or fewer. These figures describe the learned graph computation in this setup. The authors use the contrast to motivate transfer from manageable training examples to longer ones. Their comparison of bounded prediction with actual traces also makes clear that the allotted steps are insufficient to reproduce many full executions.

The practicality claims remain proposals. The authors suggest that predicting the outputs of incomplete programs may help guide programming by example. They also suggest that learned source embeddings could convey some of a program’s semantics. Both directions would need evaluation in the relevant downstream setting. The paper’s broader discussion adds that uncertain analysis results can cause errors or erode trust if developer tools present them with more confidence than they merit.

Limits of the evidence in this setup

Program length supplies a clear and reproducible split, but it is a proxy for the computation required by a particular example. A long source program can have short active paths. A shorter source program can repeatedly visit a loop body. The test score at a given length pools such cases. It answers how well the architecture handles the generated mixture at that length, with the associated budget. It does not give accuracy at fixed trace lengths or fixed nesting depths. Those would be different measurements of the same broad challenge.

The target observes part of the final state through a residue. Two computations with different intermediate values can end in the same residue, and two final values can belong to the same target class. Correct output predictions establish correctness for the measured property. They leave the exact execution sequence, the remaining variable values and the complete arithmetic history undetermined. This is also why the formal equivalence to hard or oracle-guided recurrence and the empirical success of the trained network have distinct implications. The equivalence describes what the architecture becomes under specific routing conditions. The scores describe its ability to produce the label on generated examples.

The partial task presents a particular kind of missing code. It masks a uniformly sampled eligible expression from a completed program while retaining the label from that completion. An unfinished program encountered during synthesis could admit several completions with different behaviors. The benchmark supplies a particular distribution over the hidden expressions and visible contexts, inherited from its generator and masking rule. Its result measures prediction under that distribution. It leaves questions about different hole locations, multiple holes, missing control structures, and the treatment of uncertainty across completions open.

The trace oracle likewise has a specific scope. It reveals which instructions executed and in what order, giving the recurrent predictor an informative view of the program. It still learns the map from its inputs to the target. The oracle score measures that architecture with that extra input. It does not establish a ceiling on learned prediction, and IPA-GNN’s stronger performance at some lengths is compatible with that interpretation. It also provides no comparison for masked programs, where an actual trace of the complete original program would itself disclose some consequences of the missing statement.

The qualitative evidence supports a similarly bounded reading. Concentrated pointer mass establishes where the architecture sends weight. It provides a means to see whether the network revisits a body, leaves a branch largely unused, or distributes its attention. The semantic content of its hidden vectors is harder to recover from those displays. The observed loop shortcut shows that a correct residue can be obtained after a compressed pattern of visits. It cannot establish that the same shortcut would yield a complete program state or work for a different arithmetic language.

Finally, the paper demonstrates a design advantage among the architectures and training settings it compares. NoExecute’s advantage over NoControl identifies a useful group of design choices. Isolating the individual choices would require varying them independently. The R-GAT result reports what happened under the authors’ training attempts, with no scored candidate in the main comparison. Those qualifications matter when moving from this benchmark to a broader claim about attention, recurrence or graph neural networks as families.

What came after

The later publications that cite IPA-GNN address several ways to connect source code with behavior. Some make execution itself the prediction task. Others place intermediate computation in the process of reaching an answer or study generation of code that should satisfy a requirement. The citation links those questions to the earlier investigation. The titles establish the focus of each later work, while a specific transfer of the soft pointer or its graph update would require further evidence.

Program Synthesis with Large Language Models (2021) takes up the generation side of the problem. IPA-GNN starts with code and asks what behavior can be inferred. Program synthesis starts with a requirement and asks what code could satisfy it. This is the context for the original paper’s suggestion about partial programs. If a search generates incomplete code, a predictor of its likely behavior could provide information about which candidates are worth expanding. The later work’s stated topic is synthesis with large language models, placing the shared concern with program behavior in a generation setting.

Show your work: Scratchpads for intermediate computation with language models (2021) emphasizes intermediate computation. IPA-GNN has intermediate quantities at each propagation step, including the hidden state of each statement and the weight assigned to it by the pointer. Scratchpads frame the corresponding broad question in terms of intermediate work that can be recorded in the process of producing an answer. The connection is especially clear for a multi-step task like execution. The final result can depend on a series of state changes, and the architecture or representation determines how those changes are carried forward.

Code Execution with Pre-trained Language Models (2023) revisits the execution problem in the setting of pretraining. The question is again whether a system can infer behavior from code. IPA-GNN builds a statement-level graph and an instruction pointer expressly for that task. The later title puts a different starting point at the center of the inquiry: a pretrained system brought to bear on code execution. Both approaches make predicting behavior a concrete way to assess what a learned representation of code can support.

NExT: Teaching Large Language Models to Reason about Code Execution (2024) frames execution as a form of reasoning to be taught. IPA-GNN builds execution order and state-dependent branching into the way information moves. NExT’s stated focus is on teaching a system to reason about execution. This carries forward the distinction between recognizing properties of source text and accounting for the state changes and control decisions that produce behavior.

Together, these connections show how the original problem extends across prediction, intermediate computation and synthesis. IPA-GNN isolates one particular contribution to that discussion. It gives instruction location and learned state distinct roles in a graph computation, then tests whether that arrangement helps after a shift in program length. Later work can share the behavioral question while placing its intervention at another point, such as how intermediate steps are represented, what is learned during training, or what role the prediction plays in generating code.

Cite

Cite as David Bieber, Charles Sutton, Hugo Larochelle and Daniel Tarlow. 2020. Learning to Execute Programs with Instruction Pointer Attention Graph Neural Networks. arXiv:2010.12621.

The paper itself, not this page. BibTeX from the library's record of the work. DOI 10.48550/arxiv.2010.12621 · arXiv 2010.12621

@misc{bieber2020learning,
  title = {{Learning to Execute Programs with Instruction Pointer Attention Graph Neural Networks}},
  author = {David Bieber, Charles Sutton, Hugo Larochelle and Daniel Tarlow},
  year = {2020},
  doi = {10.48550/arxiv.2010.12621},
  eprint = {2010.12621},
  archivePrefix = {arXiv},
  url = {https://doi.org/10.48550/arxiv.2010.12621}
}

↑ back to top

This page in Markdown https://md.research.elamur.ai/free/en/papers/bieber-2020-learning-execute-programs-instruction-pointer/