base

package
v0.32.2 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(arch string, fn func(root *model.Root) (Model, error))

Register registers a model constructor by architecture name. Called from init() in model packages. Panics on duplicate registration.

func RegisterDraft added in v0.23.1

func RegisterDraft(arch string, fn func(root *model.Root, target Model) (DraftModel, error))

RegisterDraft registers a draft model constructor by architecture name.

func Weights

func Weights(m Model) func(map[string]*mlx.Array) error

Weights returns a function that loads model weights, then pins all arrays reachable from the model struct and sweeps everything else.

Types

type DraftModel added in v0.23.1

type DraftModel interface {
	// Draft fuses b.Hidden (the target hidden state) into its own forward and
	// returns the head's hidden plus the projected hidden seeding the next step.
	Draft(b *batch.Batch, caches []cache.Cache) (hidden, projected *mlx.Array)

	// Unembed projects a hidden state to vocabulary logits.
	Unembed(x *mlx.Array) *mlx.Array

	// DraftCaches selects the draft model's own KV caches from the full
	// per-request slice — any subset, or nil when the draft keeps no KV.
	DraftCaches(caches []cache.Cache) []cache.Cache

	// LoadWeights assigns manifest tensors to the draft head's fields.
	LoadWeights(tensors map[string]*mlx.Array) error
}

DraftModel is an auxiliary model alongside a target that proposes speculative tokens.

func NewDraft added in v0.23.1

func NewDraft(root *model.Root, target Model) (DraftModel, error)

NewDraft constructs the draft model described by the manifest config, if any.

type Model

type Model interface {
	Forward(b *batch.Batch, cache []cache.Cache) *mlx.Array
	Unembed(x *mlx.Array) *mlx.Array
	NumLayers() int
	Tokenizer() *tokenizer.Tokenizer
	MaxContextLength() int

	// LoadWeights receives all tensors loaded from the manifest and assigns
	// them to model fields. Model-specific logic (MLA absorption, expert
	// stacking, quantized layer creation) happens here.
	LoadWeights(tensors map[string]*mlx.Array) error
}

Model is the interface that model implementations must satisfy.

func New

func New(root *model.Root) (Model, error)

New reads config.json from the manifest, detects the architecture, looks up the registered constructor, and calls it to create the model (with config parsed and struct created, but weights not yet loaded).

type SelfDraft added in v0.30.11

type SelfDraft interface {
	SelfDraft() DraftModel
}

SelfDraft is implemented by models whose draft head ships inline with the target weights; it returns the head, or nil when the checkpoint shipped none.

Jump to

Keyboard shortcuts

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