localmodels

package
v0.2.13 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 27 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package localmodels owns the models one Node manages: anonymous Hub discovery, immutable pinned definitions, verified installations and the scheduler that serializes local inference.

Index

Constants

View Source
const (
	// DefaultEmbedding identifies the recommended Granite Multilingual model.
	DefaultEmbedding = "granite-multi"
	// MaxAssets bounds the files of one definition.
	MaxAssets = 8
	// MaxAssetBytes bounds one model file.
	MaxAssetBytes uint64 = 2 * 1024 * 1024 * 1024
	// MaxPrefixBytes bounds one embedding input prefix.
	MaxPrefixBytes = 1024
)
View Source
const Limit = 128

Limit is the number of registered definitions allowed per kind, beside the pinned builtins.

Variables

NodeKinds are the model kinds a Node manages. Speech belongs to the controller.

Functions

func Builtin

func Builtin(id string) bool

Builtin reports whether id names a pinned embedding model.

func Cancelled

func Cancelled() error

Cancelled reports a cancelled local model operation.

func Choice

Choice is the saved or initial choice of one kind.

func Definitions

func Definitions(records []Registration) (map[string]*protocol.ModelsDefinition, error)

Definitions joins the pinned builtins with registered definitions.

func Dimension

func Dimension(format protocol.ModelsFormat) (uint16, bool)

Dimension is the vector size of an embedding format.

func Execute

func Execute[T any](ctx context.Context, registry *Registry, resource Resource, lane Lane, operation func(ctx context.Context, engine any) (T, error)) (T, error)

Execute runs one inference operation on a captured model. Interactive work runs before background work; a full lane reports Busy.

func Failure

func Failure(reason any) error

Failure reports a local runtime or storage failure.

func FillDefaults

func FillDefaults(settings *protocol.ModelsLocalSettings)

FillDefaults adds the initial choice of every Node kind that has none.

func ID

func ID(definition *protocol.ModelsDefinition) string

ID is the content identity of a definition, independent of asset order.

func Kind

Kind is the model kind a format belongs to.

func OCR

func OCR() []protocol.ModelsDefinition

OCR lists the pinned OCR definitions.

func SameChoice

func SameChoice(left, right protocol.ModelsLocalChoice) bool

SameChoice reports whether two choices enable the same model.

func Selected

func Selected(settings *protocol.ModelsLocalSettings, kind protocol.ModelsKind) string

Selected is the enabled model of one kind, or "" when none is selected.

func ValidID

func ValidID(id string) bool

ValidID reports whether id can name a model and its directory.

func ValidateDefinition

func ValidateDefinition(definition *protocol.ModelsDefinition) error

ValidateDefinition checks a pinned definition and its format's file set.

func ValidateSearch

func ValidateSearch(search *protocol.ModelsSearch) error

ValidateSearch bounds a Hub search request.

func ValidateSettings

func ValidateSettings(settings *protocol.ModelsLocalSettings) error

ValidateSettings checks the choices and the optional Hugging Face mirror.

func ValidateSource

func ValidateSource(source protocol.ModelsSource) error

ValidateSource checks a repository and a branch, tag or commit name.

Types

type Capabilities

type Capabilities map[protocol.ModelsKind]Capability

Capabilities are the runtimes present in this build. A kind without one is unavailable.

func (Capabilities) Catalog

func (capabilities Capabilities) Catalog(models []protocol.ModelsLocalModel) protocol.ModelsCatalog

Catalog pairs models with the execution availability of every Node kind.

func (Capabilities) Ensure

func (capabilities Capabilities) Ensure(kind protocol.ModelsKind) error

Ensure reports why a kind cannot execute on this Node.

type Capability

type Capability struct {
	Load Load
	// Available reports whether this machine can run the kind. Nil means it can.
	Available func() error
	// Probe is the compatibility check an installation runs on the freshly
	// loaded engine. Nil means loading is the whole check.
	Probe func(ctx context.Context, engine any) error
}

Capability is the inference runtime of one model kind.

type Engine

type Engine struct {
	// Value is the runtime's own engine, passed back to its operations.
	Value   any
	Release func()
}

Engine is a loaded model. The scheduler owns it and calls Release once when it unloads the model.

type Hubs

type Hubs struct {
	// Transport carries the Node's proxy settings.
	Transport http.RoundTripper
	// contains filtered or unexported fields
}

Hubs performs anonymous catalog requests over the Node's outbound transport.

func (*Hubs) Fixture

func (hubs *Hubs) Fixture(hub protocol.ModelsHub, endpoint string) error

Fixture redirects one Hub to a loopback server. Tests use it; production never calls it.

func (*Hubs) RefreshOCR

func (hubs *Hubs) RefreshOCR(ctx context.Context, previous *protocol.ModelsDefinition, mirror *string) (*protocol.ModelsDefinition, error)

RefreshOCR pins the latest revision of an OCR definition's files.

func (*Hubs) Resolve

func (hubs *Hubs) Resolve(ctx context.Context, kind protocol.ModelsKind, source protocol.ModelsSource, mirror *string) (*protocol.ModelsDefinition, error)

Resolve pins a repository revision into an installable definition.

func (*Hubs) Search

func (hubs *Hubs) Search(ctx context.Context, search *protocol.ModelsSearch, mirror *string) (protocol.ModelsPage, error)

Search lists Hub models compatible with one kind. Pages without a compatible model are skipped, at most three per request.

func (*Hubs) Versions

func (hubs *Hubs) Versions(ctx context.Context, origin protocol.ModelsHub, name string, mirror *string) ([]protocol.ModelsVersion, error)

Versions lists the branches and tags of one repository.

type Lane

type Lane uint8

Lane orders queued inference. Interactive work always runs before background work.

const (
	Interactive Lane = iota
	Background
)

type Load

type Load func(resource Resource, validating bool) (Engine, error)

Load builds the engine of one verified model on the scheduler's worker. validating is true while an installation checks compatibility.

type Options

type Options struct {
	// Profile is the Node's data directory. Empty leaves model storage
	// unavailable.
	Profile string
	// Capabilities are the inference runtimes present in this build.
	Capabilities Capabilities
	// Transport performs asset downloads and carries the Node's proxy settings.
	Transport http.RoundTripper
	// Clock drives idle release. Nil uses the system clock.
	Clock clockwork.Clock
}

Options configure one Node's registry.

type Prepared

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

Prepared is a validated configuration waiting for its durable commit.

type Registration

type Registration struct {
	ID         string
	Definition protocol.ModelsDefinition
}

Registration is one registered definition and its content identity.

type Registry

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

Registry owns model identities, verified installations and configuration for one Node.

Verified stamps are the installed-state authority. Removal clears a stamp before deleting files, so queued captures fail without a separate generation counter.

func New

func New(options Options) *Registry

New starts a registry holding the pinned builtins and default settings.

func (*Registry) Apply

func (registry *Registry) Apply(prepared *Prepared)

Apply publishes a prepared configuration after its durable commit.

func (*Registry) Cached

func (registry *Registry) Cached(kind protocol.ModelsKind) []protocol.ModelsLocalModel

Cached lists the models from verified stamps, without file access.

func (*Registry) Cancel

func (registry *Registry) Cancel(id string) bool

Cancel stops the active installation of one model.

func (*Registry) Capabilities

func (registry *Registry) Capabilities() Capabilities

Capabilities are the inference runtimes this registry schedules.

func (*Registry) CheckInstalled

func (registry *Registry) CheckInstalled(kind protocol.ModelsKind, id string) error

CheckInstalled verifies that a model still has its installed files without acquiring an inference engine or hashing them in a configuration write.

func (*Registry) Configure

func (registry *Registry) Configure(settings protocol.ModelsLocalSettings, records []Registration) error

Configure prepares and applies in one step, for callers without a durable commit between them.

func (*Registry) Definition

func (registry *Registry) Definition(id string) (*protocol.ModelsDefinition, error)

Definition is the registered definition of one identity.

func (*Registry) Install

func (registry *Registry) Install(ctx context.Context, id string, report Report) error

Install downloads, verifies and validates one registered model. An installed model returns at once. Cancelling ctx, Cancel, a changed asset source or Shutdown stop the transfer and keep its resumable checkpoint.

func (*Registry) List

func (registry *Registry) List(kind protocol.ModelsKind) ([]protocol.ModelsLocalModel, error)

List verifies the files of one kind, or of every kind when kind is empty, and returns the models.

func (*Registry) Prepare

func (registry *Registry) Prepare(settings protocol.ModelsLocalSettings, definitions map[string]*protocol.ModelsDefinition) (*Prepared, error)

Prepare validates settings against the definitions they will be saved with.

func (*Registry) Remove

func (registry *Registry) Remove(id string) error

Remove unloads one model and deletes its files.

func (*Registry) Resource

func (registry *Registry) Resource(kind protocol.ModelsKind, id string, choice *protocol.ModelsLocalChoice) (Resource, error)

Resource captures a verified model. Executions check file identity once before running. A non-nil choice must still be the applied choice.

func (*Registry) Root

func (registry *Registry) Root() (string, error)

Root is the model directory of the profile, created on first use.

func (*Registry) Settings

func (registry *Registry) Settings() protocol.ModelsLocalSettings

Settings is the applied configuration.

func (*Registry) Settle

func (registry *Registry) Settle(ctx context.Context, ids ...string) error

Settle waits until the hashing Start left running for the given models has ended, so a model on disk is not reported missing while it is being verified.

func (*Registry) Shutdown

func (registry *Registry) Shutdown()

Shutdown cancels every operation and releases every engine.

func (*Registry) Start

func (registry *Registry) Start() error

Start accepts the files their receipts cover without reading contents and hashes the others off the caller's thread, so a large model without a receipt does not delay startup. Such a model is listed as missing until its hash ends; operations that need it wait through Settle. Start also sweeps what interrupted downloads left behind and cannot be resumed.

func (*Registry) Storage

func (registry *Registry) Storage() error

Storage reports whether model storage is usable, without inspecting model files.

func (*Registry) Updates

func (registry *Registry) Updates() (Update, <-chan struct{})

Updates returns the published state and a channel closed at its next change.

type Report

Report receives the real phases of an installation. Progress accompanies only actual downloads.

type Resource

type Resource struct {
	ID         string
	Definition *protocol.ModelsDefinition
	Directory  string
	Stamp      *assets.Stamp
	// Scope ends when the model's kind is reconfigured or the Node stops.
	Scope context.Context
}

Resource is a verified model captured for one operation.

type Update

type Update struct {
	Models    []protocol.ModelsLocalModel
	Embedding protocol.ModelsLocalChoice
	OCR       protocol.ModelsLocalChoice
}

Update is the published registry state.

Directories

Path Synopsis
Package assets acquires pinned model files: resumable downloads verified by size and SHA-256, and the file identities that prove a verified installation.
Package assets acquires pinned model files: resumable downloads verified by size and SHA-256, and the file identities that prove a verified installation.
Package decision runs CPU-only local decisions through the packaged, pinned llama.cpp C API.
Package decision runs CPU-only local decisions through the packaged, pinned llama.cpp C API.
Package embedding turns text into normalized vectors with a transformer model on the CPU.
Package embedding turns text into normalized vectors with a transformer model on the CPU.
tokenizer
Package tokenizer reads the Hugging Face tokenizer.json components the pinned granite-multi embedding model uses and reproduces tokenizers 0.23.2 for them: added tokens, Split (Isolated) followed by ByteLevel pre-tokenization, BPE with ignore_merges and TemplateProcessing.
Package tokenizer reads the Hugging Face tokenizer.json components the pinned granite-multi embedding model uses and reproduces tokenizers 0.23.2 for them: added tokens, Split (Isolated) followed by ByteLevel pre-tokenization, BPE with ignore_merges and TemplateProcessing.
Package ocr recognizes text in images on the CPU with PaddleOCR detection, optional text-line orientation and recognition models.
Package ocr recognizes text in images on the CPU with PaddleOCR detection, optional text-line orientation and recognition models.
Package onnx is a minimal purego binding of the onnxruntime C API: the OrtApi function table reached through OrtGetApiBase, with CPU sessions only.
Package onnx is a minimal purego binding of the onnxruntime C API: the OrtApi function table reached through OrtGetApiBase, with CPU sessions only.

Jump to

Keyboard shortcuts

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