1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// RLX — versatile ML compiler + runtime.
// Copyright (C) 2026 Eugene Hauptmann, Nataliya Kosmyna.
// SPDX-License-Identifier: MIT OR Apache-2.0
//! The **model-agnostic weight seam**. `rlx-distributed` never knows how a
//! model's weights are stored — a stage worker asks a [`ParamSource`] for each
//! parameter by name, and the source (implemented by a *model* crate, e.g.
//! wrapping an mlx / GGUF / safetensors loader) returns it as dense f32 or as
//! packed/quantized bytes. This is what keeps the crate model-agnostic: RLX
//! provides the API, `rlx-models` provides the weights.
//!
//! Ergonomics: a plain `HashMap<String, Vec<f32>>` is a `ParamSource` (great for
//! tests and small models), and so is any closure `FnMut(&str) -> Option<Param>`
//! (great for adapting an existing loader in one line):
//!
//! ```ignore
//! // adapt any loader without a newtype:
//! let mut src = |name: &str| loader.take_typed(name).map(|(b, dt)| Param::typed(b, dt));
//! serve_stage(addr, stage, &mut src, Device::Cpu, &opts, 1)?;
//! ```
use DType;
use HashMap;
/// One parameter value: dense f32, or packed bytes with a dtype (quantized /
/// f16 / bf16 weights fed to the runtime without a host cast).
/// Supplies a stage's parameters on demand, by name. `None` means "not mine"
/// (the runtime leaves the param unset — useful when a source only owns a shard).
/// A `HashMap<String, Vec<f32>>` is a source (dense f32; clones on read).
/// A `HashMap<String, Param>` is a source (mixed f32 / packed).
/// Any `FnMut(&str) -> Option<Param>` is a source — adapt an existing loader
/// inline without defining a type.