The Hierarchical Reasoning Model (HRM) improves its answer over several supervision steps and learns when to stop with a small Q-learning problem. A halting head gives two logits per example, q = (q_halt, q_continue). The reward for halting is 1 when the current answer is completely correct and 0 otherwise, and continuing gives no reward now. The Tiny Recursive Model paper points out that the continue target needs a second forward pass of the whole model, which produces q_next.
Write
act_losses(q, q_next, y_hat, y_true, last_step=False)
q, q_next: arrays of shape (B, 2) holding logits. Column 0 is halt, column 1 is continue. q comes from the current supervision step and q_next from the extra forward pass.y_hat, y_true: integer arrays of shape (B, L), the predicted and the true answer tokens.last_step is true, otherwise , where is the sigmoid.q[:, 0] and the continue loss uses q[:, 1].(halt_loss, continue_loss, halt): two floats and a list of B booleans, where an example halts when its current q_halt is strictly greater than its current q_continue.