Documentation
¶
Overview ¶
Package modelops is the daemon's on-demand model operations service: catalog browsing, operator-triggered downloads (with cancel), and runtime load/unload/default switching. It is the write-half the local API lacked — before it, models moved only at daemon startup or via the coordinator's ModelAssignment stub.
Index ¶
- Variables
- type Loader
- type MemorySnapshot
- type Service
- func (s *Service) CancelDownload(id string) bool
- func (s *Service) Catalog(ctx context.Context, refresh bool) (*models.Catalog, error)
- func (s *Service) ConfiguredMemoryBudgetMB() int64
- func (s *Service) Downloading(id string) bool
- func (s *Service) IdleSince(id string) (time.Time, bool)
- func (s *Service) IdleUnload() time.Duration
- func (s *Service) Load(ctx context.Context, id string) error
- func (s *Service) LoadInstance(ctx context.Context, id string) (rt.Instance, error)
- func (s *Service) LoadInstanceOrigin(ctx context.Context, id, origin string) (rt.Instance, error)
- func (s *Service) Loading(id string) bool
- func (s *Service) Measure(ctx context.Context)
- func (s *Service) Memory() MemorySnapshot
- func (s *Service) MemoryBudgetMB() int64
- func (s *Service) Remove(ctx context.Context, id string) error
- func (s *Service) RunHousekeeping(ctx context.Context)
- func (s *Service) SetDefault(id string) error
- func (s *Service) SetIdleUnload(d time.Duration)
- func (s *Service) SetMemoryBudgetMB(mb int64)
- func (s *Service) StartDownload(ctx context.Context, id string) (bool, error)
- func (s *Service) Unload(ctx context.Context, id string) error
- func (s *Service) UnloadIdle(ctx context.Context) []string
Constants ¶
This section is empty.
Variables ¶
var ErrDownloadRunning = errors.New("modelops: download already running")
ErrDownloadRunning is returned when a download for the id is in flight.
var ErrOverMemory = errors.New("modelops: over memory budget")
ErrOverMemory means a load does not fit the memory budget even after unloading every idle instance admission is allowed to touch. The assign service reports it to the coordinator as `cached` (the artifact stays on disk, loadable when demand returns); the local API returns it to the operator as an error.
var ErrUnknownModel = errors.New("modelops: model not in catalog")
ErrUnknownModel is returned when an id is in neither the catalog nor the local cache.
Functions ¶
This section is empty.
Types ¶
type Loader ¶
type Loader interface {
Load(ctx context.Context, m rt.ModelSpec, res rt.ResourceBudget) (rt.Instance, error)
}
Loader loads a model artifact into a serving runtime instance (*llamacpp.Adapter in production; fakes in tests).
type MemorySnapshot ¶ added in v0.4.0
type MemorySnapshot struct {
UsedMB int64
BudgetMB int64
TotalMB int64
// Models is the per-model footprint (measured when available, else the
// estimate) for every loaded model.
Models map[string]int64
}
MemorySnapshot is the /api/v1/status memory view and the heartbeat's ram_used_mb source.
type Service ¶
type Service struct {
Mgr *models.Manager
Eng *engine.Engine
Loader Loader
Budget rt.ResourceBudget
Log *slog.Logger
// Catalog sources, mirroring config (path wins).
ManifestPath string
ManifestURL string
// OnLoaded is called after a model becomes servable (used to stamp the
// runtime build id into the capability profile). May be nil.
OnLoaded func(inst rt.Instance)
// Events receives models_changed on download-complete, load, unload and
// default switches. May be nil.
Events *events.Hub
// Activity receives loaded/unloaded rows. May be nil.
Activity *activity.Ring
// Hardware sizes the auto memory budget and tells unified from
// discrete memory. Nil disables admission unless a budget is
// configured explicitly (SetMemoryBudgetMB).
Hardware *typesv1.CapabilityProfile
// ContextLength is the operator's runtime.context_length override,
// which the footprint estimate must reflect (0 = catalog/default).
ContextLength int
// OnUnloaded is called after any unload (operator, idle, memory
// pressure) with the model id; the assign service reports `cached` to
// the coordinator from it. May be nil.
OnUnloaded func(id string)
// contains filtered or unexported fields
}
Service wires catalog + cache + runtime together. Nil Service (mock runtime) means the local API reports these operations unsupported.
func (*Service) CancelDownload ¶
CancelDownload aborts an in-flight download. The .partial file is kept so a later attempt resumes.
func (*Service) Catalog ¶
Catalog returns the model catalog, cached for catalogTTL. refresh forces a refetch.
func (*Service) ConfiguredMemoryBudgetMB ¶ added in v0.4.0
ConfiguredMemoryBudgetMB returns the raw configured value (0 = auto).
func (*Service) Downloading ¶
Downloading reports whether a download for id is in flight.
func (*Service) IdleSince ¶ added in v0.4.0
IdleSince reports when a loaded model last served a request, if it is idle right now (no requests in flight).
func (*Service) IdleUnload ¶ added in v0.4.0
IdleUnload is the live idle-unload threshold (0 = never).
func (*Service) Load ¶
Load makes a model servable: cache hit or download, then runtime load and engine registration. Synchronous — llama-server startup takes seconds and callers want the outcome. No-op if already loaded.
func (*Service) LoadInstance ¶
LoadInstance is Load returning the runtime instance (startup needs it).
func (*Service) LoadInstanceOrigin ¶
LoadInstanceOrigin is LoadInstance with ownership of a fresh download (models.OriginMesh for coordinator placements: the fetch may then only evict other mesh-placed models to make room).
Memory admission happens after the artifact is on disk and before the runtime starts: the load's estimated footprint must fit the budget, idle instances are unloaded to make room (see admit), and ErrOverMemory is returned — with the file kept — when they cannot.
func (*Service) Loading ¶ added in v0.4.0
Loading reports whether a load of id is in progress (download, admission or runtime start). The store's retention pass treats it like loaded.
func (*Service) Measure ¶ added in v0.4.0
Measure samples every loaded runtime's footprint and replaces the estimates. Cheap on macOS/Linux (one syscall / one procfs read per process, inside Instance.Health).
func (*Service) Memory ¶ added in v0.4.0
func (s *Service) Memory() MemorySnapshot
Memory reports the current accounting.
func (*Service) MemoryBudgetMB ¶ added in v0.4.0
MemoryBudgetMB is the live budget for loaded models: the configured budget.max_ram_mb, or the auto derivation from hardware when it is 0. 0 means no hardware profile and no configured budget: admission is off.
func (*Service) Remove ¶ added in v0.4.0
Remove unloads id if it is loaded and deletes it from the store. Unlike Unload followed by Manager.Remove, it never reports the model as `cached` to the coordinator in between: the file is going away.
func (*Service) RunHousekeeping ¶ added in v0.4.0
RunHousekeeping measures footprints and applies idle unload every housekeepInterval until ctx ends.
func (*Service) SetDefault ¶
SetDefault switches the model served when a request names none.
func (*Service) SetIdleUnload ¶ added in v0.4.0
SetIdleUnload changes the threshold live.
func (*Service) SetMemoryBudgetMB ¶ added in v0.4.0
SetMemoryBudgetMB changes the configured budget live (0 = auto). Nothing is unloaded immediately; the next load and the idle loop apply it.
func (*Service) StartDownload ¶
StartDownload begins fetching a catalog model in the background. It returns (false, nil) if the model is already cached and ready, and ErrDownloadRunning if a download is already in flight.