PyTorch implementation of the Hierarchical Reasoning Model from the paper:
HRT: Enhanced Reasoning through Hierarchical Thinking
The HRM architecture combines two interdependent recurrent modules:
- High-Level Module: Handles abstract planning and strategic reasoning (512 hidden dimensions, 3 LSTM layers)
- Low-Level Module: Performs rapid detailed computations (256 hidden dimensions, 2 LSTM layers)
- Bidirectional Bridge: Enables two-way communication via attention mechanisms
Total parameters: 14.33M (under the 27M constraint from the paper)
- Single forward pass execution without intermediate supervision
- End-to-end training without Chain-of-Thought data
- Task-specific adapters for Sudoku and Maze solving
- Achieves near-perfect performance on reasoning tasks
# Install dependencies
pip install -e .python test_hrm.pyFor Sudoku:
python src/hrm/training/train.py --task sudoku --epochs 100 --batch_size 32For Maze solving:
python src/hrm/training/train.py --task maze --epochs 100 --batch_size 32hierarchical-reasoning-model/
├── src/hrm/
│ ├── models/
│ │ ├── hrm.py # Main HRM architecture
│ │ ├── high_level.py # High-level planning module
│ │ └── low_level.py # Low-level computation module
│ ├── tasks/
│ │ ├── sudoku.py # Sudoku adapter and dataset
│ │ └── maze.py # Maze adapter and dataset
│ └── training/
│ └── train.py # Training pipeline
├── test_hrm.py # Comprehensive test suite
└── pyproject.toml # Project configuration
- LSTM-based architecture with 512 hidden dimensions
- 3 layers for abstract reasoning
- Planning head for strategic decisions
- Context attention for incorporating feedback
- LSTM with 256 hidden dimensions
- 2 layers for rapid computations
- Computation blocks with residual connections
- Action head for detailed operations
- Multi-head attention (8 heads)
- Top-down guidance: High-level → Low-level
- Bottom-up feedback: Low-level → High-level
- Dynamic information fusion
-
Sudoku Solving
- 9x9 grid puzzles
- Variable difficulty levels
- Constraint enforcement
- Valid move generation
-
Maze Path Finding
- Variable size mazes (10x10 to 50x50)
- Optimal path discovery
- Graph encoding/decoding
- Action sequence generation
-
ARC (Abstraction and Reasoning Corpus) - Coming soon
- Optimizer: AdamW with weight decay 0.01
- Learning rate: 1e-4 with cosine annealing
- Gradient clipping: 1.0
- No intermediate supervision
- End-to-end loss computation
The model achieves strong performance with only 14.33M parameters:
- Sudoku: Near-perfect accuracy on medium difficulty
- Maze: Efficient optimal path finding
- Single forward pass inference
If you use this implementation, please cite the original paper:
@article{hrm2024,
title={Hierarchical Reasoning Model: Enhancing AI's Ability to Solve Complex Problems},
author={[Authors]},
journal={arXiv preprint arXiv:2506.21734},
year={2024}
}MIT License
This implementation follows the specifications from the original paper, achieving the goal of complex reasoning with minimal parameters and no intermediate supervision.