Research log Small Model Experimentation
GitHub

Qwen Hidden VM Mixed Domains

Finished2026-06-23imported · line YStructured Execution and CompilersGitHub ↗
Writing hidden programs beats guessing the answer

The one idea you need

Instead of blurting out a number from intuition, the model quietly fills the slots of a tiny program — choosing the operations and copying in the numbers — that a fixed, reliable calculator then runs exactly, like dictating steps to a spreadsheet instead of eyeballing the total.

The question

Can a small model be taught to turn many kinds of everyday word problems into a hidden program that a reliable calculator runs, instead of guessing the answer?

What we found

Yes. Guessing the answer directly worked only about 15% of the time across six kinds of problems — arithmetic, dates, unit conversions, list totals, yes/no thresholds, and lookups. Having the model instead write a hidden program for a fixed calculator to run hit 78%. Showing it the exact worked steps during training, not just final answers, also produced far cleaner programs — 64% exactly right versus 34%.

Why it matters

Don't ask a small model to compute arithmetic, dates, or lookups directly — have it write a structured program and run that on a fixed calculator. Train it on the full worked steps, not just final answers, for cleaner, inspectable programs.

Guessing the answer vs running a hidden program15% → 78%share of fresh mixed problems solved correctly
Same setup trained on final answers alone60%vs 78% when trained on the full worked steps
Programs the model wrote exactly right34% → 64%final-answers-only vs full-worked-steps training
Problems longer than any it trained on1 in 2plainly worded problems solved beyond the training length
On this page
  1. Results at a glance
  2. Overview
  3. Report
    1. Abstract
    2. Setup
    3. Results
    4. Interpretation
    5. Decision
    6. Limitations
    7. Artifacts
  4. Experiment log
  5. Figures
  6. Data files
  7. Reproduce
  8. Related

Results at a glance 6

Hidden program beats plain guessing on fresh mixed problems

How to read

Each bar is accuracy on fresh problems for one method: guessing the answer directly, a hidden program learned from final answers only, and a hidden program learned from full worked steps. Taller is better.

0%20%40%60%80%direct answeringdirect answering14.8%hidden VM (answer-only training)hidden VM (answer-only training)60.2%hidden VM (trace training)hidden VM (trace training)77.7%

Takeaway → The full-worked-steps bar towers at 78%, far above the 15% for direct guessing, showing the hidden program — not the model's intuition — does the work.

Data table
conditionaccuracy
direct answering14.8%
hidden VM (answer-only training)60.2%
hidden VM (trace training)77.7%

Numbers from experiments/qwen_hidden_vm_mixed_domains/analysis/summary.md (Headline + Run Summary tables)

Technical framing

Hidden VM compiler vs direct answering on fresh mixed-domain tasks — Compiling prompts into a hidden executable VM beats direct answering by 62.9 pp; trace supervision adds 17.6 pp over answer-only.

Accuracy by problem type: guessing versus hidden program

How to read

Six problem types line the bottom — arithmetic, dates, unit conversions, list totals, yes/no thresholds, lookups. Each has one bar for plain guessing and one for the hidden program; height is accuracy, taller is better.

0%25%50%75%100%4.5%84.1%arithmetic22.7%45.5%calendar0%66.7%unit0%88.1%list61.9%97.6%boolean0%85.7%lookup

Takeaway → The hidden-program bar is taller for every type; four jump from near zero to between 67% and 88%, while date problems gain the least.

Data table
task domaindirecthidden VM
arithmetic4.5%84.1%
calendar22.7%45.5%
unit0%66.7%
list0%88.1%
boolean61.9%97.6%
lookup0%85.7%

Numbers from experiments/qwen_hidden_vm_mixed_domains/analysis/summary.md (Fresh Paired Domain Breakdown table)

Technical framing

Per-domain accuracy: direct answering vs hidden VM (fresh paired) — The hidden VM lifts every domain; four domains go from near 0% direct accuracy to 67-88%, with calendar the weakest transfer.

Showing worked steps produces cleaner programs

How to read

Three quality measures along the bottom, each with two bars: training on full worked steps versus training on final answers only. Taller means better, cleaner programs.

0%25%50%75%100%hidden VM accuracyhidden VM accuracy77.7%60.2%program exactprogram exact63.7%34.4%state prefixstate prefix81%58.1%

Takeaway → Worked-step bars win on all three measures; the rate of writing the exactly-correct program nearly doubles, 64% versus 34%.

Data table
metric (fresh paired split)trace-trainedanswer-only
hidden VM accuracy77.7%60.2%
program exact63.7%34.4%
state prefix81%58.1%

Numbers from experiments/qwen_hidden_vm_mixed_domains/analysis/summary.md (Run Summary table)

Technical framing

Trace supervision yields cleaner programs than answer-only training — Answer-only gradients still learn a latent executor, but trace supervision nearly doubles exact-program recovery (63.7% vs 34.4%).

Problems longer than the training examples lose accuracy

How to read

Two prompt styles — plainly worded and reworded — each with a bar for the trained problem length and a bar for a longer, unseen length. Height is hidden-program accuracy, taller is better.

0%20%40%60%80%standard promptsstandard prompts72.9%50%paraphrased promptsparaphrased prompts75.5%35.9%

Takeaway → The longer-length bars are shorter, falling to about 36% on reworded prompts, so the program stretches only partway past its training length.

Data table
prompt stylefresh (length 4)hard (length 6)
standard prompts72.9%50%
paraphrased prompts75.5%35.9%

Numbers from experiments/qwen_hidden_vm_mixed_domains/analysis/summary.md (Final Splits table)

Technical framing

Length generalization: trained on lengths 1-4, tested at length 6 — The compiler transfers beyond training length but degrades at length 6, especially under paraphrase - not yet a length-general algorithm.

More training examples sharply improve the hidden program

How to read

Three runs ordered by how many training examples they saw — 160, 256, 512 — each with bars for three quality measures. Taller is better.

0%25%50%75%100%pilot (160 examples)pilot (160 examples)15.6%7.8%41.4%pilot balanced (256 examples)pilot balanced (256 examples)55.2%49%70.6%main (512 examples)main (512 examples)77.7%63.7%81%

Takeaway → Every bar rises with more examples; accuracy climbs from 16% at 160 examples to 78% at 512, so the method is still hungry for data.

Data table
trace-trained run (train-set size)hidden VM accuracyprogram exactstate prefix
pilot (160 examples)15.6%7.8%41.4%
pilot balanced (256 examples)55.2%49%70.6%
main (512 examples)77.7%63.7%81%

Numbers from experiments/qwen_hidden_vm_mixed_domains/analysis/summary.md (Run Summary table)

Technical framing

More trace-training examples sharply improve the hidden VM compiler — Going from 160 to 512 training examples lifts hidden VM accuracy from 15.6% to 77.7%; the compiler is still data-hungry at 4B.

Training lifts the hidden program, not plain guessing

How to read

Two phases, before and after training, each with bars for plain guessing, hidden-program accuracy, and writing the exactly-correct program. Taller is better.

0%20%40%60%80%before trainingbefore training12.5%28.9%0%after trainingafter training14.8%77.7%63.7%

Takeaway → After training the hidden program jumps from 29% to 78% and exact programs from 0% to 64%, while plain guessing barely moves.

Data table
training phasedirect answeringhidden VM executionprogram exact
before training12.5%28.9%0%
after training14.8%77.7%63.7%

Numbers from experiments/qwen_hidden_vm_mixed_domains/runs/main_hidden_vm_trace_s512/train_log.csv (step 0 baseline row) and analysis/all_final_metrics.csv (fresh_paired_mixed final row)

Technical framing

Training lifts the hidden VM, not direct answering (fresh paired) — Posttraining moves hidden VM execution from 28.9% to 77.7% and program-exact from 0% to 63.7%, while direct answering barely budges.

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

This experiment tests whether a Qwen 4B model can be posttrained to compile several natural-language task families into one hidden typed virtual machine. The model emits invisible VM slots, a deterministic runtime executes those slots, and the final answer is read from the runtime state. The task families are arithmetic chains, calendar shifts, unit-style transforms, list aggregation, boolean thresholding, and lookup/adjust rules.

Overview

This experiment trains a Qwen-attached hidden virtual machine compiler on multiple deterministic task families. The model reads natural-language prompts, writes an invisible typed program into fixed slots, executes that program in a deterministic runtime, and returns the runtime answer.

Small files stay in this experiment directory. Large model adapters and head checkpoints are stored separately under:

large_artifacts/qwen_hidden_vm_mixed_domains/checkpoints/

Layout

  • src/qwen_hidden_vm_mixed_domains_experiment.py: training and evaluation entrypoint.
  • analysis/analyze_qwen_hidden_vm_mixed_domains.py: report, chart, and summary generator.
  • runs/: run-local metrics, logs, and metadata.
  • reports/: standalone markdown and HTML reports.
  • experiment_log.md: running lab notebook.
  • checkpoint_manifest.csv: generated manifest for large artifacts.

Primary Question

Can a small QLoRA posttraining run teach a 4B Qwen model to compile several kinds of natural-language tasks into one hidden executable VM, rather than only learning a single modular-arithmetic grammar?

Report

Rendered from reports/qwen_hidden_vm_mixed_domains_paper.md

Abstract

This experiment tests whether a Qwen 4B model can be posttrained to compile several natural-language task families into one hidden typed virtual machine. The model emits invisible VM slots, a deterministic runtime executes those slots, and the final answer is read from the runtime state. The task families are arithmetic chains, calendar shifts, unit-style transforms, list aggregation, boolean thresholding, and lookup/adjust rules.

Setup

  • Primary run: main_hidden_vm_trace_s512
  • Model: Qwen/Qwen3-4B
  • Variant: trace
  • Train examples: 512
  • Train steps: 520
  • VM max steps: 6
  • Train length range: 1 to 4
  • Eval length: 4; hard length: 6

The hidden VM uses typed operation slots and copied numeric arguments. Direct logits are the model's next-token numeric answer distribution at the answer marker; hidden VM accuracy is execution of the compiled invisible program.

Results

Final Splits

SplitDirectHidden VMProgram exactState prefixPair both-correct
val_mixed13.2%70.8%63.9%81.8%n/a
fresh_standard_mixed12.0%72.9%62.5%79.4%n/a
fresh_paraphrase_mixed13.0%75.5%63.5%81.4%n/a
fresh_paired_mixed14.8%77.7%63.7%81.0%68.8%
hard_standard_mixed10.9%50.0%33.3%68.6%n/a
hard_paraphrase_mixed11.5%35.9%19.3%64.9%n/a
domain_arithmetic0.0%65.6%65.6%80.5%n/a
domain_calendar28.1%56.2%56.2%78.9%n/a
domain_unit3.1%71.9%71.9%83.6%n/a
domain_list3.1%71.9%43.8%80.5%n/a
domain_boolean46.9%90.6%81.2%86.7%n/a
domain_lookup0.0%87.5%68.8%79.7%n/a

Split accuracy

Domain Breakdown

DomainnDirectHidden VM
arithmetic44.004.5%84.1%
calendar44.0022.7%45.5%
unit42.000.0%66.7%
list42.000.0%88.1%
boolean42.0061.9%97.6%
lookup42.000.0%85.7%

Domain accuracy

Training Dynamics

Fresh paired hidden VM accuracy moved from 28.9% at initialization to 77.7% after training. Hard standard accuracy at length 6 was 50.0%.

Training curve

Run Summary

RunVariantDirectHidden VMProgram exactState prefix
control_hidden_vm_answer_only_s512answer_only12.1%60.2%34.4%58.1%
main_hidden_vm_trace_s512trace14.8%77.7%63.7%81.0%
pilot_hidden_vm_trace_balanced_l4_s256trace14.6%55.2%49.0%70.6%
pilot_hidden_vm_trace_s160trace14.1%15.6%7.8%41.4%

Run summary

Interpretation

The primary measurement is fresh paired mixed-domain accuracy. Direct logits score 14.8%, while the trace-supervised hidden VM scores 77.7% (+62.9 pp). The matched answer-only hidden-VM control scores 60.2%, so trace supervision adds +17.6 pp over the same executable architecture trained only from final answers.

The control is important: final-answer gradients alone do learn a useful latent executor, but the trace run recovers substantially cleaner programs. Program-exact accuracy is 63.7% for the trace run versus 34.4% for answer-only, and state-prefix accuracy is 81.0% versus 58.1%. That gap matters because the end goal is not just to fit short synthetic answers; it is to make the model reliably write an inspectable executable representation.

The hard-length split is the caution flag. The trace run reaches 50.0% on length-6 standard prompts after training on length 1-4 programs, but paraphrased length-6 accuracy is only 35.9%. The learned compiler transfers beyond the training length, but it is not yet a length-general algorithm.

Decision

This is a positive result for the Qwen-attached direction. A small posttraining run attached a fixed executable substrate to Qwen 3 4B and produced a large improvement over direct next-token answering on fresh symbolic tasks. It does not demonstrate a universal intelligence multiplier, but it does identify a credible mechanism: train the model to compile prompts into a hidden executable intermediate representation, then let a deterministic runtime carry the exact computation.

The highest-impact next experiments are:

  1. Hard-length curriculum and repair. Train on lengths 1-6, evaluate on 8-10, and add a verifier-driven repair pass where Qwen edits only the hidden program after failed execution. This directly attacks the remaining length-generalization weakness.
  2. Real-task trace distillation. Build VM traces from tool-verifiable word problems, date arithmetic, unit conversions, table lookup, and small algorithmic tasks, then train the same compiler/runtime interface on natural data rather than synthetic templates.
  3. Policy-gradient fine-tuning after trace warm start. Treat VM program emission as the action, deterministic execution as the environment transition, and answer verification as reward. Use trace training to initialize the policy, then optimize with a small KL-controlled RL phase to test whether the model can discover shorter or more robust programs than the teacher traces.
  4. Wider residual attachment. Keep the fixed VM, but feed execution states back into upper-layer Qwen residual streams before answer generation. This tests whether executable latent state can improve ordinary language outputs instead of only producing bounded integer answers.

Limitations

  • The domains are synthetic and deterministic.
  • Answers are integers in a bounded value vocabulary.
  • Trace supervision supplies exact hidden programs.
  • The runtime is fixed and hand-designed.
  • This is one primary run unless additional runs are added.

Artifacts

Small experiment files live in:

experiments/qwen_hidden_vm_mixed_domains/

Large artifacts live in:

large_artifacts/qwen_hidden_vm_mixed_domains/checkpoints/

Primary files:

Experiment log 1

Show the running log (1 entry, 2026-06-23)

2026-06-23

Created standalone mixed-domain hidden VM experiment.

Initial design:

  • Use a fixed typed VM with ten operations: add, subtract, multiply, calendar add/subtract modulo 7, set, max, min, xor, and greater-than.
  • Generate exact hidden traces for six task families: arithmetic chains, calendar shifts, unit-style transforms, list aggregation, boolean thresholding, and lookup/adjust rules.
  • Train Qwen 3 4B with QLoRA plus a compiler head to emit VM slots from prompts.
  • Compare trace-supervised hidden VM training against answer-only executor training.
  • Evaluate direct answer logits, compiler execution accuracy, exact program match, state-prefix accuracy, per-domain accuracy, fresh paraphrases, paired standard/paraphrase prompts, and longer/harder programs.

Next steps:

  • Implement the standalone trainer and analyzer.
  • Run a tiny smoke test.
  • If the smoke passes, run a pilot to tune training steps and loss weights.
  • Run main and answer-only control runs.
  • Generate charts, markdown, HTML, and artifact manifest.

Smoke and first pilot notes:

  • smoke_hidden_vm_mixed passed end-to-end after adding a guard that max_steps must cover train, eval, and hard program lengths.
  • pilot_hidden_vm_trace_s160 did not improve fresh mixed-domain executor accuracy. The useful signal was diagnostic rather than positive: initialization was learned, operation slots partially learned, and argument slots were weak.
  • A lookup-domain bug was found: the selected table value could appear only before the SET operation while the compiler's argument reader is intentionally local after each operation token. The renderer now repeats the selected value as the explicit SET argument.
  • Dataset construction now balances domains by cycling through the configured domain list before shuffling, so pilots cannot accidentally under-sample a hard domain.

Repaired pilot plan:

python experiments/qwen_hidden_vm_mixed_domains/src/qwen_hidden_vm_mixed_domains_experiment.py \
  --run_name pilot_hidden_vm_trace_balanced_l4_s256 --variant trace \
  --train_examples 256 --val_examples 72 --eval_examples 72 --eval_pairs 48 --domain_eval_examples 16 \
  --train_steps 260 --train_batch_size 2 --eval_batch_size 4 \
  --max_steps 6 --train_max_len 4 --eval_length 4 --hard_length 6 --max_length 512 \
  --lr 5e-5 --executor_loss_weight 0.2 --state_loss_weight 0.05 \
  --log_every 25 --seed 94 --eval_seed 94001

Repaired pilot result:

  • pilot_hidden_vm_trace_balanced_l4_s256 completed in 184.9 seconds.
  • Fresh paired hidden-VM executor accuracy improved from 24.0% at initialization to 55.2%; direct numeric-token accuracy finished at 14.6%.
  • Fresh paired program-exact accuracy reached 49.0%; state-prefix fraction reached 70.6%.
  • Per-domain fresh paired hidden-VM accuracy: arithmetic 62.5%, calendar 31.2%, unit 56.2%, list 100.0%, boolean 50.0%, lookup 31.2%.
  • Hard length-6 transfer remained weak: 18.1% on standard prompts and 29.2% on paraphrases.

Main trace run plan:

python experiments/qwen_hidden_vm_mixed_domains/src/qwen_hidden_vm_mixed_domains_experiment.py \
  --run_name main_hidden_vm_trace_s512 --variant trace \
  --train_examples 512 --val_examples 144 --eval_examples 192 --eval_pairs 128 --domain_eval_examples 32 \
  --train_steps 520 --train_batch_size 2 --eval_batch_size 8 \
  --max_steps 6 --train_max_len 4 --eval_length 4 --hard_length 6 --max_length 512 \
  --lr 5e-5 --executor_loss_weight 0.2 --state_loss_weight 0.05 \
  --log_every 65 --seed 95 --eval_seed 95001

Main trace result:

  • main_hidden_vm_trace_s512 completed in 333.2 seconds.
  • Fresh paired hidden-VM executor accuracy reached 77.7%; direct numeric-token accuracy finished at 14.8%.
  • Fresh paired program-exact accuracy reached 63.7%; state-prefix fraction reached 81.0%.
  • Fresh standard and paraphrase hidden-VM executor accuracy reached 72.9% and 75.5%.
  • Hard length-6 transfer improved to 50.0% on standard prompts and 35.9% on paraphrases.
  • Per-domain mixed hidden-VM accuracy: arithmetic 65.6%, calendar 56.2%, unit 71.9%, list 71.9%, boolean 90.6%, lookup 87.5%.

Matched answer-only control plan:

python experiments/qwen_hidden_vm_mixed_domains/src/qwen_hidden_vm_mixed_domains_experiment.py \
  --run_name control_hidden_vm_answer_only_s512 --variant answer_only \
  --train_examples 512 --val_examples 144 --eval_examples 192 --eval_pairs 128 --domain_eval_examples 32 \
  --train_steps 520 --train_batch_size 2 --eval_batch_size 8 \
  --max_steps 6 --train_max_len 4 --eval_length 4 --hard_length 6 --max_length 512 \
  --lr 5e-5 --executor_loss_weight 1.0 --state_loss_weight 0.0 --direct_answer_loss_weight 0.0 \
  --log_every 65 --seed 96 --eval_seed 95001

Matched answer-only control result:

  • control_hidden_vm_answer_only_s512 completed in 358.5 seconds.
  • Fresh paired hidden-VM executor accuracy reached 60.2%; direct numeric-token accuracy finished at 12.1%.
  • Fresh paired program-exact accuracy reached 34.4%; state-prefix fraction reached 58.1%.
  • Hard length-6 transfer reached 36.5% on standard prompts and 37.0% on paraphrases.
  • The control is materially better than chance, so final-answer gradients can discover a useful executable policy. Trace supervision still adds +17.6 percentage points on fresh paired execution, +29.3 percentage points on program exactness, and +22.9 percentage points on state-prefix recovery.

Analysis artifacts:

  • Generated analysis/summary.md.
  • Generated reports/qwen_hidden_vm_mixed_domains_paper.md.
  • Generated reports/qwen_hidden_vm_mixed_domains_paper.html.
  • Generated figures: split_accuracy.png, domain_accuracy.png, training_curve.png, and run_summary.png.
  • Generated checkpoint_manifest.csv pointing to large checkpoint artifacts under large_artifacts/qwen_hidden_vm_mixed_domains/checkpoints/.

Current interpretation:

This is a positive result for the Qwen-attached hidden-executor direction. The trace-supervised hidden VM improves fresh paired accuracy from 14.8% direct next-token answering to 77.7% executable hidden-program answering. The answer-only executable control reaches 60.2%, which is also important: the runtime architecture itself is useful, but dense trace supervision makes the compiled programs much more reliable and inspectable.

The remaining weakness is length-generalization. Training on length 1-4 transfers to length 6, but not cleanly enough: 50.0% on standard hard prompts and 35.9% on paraphrased hard prompts.

Figures 4

domain accuracy
domain accuracy · analysis/figures/
run summary
run summary · analysis/figures/
split accuracy
split accuracy · analysis/figures/
training curve
training curve · analysis/figures/

Data files 12

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

Reproduce

The run commands are documented inside the experiment folder (see the README).

Browse the experiment folder on GitHub ↗