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
- Variables
- func Builtin(id string) bool
- func Cancelled() error
- func Choice(settings *protocol.ModelsLocalSettings, kind protocol.ModelsKind) protocol.ModelsLocalChoice
- func Definitions(records []Registration) (map[string]*protocol.ModelsDefinition, error)
- func Dimension(format protocol.ModelsFormat) (uint16, bool)
- func Execute[T any](ctx context.Context, registry *Registry, resource Resource, lane Lane, ...) (T, error)
- func Failure(reason any) error
- func FillDefaults(settings *protocol.ModelsLocalSettings)
- func ID(definition *protocol.ModelsDefinition) string
- func Kind(format protocol.ModelsFormat) protocol.ModelsKind
- func OCR() []protocol.ModelsDefinition
- func SameChoice(left, right protocol.ModelsLocalChoice) bool
- func Selected(settings *protocol.ModelsLocalSettings, kind protocol.ModelsKind) string
- func ValidID(id string) bool
- func ValidateDefinition(definition *protocol.ModelsDefinition) error
- func ValidateSearch(search *protocol.ModelsSearch) error
- func ValidateSettings(settings *protocol.ModelsLocalSettings) error
- func ValidateSource(source protocol.ModelsSource) error
- type Capabilities
- type Capability
- type Engine
- type Hubs
- func (hubs *Hubs) Fixture(hub protocol.ModelsHub, endpoint string) error
- func (hubs *Hubs) RefreshOCR(ctx context.Context, previous *protocol.ModelsDefinition, mirror *string) (*protocol.ModelsDefinition, error)
- func (hubs *Hubs) Resolve(ctx context.Context, kind protocol.ModelsKind, source protocol.ModelsSource, ...) (*protocol.ModelsDefinition, error)
- func (hubs *Hubs) Search(ctx context.Context, search *protocol.ModelsSearch, mirror *string) (protocol.ModelsPage, error)
- func (hubs *Hubs) Versions(ctx context.Context, origin protocol.ModelsHub, name string, mirror *string) ([]protocol.ModelsVersion, error)
- type Lane
- type Load
- type Options
- type Prepared
- type Registration
- type Registry
- func (registry *Registry) Apply(prepared *Prepared)
- func (registry *Registry) Cached(kind protocol.ModelsKind) []protocol.ModelsLocalModel
- func (registry *Registry) Cancel(id string) bool
- func (registry *Registry) Capabilities() Capabilities
- func (registry *Registry) CheckInstalled(kind protocol.ModelsKind, id string) error
- func (registry *Registry) Configure(settings protocol.ModelsLocalSettings, records []Registration) error
- func (registry *Registry) Definition(id string) (*protocol.ModelsDefinition, error)
- func (registry *Registry) Install(ctx context.Context, id string, report Report) error
- func (registry *Registry) List(kind protocol.ModelsKind) ([]protocol.ModelsLocalModel, error)
- func (registry *Registry) Prepare(settings protocol.ModelsLocalSettings, ...) (*Prepared, error)
- func (registry *Registry) Remove(id string) error
- func (registry *Registry) Resource(kind protocol.ModelsKind, id string, choice *protocol.ModelsLocalChoice) (Resource, error)
- func (registry *Registry) Root() (string, error)
- func (registry *Registry) Settings() protocol.ModelsLocalSettings
- func (registry *Registry) Settle(ctx context.Context, ids ...string) error
- func (registry *Registry) Shutdown()
- func (registry *Registry) Start() error
- func (registry *Registry) Storage() error
- func (registry *Registry) Updates() (Update, <-chan struct{})
- type Report
- type Resource
- type Update
Constants ¶
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 )
const Limit = 128
Limit is the number of registered definitions allowed per kind, beside the pinned builtins.
Variables ¶
var NodeKinds = [...]protocol.ModelsKind{protocol.ModelsKindEmbedding, protocol.ModelsKindOcr, protocol.ModelsKindDecision}
NodeKinds are the model kinds a Node manages. Speech belongs to the controller.
Functions ¶
func Choice ¶
func Choice(settings *protocol.ModelsLocalSettings, kind protocol.ModelsKind) protocol.ModelsLocalChoice
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 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 ¶
func Kind(format protocol.ModelsFormat) protocol.ModelsKind
Kind is the model kind a format belongs to.
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 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 ¶
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.
type Lane ¶
type Lane uint8
Lane orders queued inference. Interactive work always runs before background work.
type Load ¶
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 (*Registry) Cached ¶
func (registry *Registry) Cached(kind protocol.ModelsKind) []protocol.ModelsLocalModel
Cached lists the models from verified stamps, without file access.
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 ¶
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) 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) Settings ¶
func (registry *Registry) Settings() protocol.ModelsLocalSettings
Settings is the applied configuration.
func (*Registry) Settle ¶
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 ¶
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.
type Report ¶
type Report func(protocol.InstallationPhase, *protocol.InstallationProgress)
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.
Source Files
¶
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. |