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§
- Backend
Divergence - One backend’s worst divergence from the CPU oracle for a given graph run.
- DataRef
- One data tensor the worker feeds to a graph input every step. Resolved
node-locally from
uri(afile://raw-f32 blob, or gguf/safetensors), then row-sharded: this rank owns samples[shard_start, shard_start+len), eachelemfloats wide. - 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.
- Train
Metrics - Per-worker training result.
- Train
Spec - A self-describing training job for a generic worker: everything needed to train a model the worker has no code for.
- 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§
- backend_
divergence - Run
graphon the CPU oracle and on every other backend live on this node, reporting each one’s worst divergence from CPU. Call it on each cluster node to localize where distributed numbers drift — and whether that drift is bounded round-off (suspect == false) or a candidate kernel bug (suspect == true). - pull_
shards - Worker: receive the pushed init params + data shards from the master
(rank 0), write them to node-local files under
dir, and rewritespec.params/spec.datato point at those files (data offset reset to 0). After this the genericrun_trainresolves everything locally exactly as in the shared-FS case. - push_
shards - Master: push worker
rankeverything it needs but can’t resolve locally — the init params (training-from-scratch has no node-local weights, so theWeightReffile:// URIs only exist on the master) and each data shard (only this rank’s samples). Use when the worker has no shared filesystem. Pair withpull_shardson the worker. - 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. - recv_
train - Worker: receive a
TrainSpecfrom the coordinator (rank 0). - report_
backend_ divergence - Print a
backend_divergencereport and returntrueif ANY backend looks suspect (relative error pasttol_rel) — a convenient one-liner for a CLI / CI gate on each node. A green report means the cluster’s cross-backend drift is bounded round-off; a red one names the backend + output to investigate. - 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 - run_
train - Run one worker’s full data-parallel training from a shipped
TrainSpec— the generic worker’s whole job, with no model code. - 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. - ship_
train - Coordinator: ship a training job 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.