API reference

The exported API is documented one package per page, collected automatically from the docstrings:

  • Core: the shared substrate (dtypes, protobuf messages, boundary types, manifest, config, codec, shared memory, the weight store, the staging BufferPool). ReactantServer re-exports all of it, so it is documented once, under its original bindings.
  • Worker: ReactantServer, the inference worker.
  • Gateway: ReactantServerGateway.
  • Node: ReactantServerNode, the single-container supervisor.
  • Client: ReactantServerClient.
  • Export: ReactantServerExport, the offline export tooling.

The guide pages give the worked context: Tutorials, Bundles, Node Configuration, Scheduling, On-demand Weights, Multi-GPU Gateway, Client Usage, Meta Models, Object Detection, Transformer Text Models, and Deployment.

Operational internals

A few names the guides and docstrings reach for are deliberately unexported; they are documented here so their docstrings render and the qualified references in the guides are backed by the manual. Reach them from the REPL fully qualified, for example ReactantServer.scheduler_metrics(). They are implementation details and may change without a breaking release.

ReactantServer.Scheduler — Type
Scheduler

The weighted-fair, coalescing dispatch engine. Concurrent requests land on per-model queues; a single dispatch loop runs one GPU execution at a time, coalescing same-model requests into one batched execution at a compiled size and sharing GPU time by relative model weight, charged in measured device seconds. It holds the model registry, the backend, the device memory pool, the SchedulerConfig, per-model dispatch state, and an optional on-demand WeightCache. Submit work with infer and read observability counters with scheduler_metrics.

source
ReactantServer.infer — Function
infer(scheduler, request; cancelled=nothing) -> Vector{NamedTensor}

Submit a request and block until the scheduler returns the result. Re-raises any error captured during dispatch.

Runs the model's preprocess/postprocess hooks here, on the caller's task, rather than on the dispatch loop: preprocess before the request is queued, postprocess on the raw device outputs the loop hands back. Because each gRPC request runs on its own task, many requests' hook work proceeds in parallel and overlaps the single, serialized GPU execution. The dispatch loop coalesces and runs qr.prepared and never executes a request whose preprocess has not finished, since a request is only enqueued (made visible to the loop) after preprocess returns. A request runs on the version of the model whose preprocess it went through: if a reload replaces the model in the meantime, the request fails (NOT_FOUND on the wire, which a client or gateway retries).

The wait is bounded by scheduler.dispatch_timeout_seconds (0 waits indefinitely): past it the request is withdrawn (it never runs if still queued; a running one's result is discarded) and DispatchTimeoutError is thrown. cancelled, a zero-argument function that returns true once the caller's client has cancelled the call, is polled while waiting; it withdraws the request the same way and throws RequestCancelledError. A meta's sub-calls inherit it.

scratch_out applies to a meta only (a regular model acquires no scratch). When given, the pool slots the meta's call.scratch acquires are collected there and stay held after infer returns or throws, because the outputs may alias them; the caller releases them with release_scratch! once it no longer reads the outputs (the gRPC handler does, after encoding the response). Without it, an output that aliases a slot is copied before the slot is released.

source
ReactantServer.scheduler_metrics — Function
scheduler_metrics(scheduler) -> Dict{String,NamedTuple}

Snapshot per-model observability: dispatch count, total compute consumed, current recent-compute EMA, queue-wait P50/P99, the histogram of dispatch batch sizes, and residency.

source
ReactantServer.set_policy! — Function
set_policy!(scheduler, name; weight=nothing) -> nothing

Update a model's live scheduler policy. weight is consulted only by the fair discipline and must be a positive finite number. Available in both residency modes. Raises a ModelNotFoundError on an unknown model, and an InvalidInputError for a weight that is zero, negative, infinite or NaN (the SetModelPolicy RPC answers it with INVALID_ARGUMENT).

source
ReactantServer.set_residency! — Function
set_residency!(scheduler, name, target::ResidencyState) -> ResidencyState

Move a model to the target residency floor. Only meaningful in externally-managed mode; the worker rejects it otherwise. Runs on the dispatch thread (the sole residency mutator) and blocks until applied. Raises on an unknown model or in self-managed mode, and with a WeightsReadStalledError (UNAVAILABLE) when reading the model's weights makes no progress for scheduler.weight_read_stall_seconds, or reads of model weights have stalled on this worker; the next residency change does not wait for such a read.

source
ReactantServer.control_status — Function
control_status(scheduler) -> NamedTuple

A control-plane snapshot of the worker: its residency mode and scheduling discipline, plus a per-model view. A meta is reported as a single model whose footprint is the sum of its sub-models' weights; the internal sub-models are folded into it and not reported on their own, so the gateway packs and routes the group as one unit and never sees the stages.

source
ReactantServer.compact! — Function
compact!(cache, registry; reload) -> Int

Defragment the device arena. Frees every resident non-pinned device weight buffer at once so the BFC allocator coalesces its free list, then reloads each non-pinned model named in reload that has a host copy to upload from (the dispatch loop never reads a weights file). Models not in reload are left freed; in self-managed mode they reload lazily through acquire! on their next dispatch. Host floors (host_weights) are never touched, so the reload is a pure host->device copy where a floor exists.

Device-pinned models are deliberately left in place: they are loaded once at startup, before any on-demand traffic, so they sit at the base of the arena, and compaction neither frees them nor pays to re-read them from disk. Only the on-demand churn region above them is freed and coalesced.

Runs on the dispatch-loop thread (the sole residency mutator), so no execution reads a buffer while it is being freed. In externally-managed mode acquire! will not autonomously load, so the reload list is ignored there (the control plane re-pins what it needs). Returns the number of models reloaded.

source
compact!(scheduler; reload_models=String[]) -> Int

Free the resident non-pinned device weights so the allocator coalesces its free list, then reload each model named in reload_models. An empty list frees only; non-pinned models not listed reload lazily on their next dispatch (self-managed mode). Device-pinned models are left in place (loaded once at startup, never reloaded from disk). A no-op when the on-demand weight cache is disabled. Runs on the dispatch thread (the sole residency mutator) and blocks until applied. Returns the number of models reloaded.

source
ReactantServer.acquire! — Function
acquire!(cache, entry; staged=nothing) -> nothing

Guarantee entry.executable.weights is resident before the model runs. Device-pinned and already-resident models return immediately (the latter is bumped to most-recently-used and its eviction priority raised). In self-managed mode an evicted model is admitted autonomously by admit_weights!: it evicts the cheapest set of resident models that makes the weights and the execution scratch fit, compacting only as a fallback. Without device memory statistics (CPU, mocks) admission falls back to the byte budget alone, and a model larger than the whole budget is loaded anyway after evicting everything, with a warning, since it cannot run otherwise. In externally-managed mode the worker does not autonomously load: an evicted model raises NotResidentError.

staged (a StagedWeights, see hostcache.jl) is the model's weights already read into host memory by a background task; the load then only uploads them. It is released here either way. A load runs off the interactive thread (see [`offinteractive`](@ref)).

source
ReactantServer.admit_weights! — Function
admit_weights!(cache, entry; staged=nothing) -> nothing

Make the evicted model entry resident, evicting what it must (see the file header for the steps). Throws AdmissionError when the model cannot be placed, leaving it off the device, and at once, without evicting anything, while an earlier failure stands. Runs for the dispatch loop, the sole residency mutator. staged is the model's weights already read into host memory (see stage_host_weights), which every upload of entry here uses; the caller releases it.

source
ReactantServer.AdmissionError — Type
AdmissionError

Raised when a model cannot be placed on the device: either it cannot fit even with every evictable model gone, or eviction and compaction together could not make room, or one of those happened before and nothing that could make it fit has changed since. Carries the reason and a memory report for the log. The transport answers a request that meets it with UNAVAILABLE: the model cannot be placed on this worker now, and another replica may have room.

source
ReactantServer.migrate_bundle_weights! — Function
migrate_bundle_weights!(dir, mode::WeightsMigration) -> Symbol

Migrate one bundle's weights file to the program's axis order (see WeightsMigration). Returns :off, :skipped (nothing to migrate: a meta bundle, or a custom weights_file), :current (already in the program's axis order, or already copied under copy), :copied, :replaced, or :failed (logged; the bundle is left loadable as it was). When a weights.safetensors in the program's axis order was deployed over a copy-migrated bundle, the manifest is pointed back at it and the copy, made from the file it replaced, is removed: under copy that is :current and format_version is left as it is; under replace the manifest is also marked format_version: "2.1", as after any replace, and the result is :replaced.

source
ReactantServer.verify_transposed — Function
verify_transposed(old, new; reference = nothing) -> nothing

Prove that new is an exact copy of the legacy file old in the program's axis order.

new must be marked axis_order: xla and hold the same tensor names, dtypes and byte counts, each header shape reversed, the same metadata apart from the migration keys, and every tensor's data equal byte for byte (so NaN payloads and signed zeros count) to the array the legacy path reads. With reference (the path of old), each legacy array is also read by SafeTensors.jl and must match ours. Throws WeightsMigrationError naming the first difference.

source
ReactantServer.resolve_weights_path — Function
resolve_weights_path(dir, m::Manifest) -> String

The weights file to load for a bundle. Normally the manifest's weights_file; but a migrated copy is loaded only while weights.safetensors is still the file it was made from, compared by SHA-256 (not by size and modification time, which a redeploy can keep). A weights.safetensors in the program's axis order (an export deployed over the original) is loaded itself, and a redeployed legacy original is loaded instead of the stale copy, so a deploy is never ignored, whatever runtime.weights_migration is.

source
ReactantServer.NotResidentError — Type
NotResidentError

Raised by acquire! in externally-managed mode when a request targets a model whose weights are not currently resident. A control plane is authoritative for residency in that mode, so the worker does not autonomously load; the model must be pinned first.

source
ReactantServer.QueueFullError — Type
QueueFullError(model, depth)

Raised when a request is rejected at submission because its model's queue already holds scheduler.max_queue_depth requests. The gRPC layer maps it to RESOURCE_EXHAUSTED: transient backpressure, retryable after a backoff.

source
ReactantServer.WorkerUnavailableError — Type
WorkerUnavailableError(msg)

Raised when the worker cannot serve any request right now: it is shutting down or draining, or its dispatch loop has died. The gRPC layer maps it to UNAVAILABLE, so a gateway fails the request over to another replica and a client may retry.

source
ReactantServer.WeightsReadStalledError — Type
WeightsReadStalledError(model, msg)

Raised to a request for a model this worker cannot load now because reading weights stalled. The background read of the model's weights made no progress for scheduler.weight_read_stall_seconds and was abandoned, an earlier read of them stalled and has not returned, or so many reads have stalled that the worker starts no new ones. Models already on the device keep serving. The gRPC layer maps it to UNAVAILABLE, so a gateway fails the request over to another replica and a client may retry.

source
ReactantServer.ModelNotFoundError — Type
ModelNotFoundError(model[, msg])

Raised when a request names a model this worker does not serve: it was never loaded, or it was unloaded or replaced while the request waited. The gRPC layer maps it to NOT_FOUND, which a gateway treats as a stale route (it refreshes its routing table and tries another replica).

source
ReactantServer.DispatchTimeoutError — Type
DispatchTimeoutError(model, seconds)

Raised to a caller that waited scheduler.dispatch_timeout_seconds for its request without a result. The request is withdrawn: if it is still queued it never runs, and if it is already executing its result is discarded. The gRPC layer maps it to DEADLINE_EXCEEDED.

source
ReactantServer.RequestCancelledError — Type
RequestCancelledError(model)

Raised to a caller whose client cancelled the call while the request waited. The request is withdrawn exactly as on a dispatch timeout. The gRPC layer maps it to CANCELLED.

source
ReactantServer.RunningServer — Type
RunningServer

Handle to a server started with serve(...; blocking=false). It holds the resolved ServerConfig, the model registry, the running Scheduler, the device memory pool, the shared-memory registry, the underlying gRPC server, and the listen port. Pass it to stop! to shut the server down.

source
ReactantServer.weight_budget — Function
weight_budget(; arena, fraction, wiggle, max_scratch, pinned_bytes) -> (; on_demand_budget, weight_pool, scratch_ceiling, pinned_over_commit)

Solve for the on-demand weight-cache byte budget from the unified memory model. The arena holds, at the worst instant, pinned weights + on-demand weights + one model's execution max_scratch + a wiggle fraction of free slack:

scratch_ceiling  = (1 - wiggle) * arenaweight_pool      = min(fraction * arena, scratch_ceiling - max_scratch)   # for pinned + on-demandon_demand_budget = clamp(weight_pool - pinned_bytes, 0, weight_pool)

fraction caps the share of the arena devoted to weights (1.0 = all of it, minus scratch + wiggle). Pinned models reserve their footprint off the top, so the operator never subtracts it by hand. pinned_over_commit (pinned exceed the pool) flags a genuine over-commit no sizing can fix. Pure arithmetic, no device access, so it is unit testable.

source
ReactantServer.free_weights! — Function
free_weights!(backend, bufs) -> nothing

Release every device buffer in bufs. Used to evict an unpinned model's resident weights.

source
ReactantServer.transfer_to_device — Function
transfer_to_device(backend, pool, hosts) -> Vector{Any}

Transfer already-materialized host weight Arrays to device buffers, in order. This is the only cost paid on an on-demand load when weights are pinned in host RAM.

source
ReactantServerClient.RetryPolicy — Type
RetryPolicy(; enabled=true, initial_backoff=1.0, factor=2.0, max_backoff=Inf,
              min_budget=0.05, jitter=true, retry_unavailable=true)

Client-side retry policy for requests the server sheds under overload. When a ModelInfer call is rejected with RESOURCE_EXHAUSTED (a worker or gateway at its concurrency cap, see endpoints.max_concurrent_requests), the client waits initial_backoff seconds and retries, growing the interval by factor each attempt (1s, 2s, 4s, ...) up to max_backoff, until the model's deadline budget is spent. The per-attempt deadline sent to the server shrinks to the remaining budget, so the retries never push total wall time past the original deadline.

jitter picks each wait uniformly in [0, backoff] (full jitter) so that concurrent chunk requests do not synchronize into a retry storm against the same worker. min_budget (seconds) is the smallest remaining budget worth another attempt; below it the client stops and surfaces the shed error. retry_unavailable also retries UNAVAILABLE (no replica reachable). Deadline, NOTFOUND, and INVALIDARGUMENT errors always fail fast. Set enabled=false to restore the old fail-fast behavior.

source