Documentation
¶
Overview ¶
Package runtime defines the inference Runtime interface (SPEC §A1.3) and its adapters. llama.cpp is supervised as a subprocess (never cgo); the mock runtime backs tests and --standalone demos.
Index ¶
Constants ¶
const MockRuntimeBuildID = "mock-runtime-v1"
MockRuntimeBuildID identifies the in-process mock as a runtime build. It is deliberately distinct from any real llama.cpp build id so that fingerprint expected outputs generated against a mock can never be mistaken for a reference for real hardware (SPEC §2.2).
Variables ¶
var ErrNotLoaded = errors.New("runtime: model not loaded")
ErrNotLoaded is returned when an Instance is used after Shutdown or before the backing process is ready.
Functions ¶
This section is empty.
Types ¶
type BuildIdentified ¶
type BuildIdentified interface {
RuntimeBuildID() string
}
BuildIdentified is implemented by runtime instances that know which runtime build they are running. The daemon reports this in its CapabilityProfile; it is one third of the fingerprint trust tuple (model_sha, quant, runtime_build_id) — SPEC §2.2, §A2.5.
type Chunk ¶
type Chunk struct {
Delta string
// Reasoning is a chain-of-thought delta (OpenAI's `reasoning_content`).
// Empty for models the runtime cannot parse, whose thinking then
// arrives inline in Delta (e.g. as `<think>…</think>`).
Reasoning string
TokenCount int
Done bool
FinishReason string // "stop", "length", "cancelled", "error"
Usage *Usage
Embeddings [][]float32
Err string
}
Chunk is one streamed unit. For KindEmbedding a single final chunk carries Embeddings. Usage is set on the final chunk.
Every token the model produces is relayed as either Delta (the answer) or Reasoning (chain-of-thought, for models whose runtime separates it), and TokenCount covers both: the customer is billed for reasoning tokens and canary comparison diffs the whole stream, so nothing is dropped on the node. A chunk may carry both when the runtime emits them together.
type CompletionRequest ¶
type GenerationParams ¶
type GenerationParams struct {
Seed uint64
Temperature float64
TopP float64
MaxTokens int
Stop []string
FrequencyPenalty float64
PresencePenalty float64
}
GenerationParams: seed is always set upstream so retries and canary comparisons are deterministic for greedy decoding (SPEC §6).
type Instance ¶
type Instance interface {
Complete(ctx context.Context, req CompletionRequest) (TokenStream, error)
Health(ctx context.Context) (Stats, error)
Shutdown(ctx context.Context) error
}
Instance is one loaded model.
type MockRuntime ¶
type MockRuntime struct {
// TokensPerSec throttles generation; <= 0 means unthrottled.
TokensPerSec float64
// FailLoads causes the next N Load calls to fail (supervisor tests).
FailLoads int
// ReasoningTokens makes chat generations emit this many chain-of-thought
// tokens (Chunk.Reasoning) before the answer, the way llama.cpp's
// reasoning_content parsing does for reasoning models. They count
// toward max_tokens and completion_tokens like any other token.
ReasoningTokens int
}
MockRuntime is a deterministic in-process runtime used by tests, the fake coordinator path, and `flockd --standalone --runtime=mock`. Same seed -> same output, so it also exercises the fingerprint-challenge flow.
func NewMockRuntime ¶
func NewMockRuntime(tps float64) *MockRuntime
NewMockRuntime returns a mock producing ~tps tokens/second.
func (*MockRuntime) Load ¶
func (m *MockRuntime) Load(_ context.Context, spec ModelSpec, res ResourceBudget) (Instance, error)
type ModelSpec ¶
type ModelSpec struct {
ID string
Family string
Quant string
SHA256 string
Path string // local GGUF path (part 1 of a sharded model)
ContextLength int
Embeddings bool // model is served for /v1/embeddings
// MmprojPath is the vision projector sidecar passed to the runtime
// (llama-server --mmproj); "" when the model has none.
MmprojPath string
// SizeBytes is what the artifact occupies on disk across all of its
// files; 0 = unknown (the runtime stats Path instead).
SizeBytes int64
}
ModelSpec identifies a locally available model artifact ready to load. It is derived from the catalog's typesv1.ModelSpec after download+verify.
type ResourceBudget ¶
type ResourceBudget struct {
MaxVRAMPercent int
MaxRAMMB int64
// MaxConcurrent is the slot ceiling (budget.max_concurrent, or the
// hardware default when that is 0).
MaxConcurrent int
// Slots and ContextTokens are what memory.PlanContext decided for
// this load: --parallel and --ctx-size. 0 = unplanned; the adapter
// falls back to MaxConcurrent and its own context resolution.
Slots int
ContextTokens int
}
ResourceBudget is the operator-configured ceiling passed to Load, plus the layout admission planned for this particular load.
type Runtime ¶
type Runtime interface {
Load(ctx context.Context, m ModelSpec, res ResourceBudget) (Instance, error)
}
Runtime loads models into serving Instances. Exactly per SPEC §A1.3.
type Stats ¶
type Stats struct {
Healthy bool
ModelID string
QueueDepth int
TokensPerSec float64
MemUsedMB int64
Restarts int
}
Stats is the Health snapshot.
type TokenStream ¶
TokenStream yields Chunks until io.EOF. Close releases resources early (cancels generation server-side where supported).
func NewChanStream ¶
func NewChanStream(ch <-chan Chunk, cancel context.CancelFunc) TokenStream
NewChanStream builds a TokenStream from a channel; cancel (may be nil) is invoked on Close.