model

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 21 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoVisionModel        = errors.New("this model is missing data required for image input")
	ErrUnsupportedModel     = errors.New("model not supported")
	ErrUnsupportedTokenizer = errors.New("tokenizer not supported")
)

Functions

func Forward

func Forward(ctx ml.Context, m Model, batch input.Batch) (ml.Tensor, error)

func NewTextProcessor added in v0.6.0

func NewTextProcessor(s string) (tokenizer.Tokenizer, error)

func Register

func Register(name string, f func(fs.Config) (Model, error))

Register registers a model constructor for the given architecture

Types

type Base

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

Base implements the common fields and methods for all models

func (*Base) Backend

func (m *Base) Backend() ml.Backend

Backend returns the underlying backend that will run the model

func (*Base) Config

func (m *Base) Config() config

type Model

type Model interface {
	Forward(ml.Context, input.Batch) (ml.Tensor, error)

	Backend() ml.Backend
	Config() config
}

Model implements a specific model architecture, defining the forward pass and any model-specific configuration

func New

func New(modelPath string, params ml.BackendParams) (Model, error)

New initializes a new model instance with the provided configuration based on the metadata in the model file

type MultimodalProcessor added in v0.6.0

type MultimodalProcessor interface {
	// EncodeMultimodal processes a single input (such as an image) and
	// generates an output (typically an embedding) that can be used by the model.
	//
	// The return value is one or more tensors, each with optional model-specific
	// opaque metadata. Typically, the tensors might be views into an embedding
	// with each view representing a chunk of data that can be processed independently
	// in different batches.
	//
	// The result may be cached by the runner.
	EncodeMultimodal(ml.Context, []byte) ([]input.Multimodal, error)

	// PostTokenize is called after tokenization to allow the model to edit the
	// input stream to correctly arrange multimodal elements.
	//
	// The input is a slice of tokens with the results of EncodeMultimodal interleaved
	// in the order that the user provided them. Each element of the slice will be
	// either a single token or single multimodal object.
	//
	// The model must ensure that inputs are stored according to how they will be
	// processed and stored in the cache. For example, Llava-style models should insert
	// placeholder tokens equal to the feature size of the corresponding image with
	// the image itself attached to and split across these tokens. When Forward is called
	// a partial subset of these tokens may be submitted according to the batch size.
	//
	// This function is also responsible for updating MultimodalHash for any Multimodal
	// that is modified to ensure that there is a unique hash value that accurately
	// represents the contents.
	PostTokenize([]*input.Input) ([]*input.Input, error)
}

MultimodalProcessor must be implemented by multimodal models.

type Tag

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

type Validator added in v0.15.0

type Validator interface {
	Validate() error
}

Validator is an optional interface that models can implement to perform validation after tensors have been loaded. If validation fails, model loading will fail with the returned error.

Jump to

Keyboard shortcuts

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