HRM README

The project's README from github.com/sapientinc/HRM. As one markdown file: README.md.

Hierarchical Reasoning Model

Reasoning, the process of devising and executing complex goal-oriented action sequences, remains a critical challenge in AI. Current large language models (LLMs) primarily employ Chain-of-Thought (CoT) techniques, which suffer from brittle task decomposition, extensive data requirements, and high latency. Inspired by the hierarchical and multi-timescale processing in the human brain, we propose the Hierarchical Reasoning Model (HRM), a novel recurrent architecture that attains significant computational depth while maintaining both training stability and efficiency. HRM executes sequential reasoning tasks in a single forward pass without explicit supervision of the intermediate process, through two interdependent recurrent modules: a high-level module responsible for slow, abstract planning, and a low-level module handling rapid, detailed computations. With only 27 million parameters, HRM achieves exceptional performance on complex reasoning tasks using only 1000 training samples. The model operates without pre-training or CoT data, yet achieves nearly perfect performance on challenging tasks including complex Sudoku puzzles and optimal path finding in large mazes. Furthermore, HRM outperforms much larger models with significantly longer context windows on the Abstraction and Reasoning Corpus (ARC), a key benchmark for measuring artificial general intelligence capabilities. These results underscore HRM’s potential as a transformative advancement toward universal computation and general-purpose reasoning systems.

Read Our Paper: https://arxiv.org/abs/2506.21734

Join Our Discord Community: https://discord.gg/sapient

Quick Start Guide 🚀

Prerequisites ⚙️

Ensure PyTorch and CUDA are installed. The repo needs CUDA extensions to be built. If not present, run the following commands:

# Install CUDA 12.6
CUDA_URL=https://developer.download.nvidia.com/compute/cuda/12.6.3/local_installers/cuda_12.6.3_560.35.05_linux.run

wget -q --show-progress --progress=bar:force:noscroll -O cuda_installer.run $CUDA_URL
sudo sh cuda_installer.run --silent --toolkit --override

export CUDA_HOME=/usr/local/cuda-12.6

# Install PyTorch with CUDA 12.6
PYTORCH_INDEX_URL=https://download.pytorch.org/whl/cu126

pip3 install torch torchvision torchaudio --index-url $PYTORCH_INDEX_URL

# Additional packages for building extensions
pip3 install packaging ninja wheel setuptools setuptools-scm

Then install FlashAttention. For Hopper GPUs, install FlashAttention 3

git clone [email protected]:Dao-AILab/flash-attention.git
cd flash-attention/hopper
python setup.py install

For Ampere or earlier GPUs, install FlashAttention 2

pip3 install flash-attn

Install Python Dependencies 🐍

pip install -r requirements.txt

W&B Integration 📈

This project uses Weights & Biases for experiment tracking and metric visualization. Ensure you're logged in:

wandb login

Run Experiments

Quick Demo: Sudoku Solver 💻🗲

Train a master-level Sudoku AI capable of solving extremely difficult puzzles on a modern laptop GPU. 🧩

# Download and build Sudoku dataset
python dataset/build_sudoku_dataset.py --output-dir data/sudoku-extreme-1k-aug-1000  --subsample-size 1000 --num-aug 1000

# Start training (single GPU, smaller batch size)
OMP_NUM_THREADS=8 python pretrain.py data_path=data/sudoku-extreme-1k-aug-1000 epochs=20000 eval_interval=2000 global_batch_size=384 lr=7e-5 puzzle_emb_lr=7e-5 weight_decay=1.0 puzzle_emb_weight_decay=1.0

Runtime: ~10 hours on a RTX 4070 laptop GPU

Trained Checkpoints 🚧

To use the checkpoints, see Evaluation section below.

Full-scale Experiments 🔵

Experiments below assume an 8-GPU setup.

Dataset Preparation

# Initialize submodules
git submodule update --init --recursive

# ARC-1
python dataset/build_arc_dataset.py  # ARC offical + ConceptARC, 960 examples
# ARC-2
python dataset/build_arc_dataset.py --dataset-dirs dataset/raw-data/ARC-AGI-2/data --output-dir data/arc-2-aug-1000  # ARC-2 official, 1120 examples

# Sudoku-Extreme
python dataset/build_sudoku_dataset.py  # Full version
python dataset/build_sudoku_dataset.py --output-dir data/sudoku-extreme-1k-aug-1000  --subsample-size 1000 --num-aug 1000  # 1000 examples

# Maze
python dataset/build_maze_dataset.py  # 1000 examples

Dataset Visualization

Explore the puzzles visually:

Launch experiments

Small-sample (1K)

ARC-1:

OMP_NUM_THREADS=8 torchrun --nproc-per-node 8 pretrain.py 

Runtime: ~24 hours

ARC-2:

OMP_NUM_THREADS=8 torchrun --nproc-per-node 8 pretrain.py data_path=data/arc-2-aug-1000

Runtime: ~24 hours (checkpoint after 8 hours is often sufficient)

Sudoku Extreme (1k):

OMP_NUM_THREADS=8 torchrun --nproc-per-node 8 pretrain.py data_path=data/sudoku-extreme-1k-aug-1000 epochs=20000 eval_interval=2000 lr=1e-4 puzzle_emb_lr=1e-4 weight_decay=1.0 puzzle_emb_weight_decay=1.0

Runtime: ~10 minutes

Maze 30x30 Hard (1k):

OMP_NUM_THREADS=8 torchrun --nproc-per-node 8 pretrain.py data_path=data/maze-30x30-hard-1k epochs=20000 eval_interval=2000 lr=1e-4 puzzle_emb_lr=1e-4 weight_decay=1.0 puzzle_emb_weight_decay=1.0

Runtime: ~1 hour

Full Sudoku-Hard

OMP_NUM_THREADS=8 torchrun --nproc-per-node 8 pretrain.py data_path=data/sudoku-hard-full epochs=100 eval_interval=10 lr_min_ratio=0.1 global_batch_size=2304 lr=3e-4 puzzle_emb_lr=3e-4 weight_decay=0.1 puzzle_emb_weight_decay=0.1 arch.loss.loss_type=softmax_cross_entropy arch.L_cycles=8 arch.halt_max_steps=8 arch.pos_encodings=learned

Runtime: ~2 hours

Evaluation

Evaluate your trained models:

OMP_NUM_THREADS=8 torchrun --nproc-per-node 8 evaluate.py checkpoint=<CHECKPOINT_PATH>

Notes

Citation 📜

@misc{wang2025hierarchicalreasoningmodel,
      title={Hierarchical Reasoning Model}, 
      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},
      year={2025},
      eprint={2506.21734},
      archivePrefix={arXiv},
      primaryClass={cs.AI},
      url={https://arxiv.org/abs/2506.21734}, 
}

HRM (sapientinc/HRM)

Searching Database…

12.7K ·GitHub
What is this?The official release of the Hierarchical Reasoning Model (HRM): a brain-inspired recurrent architecture that reaches significant computational depth with only 27 million parameters, trained on ~1000 examples without pretraining or chain-of-thought data.
Is it a ready-made trained model, or code I have to train myself?Both. The repo is the architecture plus a full training pipeline, and the authors also ship trained checkpoints for ARC-AGI-2, 9x9 Extreme Sudoku and 30x30 Hard Maze that you can evaluate without training.
How do I get it running?Install PyTorch with CUDA first, because the repo builds CUDA extensions; then add FlashAttention (version 3 for Hopper GPUs, version 2 for Ampere or older), install the Python dependencies and log in to Weights & Biases for tracking.
How long does training take, and are there any gotchas?From 1k-sample datasets, Sudoku Extreme trains in ~10 minutes on the reference 8-GPU setup, the 30x30 maze in about an hour and ARC in about 24 hours. Expect roughly ±2 accuracy-point variance on small samples, and use early stopping on Sudoku-Extreme, where late-stage overfitting can destabilize training and Q-learning.
What kind of hardware do I need to train it?An NVIDIA GPU is required — the whole stack is PyTorch, CUDA extensions and FlashAttention. The Sudoku demo trains in about 10 hours on an RTX 4070 laptop GPU, while the full-scale experiments assume an 8-GPU setup.
How is this different from how large language models reason?It skips chain-of-thought text entirely: HRM executes sequential reasoning in a single forward pass through two interdependent recurrent modules — a slow high-level module for abstract planning and a fast low-level one for detailed computation — with no explicit supervision of intermediate steps.
What tasks can it actually solve, and how well?Three puzzle-style tasks out of the box: 9x9 Extreme Sudoku, 30x30 Hard mazes and the Abstraction and Reasoning Corpus (ARC), where it outperforms much larger models with far longer context windows — nearly perfect on the Sudoku and maze tasks.
How do I check how good a trained model is?Run the evaluation script and read eval/exactaccuracy in Weights & Biases; for ARC there are extra steps, and you finalize and inspect results in the provided arceval.ipynb notebook.
Can I look at the training puzzles myself?Yes — generate a dataset, open puzzlevisualizer.html in your browser and upload the folder from data/ to explore the puzzles visually.
Creator
sapientinc
Size
0.1 MB
Stars
12.7K
Updated
CommitMar 31
Age
1y
Commits · 90 Days