Adaptive computation

A network usually spends the same effort on every input. Two mechanisms of the library let it spend more where the problem is hard: a layer that chooses its own number of steps, and a recurrent structure that reasons at two speeds.

Effort that follows difficulty

A fixed stack of layers gives a comma and a proof the same depth. Adapting the computation to the input extends what a small model can do: it iterates on the hard parts and moves quickly over the rest.

Depth where it is needed

The number of steps becomes a quantity the network learns, position by position or puzzle by puzzle.

A cost that must be earned

Each extra step is charged to the loss, so the network keeps it only when the answer improves.

Small models that reason longer

Reusing the same weights over several passes gives depth without adding parameters.

ACT, a layer that chooses its number of steps

The layer implements adaptive computation time, the method Alex Graves published in 2016. It takes the place of the feed-forward of a transformer block and applies it several times: at each step a halting unit says how sure the position is, the states are averaged with these weights, and the position stops once the total reaches the threshold.

The adaptive computation layer around the feed-forward of a block.

This layer is an implementation of our own, written for Dlib and maintained in Dlib-Transformer-extensions. To our knowledge, no other C++ deep learning library offers adaptive computation time as a ready-to-use layer.

  • One template argument turns a block into an adaptive block: any Dlib network can serve as the transition.
  • Defaults: 8 steps at most, a halting threshold of 0.99 and a ponder penalty of 0.01, each adjustable.
  • The backward pass follows the gradients of the original paper, through every step taken.
  • The transition network is trained by solvers of its own, and its parameters are counted with the model.
  • The layer reports the average number of steps and the ponder cost at each pass.

HRM, two modules that reason at two speeds

The hierarchical reasoning model, published by Sapient Intelligence in 2025, couples two recurrent modules. The low-level module takes several fast steps on the details; the high-level module then updates the plan once, and the cycle starts again. The library provides this structure as a layer, and two example programs train it on Sudoku-Extreme and on ARC-AGI the way the published work trains it.

The hierarchical layer, its halting head and the path of the gradient.
  • N slow cycles of T fast steps: N × T steps of depth for the weights of two small modules.
  • A one-step gradient: only the last step of each module is differentiated, so memory does not grow with the number of steps.
  • A state carried from one pass to the next and restarted sample by sample, so that a solved puzzle gives its place to a new one.
  • The reference structure of the publication is one template argument away from the pre-norm structure of the library.

Four halting criteria

The ARC-AGI example puts them side by side on the same data, the same network and the same budget.

OptionDeciding criterion
--halting externalA halting logit read at the identifier position and trained towards whether the answer is exact: the published arrangement, and the default.
--halting noneNo decision: every example runs the maximum number of passes, each one supervised.
--halting internalThe adaptive computation layer placed around the feed-forward of every block, trained by its ponder cost.
--halting bothBoth: the adaptive layer inside the modules and the halting head outside them.

Contribution of this R&D work to the library

Each part written for these examples is available to the other models of the repository.

Halting loss
A loss layer that scores the tokens and trains the halting logit towards the exactness of the whole answer.
Adam-atan2 solver
The optimizer of the published configuration, offered beside AdamW.
Stablemax cross-entropy
The loss the published configuration uses in place of softmax cross-entropy.
Average of the weights
An exponential moving average read by every measurement, which prevents the late collapse on a small training set.
Identifier table
An embedding table trained by sparse sign descent, one row per puzzle.

Try the examples, or suggest what to explore next

The programs build with the library and print their settings and their measurements.