Last updated: 2026-11-17
API Server
Runtime
Backend-specific server runtime aliases and wrappers.
Keeps the HTTP/routes layer shared across Vulkan and Metal backends.
38 exports shown
constant
is_metal
pub const is_metal = gpu.is_metal Whether the active GPU backend is Apple Metal.
constant
is_vulkan
pub const is_vulkan = gpu.is_vulkan Whether the active GPU backend is Vulkan.
constant
supports_model_management
pub const supports_model_management = gpu.is_vulkan or gpu.is_metal Whether the backend supports loading/unloading models at runtime.
constant
supports_sampling_controls
pub const supports_sampling_controls = gpu.is_vulkan or gpu.is_metal Whether the backend supports temperature, top-p, top-k, and repetition penalty.
constant
supports_runtime_profiling
pub const supports_runtime_profiling = gpu.is_vulkan or gpu.is_metal Whether the backend supports GPU kernel profiling during inference.
function
mtpRequestError
pub fn mtpRequestError(enabled: ?bool) ?[]const u8 No public doc comment yet.
constant
tokenizer_mod
pub const tokenizer_mod = @import("../model/tokenizer.zig") Tokenizer module (shared across all backends).
constant
forward_mod
pub const forward_mod = if (gpu.is_metal) @import("../compute/forward_metal.zig") else @import("../compute/forward.zig") Forward-pass module, selected by the active backend.
constant
loader_mod
pub const loader_mod = if (gpu.is_metal) @import("../model/loader_metal.zig") else @import("../model/loader.zig") Model-loading module, selected by the active backend.
constant
model_manager_mod
pub const model_manager_mod = if (gpu.is_metal) @import("model_manager_metal.zig") else @import("model_manager.zig") Model-manager module, selected by the active backend.
constant
InferenceEngine
pub const InferenceEngine = forward_mod.InferenceEngine Backend-specific inference engine that runs the forward pass.
constant
DecodeState
pub const DecodeState = forward_mod.DecodeState Per-sequence decode state (KV cache position, token history, etc.).
constant
RequestControl
pub const RequestControl = @import("../gpu/request_control.zig").RequestControl No public doc comment yet.
function
setPrefillControl
pub fn setPrefillControl(engine: *InferenceEngine, control: ?RequestControl) void Vulkan checks client liveness between prefill tokens/submissions.
The Metal preview retains its existing decode-time cancellation behavior.
constant
Model
pub const Model = loader_mod.Model Loaded model handle (weights, hyperparams, GGUF metadata).
constant
ModelManager
pub const ModelManager = model_manager_mod.ModelManager Manages loading, unloading, and switching between models at runtime.
constant
SamplingParams
pub const SamplingParams = forward_mod.SamplingParams Token sampling parameters (shared across Vulkan and Metal backends).
function
enableLogitsReadback
pub fn enableLogitsReadback(_engine: *InferenceEngine) void Enable logits readback from GPU so sampling can inspect raw logits.
On Metal (UMA) logits are always CPU-accessible, so this is a no-op.
function
logitsReadbackEnabled
pub fn logitsReadbackEnabled(_engine: *const InferenceEngine) bool Return whether logits readback is currently enabled on the engine.
Always returns `true` on Metal because UMA makes logits CPU-accessible without an explicit readback step.
function
setLogitsReadbackEnabled
pub fn setLogitsReadbackEnabled(_engine: *InferenceEngine, _enabled: bool) void Set the logits readback intent flag on backends that can elide full logit materialization.
function
enableProfiling
pub fn enableProfiling(_engine: *InferenceEngine) !void Enable GPU kernel profiling on the inference engine.
Supported on both Vulkan and Metal backends; calls the backend's own `enableProfiling` method.
function
decodeStep
pub fn decodeStep( _engine: *InferenceEngine, _state: *DecodeState, _token_id: u32, _collect_output: bool, ) !void Run a single autoregressive decode step, advancing the KV cache by one token.
constant
mtp_max_draft
pub const mtp_max_draft: u32 = if (gpu.is_vulkan) InferenceEngine.mtp_max_draft_tokens else 3 NextN/MTP speculative decoding (Vulkan backend).
Greedy requests only.
function
mtpBeginRequest
pub fn mtpBeginRequest(_engine: *InferenceEngine) void Reset per-request MTP state; call before the prompt prefill.
function
mtpLogRequest
pub fn mtpLogRequest(_engine: *const InferenceEngine) void Log counters for the completed request, before another request can reset them.
function
mtpPrime
pub fn mtpPrime(_engine: *InferenceEngine, _state: *DecodeState, _prompt_tokens: []const u32) bool Prime the NextN block over the freshly prefilled prompt.
Returns false when MTP is unavailable (env off, model without NextN block, partial prefill).
function
mtpSetPrimeDuringPrefill
pub fn mtpSetPrimeDuringPrefill(_engine: *InferenceEngine, _on: bool) void Whether a chunked prefill primes the draft block chunk by chunk (off for requests that sample non-greedily, where speculation is unused).
function
ssmCheckpointTake
pub fn ssmCheckpointTake(_engine: *InferenceEngine, _state: *DecodeState) bool Recurrent-state checkpoints for chat reuse on hybrid models (see InferenceEngine.ssm_checkpoint).
All return false / null on other backends.
function
ssmCheckpointRestore
pub fn ssmCheckpointRestore(_engine: *InferenceEngine, _state: *DecodeState) bool No public doc comment yet.
function
ssmCheckpointPosition
pub fn ssmCheckpointPosition(_engine: *const InferenceEngine) ?u32 No public doc comment yet.
function
ssmCheckpointInvalidate
pub fn ssmCheckpointInvalidate(_engine: *InferenceEngine) void No public doc comment yet.
function
canRewindAttentionPrefix
pub fn canRewindAttentionPrefix(_engine: *const InferenceEngine) bool A canonical suffix may overwrite old KV rows only when there is no recurrent or draft state to restore.
An enabled lazy draft counts too.
function
canonicalPrefixDefault
pub fn canonicalPrefixDefault(_engine: *const InferenceEngine) bool No public doc comment yet.
function
mtpResetCapture
pub fn mtpResetCapture(_engine: *InferenceEngine) void Forget captured prefill rows so the next prefill's capture starts at row 0.
function
mtpPrimeSuffix
pub fn mtpPrimeSuffix(_engine: *InferenceEngine, _state: *DecodeState, _prompt_tokens: []const u32, _reused_prefix_len: u32) bool Prime the NextN block over only the tokens appended after a reused prompt prefix.
Returns false when the engine no longer holds that prefix, in which case the caller keeps ordinary decode.
struct
MtpSource
pub const MtpSource = struct Token source that replaces `decodeStep` + greedy `sample` with NextN/MTP cycles when active, and falls back to the plain path otherwise.
Methods
2method
MtpSource.step
pub fn step( self: *MtpSource, _engine: *InferenceEngine, _state: *DecodeState, prev: u32, tokens_remaining: u32, _params: SamplingParams, _random: std.Random, ) !u32 Feed `prev` to the model and return the next token.
`tokens_remaining` is the number of tokens the request may still produce (>= 1).
method
MtpSource.finish
pub fn finish(_: *MtpSource, _engine: *InferenceEngine) void Wait for any decode step queued ahead by `step` (Vulkan chained greedy decode) so the engine is idle when the request ends.
function
sample
pub fn sample( _engine: *const InferenceEngine, _state: *const DecodeState, _params: SamplingParams, _random: std.Random, ) u32 Sample the next token from the model's logit distribution.