model

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: Apache-2.0 Imports: 23 Imported by: 1

Documentation

Overview

Package model provides adapter implementations for bridging existing and new model interfaces.

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

Package model provides generic interfaces for model management and abstraction.

Package model provides a comprehensive model registry for managing pluggable model components.

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

View Source
var (
	Float32ModelRegistry = NewModelRegistry[float32]()
	Float64ModelRegistry = NewModelRegistry[float64]()
)

Global registry instances for common numeric types

Functions

func BuildFromZMF

func BuildFromZMF[T tensor.Numeric](
	engine compute.Engine[T],
	ops numeric.Arithmetic[T],
	model *zmf.Model,
	opts ...BuildOption,
) (*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 ResolveAll added in v0.2.1

func ResolveAll[V any](r ParamResolver, params map[string]V) map[string]V

ResolveAll takes a resolver and a map keyed by model-specific names, and returns a new map containing both the original names and any canonical aliases produced by the resolver. This allows parameter lookups by either the original or canonical name.

func SetLogger added in v0.2.1

func SetLogger(l log.Logger)

SetLogger sets the package-level logger for model operations.

func UnregisterLayer added in v0.2.1

func UnregisterLayer(opType string)

UnregisterLayer removes a layer builder from the registry.

Types

type BasicModelValidator added in v0.2.1

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

BasicModelValidator provides basic model validation functionality.

func NewBasicModelValidator added in v0.2.1

func NewBasicModelValidator[T tensor.Numeric]() *BasicModelValidator[T]

NewBasicModelValidator creates a new BasicModelValidator.

func (*BasicModelValidator[T]) GetValidatorInfo added in v0.2.1

func (v *BasicModelValidator[T]) GetValidatorInfo() ValidatorInfo

GetValidatorInfo implements ModelValidator.GetValidatorInfo

func (*BasicModelValidator[T]) ValidateArchitecture added in v0.2.1

func (v *BasicModelValidator[T]) ValidateArchitecture(ctx context.Context, model ModelInstance[T]) error

ValidateArchitecture implements ModelValidator.ValidateArchitecture

func (*BasicModelValidator[T]) ValidateInputs added in v0.2.1

func (v *BasicModelValidator[T]) ValidateInputs(ctx context.Context, model ModelInstance[T], inputs ...*tensor.TensorNumeric[T]) error

ValidateInputs implements ModelValidator.ValidateInputs

func (*BasicModelValidator[T]) ValidateModel added in v0.2.1

func (v *BasicModelValidator[T]) ValidateModel(ctx context.Context, model ModelInstance[T]) (*ValidationResult, error)

ValidateModel implements ModelValidator.ValidateModel

type BuildOption added in v1.1.0

type BuildOption func(*buildConfig)

BuildOption configures optional behavior for BuildFromZMF.

func WithGlobalAttributes added in v1.1.0

func WithGlobalAttributes(attrs map[string]interface{}) BuildOption

WithGlobalAttributes injects extra key-value pairs into every node's attribute map during graph construction. This is used, for example, to propagate rope_scaling_* config from config.json into every GQA node without requiring the ZMF file to carry these attributes.

func WithParamResolver added in v1.1.0

func WithParamResolver(r ParamResolver) BuildOption

WithParamResolver supplies an architecture-aware parameter name resolver. When provided, the resolver adds canonical aliases to the parameter map so that layer builders can look up parameters by canonical name even when the ZMF file uses architecture-specific names.

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 ExporterInfo added in v0.2.1

type ExporterInfo struct {
	Name             string   `json:"name"`
	Version          string   `json:"version"`
	Description      string   `json:"description"`
	SupportedFormats []string `json:"supported_formats"`
	Optimization     bool     `json:"supports_optimization"`
	Quantization     bool     `json:"supports_quantization"`
}

ExporterInfo contains metadata about a model exporter.

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 LoaderInfo added in v0.2.1

type LoaderInfo struct {
	Name             string   `json:"name"`
	Version          string   `json:"version"`
	Description      string   `json:"description"`
	SupportedFormats []string `json:"supported_formats"`
	StreamingLoad    bool     `json:"supports_streaming_load"`
	LazyLoad         bool     `json:"supports_lazy_load"`
}

LoaderInfo contains metadata about a model loader.

type MmapReader added in v0.2.1

type MmapReader struct {
	// contains filtered or unexported fields
}

MmapReader memory-maps a file and provides access to its contents as a byte slice backed by the OS page cache.

func LoadZMFMmap added in v1.1.0

func LoadZMFMmap(filePath string) (*zmf.Model, *MmapReader, error)

LoadZMFMmap memory-maps a ZMF file and unmarshals the protobuf directly from the mmap byte slice, avoiding the heap allocation of os.ReadFile. The returned MmapReader must be kept open for the lifetime of the model so tensor data backed by mmap pages remains accessible.

func NewMmapReader added in v0.2.1

func NewMmapReader(path string) (*MmapReader, error)

NewMmapReader memory-maps the file at path and returns an MmapReader. The caller must call Close when done to release the mapping.

func (*MmapReader) Bytes added in v0.2.1

func (r *MmapReader) Bytes() []byte

Bytes returns the memory-mapped file contents.

func (*MmapReader) Close added in v0.2.1

func (r *MmapReader) Close() error

Close releases the memory mapping. It is safe to call multiple times.

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 BuildModelFromProto added in v1.1.0

func BuildModelFromProto[T tensor.Numeric](
	engine compute.Engine[T],
	ops numeric.Arithmetic[T],
	zmfModel *zmf.Model,
	buildOpts ...BuildOption,
) (*Model[T], error)

BuildModelFromProto builds a Model from an already-parsed ZMF protobuf. This is useful when the caller has obtained the *zmf.Model through a different loading mechanism (e.g., mmap).

func LoadModelFromZMF added in v0.3.0

func LoadModelFromZMF[T tensor.Numeric](
	engine compute.Engine[T],
	ops numeric.Arithmetic[T],
	filePath string,
	buildOpts ...BuildOption,
) (*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.

type ModelCapabilities added in v0.2.1

type ModelCapabilities struct {
	SupportedTypes      []string `json:"supported_types"`
	SupportedPrecisions []string `json:"supported_precisions"`
	SupportsTraining    bool     `json:"supports_training"`
	SupportsInference   bool     `json:"supports_inference"`
	SupportsBatching    bool     `json:"supports_batching"`
	SupportsStreaming   bool     `json:"supports_streaming"`
	MaxBatchSize        int      `json:"max_batch_size"`
	MaxSequenceLength   int      `json:"max_sequence_length"`
}

ModelCapabilities describes what a model provider can do.

type ModelConfig added in v0.2.1

type ModelConfig struct {
	// Core configuration
	Type         string                 `json:"type"`         // "standard", "hrm", "ensemble", etc.
	Architecture map[string]interface{} `json:"architecture"` // Architecture-specific parameters
	Parameters   map[string]interface{} `json:"parameters"`   // Model parameters

	// Behavior configuration
	TrainingMode bool `json:"training_mode"` // Whether to initialize in training mode
	BatchSize    int  `json:"batch_size"`    // Default batch size for inference

	// Format and compatibility
	InputFormat  string `json:"input_format"`  // Expected input format
	OutputFormat string `json:"output_format"` // Expected output format
	Version      string `json:"version"`       // Model format version

	// Extension point for domain-specific configuration
	Extensions map[string]interface{} `json:"extensions"` // Domain-specific extensions
}

ModelConfig configures model creation and behavior.

type ModelExporter added in v0.2.1

type ModelExporter[T tensor.Numeric] interface {
	// ExportToPath exports a model to a file path
	ExportToPath(ctx context.Context, model ModelInstance[T], path string) error

	// ExportToWriter exports a model to an io.Writer
	ExportToWriter(ctx context.Context, model ModelInstance[T], writer io.Writer) error

	// ExportToBytes exports a model to byte data
	ExportToBytes(ctx context.Context, model ModelInstance[T]) ([]byte, error)

	// SupportsFormat returns whether the exporter supports the given format
	SupportsFormat(format string) bool

	// GetExporterInfo returns metadata about this exporter
	GetExporterInfo() ExporterInfo
}

ModelExporter provides a generic interface for exporting models to various formats.

type ModelExporterFactory added in v0.2.1

type ModelExporterFactory[T tensor.Numeric] func(ctx context.Context, config map[string]interface{}) (ModelExporter[T], error)

ModelExporterFactory creates ModelExporter instances

type ModelInstance added in v0.2.1

type ModelInstance[T tensor.Numeric] interface {
	// Forward performs model inference
	Forward(ctx context.Context, inputs ...*tensor.TensorNumeric[T]) (*tensor.TensorNumeric[T], error)

	// Backward performs backpropagation (for training)
	Backward(ctx context.Context, inputs ...*tensor.TensorNumeric[T]) error

	// GetGraph returns the underlying computation graph
	GetGraph() *graph.Graph[T]

	// GetMetadata returns model metadata
	GetMetadata() ModelMetadata

	// Parameters returns model parameters for optimization
	Parameters() []*graph.Parameter[T]

	// SetTrainingMode sets the model to training or inference mode
	SetTrainingMode(training bool)

	// IsTraining returns whether the model is in training mode
	IsTraining() bool
}

ModelInstance represents a specific model instance with inference and training capabilities.

type ModelLoader added in v0.2.1

type ModelLoader[T tensor.Numeric] interface {
	// LoadFromPath loads a model from a file path
	LoadFromPath(ctx context.Context, path string) (ModelInstance[T], error)

	// LoadFromReader loads a model from an io.Reader
	LoadFromReader(ctx context.Context, reader io.Reader) (ModelInstance[T], error)

	// LoadFromBytes loads a model from byte data
	LoadFromBytes(ctx context.Context, data []byte) (ModelInstance[T], error)

	// SupportsFormat returns whether the loader supports the given format
	SupportsFormat(format string) bool

	// GetLoaderInfo returns metadata about this loader
	GetLoaderInfo() LoaderInfo
}

ModelLoader provides a generic interface for loading models from various sources.

type ModelLoaderFactory added in v0.2.1

type ModelLoaderFactory[T tensor.Numeric] func(ctx context.Context, config map[string]interface{}) (ModelLoader[T], error)

ModelLoaderFactory creates ModelLoader instances

type ModelMetadata added in v0.2.1

type ModelMetadata struct {
	Name         string                 `json:"name"`
	Version      string                 `json:"version"`
	Architecture string                 `json:"architecture"`
	Framework    string                 `json:"framework"`
	CreatedAt    string                 `json:"created_at"`
	ModifiedAt   string                 `json:"modified_at"`
	Parameters   int64                  `json:"parameter_count"`
	InputShape   [][]int                `json:"input_shapes"`
	OutputShape  []int                  `json:"output_shape"`
	Tags         []string               `json:"tags"`
	Extensions   map[string]interface{} `json:"extensions"`
}

ModelMetadata contains information about a model instance.

type ModelOptimizer added in v0.2.1

type ModelOptimizer[T tensor.Numeric] interface {
	// OptimizeModel applies optimizations to improve performance
	OptimizeModel(ctx context.Context, model ModelInstance[T], config OptimizationConfig) (ModelInstance[T], error)

	// GetOptimizations returns available optimization strategies
	GetOptimizations() []OptimizationStrategy

	// GetOptimizerInfo returns metadata about this optimizer
	GetOptimizerInfo() OptimizerInfo
}

ModelOptimizer provides model optimization capabilities.

type ModelOptimizerFactory added in v0.2.1

type ModelOptimizerFactory[T tensor.Numeric] func(ctx context.Context, config map[string]interface{}) (ModelOptimizer[T], error)

ModelOptimizerFactory creates ModelOptimizer instances

type ModelProvider added in v0.2.1

type ModelProvider[T tensor.Numeric] interface {
	// CreateModel creates a new model instance from configuration
	CreateModel(ctx context.Context, config ModelConfig) (ModelInstance[T], error)

	// CreateFromGraph creates a model instance from an existing graph
	CreateFromGraph(ctx context.Context, g *graph.Graph[T], config ModelConfig) (ModelInstance[T], error)

	// GetCapabilities returns the capabilities supported by this provider
	GetCapabilities() ModelCapabilities

	// GetProviderInfo returns metadata about this provider
	GetProviderInfo() ProviderInfo
}

ModelProvider creates and manages model instances with pluggable architectures. This interface allows different model implementations to be used interchangeably while maintaining consistent creation and management patterns.

type ModelProviderFactory added in v0.2.1

type ModelProviderFactory[T tensor.Numeric] func(ctx context.Context, config map[string]interface{}) (ModelProvider[T], error)

ModelProviderFactory creates ModelProvider instances

type ModelRegistry added in v0.2.1

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

ModelRegistry manages registered model components and provides factory functions. This registry enables runtime component selection and supports multiple implementations of each model interface.

func NewModelRegistry added in v0.2.1

func NewModelRegistry[T tensor.Numeric]() *ModelRegistry[T]

NewModelRegistry creates a new model registry.

func (*ModelRegistry[T]) Clear added in v0.2.1

func (r *ModelRegistry[T]) Clear()

Clear removes all registrations.

func (*ModelRegistry[T]) FindProviderByCapability added in v0.2.1

func (r *ModelRegistry[T]) FindProviderByCapability(ctx context.Context, requirement string) ([]string, error)

FindProviderByCapability finds providers that support specific capabilities.

func (*ModelRegistry[T]) GetAllRegistrations added in v0.2.1

func (r *ModelRegistry[T]) GetAllRegistrations() map[string][]string

GetAllRegistrations returns all registered component names by type.

func (*ModelRegistry[T]) GetModelExporter added in v0.2.1

func (r *ModelRegistry[T]) GetModelExporter(ctx context.Context, name string, config map[string]interface{}) (ModelExporter[T], error)

GetModelExporter retrieves a registered model exporter factory and creates an instance.

func (*ModelRegistry[T]) GetModelLoader added in v0.2.1

func (r *ModelRegistry[T]) GetModelLoader(ctx context.Context, name string, config map[string]interface{}) (ModelLoader[T], error)

GetModelLoader retrieves a registered model loader factory and creates an instance.

func (*ModelRegistry[T]) GetModelOptimizer added in v0.2.1

func (r *ModelRegistry[T]) GetModelOptimizer(ctx context.Context, name string, config map[string]interface{}) (ModelOptimizer[T], error)

GetModelOptimizer retrieves a registered model optimizer factory and creates an instance.

func (*ModelRegistry[T]) GetModelProvider added in v0.2.1

func (r *ModelRegistry[T]) GetModelProvider(ctx context.Context, name string, config map[string]interface{}) (ModelProvider[T], error)

GetModelProvider retrieves a registered model provider factory and creates an instance.

func (*ModelRegistry[T]) GetModelSerializer added in v0.2.1

func (r *ModelRegistry[T]) GetModelSerializer(ctx context.Context, name string, config map[string]interface{}) (ModelSerializer[T], error)

GetModelSerializer retrieves a registered model serializer factory and creates an instance.

func (*ModelRegistry[T]) GetModelValidator added in v0.2.1

func (r *ModelRegistry[T]) GetModelValidator(ctx context.Context, name string, config map[string]interface{}) (ModelValidator[T], error)

GetModelValidator retrieves a registered model validator factory and creates an instance.

func (*ModelRegistry[T]) ListModelExporters added in v0.2.1

func (r *ModelRegistry[T]) ListModelExporters() []string

ListModelExporters returns all registered model exporter names.

func (*ModelRegistry[T]) ListModelLoaders added in v0.2.1

func (r *ModelRegistry[T]) ListModelLoaders() []string

ListModelLoaders returns all registered model loader names.

func (*ModelRegistry[T]) ListModelOptimizers added in v0.2.1

func (r *ModelRegistry[T]) ListModelOptimizers() []string

ListModelOptimizers returns all registered model optimizer names.

func (*ModelRegistry[T]) ListModelProviders added in v0.2.1

func (r *ModelRegistry[T]) ListModelProviders() []string

ListModelProviders returns all registered model provider names.

func (*ModelRegistry[T]) ListModelSerializers added in v0.2.1

func (r *ModelRegistry[T]) ListModelSerializers() []string

ListModelSerializers returns all registered model serializer names.

func (*ModelRegistry[T]) ListModelValidators added in v0.2.1

func (r *ModelRegistry[T]) ListModelValidators() []string

ListModelValidators returns all registered model validator names.

func (*ModelRegistry[T]) RegisterModelExporter added in v0.2.1

func (r *ModelRegistry[T]) RegisterModelExporter(name string, factory ModelExporterFactory[T]) error

RegisterModelExporter registers a model exporter factory.

func (*ModelRegistry[T]) RegisterModelLoader added in v0.2.1

func (r *ModelRegistry[T]) RegisterModelLoader(name string, factory ModelLoaderFactory[T]) error

RegisterModelLoader registers a model loader factory.

func (*ModelRegistry[T]) RegisterModelOptimizer added in v0.2.1

func (r *ModelRegistry[T]) RegisterModelOptimizer(name string, factory ModelOptimizerFactory[T]) error

RegisterModelOptimizer registers a model optimizer factory.

func (*ModelRegistry[T]) RegisterModelProvider added in v0.2.1

func (r *ModelRegistry[T]) RegisterModelProvider(name string, factory ModelProviderFactory[T]) error

RegisterModelProvider registers a model provider factory.

func (*ModelRegistry[T]) RegisterModelSerializer added in v0.2.1

func (r *ModelRegistry[T]) RegisterModelSerializer(name string, factory ModelSerializerFactory[T]) error

RegisterModelSerializer registers a model serializer factory.

func (*ModelRegistry[T]) RegisterModelValidator added in v0.2.1

func (r *ModelRegistry[T]) RegisterModelValidator(name string, factory ModelValidatorFactory[T]) error

RegisterModelValidator registers a model validator factory.

func (*ModelRegistry[T]) Summary added in v0.2.1

func (r *ModelRegistry[T]) Summary() map[string]int

Summary returns a summary of all registered components.

func (*ModelRegistry[T]) UnregisterModelExporter added in v0.2.1

func (r *ModelRegistry[T]) UnregisterModelExporter(name string)

UnregisterModelExporter removes a model exporter registration.

func (*ModelRegistry[T]) UnregisterModelLoader added in v0.2.1

func (r *ModelRegistry[T]) UnregisterModelLoader(name string)

UnregisterModelLoader removes a model loader registration.

func (*ModelRegistry[T]) UnregisterModelOptimizer added in v0.2.1

func (r *ModelRegistry[T]) UnregisterModelOptimizer(name string)

UnregisterModelOptimizer removes a model optimizer registration.

func (*ModelRegistry[T]) UnregisterModelProvider added in v0.2.1

func (r *ModelRegistry[T]) UnregisterModelProvider(name string)

UnregisterModelProvider removes a model provider registration.

func (*ModelRegistry[T]) UnregisterModelSerializer added in v0.2.1

func (r *ModelRegistry[T]) UnregisterModelSerializer(name string)

UnregisterModelSerializer removes a model serializer registration.

func (*ModelRegistry[T]) UnregisterModelValidator added in v0.2.1

func (r *ModelRegistry[T]) UnregisterModelValidator(name string)

UnregisterModelValidator removes a model validator registration.

type ModelSerializer added in v0.2.1

type ModelSerializer[T tensor.Numeric] interface {
	// Save serializes a model to the specified path or writer
	Save(ctx context.Context, model ModelInstance[T], destination interface{}) error

	// Load deserializes a model from the specified path or reader
	Load(ctx context.Context, source interface{}) (ModelInstance[T], error)

	// GetSupportedFormats returns the file formats supported by this serializer
	GetSupportedFormats() []string

	// GetSerializerInfo returns metadata about this serializer
	GetSerializerInfo() SerializerInfo
}

ModelSerializer handles model persistence in various formats.

type ModelSerializerFactory added in v0.2.1

type ModelSerializerFactory[T tensor.Numeric] func(ctx context.Context, config map[string]interface{}) (ModelSerializer[T], error)

ModelSerializerFactory creates ModelSerializer instances

type ModelValidator added in v0.2.1

type ModelValidator[T tensor.Numeric] interface {
	// ValidateModel performs comprehensive model validation
	ValidateModel(ctx context.Context, model ModelInstance[T]) (*ValidationResult, error)

	// ValidateInputs checks if inputs are compatible with the model
	ValidateInputs(ctx context.Context, model ModelInstance[T], inputs ...*tensor.TensorNumeric[T]) error

	// ValidateArchitecture checks model architecture consistency
	ValidateArchitecture(ctx context.Context, model ModelInstance[T]) error

	// GetValidatorInfo returns metadata about this validator
	GetValidatorInfo() ValidatorInfo
}

ModelValidator validates model correctness and compatibility.

type ModelValidatorFactory added in v0.2.1

type ModelValidatorFactory[T tensor.Numeric] func(ctx context.Context, config map[string]interface{}) (ModelValidator[T], error)

ModelValidatorFactory creates ModelValidator instances

type NodeDeserializer added in v1.1.0

type NodeDeserializer[T tensor.Numeric] interface {
	// DeserializeNode converts a ZMF node to a graph node.
	DeserializeNode(zmfNode *zmf.Node, params map[string]*graph.Parameter[T]) (graph.Node[T], error)
}

NodeDeserializer defines the interface for deserializing specific node types from ZMF format.

type NodeSerializer added in v1.1.0

type NodeSerializer[T tensor.Numeric] interface {
	// SerializeNode converts a graph node to ZMF node representation.
	SerializeNode(node graph.Node[T], metadata map[string]interface{}) (*zmf.Node, error)
}

NodeSerializer defines the interface for serializing specific node types to ZMF format.

type OptimizationConfig added in v0.2.1

type OptimizationConfig struct {
	Strategies   []string               `json:"strategies"`    // Optimization strategies to apply
	TargetDevice string                 `json:"target_device"` // Target device for optimization
	Precision    string                 `json:"precision"`     // Target precision (fp32, fp16, int8)
	MaxMemory    int64                  `json:"max_memory"`    // Memory constraints
	Extensions   map[string]interface{} `json:"extensions"`    // Strategy-specific options
}

OptimizationConfig configures model optimization.

type OptimizationStrategy added in v0.2.1

type OptimizationStrategy struct {
	Name         string                 `json:"name"`
	Description  string                 `json:"description"`
	Category     string                 `json:"category"`     // "performance", "memory", "accuracy"
	Impact       string                 `json:"impact"`       // "low", "medium", "high"
	Requirements []string               `json:"requirements"` // Prerequisites for this optimization
	Options      map[string]interface{} `json:"options"`      // Strategy-specific options
}

OptimizationStrategy describes an optimization approach.

type OptimizerInfo added in v0.2.1

type OptimizerInfo struct {
	Name          string   `json:"name"`
	Version       string   `json:"version"`
	Description   string   `json:"description"`
	Strategies    []string `json:"available_strategies"`
	TargetDevices []string `json:"target_devices"`
}

OptimizerInfo contains metadata about a model optimizer.

type ParamResolver added in v0.2.1

type ParamResolver interface {
	// Resolve returns the canonical name for a model-specific parameter name.
	// Returns the input unchanged if no mapping applies.
	Resolve(name string) string
}

ParamResolver maps architecture-specific parameter names to canonical names used by Zerfoo layers during model building. Canonical names follow the Llama/Gemma convention (the most common HuggingFace naming pattern).

func NewParamResolver added in v0.2.1

func NewParamResolver(arch string) ParamResolver

NewParamResolver returns a resolver for the given architecture type. Architecture types match the model_type field from HuggingFace config.json.

type ProviderInfo added in v0.2.1

type ProviderInfo struct {
	Name         string   `json:"name"`
	Version      string   `json:"version"`
	Description  string   `json:"description"`
	SupportedOps []string `json:"supported_operations"`
	Website      string   `json:"website"`
	License      string   `json:"license"`
}

ProviderInfo contains metadata about a model provider.

type SerializerInfo added in v0.2.1

type SerializerInfo struct {
	Name             string   `json:"name"`
	Version          string   `json:"version"`
	Description      string   `json:"description"`
	SupportedFormats []string `json:"supported_formats"`
	Compression      bool     `json:"supports_compression"`
	Encryption       bool     `json:"supports_encryption"`
}

SerializerInfo contains metadata about a model serializer.

type StandardModelInstance added in v0.2.1

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

StandardModelInstance adapts the existing Model struct to implement ModelInstance interface.

func NewStandardModelInstance added in v0.2.1

func NewStandardModelInstance[T tensor.Numeric](model *Model[T]) *StandardModelInstance[T]

NewStandardModelInstance creates a new StandardModelInstance adapter.

func (*StandardModelInstance[T]) Backward added in v0.2.1

func (s *StandardModelInstance[T]) Backward(ctx context.Context, inputs ...*tensor.TensorNumeric[T]) error

Backward implements ModelInstance.Backward. The first variadic input is the gradient of the loss with respect to the model output (initial gradient). Exactly one gradient tensor must be provided.

func (*StandardModelInstance[T]) Forward added in v0.2.1

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

Forward implements ModelInstance.Forward

func (*StandardModelInstance[T]) GetGraph added in v0.2.1

func (s *StandardModelInstance[T]) GetGraph() *graph.Graph[T]

GetGraph implements ModelInstance.GetGraph

func (*StandardModelInstance[T]) GetMetadata added in v0.2.1

func (s *StandardModelInstance[T]) GetMetadata() ModelMetadata

GetMetadata implements ModelInstance.GetMetadata

func (*StandardModelInstance[T]) IsTraining added in v0.2.1

func (s *StandardModelInstance[T]) IsTraining() bool

IsTraining implements ModelInstance.IsTraining

func (*StandardModelInstance[T]) Parameters added in v0.2.1

func (s *StandardModelInstance[T]) Parameters() []*graph.Parameter[T]

Parameters implements ModelInstance.Parameters

func (*StandardModelInstance[T]) SetTrainingMode added in v0.2.1

func (s *StandardModelInstance[T]) SetTrainingMode(training bool)

SetTrainingMode implements ModelInstance.SetTrainingMode

type StandardModelProvider added in v0.2.1

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

StandardModelProvider provides standard model creation capabilities.

func NewStandardModelProvider added in v0.2.1

func NewStandardModelProvider[T tensor.Numeric]() *StandardModelProvider[T]

NewStandardModelProvider creates a new StandardModelProvider.

func (*StandardModelProvider[T]) CreateFromGraph added in v0.2.1

func (p *StandardModelProvider[T]) CreateFromGraph(ctx context.Context, g *graph.Graph[T], config ModelConfig) (ModelInstance[T], error)

CreateFromGraph implements ModelProvider.CreateFromGraph

func (*StandardModelProvider[T]) CreateModel added in v0.2.1

func (p *StandardModelProvider[T]) CreateModel(ctx context.Context, config ModelConfig) (ModelInstance[T], error)

CreateModel implements ModelProvider.CreateModel

func (*StandardModelProvider[T]) GetCapabilities added in v0.2.1

func (p *StandardModelProvider[T]) GetCapabilities() ModelCapabilities

GetCapabilities implements ModelProvider.GetCapabilities

func (*StandardModelProvider[T]) GetProviderInfo added in v0.2.1

func (p *StandardModelProvider[T]) GetProviderInfo() ProviderInfo

GetProviderInfo implements ModelProvider.GetProviderInfo

type ValidationError added in v0.2.1

type ValidationError struct {
	Type       string `json:"type"`
	Message    string `json:"message"`
	Component  string `json:"component"`
	Severity   string `json:"severity"`
	Suggestion string `json:"suggestion"`
}

ValidationError represents a validation error.

type ValidationResult added in v0.2.1

type ValidationResult struct {
	IsValid    bool                   `json:"is_valid"`
	Errors     []ValidationError      `json:"errors"`
	Warnings   []ValidationWarning    `json:"warnings"`
	Metrics    map[string]float64     `json:"metrics"`
	Summary    string                 `json:"summary"`
	Extensions map[string]interface{} `json:"extensions"`
}

ValidationResult contains model validation results.

type ValidationWarning added in v0.2.1

type ValidationWarning struct {
	Type       string `json:"type"`
	Message    string `json:"message"`
	Component  string `json:"component"`
	Suggestion string `json:"suggestion"`
}

ValidationWarning represents a validation warning.

type ValidatorInfo added in v0.2.1

type ValidatorInfo struct {
	Name        string   `json:"name"`
	Version     string   `json:"version"`
	Description string   `json:"description"`
	CheckTypes  []string `json:"check_types"`
	Strictness  string   `json:"strictness"`
}

ValidatorInfo contains metadata about a model validator.

type ZMFExporter added in v1.1.0

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

ZMFExporter implements the Exporter interface for ZMF format.

func NewZMFExporter added in v1.1.0

func NewZMFExporter[T tensor.Numeric]() *ZMFExporter[T]

NewZMFExporter creates a new ZMF exporter with default serializers.

func (*ZMFExporter[T]) Export added in v1.1.0

func (e *ZMFExporter[T]) Export(model *Model[T], path string) error

Export saves the given model to ZMF format at the specified path.

func (*ZMFExporter[T]) RegisterNodeSerializer added in v1.1.0

func (e *ZMFExporter[T]) RegisterNodeSerializer(opType string, serializer NodeSerializer[T])

RegisterNodeSerializer registers a custom serializer for a specific node type.

type ZMFModelExporter added in v1.1.0

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

ZMFModelExporter adapts existing ZMF export functionality to the ModelExporter interface.

func NewZMFModelExporter added in v1.1.0

func NewZMFModelExporter[T tensor.Numeric]() *ZMFModelExporter[T]

NewZMFModelExporter creates a new ZMFModelExporter.

func (*ZMFModelExporter[T]) ExportToBytes added in v1.1.0

func (e *ZMFModelExporter[T]) ExportToBytes(_ context.Context, model ModelInstance[T]) ([]byte, error)

ExportToBytes implements ModelExporter.ExportToBytes

func (*ZMFModelExporter[T]) ExportToPath added in v1.1.0

func (e *ZMFModelExporter[T]) ExportToPath(ctx context.Context, model ModelInstance[T], path string) error

ExportToPath implements ModelExporter.ExportToPath

func (*ZMFModelExporter[T]) ExportToWriter added in v1.1.0

func (e *ZMFModelExporter[T]) ExportToWriter(_ context.Context, model ModelInstance[T], writer io.Writer) error

ExportToWriter implements ModelExporter.ExportToWriter

func (*ZMFModelExporter[T]) GetExporterInfo added in v1.1.0

func (e *ZMFModelExporter[T]) GetExporterInfo() ExporterInfo

GetExporterInfo implements ModelExporter.GetExporterInfo

func (*ZMFModelExporter[T]) SupportsFormat added in v1.1.0

func (e *ZMFModelExporter[T]) SupportsFormat(format string) bool

SupportsFormat implements ModelExporter.SupportsFormat

type ZMFModelLoader added in v1.1.0

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

ZMFModelLoader adapts existing ZMF loading functionality to the ModelLoader interface.

func NewZMFModelLoader added in v1.1.0

func NewZMFModelLoader[T tensor.Numeric](engine compute.Engine[T], ops numeric.Arithmetic[T]) *ZMFModelLoader[T]

NewZMFModelLoader creates a new ZMFModelLoader. The engine and ops are required to reconstruct the computation graph from the serialized ZMF model.

func (*ZMFModelLoader[T]) GetLoaderInfo added in v1.1.0

func (l *ZMFModelLoader[T]) GetLoaderInfo() LoaderInfo

GetLoaderInfo implements ModelLoader.GetLoaderInfo

func (*ZMFModelLoader[T]) LoadFromBytes added in v1.1.0

func (l *ZMFModelLoader[T]) LoadFromBytes(_ context.Context, data []byte) (ModelInstance[T], error)

LoadFromBytes implements ModelLoader.LoadFromBytes

func (*ZMFModelLoader[T]) LoadFromPath added in v1.1.0

func (l *ZMFModelLoader[T]) LoadFromPath(_ context.Context, path string) (ModelInstance[T], error)

LoadFromPath implements ModelLoader.LoadFromPath

func (*ZMFModelLoader[T]) LoadFromReader added in v1.1.0

func (l *ZMFModelLoader[T]) LoadFromReader(_ context.Context, reader io.Reader) (ModelInstance[T], error)

LoadFromReader implements ModelLoader.LoadFromReader

func (*ZMFModelLoader[T]) SupportsFormat added in v1.1.0

func (l *ZMFModelLoader[T]) SupportsFormat(format string) bool

SupportsFormat implements ModelLoader.SupportsFormat

Directories

Path Synopsis
Package gguf implements a pure-Go parser for the GGUF v3 model format used by llama.cpp.
Package gguf implements a pure-Go parser for the GGUF v3 model format used by llama.cpp.
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