Findings of EMNLP 2026

Towards Training Transformers
as a Universal Computer

Program-level CoT through PENCIL: our transformer learns atomic execution steps from random programs and generalizes to human-written programs.

Ruize Xu1Chenxiao Yang2Yanhong Li3David McAllester2
1The University of Chicago2Toyota Technological Institute at Chicago3Allen Institute for AI

MicroPy in action

Executing a SAT solver,
one step at a time.

Find x, y, and z that satisfy every clause. Follow the search tree alongside the stack and the next completion the model is trained to predict.

(¬x ∨ y)∧(¬y ∨ z)∧(¬z ∨ ¬x)∧(x ∨ y)

¬ means NOT · ∨ means OR · ∧ means AND. A clause is satisfied when at least one literal is true.

Search tree
current failed satisfying unvisited

The corresponding execution stepReadable sketch
write current variable = True
check clauses at a full assignment
if failure: discard branch effects
retry current variable = False
on success: keep the witness

Completion · reference next-step output

Inspect all 1,531 exact interpreter steps

Definitions, effects, stack, and completion are separated for reading. Only whitespace and layout change.

1 / 1531

Model input · FunDefs / ExpDefs / Eff / General Stack

Completion · next-step output

View the actual MicroPy assignment-search function

The same sat_assign function used for this recorded run. eval_cnf checks the linked-list representation of the clauses; Try discards effects when an attempt returns fail_.

@mp.MicroPy
def sat_assign(var, cnf_head_, out_):
    return mp.If(
        mp.HasAttr(var, NEXT),
        mp.Try(
            mp.Seq(
                mp.Assert(var, VALUE, mp.true_),
                sat_assign(mp.LookupAttr(var, NEXT), cnf_head_, out_),
            ),
            mp.Seq(
                mp.Assert(var, VALUE, mp.false_),
                sat_assign(mp.LookupAttr(var, NEXT), cnf_head_, out_),
            ),
        ),
        mp.Try(
            mp.Seq(
                mp.Assert(var, VALUE, mp.true_),
                mp.If(
                    eval_cnf(cnf_head_, mp.LookupAttr(cnf_head_, VALUE)),
                    mp.Assert(out_, VALUE, mp.true_),
                    mp.fail_,
                ),
            ),
            mp.Seq(
                mp.Assert(var, VALUE, mp.false_),
                mp.If(
                    eval_cnf(cnf_head_, mp.LookupAttr(cnf_head_, VALUE)),
                    mp.Assert(out_, VALUE, mp.true_),
                    mp.fail_,
                ),
            ),
        ),
    )

Replay of a real reference-interpreter run, with exact prompt/completion pairs. This replay is not live neural-model inference. Only visited assignments are marked; unexplored branches remain gray.

59.5Mmodel parameters
6held-out task families
128 → 7,552training cap → longest test trace
4,096tokens per model context

The idea

Program-level CoT through PENCIL

MicroPy is a small, Turing-complete language. A decoder-only Transformer learns to predict each atomic step of program evaluation through next-token prediction. Repeating these steps lets the model evaluate and execute whole programs, including human-written programs unseen during training.

PENCIL manages the execution context. When a call finishes, it erases that call’s completed execution history and keeps its returned value and effects. The next prediction uses the remaining live state, so execution can continue without retaining every intermediate step.

01 · PredictOne atomic execution step

The model generates the next completion.

02 · ReducePENCIL erases finished work

Keep returned values, effects, and live state.

03 · ContinueEvaluate the whole program

Use the reduced context for the next step.

01 / Model and training data

Choose the stack you need.
Build a program that reaches it.

Random programs provide broad syntax coverage. The plan compiler deliberately constructs the runtime configurations that random sampling can miss.

Model setup

Decoder-only Transformer59.5M parameters4,096-token contextNext-token prediction only

Model and optimizer follow Karpathy’s nanochat definitions. We hold the architecture and optimizer fixed and train on program execution traces.

A

PCFG sampler

Pretraining-like role

A probabilistic context-free grammar samples a production at each branch to build a MicroPy program. Run the program and collect its execution steps to learn basic syntax and common patterns.

B

Plan compiler

Post-training-like role

Sample an ordered sequence of stack frames, with constraints on bindings and effects. Compile it into an executable expression, then run it to realize the planned stack and collect the matched input/output step. The sequence describes stack nesting, not execution order.

These labels describe sampler roles; training mixes both sources. The plan compiler targets long-tail retrieval spans, effect lengths, and repeated stack reads and writes—coverage that is critical for program-level generalization.

Target / retrieve a recently written fact

[call] Eff(a.value = True)
[call] LookupAttr(a, value)

The plan specifies both the operation and the fact that must be available in the live effects.

→

Construct / lead execution to that state

Seq(Assert(a, value, true_),
    LookupAttr(a, value))

The first expression writes the fact. The second reads it while the effect is on the stack.

→

Supervise / the matching step

input: … LookupAttr(a, value)
output: ⇒ Eff(empty) True [ret]

Vary outer frames, bindings, and distractor effects around the intended retrieval.

Simplified semantic illustration of plan-directed construction. Exact interpreter serialization is available in the playground below.

Which execution patterns does the paper target?

Retrieval leaves: LookupVar, LookupAttr, and TailApp with concrete environment / effect requirements. These put the correct binding or object fact among other context entries.

Continuation frames: Seq, If, Try, Env, and Eff. The paper additionally documents long pre-TailApp effect writes and zero-argument call boundaries as coverage gaps.

Source: paper §4.1 and appendix “Distribution-Shape Failure Examples”. This inventory does not establish an independent ablation for each pattern.

02 / Try MicroPy

A program in.
An execution you can inspect.

Edit the program, run it, and step through the stack. The output shows both the result and the changes to object attributes.

Reference interpreter · runs in your browser
MicroPy constructors
Loading example…
Program output

Final object attributes

PENCIL

Program-level CoT through PENCIL: the model predicts an atomic execution step. At [ret], PENCIL erases the completed call’s execution history and retains its returned value and effects. Prediction continues from this reduced context.

The trained transformer learns these targets. This playground uses the Python reference interpreter, not a model checkpoint.

1 · General Stack: model input

2 · Completion: next-step target

3 · After PENCIL reduction

Full model input · pretty-printed sections
What can I type?

Use Obj("a"), Attr("value"), true_, false_, unit_, and fail_; compose Seq, If, Equal, Assert, LookupAttr, HasAttr, and Try. Define recursive functions with def and one return expression. Set program = … to choose the entry point.

MicroPy is its own language, not general Python. This demo accepts its constructor syntax and stops at 2,000 steps or a 10-second execution limit. The first custom run downloads the Python runtime; bundled examples can be inspected immediately.

Resources

The reference-interpreter notebook is available now. The next release will include training code and additional materials.