Expand description
Ship-graph distributed execution (build the worker once, run any model). Ship-graph distributed execution — build the worker once, run any model.
A worker is a generic executor: it compiles and runs a graph the
coordinator ships at runtime, so no model is baked into the worker binary
and there is no per-node / per-model recompile. Build one worker binary
per architecture (Node::from_env().connect() + [serve_stage]), deploy it
to every node, and drive any model from a coordinator.
The coordinator — which owns the model’s graph builders (e.g. a crate in
rlx-models) — partitions the model into stages and ships each worker a
[StageSpec]: the serialized subgraph, its I/O node names, where to fetch
each weight, and a device directive. Weights are resolved locally by a
caller-provided closure (GGUF / safetensors / HF — rlx core stays
model-agnostic), so only specs (KB) and activations cross the wire — never
the weights.
// Generic worker binary — the SAME build runs any model:
let mut stage = dist::recv_stage(&group, |uri| load_weights(uri))?;
let x = dist::recv_activation(&group, group.rank() - 1)?;
let y = stage.run(&x);
dist::send_activation(&group, /*next*/ 0, &y)?;Structs§
- Stage
Spec - A self-describing unit of work for a worker: everything needed to run one stage of a model, with nothing implied by convention.
- Weight
Cache - Parse-once, serve-many weight cache. A GGUF file is parsed a single time and
then serves any number of its tensors (f32 or packed) — the right shape for
a worker whose stage pulls many tensors (q/k/v/o/ffn) from one model file.
Created per stage inside
recv_stage; also usable standalone. - Weight
Ref - Where one parameter’s data comes from. The worker resolves the
uriitself, so large weights stay node-local. - Worker
Stage - A compiled stage sitting on this worker, ready to run activations.
Functions§
- recv_
activation - Receive an activation tensor from
from. - recv_
stage - Worker: receive a
StageSpecfrom the coordinator (rank 0), resolve its weights viaresolve(uri -> f32), pick the directed device, and compile. This is the generic worker’s setup — the same code runs any model’s stage. - resolve_
weight_ bytes - Load the quantized bytes of a weight as-is (no dequant), for the
on-device-quant path.
gguf://<path>#<tensor>returns the packed block bytes;file://<path>returns the raw file. Feed toset_param_typed(_, _, U8)behind aDequantMatMulgraph. - resolve_
weight_ uri - Resolve a weight tensor to f32 from its source URI. Supported schemes:
gguf://<path>#<tensor>— dequantize a GGUF tensor (any K-quant)safetensors://<path>#<tensor>— read a safetensors tensor (F32/F16/BF16)file://<path>— raw little-endian f32 array - send_
activation - Send an activation tensor to
to(a worker, or the next pipeline stage). - serve_
stage - Worker convenience: set up the stage, then run one activation cycle —
receive from the previous rank (or an external feed for rank 1), run, and
forward to the next rank (or back to the coordinator if last). Returns the
device it ran on. For a serving loop, call
recv_stageonce and driveWorkerStage::run+recv_activation/send_activationyourself. - serve_
stage_ uri - Same as
serve_stagebut with no custom resolver — a worker binary that serves GGUF / safetensors / raw-f32 models out of the box (recv_stage’s built-inWeightCachehandles those schemes; anything else warns). - ship_
stage - Coordinator: ship a stage spec to worker
rank. - uri_
resolver - Built-in resolver for
serve_stage_uri:resolve_weight_uri, logging and returning empty on failure so a missing shard surfaces loudly rather than panicking mid-collective.