llamacpp

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 34 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 llamacpp adapts a supervised llama-server subprocess to the runtime.Runtime interface (SPEC §A1.3: subprocess, never cgo).

Index

Constants

View Source
const MinDecisionTag = 11382

MinDecisionTag is the first upstream llama.cpp build tag that serves decision models (POST /v1/systemone; ggml-org/llama.cpp#29818 and #29831 for Clef). The runtimes pin moves from b9892 to at least this.

Variables

View Source
var ErrNoBuild = errors.New("llamacpp: no runtime build for this platform")

ErrNoBuild marks a manifest that publishes no build this OS/arch can run (not even a CPU one), as opposed to a manifest that could not be fetched or trusted. Test with errors.Is.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	Fetcher *Fetcher
	// Accels is the accelerator preference chain from
	// hardware.AccelPreference (cuda12 > rocm > vulkan > cpu, flockd#21):
	// the Fetcher serves the first lane the manifest publishes. Accel is
	// the head of that chain; either may be set, Accels wins.
	Accels []string
	Accel  string
	// VRAMMB is the detected GPU memory (system RAM on Apple Silicon);
	// with budget.max_vram_percent it bounds GPU offload. 0 = unknown.
	VRAMMB uint64
	Log    *slog.Logger
	// ContextLength override (0 = model/catalog default).
	ContextLength int
	// MaxContext caps the window passed as --ctx-size (0 = no cap); see
	// config.Runtime.MaxContext.
	MaxContext int
	// contains filtered or unexported fields
}

Adapter implements runtime.Runtime by supervising llama-server and translating CompletionRequests to its OpenAI-compatible HTTP API.

func (*Adapter) Load

func (a *Adapter) Load(ctx context.Context, m rt.ModelSpec, res rt.ResourceBudget) (rt.Instance, error)

Load fetches/verifies the pinned llama-server build, launches it on an ephemeral loopback port with the model, health-gates it and returns the serving Instance. A sharded model is passed as its first part (<name>-00001-of-0000N.gguf): llama-server opens the siblings itself.

func (*Adapter) Prepare added in v0.6.8

func (a *Adapter) Prepare(ctx context.Context) (string, error)

Prepare resolves (fetching and verifying if needed) the llama-server build for this machine without loading a model, and returns its build id. Boot calls it before the tunnel connects so the session Hello carries runtime_build_id — fingerprint challenges key on it — even while the first model is still on its way (flockd#48). Cached after the first boot.

func (*Adapter) SelectedAccel added in v0.6.0

func (a *Adapter) SelectedAccel() string

SelectedAccel is the backend of the llama-server build actually running — "vulkan" on an AMD box whose manifest has no rocm lane — so status surfaces can show it; before the first Load it is the preferred accel. A configured local binary reports the preferred accel too (its backend is unknown to the daemon).

func (*Adapter) SupportsModel added in v0.7.0

func (a *Adapter) SupportsModel(ctx context.Context, m rt.ModelSpec) error

SupportsModel implements runtime.ModelSupporter: it resolves the runtime build this node runs (cached after boot) and reports whether it can serve m, so a decision model is refused before anything is downloaded when the build predates decision support.

type Artifact

type Artifact struct {
	OS     string `json:"os"`    // darwin|linux|windows
	Arch   string `json:"arch"`  // arm64|amd64
	Accel  string `json:"accel"` // metal|cuda12|rocm|vulkan|cpu-avx2
	URL    string `json:"url"`
	SHA256 string `json:"sha256"` // of the tarball
	Size   int64  `json:"size_bytes"`
	// CosignSignatureURL is the detached `cosign sign-blob` signature over
	// the tarball: a bare base64 DER ECDSA signature over its SHA-256
	// (.sig) or a Sigstore bundle carrying the same (.sigstore.json); see
	// trust.go. Verified against the pinned key before anything is
	// unpacked; optional until every published manifest carries one
	// (runtime.require_signature).
	CosignSignatureURL string `json:"cosign_signature_url"`
	// CosignCertificateURL is modelled because the runtimes schema defines
	// it, but unused: key-mode signatures have no certificate, and a
	// certificate served by the artifact host proves nothing on its own.
	// Only a keyless (Fulcio) custody decision would make it load-bearing;
	// see trust.go.
	CosignCertificateURL string `json:"cosign_certificate_url"`
}

type ArtifactManifest

type ArtifactManifest struct {
	RuntimeBuildID string     `json:"runtime_build_id"`
	Artifacts      []Artifact `json:"artifacts"`
}

ArtifactManifest mirrors teraflock/runtimes manifests/schema.json: one manifest per runtime_build_id, published alongside the tarballs. The build id participates in the fingerprint trust tuple (model_sha, quant, runtime_build_id) — SPEC §2.2. Fields the daemon does not act on (upstream_tag, created_at, …) are ignored rather than modelled, so a manifest format addition never requires a daemon release.

type Fetcher

type Fetcher struct {
	// ManifestURL points at the ArtifactManifest JSON. Required unless
	// BinaryPath overrides fetching entirely.
	ManifestURL string
	// BinaryPath, when set, skips download and uses an existing binary
	// (config runtime.llama_server_path).
	BinaryPath string
	CacheDir   string // e.g. <data_dir>/runtimes
	HTTPClient *http.Client

	// SigningKeyPEM is the resolved public key (PKIX PEM) that artifact and
	// manifest signatures are verified against (config
	// runtime.artifact_signing_key). nil falls back to the daemon's
	// embedded pin (trust.go); when that is empty too there is no verifier
	// and signatures cannot be checked.
	SigningKeyPEM []byte
	// RequireSignature refuses manifests and artifacts that advertise no
	// cosign signature, refuses cached extracts trusted by sha256 only, and
	// refuses to run at all without a pinned key (config
	// runtime.require_signature).
	RequireSignature bool
	// Log receives the one-time trust warnings and the "runtime signature
	// verified" line; nil uses slog.Default().
	Log *slog.Logger
	// contains filtered or unexported fields
}

Fetcher downloads, SHA-verifies, signature-verifies and unpacks the pinned llama-server build.

func (*Fetcher) Ensure

func (f *Fetcher) Ensure(ctx context.Context, accels ...string) (path, buildID string, err error)

Ensure returns the path to a verified llama-server binary and its build id for the accelerator chain (hardware.AccelPreference order: the first accel with a published build wins, then the CPU build).

func (*Fetcher) EnsureSelection added in v0.6.0

func (f *Fetcher) EnsureSelection(ctx context.Context, accels ...string) (Selection, error)

EnsureSelection is Ensure plus which accel the build actually is.

func (*Fetcher) Preflight added in v0.1.1

func (f *Fetcher) Preflight(ctx context.Context, accels ...string) error

Preflight checks that a runtime binary is *resolvable* for this (GOOS, GOARCH) and accelerator chain without actually downloading the tarball. Used by `tera up` to refuse installing a service unit that would crash-loop on first start when the pinned catalog has no build for this machine. Returns nil when either f.BinaryPath is present on disk or f.ManifestURL advertises a matching artifact (cpu fallback included, same rule as Ensure) that satisfies the signature policy.

func (*Fetcher) Resolve added in v0.9.4

func (f *Fetcher) Resolve(ctx context.Context, accels ...string) (Selection, error)

Resolve reports which build EnsureSelection would run for the accelerator chain, without downloading or unpacking anything: the configured local binary, or the manifest's pick for this (GOOS, GOARCH) under the signature policy. It is the read-only half of EnsureSelection (`tera up` preflight, `tera doctor`). Selection.Path is set only when that build is already usable on disk: the local binary, or an extract of the picked build in CacheDir that EnsureSelection would reuse as is.

type Selection added in v0.6.0

type Selection struct {
	Path    string
	BuildID string
	// Accel is the backend of the build actually chosen — the first entry
	// of the requested chain the manifest publishes, or the CPU build.
	// Empty for a configured local binary (runtime.llama_server_path),
	// whose backend the daemon cannot know.
	Accel string
	// Reason says why that build was chosen, for the "runtime accel
	// selected" log line: "preferred", "no cuda12 artifact for linux/amd64",
	// "configured llama_server_path".
	Reason string
}

Selection is the llama-server build Ensure resolved for this node.

type Verifier added in v0.6.1

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

Verifier checks cosign key-mode blob signatures against one pinned ECDSA P-256 public key.

func ParseVerifier added in v0.6.1

func ParseVerifier(pemBytes []byte) (*Verifier, error)

ParseVerifier parses a PEM-encoded PKIX public key (the cosign.pub format, "-----BEGIN PUBLIC KEY-----") and returns a verifier for it. Only ECDSA over P-256 is accepted, matching cosign's default ecdsa-sha2-256-nistp256 signing algorithm and the docs#34 recommendation; every other key type is rejected with a clear error so a misconfigured pin fails at startup, not at the first fetch.

func (*Verifier) Verify added in v0.6.1

func (v *Verifier) Verify(blobSHA256 []byte, sig []byte) error

Verify checks sig — the contents of a cosign_signature_url, in any of the three shapes cosign sign-blob has written over blobSHA256, the SHA-256 digest of the signed blob: a bare base64 ASN.1/DER ECDSA signature (--output-signature, surrounding whitespace tolerated), or JSON (first non-space byte '{') that is either cosign's own key-mode bundle {"base64Signature": ...} — what --bundle writes with --tlog-upload=false, so what the release workflow actually publishes (runtimes llamacpp-b9892-4) — or a Sigstore bundle with messageSignature.signature. cosign sign-blob signs the digest, so callers pass the same hash they already computed for the sha256 pin — never the blob itself. A bundle that records a different digest than the one being verified is rejected before the signature is even looked at.

Jump to

Keyboard shortcuts

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