Research log Small Model Experimentation
GitHub

Qwen Numeric-Copy Compiler

Finished2026-06-21imported · line YStructured Execution and CompilersGitHub ↗
Point to the numbers, don't recompute them

The one idea you need

Instead of doing chained arithmetic in its head and reading the digits back, the four-billion-parameter model only points: which word is the starting number, which words are the operations, which are their arguments, and in what order. An exact calculator then copies those symbols and runs the math flawlessly.

The question

Can a small model reliably run multi-step arithmetic if it just locates the numbers and operations in the text and lets an exact calculator do the math?

What we found

Yes. When the model just points to where each number and operation sits and copies the exact symbols for a hidden calculator to run, it solves four-step problems about 90% of the time. A version trained to write the answer itself never left the floor, at most 3% at any length. A shortcut trained only on final answers aced four steps but crashed to zero at eight, never learning the ordered pointing that stretches to longer chains.

Why it matters

For long step-by-step symbolic work, stop making a small model regenerate exact values from memory. Have it mark the right token positions and copy symbols verbatim into a real executor; reliability then hinges on locating slots, not doing arithmetic.

Short chains solved end to end3% → 90%writing the answer yourself vs pointing and copying, at four steps
Chains twice the practiced length20%still solved correctly at 24 steps, with training capped at 12
The final-answer-only shortcut100% → 0%perfect at four steps, total failure at eight
Where accuracy still leaks100% vs 93%operations located almost perfectly, number slots slip at 24 steps
On this page
  1. Results at a glance
  2. Overview
  3. Report
    1. Summary
    2. Setup
    3. Runs
    4. Main QLoRA Result
    5. Frozen Pilot
    6. Controls
    7. Interpretation
    8. Recommended Next Experiment
    9. Artifacts
  4. Experiment log
  5. Figures
  6. Data files
  7. Reproduce
  8. Related

Results at a glance 3

How often each method solves the whole chain, by length

How to read

Bars are grouped by chain length (4, 8, 12, and 24 steps); bar height is the share of chains a method solves correctly end to end, so taller is better. The four colors are four methods, from point-and-copy down to writing the answer directly.

0%25%50%75%100%89.8%83.6%100%3.1%4 steps72.7%46.1%0%0.8%8 steps46.9%16.4%1.6%0%12 steps20.3%1.6%2.3%0.8%24 steps

Takeaway → The point-and-copy bars tower over the rest at every length past four steps; at four steps the shortcut method spikes to a perfect score, just edging out point-and-copy, while writing the answer directly stays pinned near the floor throughout.

Data table
program lengthQLoRA copy-trace compilerfrozen-backbone copy-traceanswer-only compiler controldirect final-answer QLoRA
4 steps89.8%83.6%100%3.1%
8 steps72.7%46.1%0%0.8%
12 steps46.9%16.4%1.6%0%
24 steps20.3%1.6%2.3%0.8%

Numbers from experiments/qwen_numeric_copy_compiler/analysis/final_metrics.csv

Technical framing

Exact program execution by chain length (standard prompts) — Trace-supervised numeric-copy compiling executes long modular programs; direct answering stays at chance and answer-only training only memorizes length 4.

Staying accurate as chains grow past the practiced length

How to read

Lines track the share of chains solved correctly as they lengthen up to 24 steps, though practice stopped at 12; higher is better. Colors compare the point-and-copy model against a frozen-backbone version, each on plain and reworded prompts.

0%25%50%75%100%5101520QLoRA, standardfrozen, paraphraseQLoRA, paraphrasefrozen, standard

Takeaway → The point-and-copy line on plain prompts holds near 20% at 24 steps, while the frozen version collapses to almost nothing there.

Data table
program length (trained on 1-12 steps)QLoRA, standardQLoRA, paraphrasefrozen, standardfrozen, paraphrase
489.8%85.9%83.6%87.5%
872.7%63.3%46.1%68.8%
1246.9%46.1%16.4%46.1%
2420.3%5.5%1.6%14.8%

Numbers from experiments/qwen_numeric_copy_compiler/analysis/final_metrics.csv

Technical framing

Length generalization: executor accuracy vs chain length — QLoRA keeps 20% exact execution at 24 steps, twice the training length, where the frozen pilot collapses on standard prompts.

Which part of the program the errors come from

How to read

Lines show the share correct for each program piece — the starting value, the operations, the number arguments, and the whole program together — as chains lengthen; higher is better.

0%25%50%75%100%125%5101520initial valueoperationsargumentswhole program exactwhole program exa…

Takeaway → Starting values and operations stay pinned near perfect while the whole-program line sags, showing tiny slips in the number slots are what compound.

Data table
program lengthinitial valueoperationsargumentswhole program exact
4100%100%97.5%89.8%
8100%100%96.1%72.7%
12100%100%94.1%46.9%
24100%99.9%92.9%18%

Numbers from experiments/qwen_numeric_copy_compiler/analysis/final_metrics.csv

Technical framing

Where the QLoRA compiler loses accuracy (standard prompts) — Initial values and operations are solved almost perfectly; small per-slot argument errors compound into the whole-program exact-match falloff.

In the author’s words from the Report · “Summary”

The full QLoRA trace condition reached 89.8% exact execution at standard length 4, 72.7% at length 8, 46.9% at length 12, and 20.3% at length 24. Direct final-answer QLoRA stayed at chance. An answer-only numeric-copy compiler learned length-4 programs exactly but did not generalize to longer chains. The key finding is that exact numeric copying changes the failure mode. The model no longer has to infer numeric values from hidden states; it only has to learn where the program tokens are. That makes the latent compiler much more reliable, especially on trained-length and moderately longer programs.

Overview

Standalone numeric-copy compiler experiment for a Qwen causal language model.

The experiment tests whether a model can learn token roles and ordered program slots while numeric and operator symbols are copied from a deterministic token map. The frozen pilot trains only the compiler heads over frozen hidden states. The full condition trains QLoRA adapters plus the same numeric-copy compiler.

Layout

src/qwen_numeric_copy_compiler_experiment.py    training and evaluation harness
src/analyze_qwen_numeric_copy_compiler.py       run aggregation and plots
runs/                                           lightweight JSON and CSV outputs
reports/                                        experiment log and standalone write-up
analysis/                                       aggregate tables and figures

Large checkpoints are stored outside the experiment directory:

large_artifacts/qwen_numeric_copy_compiler/checkpoints/

Reading Order

  1. reports/qwen_numeric_copy_compiler_paper.md
  2. analysis/summary.md
  3. analysis/final_metrics.csv
  4. reports/qwen_numeric_copy_compiler_experiment_log.md

Main Artifact

The main trained QLoRA condition is:

large_artifacts/qwen_numeric_copy_compiler/checkpoints/main_qwen3_4b_qlora_numeric_copy_trace_mixed_l12/

The checkpoint manifest is:

experiments/qwen_numeric_copy_compiler/checkpoint_manifest.csv

Report

Rendered from reports/qwen_numeric_copy_compiler_paper.md

Summary

This experiment tested whether a Qwen causal language model can expose a modular-arithmetic program through learned token roles while exact numeric and operation symbols are copied from a lexical token map. The frozen pilot trained only compiler heads over frozen hidden states. The full condition trained QLoRA adapters and compiler heads live. Both used the same executable modular runtime.

The result is positive. The full QLoRA trace condition reached 89.8% exact execution at standard length 4, 72.7% at length 8, 46.9% at length 12, and 20.3% at length 24. Direct final-answer QLoRA stayed at chance. An answer-only numeric-copy compiler learned length-4 programs exactly but did not generalize to longer chains.

The key finding is that exact numeric copying changes the failure mode. The model no longer has to infer numeric values from hidden states; it only has to learn where the program tokens are. That makes the latent compiler much more reliable, especially on trained-length and moderately longer programs.

Setup

  • Base model: Qwen/Qwen3-4B
  • Quantization: 4-bit NF4
  • Full-condition trainable update: LoRA rank 8, alpha 16, dropout 0.05, target all-linear
  • Task: modular arithmetic instructions modulo 97
  • Train lengths: 1-12 steps
  • Evaluation lengths: 4, 8, 12, 24 steps
  • Evaluation templates: standard and paraphrase
  • Evaluation size: 128 examples per split
  • Large checkpoints: large_artifacts/qwen_numeric_copy_compiler/checkpoints/

Each prompt describes an initial value and a sequence of add, subtract, and multiply updates. The compiler predicts:

  • the token position of the initial value;
  • ordered operation token positions;
  • ordered argument token positions.

Numeric residues and operation IDs are then copied from deterministic per-token maps. The executor applies the copied program exactly modulo 97.

Runs

RunVariantPurpose
pilot_qwen3_4b_frozen_numeric_copy_trace_mixed_l12copy_traceFrozen-backbone pilot gate with trace and executor loss.
main_qwen3_4b_qlora_numeric_copy_trace_mixed_l12copy_traceFull QLoRA numeric-copy compiler condition.
control_qwen3_4b_direct_numeric_copy_distribution_l12directFinal-answer QLoRA control without compiler structure.
control_qwen3_4b_qlora_numeric_copy_answer_only_l12copy_answer_onlyNumeric-copy compiler trained only from final-answer loss.

Smoke runs verify the harness and are not part of the main comparison.

Main QLoRA Result

SplitExecutorInitOpArgArg PosProgram Exact
Standard L489.8%100.0%100.0%97.5%96.9%89.8%
Standard L872.7%100.0%100.0%96.1%95.7%72.7%
Standard L1246.9%100.0%100.0%94.1%94.0%46.9%
Standard L2420.3%100.0%99.9%92.9%95.3%18.0%
Paraphrase L485.9%100.0%100.0%96.5%95.1%85.9%
Paraphrase L863.3%100.0%100.0%94.5%93.6%63.3%
Paraphrase L1246.1%100.0%100.0%93.6%92.6%46.1%
Paraphrase L245.5%100.0%97.4%85.8%84.9%5.5%

The compiler solves initial values and operations almost completely. The remaining loss comes from argument slot errors, especially on paraphrase length 24. The standard length-24 result is notable: argument value accuracy stays at 92.9% and program exact reaches 18.0%, even though evaluation length is twice the maximum training length.

Frozen Pilot

SplitExecutorInitOpArgArg PosProgram Exact
Standard L483.6%100.0%100.0%95.5%94.5%82.8%
Standard L846.1%100.0%100.0%90.2%88.5%45.3%
Standard L1216.4%100.0%100.0%86.5%84.2%16.4%
Standard L241.6%100.0%93.9%77.6%75.3%0.0%
Paraphrase L487.5%100.0%100.0%96.9%94.1%87.5%
Paraphrase L868.8%100.0%100.0%95.4%91.5%68.8%
Paraphrase L1246.1%100.0%100.0%93.7%90.4%45.3%
Paraphrase L2414.8%100.0%99.5%90.2%88.2%13.3%

The frozen pilot passed the gate. It showed that Qwen hidden states already support a numeric-copy compiler when trained with token-role traces. The QLoRA condition improves standard long-chain performance but does not uniformly improve every paraphrase split.

Controls

RunStandard L4Standard L8Standard L12Standard L24Paraphrase L4Paraphrase L8Paraphrase L12Paraphrase L24
Direct final-answer QLoRA3.1%0.8%0.0%0.8%1.6%3.1%3.9%1.6%
Answer-only numeric-copy compiler100.0%0.0%1.6%2.3%100.0%7.0%1.6%0.0%

The direct control stayed at chance. The answer-only compiler control is more interesting: it solved length-4 programs perfectly but did not extend to longer chains. Its slot-position diagnostics were poor despite perfect length-4 execution, indicating that it found a short-horizon solution rather than the ordered slot interface learned by trace supervision.

Interpretation

The experiment isolates a concrete bottleneck. A compiler that classifies numeric values from hidden states is too noisy for exact multi-step execution. A compiler that copies numeric values from selected tokens is much stronger. Once numeric copying is used, performance tracks slot localization accuracy.

The result supports three claims:

  1. Frozen Qwen hidden states contain enough information for a trace-supervised numeric-copy compiler.
  2. Live QLoRA training can improve the compiler on standard longer chains.
  3. Final-answer training alone can find a short numeric-copy solution, but it does not discover a length-generalizing ordered compiler under this budget.

The result does not show a universal intelligence improvement. It shows a practical recipe for this class of serial symbolic tasks: learn where the program tokens are, copy exact symbols, and run an invisible executor.

The next experiment should target robust slot generalization rather than numeric value decoding.

Recommended design:

  1. Keep numeric-copy readout.
  2. Train a slot-stability objective that penalizes drift in ordered operation and argument slots across paraphrase variants of the same program.
  3. Add a curriculum that mixes short and long lengths every batch instead of relying on uniform random lengths.
  4. Save mid-run checkpoints and select by validation program exactness, because the frozen pilot showed different splits peaking at different times.

Success criteria:

  • standard and paraphrase L12 program exact above 60%;
  • paraphrase L24 above 20%;
  • answer-only control remains unable to solve L8+ without traces.

Artifacts

Small files:

Large files:

  • Frozen pilot heads: large_artifacts/qwen_numeric_copy_compiler/checkpoints/pilot_qwen3_4b_frozen_numeric_copy_trace_mixed_l12/
  • Main QLoRA adapter and heads: large_artifacts/qwen_numeric_copy_compiler/checkpoints/main_qwen3_4b_qlora_numeric_copy_trace_mixed_l12/
  • Direct control adapter and heads: large_artifacts/qwen_numeric_copy_compiler/checkpoints/control_qwen3_4b_direct_numeric_copy_distribution_l12/
  • Answer-only control adapter and heads: large_artifacts/qwen_numeric_copy_compiler/checkpoints/control_qwen3_4b_qlora_numeric_copy_answer_only_l12/

Experiment log 7

Show the running log (7 entries, 2026-06-21)

Objective

Test whether a Qwen model can expose a symbolic modular-arithmetic program through learned token roles while exact numeric and operator values are copied from lexical token maps instead of inferred by semantic value classifiers.

Experiment Question

Can a frozen hidden-state parser pass a numeric-copy pilot gate, and does live QLoRA training improve or preserve that compiler interface on standard and paraphrased arithmetic programs?

Planned Gates

  1. Frozen numeric-copy pilot: train compiler heads over frozen model hidden states, with the backbone kept fixed.
  2. QLoRA numeric-copy compiler: train LoRA adapters and compiler heads live.
  3. Controls: final-answer direct adaptation and answer-only compiler training.

Primary Metrics

  • init_pos_accuracy, op_pos_accuracy, arg_pos_accuracy: role and slot localization.
  • init_accuracy, op_accuracy, arg_accuracy: copied program-symbol correctness.
  • program_exact: exact compiled program correctness.
  • executor_accuracy: exact modular execution accuracy.
  • Standard and paraphrase splits are evaluated separately at multiple chain lengths.

Artifact Policy

Lightweight outputs stay in experiments/qwen_numeric_copy_compiler/runs/.

Large adapters and head checkpoints stay in large_artifacts/qwen_numeric_copy_compiler/checkpoints/.

Log

2026-06-21

  • Created standalone experiment directory and external checkpoint path.
  • Implemented the numeric-copy harness and analyzer.
  • Tiny frozen-backbone smoke test passed as runs/smoke_tiny_frozen_copy_trace/.
  • Qwen frozen micro-smoke passed as runs/smoke_qwen3_4b_frozen_copy_trace/.
  • Frozen numeric-copy pilot completed as runs/pilot_qwen3_4b_frozen_numeric_copy_trace_mixed_l12/.

    • Final standard executor accuracy: L4 83.6%, L8 46.1%, L12 16.4%, L24 1.6%.
    • Final paraphrase executor accuracy: L4 87.5%, L8 68.8%, L12 46.1%, L24 14.8%.
    • Final copied argument accuracy stayed high through paraphrase L12 at 93.7%, but standard long-chain argument accuracy was lower.
    • The frozen pilot gate passed, so the live QLoRA numeric-copy condition was run next.
  • QLoRA numeric-copy trace condition completed as runs/main_qwen3_4b_qlora_numeric_copy_trace_mixed_l12/.

    • Final standard executor accuracy: L4 89.8%, L8 72.7%, L12 46.9%, L24 20.3%.
    • Final paraphrase executor accuracy: L4 85.9%, L8 63.3%, L12 46.1%, L24 5.5%.
    • Standard L24 copied argument accuracy reached 92.9%, up from 77.6% in the frozen pilot.
    • Final-answer controls were run after this condition.
  • Direct final-answer QLoRA control completed as runs/control_qwen3_4b_direct_numeric_copy_distribution_l12/.

    • Final accuracy stayed near chance on every split.
  • Answer-only numeric-copy compiler control completed as runs/control_qwen3_4b_qlora_numeric_copy_answer_only_l12/.

    • It solved length-4 programs exactly, but stayed near chance at length 8 and above.
    • This indicates final-answer loss can discover a short numeric-copy shortcut, but did not discover the length-generalizing slot interface under this budget.
  • Regenerated aggregate analysis and checkpoint manifest.
  • Wrote standalone Markdown and HTML reports.
  • Completion audit passed:

    • Source compilation passed.
    • Analyzer regeneration passed.
    • Standalone wording scan found no stale references.
    • Expected README, report, log, analysis, run, source, and manifest files are present.
    • checkpoint_manifest.csv indexes 18 large checkpoint files.

Figures 3

direct accuracy
direct accuracy · analysis/figures/
executor accuracy
executor accuracy · analysis/figures/
program exact
program exact · analysis/figures/

Data files 7

Result tables and metrics copied from the experiment folder — preview inline or open the raw file.

Reproduce

This entry is source code or analysis only — there is no separate run to reproduce.

Browse the experiment folder on GitHub ↗