model

package
v0.6.1-rc0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2025 License: MIT Imports: 24 Imported by: 24

Documentation

Index

Constants

View Source
const (
	TOKEN_TYPE_NORMAL = iota + 1
	TOKEN_TYPE_UNKNOWN
	TOKEN_TYPE_CONTROL
	TOKEN_TYPE_USER_DEFINED
	TOKEN_TYPE_UNUSED
	TOKEN_TYPE_BYTE
)

Variables

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

Functions

func Forward

func Forward(ctx ml.Context, m Model, opts input.Options) (ml.Tensor, error)

func Register

func Register(name string, f func(ml.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 BytePairEncoding

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

func NewBytePairEncoding

func NewBytePairEncoding(pre string, vocab *Vocabulary) BytePairEncoding

func (BytePairEncoding) Decode

func (bpe BytePairEncoding) Decode(ids []int32) (string, error)

func (BytePairEncoding) Encode

func (bpe BytePairEncoding) Encode(s string, addSpecial bool) ([]int32, error)

func (BytePairEncoding) Is

func (bpe BytePairEncoding) Is(id int32, special Special) bool

type Model

type Model interface {
	Forward(ml.Context, input.Options) (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 most typically an ml.Tensor, however, different
	// type are possible, such as an object containing a tensor plus
	// additional metadata, a slice of tensors or even just the original input.
	//
	// The result may be cached by the runner.
	EncodeMultimodal(ml.Context, []byte) (any, 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(ml.Context, []input.Input) ([]input.Input, error)
}

MultimodalProcessor must be implemented by multimodal models.

type SentencePieceModel added in v0.6.0

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

func NewSentencePieceModel added in v0.6.0

func NewSentencePieceModel(pre string, vocab *Vocabulary) SentencePieceModel

func (SentencePieceModel) Decode added in v0.6.0

func (spm SentencePieceModel) Decode(ids []int32) (string, error)

func (SentencePieceModel) Encode added in v0.6.0

func (spm SentencePieceModel) Encode(s string, addSpecial bool) ([]int32, error)

func (SentencePieceModel) Is added in v0.6.0

func (spm SentencePieceModel) Is(id int32, special Special) bool

type Special

type Special int32
const (
	SpecialBOS Special = iota
	SpecialEOS
)

type Tag

type Tag struct {
	Name      string
	Alternate []string
}

func ParseTags

func ParseTags(s string) (tag Tag)

type TextProcessor

type TextProcessor interface {
	Encode(s string, addSpecial bool) ([]int32, error)
	Decode([]int32) (string, error)
	Is(int32, Special) bool
}

func NewTextProcessor added in v0.6.0

func NewTextProcessor(s string) (TextProcessor, error)

type Vocabulary

type Vocabulary struct {
	Values []string
	Types  []uint32
	Scores []float32
	Merges []string

	BOS, EOS, EOT          int32
	AddBOS, AddEOS, AddEOT bool
	// contains filtered or unexported fields
}

func (*Vocabulary) Decode

func (v *Vocabulary) Decode(id int32) string

func (*Vocabulary) Encode

func (v *Vocabulary) Encode(s string) int32

func (*Vocabulary) Is

func (v *Vocabulary) Is(id int32, special Special) bool

func (*Vocabulary) Merge

func (v *Vocabulary) Merge(left, right string) int

func (*Vocabulary) SpecialVocabulary

func (v *Vocabulary) SpecialVocabulary() []string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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