Qwen Hidden VM Mixed Domains
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.
On this page
Results at a glance 6
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.
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
| condition | accuracy |
|---|---|
| direct answering | 14.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.
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.
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 domain | direct | hidden VM |
|---|---|---|
| arithmetic | 4.5% | 84.1% |
| calendar | 22.7% | 45.5% |
| unit | 0% | 66.7% |
| list | 0% | 88.1% |
| boolean | 61.9% | 97.6% |
| lookup | 0% | 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.
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.
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-trained | answer-only |
|---|---|---|
| hidden VM accuracy | 77.7% | 60.2% |
| program exact | 63.7% | 34.4% |
| state prefix | 81% | 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%).
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.
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 style | fresh (length 4) | hard (length 6) |
|---|---|---|
| standard prompts | 72.9% | 50% |
| paraphrased prompts | 75.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.
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.
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 accuracy | program exact | state 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.
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.
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 phase | direct answering | hidden VM execution | program exact |
|---|---|---|---|
| before training | 12.5% | 28.9% | 0% |
| after training | 14.8% | 77.7% | 63.7% |
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:
1to4 - 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
| Split | Direct | Hidden VM | Program exact | State prefix | Pair both-correct |
|---|---|---|---|---|---|
| val_mixed | 13.2% | 70.8% | 63.9% | 81.8% | n/a |
| fresh_standard_mixed | 12.0% | 72.9% | 62.5% | 79.4% | n/a |
| fresh_paraphrase_mixed | 13.0% | 75.5% | 63.5% | 81.4% | n/a |
| fresh_paired_mixed | 14.8% | 77.7% | 63.7% | 81.0% | 68.8% |
| hard_standard_mixed | 10.9% | 50.0% | 33.3% | 68.6% | n/a |
| hard_paraphrase_mixed | 11.5% | 35.9% | 19.3% | 64.9% | n/a |
| domain_arithmetic | 0.0% | 65.6% | 65.6% | 80.5% | n/a |
| domain_calendar | 28.1% | 56.2% | 56.2% | 78.9% | n/a |
| domain_unit | 3.1% | 71.9% | 71.9% | 83.6% | n/a |
| domain_list | 3.1% | 71.9% | 43.8% | 80.5% | n/a |
| domain_boolean | 46.9% | 90.6% | 81.2% | 86.7% | n/a |
| domain_lookup | 0.0% | 87.5% | 68.8% | 79.7% | n/a |

Domain Breakdown
| Domain | n | Direct | Hidden VM |
|---|---|---|---|
| arithmetic | 44.00 | 4.5% | 84.1% |
| calendar | 44.00 | 22.7% | 45.5% |
| unit | 42.00 | 0.0% | 66.7% |
| list | 42.00 | 0.0% | 88.1% |
| boolean | 42.00 | 61.9% | 97.6% |
| lookup | 42.00 | 0.0% | 85.7% |

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%.

Run Summary
| Run | Variant | Direct | Hidden VM | Program exact | State prefix |
|---|---|---|---|---|---|
| control_hidden_vm_answer_only_s512 | answer_only | 12.1% | 60.2% | 34.4% | 58.1% |
| main_hidden_vm_trace_s512 | trace | 14.8% | 77.7% | 63.7% | 81.0% |
| pilot_hidden_vm_trace_balanced_l4_s256 | trace | 14.6% | 55.2% | 49.0% | 70.6% |
| pilot_hidden_vm_trace_s160 | trace | 14.1% | 15.6% | 7.8% | 41.4% |

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:
- 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.
- 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.
- 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.
- 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:
analysis/summary.mdanalysis/final_metrics.csvanalysis/all_final_metrics.csvanalysis/figures/split_accuracy.pnganalysis/figures/domain_accuracy.pnganalysis/figures/training_curve.pnganalysis/figures/run_summary.pngruns/main_hidden_vm_trace_s512/metrics.csvruns/main_hidden_vm_trace_s512/train_log.csvreports/qwen_hidden_vm_mixed_domains_paper.mdreports/qwen_hidden_vm_mixed_domains_paper.htmlcheckpoint_manifest.csv
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_mixedpassed end-to-end after adding a guard thatmax_stepsmust cover train, eval, and hard program lengths.pilot_hidden_vm_trace_s160did 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
SEToperation while the compiler's argument reader is intentionally local after each operation token. The renderer now repeats the selected value as the explicitSETargument. - 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 94001Repaired pilot result:
pilot_hidden_vm_trace_balanced_l4_s256completed 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 95001Main trace result:
main_hidden_vm_trace_s512completed 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 95001Matched answer-only control result:
control_hidden_vm_answer_only_s512completed 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, andrun_summary.png. - Generated
checkpoint_manifest.csvpointing to large checkpoint artifacts underlarge_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
Data files 12
Result tables and metrics copied from the experiment folder — preview inline or open the raw file.
analysis/all_final_metrics.csv15 kBanalysis/final_metrics.csv3.7 kBruns/control_hidden_vm_answer_only_s512/metrics.csv3.8 kBruns/control_hidden_vm_answer_only_s512/results.json26 kBruns/main_hidden_vm_trace_s512/metrics.csv3.7 kBruns/main_hidden_vm_trace_s512/results.json29 kBruns/pilot_hidden_vm_trace_balanced_l4_s256/metrics.csv4.1 kBruns/pilot_hidden_vm_trace_balanced_l4_s256/results.json31 kBruns/pilot_hidden_vm_trace_s160/metrics.csv3.8 kBruns/pilot_hidden_vm_trace_s160/results.json29 kBruns/smoke_hidden_vm_mixed/metrics.csv2.8 kBruns/smoke_hidden_vm_mixed/results.json21 kB
Reproduce
The run commands are documented inside the experiment folder (see the README).