|
| 1 | +# Less is More: Recursive Reasoning with Tiny Networks |
| 2 | + |
| 3 | +This is the codebase for the paper: "Less is More: Recursive Reasoning with Tiny Networks" were we present a recursive reasoning approach that achieves amazing scores of 45% on ARC-AGI-1 and 8% on ARC-AGI-2 using a tiny 7M parameters neural network. |
| 4 | + |
| 5 | +[Paper](https://arxiv.org/abs/2510.04871) |
| 6 | + |
| 7 | +### How TRM works |
| 8 | + |
| 9 | +Tiny Recursion Model (TRM) recursively improves its predicted answer y with a tiny network. It starts with the embedded input question x and initial embedded answer y and latent z. For up to K improvements steps, it tries to improve its answer y. It does so by i) recursively updating n times its latent z given the question x, current answer y, and current latent z (recursive reasoning), and then ii) updating its answer y given the current answer y and current latent z. This recursive process allows the model to progressively improve its answer (potentially addressing any errors from its previous answer) in an extremely parameter-efficient manner while minimizing overfitting. |
| 10 | + |
| 11 | +<p align="center"> |
| 12 | +<img src="{{ site.baseurl }}/assets/images/TRM_fig.png" alt="TRM-Figure" style="width:50%"> |
| 13 | +</p> |
| 14 | + |
| 15 | +### Requirements |
| 16 | + |
| 17 | +- Python 3.10 (or similar) |
| 18 | +- Cuda 12.6.0 (or similar) |
| 19 | + |
| 20 | +```bash |
| 21 | +pip install --upgrade pip wheel setuptools |
| 22 | +pip install --pre --upgrade torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu126 # install torch based on your cuda version |
| 23 | +pip install -r requirements.txt # install requirements |
| 24 | +pip install --no-cache-dir --no-build-isolation adam-atan2 |
| 25 | +wandb login YOUR-LOGIN # login if you want the logger to sync results to your Weights & Biases (https://wandb.ai/) |
| 26 | +``` |
| 27 | + |
| 28 | +### Dataset Preparation |
| 29 | + |
| 30 | +```bash |
| 31 | +# ARC-AGI-1 |
| 32 | +python -m dataset.build_arc_dataset \ |
| 33 | + --input-file-prefix kaggle/combined/arc-agi \ |
| 34 | + --output-dir data/arc1concept-aug-1000 \ |
| 35 | + --subsets training evaluation concept \ |
| 36 | + --test-set-name evaluation |
| 37 | + |
| 38 | +# ARC-AGI-2 |
| 39 | +python -m dataset.build_arc_dataset \ |
| 40 | + --input-file-prefix kaggle/combined/arc-agi \ |
| 41 | + --output-dir data/arc2concept-aug-1000 \ |
| 42 | + --subsets training2 evaluation2 concept \ |
| 43 | + --test-set-name evaluation2 |
| 44 | + |
| 45 | +## Note: You cannot train on both ARC-AGI-1 and ARC-AGI-2 and evaluate them both because ARC-AGI-2 training data contains some ARC-AGI-1 eval data |
| 46 | + |
| 47 | +# Sudoku-Extreme |
| 48 | +python dataset/build_sudoku_dataset.py --output-dir data/sudoku-extreme-1k-aug-1000 --subsample-size 1000 --num-aug 1000 # 1000 examples, 1000 augments |
| 49 | + |
| 50 | +# Maze-Hard |
| 51 | +python dataset/build_maze_dataset.py # 1000 examples, 8 augments |
| 52 | +``` |
| 53 | + |
| 54 | +## Experiments |
| 55 | + |
| 56 | +### ARC-AGI (assuming 4 H-100 GPUs): |
| 57 | + |
| 58 | +```bash |
| 59 | +run_name="pretrain_att_arc12concept_4" |
| 60 | +torchrun --nproc-per-node 4 --rdzv_backend=c10d --rdzv_endpoint=localhost:0 --nnodes=1 pretrain.py \ |
| 61 | +arch=trm \ |
| 62 | +data_paths="[data/arc12concept-aug-1000]" \ |
| 63 | +arch.L_layers=2 \ |
| 64 | +arch.H_cycles=3 arch.L_cycles=4 \ |
| 65 | ++run_name=${run_name} ema=True |
| 66 | + |
| 67 | +``` |
| 68 | + |
| 69 | +*Runtime:* ~3 days |
| 70 | + |
| 71 | +### Sudoku-Extreme (assuming 1 L40S GPU): |
| 72 | + |
| 73 | +```bash |
| 74 | +run_name="pretrain_mlp_t_sudoku" |
| 75 | +python pretrain.py \ |
| 76 | +arch=trm \ |
| 77 | +data_paths="[data/sudoku-extreme-1k-aug-1000]" \ |
| 78 | +evaluators="[]" \ |
| 79 | +epochs=50000 eval_interval=5000 \ |
| 80 | +lr=1e-4 puzzle_emb_lr=1e-4 weight_decay=1.0 puzzle_emb_weight_decay=1.0 \ |
| 81 | +arch.mlp_t=True arch.pos_encodings=none \ |
| 82 | +arch.L_layers=2 \ |
| 83 | +arch.H_cycles=3 arch.L_cycles=6 \ |
| 84 | ++run_name=${run_name} ema=True |
| 85 | + |
| 86 | +run_name="pretrain_att_sudoku" |
| 87 | +python pretrain.py \ |
| 88 | +arch=trm \ |
| 89 | +data_paths="[data/sudoku-extreme-1k-aug-1000]" \ |
| 90 | +evaluators="[]" \ |
| 91 | +epochs=50000 eval_interval=5000 \ |
| 92 | +lr=1e-4 puzzle_emb_lr=1e-4 weight_decay=1.0 puzzle_emb_weight_decay=1.0 \ |
| 93 | +arch.L_layers=2 \ |
| 94 | +arch.H_cycles=3 arch.L_cycles=6 \ |
| 95 | ++run_name=${run_name} ema=True |
| 96 | +``` |
| 97 | + |
| 98 | +*Runtime:* < 36 hours |
| 99 | + |
| 100 | +### Maze-Hard (assuming 4 L40S GPUs): |
| 101 | + |
| 102 | +```bash |
| 103 | +run_name="pretrain_att_maze30x30" |
| 104 | +torchrun --nproc-per-node 4 --rdzv_backend=c10d --rdzv_endpoint=localhost:0 --nnodes=1 pretrain.py \ |
| 105 | +arch=trm \ |
| 106 | +data_paths="[data/maze-30x30-hard-1k]" \ |
| 107 | +evaluators="[]" \ |
| 108 | +epochs=50000 eval_interval=5000 \ |
| 109 | +lr=1e-4 puzzle_emb_lr=1e-4 weight_decay=1.0 puzzle_emb_weight_decay=1.0 \ |
| 110 | +arch.L_layers=2 \ |
| 111 | +arch.H_cycles=3 arch.L_cycles=4 \ |
| 112 | ++run_name=${run_name} ema=True |
| 113 | +``` |
| 114 | + |
| 115 | +*Runtime:* < 24 hours |
| 116 | + |
| 117 | +## Reference |
| 118 | + |
| 119 | +If you find our work useful, please consider citing: |
| 120 | + |
| 121 | +```bibtex |
| 122 | +@misc{jolicoeurmartineau2025tinyrecursionmodel, |
| 123 | + title={Less is More: Recursive Reasoning with Tiny Networks}, |
| 124 | + author={Alexia Jolicoeur-Martineau}, |
| 125 | + year={2025}, |
| 126 | + eprint={xxxxxxx}, |
| 127 | + archivePrefix={arXiv}, |
| 128 | + primaryClass={cs.AI}, |
| 129 | + url={https://arxiv.org/abs/xxxxxxxxx}, |
| 130 | +} |
| 131 | +``` |
| 132 | + |
| 133 | +and the Hierarchical Reasoning Model (HRM): |
| 134 | + |
| 135 | +```bibtex |
| 136 | +@misc{wang2025hierarchicalreasoningmodel, |
| 137 | + title={Hierarchical Reasoning Model}, |
| 138 | + author={Guan Wang and Jin Li and Yuhao Sun and Xing Chen and Changling Liu and Yue Wu and Meng Lu and Sen Song and Yasin Abbasi Yadkori}, |
| 139 | + year={2025}, |
| 140 | + eprint={2506.21734}, |
| 141 | + archivePrefix={arXiv}, |
| 142 | + primaryClass={cs.AI}, |
| 143 | + url={https://arxiv.org/abs/2506.21734}, |
| 144 | +} |
| 145 | +``` |
| 146 | + |
| 147 | +This code is based on the Hierarchical Reasoning Model [code](https://github.com/sapientinc/HRM) and the Hierarchical Reasoning Model Analysis [code](https://github.com/arcprize/hierarchical-reasoning-model-analysis). |
0 commit comments