hrm

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package hrm provides experimental Hierarchical Reasoning Model types.

The placeholder file ensures the package is discoverable by `go test ./...` without the tag, avoiding build-constraint errors.

Package hrm implements the Hierarchical Reasoning Model.

Package hrm implements the Hierarchical Reasoning Model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HRM

type HRM[T tensor.Numeric] struct {
	HModule   *hrm.HModule[T]
	LModule   *hrm.LModule[T]
	InputNet  graph.Node[T]
	OutputNet graph.Node[T]
}

HRM represents the Hierarchical Reasoning Model.

func NewHRM

func NewHRM[T tensor.Numeric](
	engine compute.Engine[T],
	ops numeric.Arithmetic[T],
	modelDim, ffnDim, inputDim, outputDim int,
	hAttention, lAttention graph.Node[T],
) (*HRM[T], error)

NewHRM creates a new HRM model.

func (*HRM[T]) Build

func (m *HRM[T]) Build(
	builder *graph.Builder[T],
	_N, _T int,
	input, hStateIn, lStateIn graph.Node[T],
) (graph.Node[T], error)

Build wires a minimal static graph for a single-step HRM pass. This simplified version ignores the N and T loop structure and just composes: input -> InputNet -> Add(hStateIn) -> LModule.Block -> Add(hStateIn) -> HModule.Block -> OutputNet.

func (*HRM[T]) Forward

func (m *HRM[T]) Forward(ctx context.Context, nSteps, tSteps int, inputs ...*tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)

Forward computes the forward pass of the HRM model.

func (*HRM[T]) Parameters

func (m *HRM[T]) Parameters() []*graph.Parameter[T]

Parameters returns the parameters of the HRM model.

type HRMTrainer

type HRMTrainer[T tensor.Numeric] struct {
	// contains filtered or unexported fields
}

HRMTrainer implements the one-step gradient approximation training for the HRM.

func NewHRMTrainer

func NewHRMTrainer[T tensor.Numeric](hrm *HRM[T], loss graph.Node[T]) *HRMTrainer[T]

NewHRMTrainer creates a new HRMTrainer.

func (*HRMTrainer[T]) TrainStep

func (t *HRMTrainer[T]) TrainStep(
	ctx context.Context,
	optimizer opt.Optimizer[T],
	inputs map[graph.Node[T]]*tensor.TensorNumeric[T],
	targets *tensor.TensorNumeric[T],
	nSteps, tSteps int,
) (T, error)

TrainStep performs a single training step for the HRM.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL