launch

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package launch builds the exact command that serves a local model, without running it. It is the boundary between deciding how a model should run and actually running it: this package composes the gated runtime binary, the verified weights, a trusted prompt contract, and a loopback-only listener into a command line and the address the model will answer on. A caller executes that command inside the isolation sandbox and then reaches the model at the plan's base URL.

The plan is pure data and the builder does no I/O, so what will be executed is fully determined and testable before anything runs. Two safety properties are enforced here rather than left to the runtime: the server is pinned to a loopback address so the model is never exposed off the machine, and the chat template is forced to a trusted, recognized name so a template embedded in hostile weights cannot set the prompt contract. A plan is refused unless both hold.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InspectTemplate

func InspectTemplate(weightsPath, trusted string) (gguf.ChatTemplateDecision, error)

InspectTemplate reads the weights' GGUF metadata with the hardened reader, never the runtime's own parser, and decides the chat template to run with. The decision is always the trusted name, never the model's; the returned flag reports whether the model embedded a template of its own, so a caller can set Config.ModelEmbedsTemplate and record that an override was needed. It reads only the header, not the tensors.

func KnownChatTemplate

func KnownChatTemplate(name string) bool

KnownChatTemplate reports whether name is a trusted template a plan may use.

func KnownVLLMQuant

func KnownVLLMQuant(scheme string) bool

KnownVLLMQuant reports whether scheme is a vLLM quantization a plan may request.

Types

type Config

type Config struct {
	// BinPath is the gated runtime server executable to run (an installed build).
	BinPath string
	// WeightsPath is the verified GGUF weights file on disk to load.
	WeightsPath string
	// Model is the catalog entry being served; its ChatTemplate is the trusted contract.
	Model catalog.ModelSpec
	// Format is the weight encoding being served, which selects the runtime engine. Empty
	// is treated as GGUF/llama.cpp so existing callers keep their behavior.
	Format catalog.Format
	// Port is the loopback TCP port the server listens on. The caller picks a free one.
	Port int
	// CtxSize is the context window to run with; 0 lets the runtime use the model default.
	CtxSize int
	// CPUOnly forces the model to run entirely on the CPU with no GPU offload, the last-resort
	// footprint for a model that will not fit in device memory. The default offloads to the GPU
	// as the runtime sees fit. It overrides GPULayers and MoECPULayers.
	CPUOnly bool
	// GPULayers, when positive, is the number of model layers offloaded to the GPU
	// (llama.cpp -ngl). Zero leaves the offload to the runtime's default. Ignored when
	// CPUOnly is set.
	GPULayers int
	// MoECPULayers, when positive, keeps that many mixture-of-experts layers on the CPU
	// while the rest of the model stays on the GPU (llama.cpp -ncmoe). This is what lets a
	// large-total, small-active MoE run on a modest GPU: hot weights in VRAM, the cold
	// expert pages in system RAM. Ignored when CPUOnly is set.
	MoECPULayers int
	// KVCacheType, when set, quantizes the KV cache to this element type (llama.cpp
	// --cache-type-k/--cache-type-v), trading a little quality for room to hold more
	// context in the same VRAM. It must be a recognized type or the plan is refused.
	KVCacheType string
	// DraftWeightsPath, when set, names a small draft model the runtime uses for
	// speculative decoding: the draft proposes tokens the primary verifies in a batch,
	// raising throughput at no quality cost. Empty disables speculation.
	DraftWeightsPath string
	// DraftMax and DraftMin bound how many tokens the draft proposes per step (llama.cpp
	// --draft-max/--draft-min). They apply only when DraftWeightsPath is set; zero leaves
	// the runtime default.
	DraftMax int
	DraftMin int
	// Quantization, when set, names the on-disk quantization scheme the vLLM engine loads
	// the weights with (vLLM --quantization), for example "awq", "fp8", or "modelopt_fp4"
	// for an NVFP4 checkpoint. It must be a recognized scheme or the plan is refused. It
	// applies only to the vLLM engine; the llama.cpp engine reads the quantization from
	// the GGUF file itself.
	Quantization string
	// GPUMemoryUtilization, when positive, is the fraction of GPU memory vLLM may reserve
	// for weights and the KV cache (vLLM --gpu-memory-utilization), a value in (0,1]. Zero
	// leaves vLLM's default. vLLM engine only.
	GPUMemoryUtilization float64
	// KVCacheDtype, when set, quantizes the vLLM KV cache to this element type (vLLM
	// --kv-cache-dtype), for example "fp8". It must be a recognized vLLM type or the plan
	// is refused. This is the vLLM counterpart to KVCacheType, which is llama.cpp's; a plan
	// uses whichever matches its engine. vLLM engine only.
	KVCacheDtype string
	// Containerized records that the vLLM server runs inside a container, so it must bind
	// all interfaces inside the container's isolated network namespace for the engine's
	// loopback-only published port to reach it. The off-host exposure stays closed: the
	// container tier publishes the port bound to the host's loopback only, so binding
	// 0.0.0.0 inside the container is reachable from the host loopback and nowhere else, and
	// the client still targets the loopback BaseURL. A non-containerized server binds
	// loopback directly. vLLM engine only.
	Containerized bool
	// APIKey, when set, is required by the server on every request, so even a local
	// process cannot reach the model without the token the caller holds. Optional.
	APIKey string
	// ModelEmbedsTemplate records that the weights carry their own chat template, a
	// signal from inspecting the file. The plan overrides it regardless; the field only
	// surfaces that an override was necessary. Optional.
	ModelEmbedsTemplate bool
}

Config is everything needed to build a serve command for one local model.

type Engine

type Engine string

Engine is the inference runtime a serve command is built for. A weight format determines its engine: a different format is a different command vocabulary, so the plan builder dispatches on it rather than assuming one runtime.

const (
	// EngineLlamaCpp serves GGUF weights with the llama.cpp server (CPU-offload capable,
	// the portable path). It is also the default for an unspecified format.
	EngineLlamaCpp Engine = "llama.cpp"
	// EngineVLLM serves safetensors weights with vLLM (the GPU-resident, high-throughput
	// path). Its command builder is not wired yet, so a plan for it is refused rather than
	// served with the wrong runtime.
	EngineVLLM Engine = "vllm"
)

func EngineForFormat

func EngineForFormat(f catalog.Format) (Engine, bool)

EngineForFormat reports which runtime serves a weight format, and whether the format is one a plan can be built for. An empty format defaults to llama.cpp so a caller that does not record a format still gets the GGUF path it had before. A pickle (code-on-load) format has no serving engine: it is refused at fetch and never reaches here.

type Plan

type Plan struct {
	// Argv is the full command: the binary followed by its flags, ready to execute.
	Argv []string
	// Host and Port are the loopback address the server binds.
	Host string
	Port int
	// BaseURL is the OpenAI-compatible endpoint a client targets once the server is up.
	BaseURL string
	// TemplateOverridden is true when the model shipped its own chat template that this
	// plan replaced with the trusted one.
	TemplateOverridden bool
}

Plan is a built, not-yet-run serve command and where it will answer.

func BuildPlan

func BuildPlan(cfg Config) (Plan, error)

BuildPlan composes the serve command for cfg, or refuses it. It enforces the safety invariants every runtime shares, once and centrally, before handing off to the engine-specific command builder: the weights and binary are named, the port is a usable TCP port, the model carries a trusted recognized chat template, and the format maps to a runtime whose builder exists. So a plan can only ever describe a loopback-bound server running a known prompt contract, whichever engine serves it. It performs no I/O and starts nothing.

Jump to

Keyboard shortcuts

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