model

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: 16 Imported by: 1

Documentation

Overview

Package model provides the core structures and loading mechanisms for Zerfoo models.

Package model provides the core structures and loading mechanisms for Zerfoo models.

Package model provides the core structures and loading mechanisms for Zerfoo models.

Package model provides the core structures and loading mechanisms for Zerfoo models.

Package model provides the core structures and loading mechanisms for Zerfoo models.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildFromZMF

func BuildFromZMF[T tensor.Numeric](
	engine compute.Engine[T],
	ops numeric.Arithmetic[T],
	model *zmf.Model,
) (*graph.Graph[T], error)

BuildFromZMF constructs a Zerfoo computation graph from a ZMF model definition. This function iterates through the nodes in the graph, instantiates the corresponding layers using a registered builder, and connects them into an executable graph.

func DecodeTensor

func DecodeTensor[T tensor.Numeric](tensorProto *zmf.Tensor) (*tensor.TensorNumeric[T], error)

DecodeTensor converts a ZMF Tensor protobuf message into a Zerfoo Tensor.

func EncodeTensor

func EncodeTensor[T tensor.Numeric](t *tensor.TensorNumeric[T]) (*zmf.Tensor, error)

EncodeTensor converts a Zerfoo Tensor into a ZMF Tensor protobuf message.

func LoadZMF

func LoadZMF(filePath string) (*zmf.Model, error)

LoadZMF reads a Zerfoo Model Format (.zmf) file from the specified path, deserializes it, and returns the parsed Model object.

func RegisterLayer

func RegisterLayer[T tensor.Numeric](opType string, builder LayerBuilder[T])

RegisterLayer adds a new layer builder to the registry. It is intended to be called at initialization time (e.g., in an init() function).

func UnregisterLayer

func UnregisterLayer(opType string)

UnregisterLayer removes a layer builder from the registry.

Types

type Exporter

type Exporter[T tensor.Numeric] interface {
	// Export saves the given model to the specified path.
	Export(model *Model[T], path string) error
}

Exporter defines the interface for saving a zerfoo model to an external format.

type LayerBuilder

type LayerBuilder[T tensor.Numeric] func(
	engine compute.Engine[T],
	ops numeric.Arithmetic[T],
	name string,
	params map[string]*graph.Parameter[T],
	attributes map[string]interface{},
) (graph.Node[T], error)

LayerBuilder is a function that constructs a graph.Node (a layer) from ZMF parameters.

func GetLayerBuilder

func GetLayerBuilder[T tensor.Numeric](opType string) (LayerBuilder[T], error)

GetLayerBuilder retrieves a layer builder from the registry for a given op_type.

type Model

type Model[T tensor.Numeric] struct {
	Embedding  *embeddings.TokenEmbedding[T]
	Graph      *graph.Graph[T]
	ZMFVersion string
}

Model represents a complete model, including a token embedding layer and a computation graph.

func LoadModelFromZMF

func LoadModelFromZMF[T tensor.Numeric](
	engine compute.Engine[T],
	ops numeric.Arithmetic[T],
	filePath string,
) (*Model[T], error)

LoadModelFromZMF loads a ZMF model from a file, builds the computation graph, and returns a complete Model object.

func NewModel

func NewModel[T tensor.Numeric](embedding *embeddings.TokenEmbedding[T], g *graph.Graph[T]) *Model[T]

NewModel creates a new model.

func (*Model[T]) Forward

func (m *Model[T]) Forward(ctx context.Context, inputs ...*tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)

Forward performs the forward pass of the model.

Directories

Path Synopsis
Package hrm provides experimental Hierarchical Reasoning Model types.
Package hrm provides experimental Hierarchical Reasoning Model types.

Jump to

Keyboard shortcuts

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