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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//! Realized-work vocabulary: the mass semantics every plane of the
//! distributed reduce shares.
//!
//! A *mass* is the scalar realized-work weight riding each contribution
//! to a reduce round. The algebra has three moves, and only three:
//!
//! 1. **Pre-scale at the source.** The contributing unit scales its
//! tensors by its mass and ships the mass atomically with them (the
//! same frame on the CPU wire; the same fused collective on NCCL).
//! 2. **Sum through folds.** Scaled tensors and masses sum element-wise
//! through any number of fold tiers (per-host relay today,
//! intermediate aggregators tomorrow). Summation is associative, so
//! fold depth never changes the result: no averaging-of-averages.
//! 3. **Divide once at the root.** The final reduce divides the summed
//! tensors exactly once, by the summed mass of exactly the
//! contributions it accepted into the round.
//!
//! The load-bearing law: **the sum and its divisor come from the same
//! accepted contributions.** Work that was never accepted (dead rank,
//! lost frame) enters neither, so they cannot disagree, whatever the
//! cohort did between rounds. A fold tier that divided would break the
//! law; only the root divides (see
//! [`crate::distributed::controller`]'s reduce).
//!
//! **Mass is policy-supplied, not definitionally `n^γ`.** What a unit's
//! mass *is* belongs to the caller's policy; this module provides the
//! current policies and the shared rules:
//!
//! - [`gamma_mass`] — params consensus: `n^γ` for `n` optimizer steps
//! since the last sync, with the idle guard below. `γ = 1.0`
//! (default) is plain work-weighting; `γ = 0.0` an unweighted
//! average over movers; `γ = −1.0` per-step-equal.
//! - [`mover_mass`] — buffers consensus: a 0/1 mover indicator (moved
//! ranks equal-weighted, idle excluded).
//! - [`is_realized`] — the zero-mass round rule: a round whose accepted
//! mass is zero realized nothing; its summed tensors are meaningless
//! zeros and receivers keep their local state.
//!
//! **The idle guard is part of the vocabulary, not an implementation
//! detail.** A unit that did no work has zero mass for *any* policy
//! parameter. Left to raw `powf`, IEEE gives `0^0 = 1` (an idle unit
//! voting with full weight at `γ = 0`) and `0^{γ<0} = ∞` (poisoning the
//! cohort mass into NaN). Both backends import [`gamma_mass`] so the
//! guard cannot drift between them.
/// Realized-work mass of one unit's params contribution under the gamma
/// allocation-weighting policy: `n^γ`, where `n` is the unit's optimizer
/// steps since the last sync.
///
/// Idle units (`n <= 0`) have zero mass for any `γ` — see the module
/// docs for why this is guarded here rather than left to `powf`.
/// `γ = 1.0` short-circuits to `n` (the default path stays exact and
/// cheap).
pub
/// Realized-work mass of one unit's buffers contribution: the 0/1 mover
/// indicator. Buffers (BatchNorm running stats and the like) average
/// equal-weighted over the units that moved; idle units are excluded by
/// zero mass, not by leaving the collective.
pub
/// The zero-mass round rule: `true` when `mass` represents realized
/// work. A round whose accepted mass is not positive realized nothing —
/// the summed tensors are meaningless zeros and the receiver must keep
/// its local state (and an outer optimizer must not step on it).
pub