AbstractPhil commited on
Commit
120cfb6
·
verified ·
1 Parent(s): 18bbb49

mirror geolip 0.8.8: relay.py docstring cleanup + from_patchwork rename

Browse files
Files changed (1) hide show
  1. relay.py +34 -37
relay.py CHANGED
@@ -1,7 +1,8 @@
1
- """RelayPatchwork + RelayEMA — the relay organ and its causal-EMA memory taps.
 
2
 
3
- The organ is the certified residual patchwork (amoe-lora's arm geometry,
4
- brought here as a native model component):
5
 
6
  slots_t = proj(x_t) (B, n, n_slots, D) orthogonal, no bias
7
  f_t = m_hat(slots_t) flattened the reconstructive signed read
@@ -10,30 +11,25 @@ brought here as a native model component):
10
  y_t = x_t + sigmoid(gate) * consume(f_t)
11
 
12
  consume = Linear(nD -> hidden), ReLU^2, LayerNorm, Linear(hidden -> d) with the
13
- output layer zero-initialized (weight AND bias — the strict C6 null path: a
14
- fresh organ is bit-inert, y == x exactly). Gate initialized -3. Reconstructive,
15
- never comparative: no softmax-over-choices, no argmax, no top-k.
16
 
17
- RelayEMA adds ONE mechanism: two fixed-decay causal EMAs of the organ's own
18
- read, fed to the head through input columns that are ZERO at birth —
19
 
20
  F1_t = (1 - r1) F1_{t-1} + r1 f_t r1 = 1/16
21
  F2_t = (1 - r2) F2_{t-1} + r2 f_t r2 = 1/64
22
  y_t = x_t + sigmoid(gate) * consume(cat(f_t, F1_t, F2_t))
23
 
24
- so at birth RelayEMA's forward EQUALS the memory-free organ. Training uses the
25
- chunked closed-form scan (ema_chunked, renormalized so q^-t never overflows);
26
- decode carries (F1, F2) state and updates one step at a time — exact, because
27
  the head is position-wise.
28
 
29
- The record (canon btx_e003, E-G2 2026-09-14, on frozen mini-beatrix-2s):
30
- the memory-free organ form, trained answer-only with the rule-order shortcut
31
- blocked in the data, internalized a 5-step rule chain — .527 as-is / .553
32
- rules-shuffled on out-of-vocabulary words (order-invariant; heuristic ceiling
33
- ~.2), 1.000 in-vocabulary. The EMA taps added nothing measurable on that task
34
- (.527/.587). Packaged with the taps because they are free at birth and the
35
- accumulator is the certified form. Default geometry below is the validated
36
- wide arm (n_slots 32, K 64, D 4, hidden 256 at d 1024: 428k params/site).
37
  """
38
  from __future__ import annotations
39
 
@@ -92,8 +88,8 @@ def _feats(m, x: torch.Tensor) -> torch.Tensor:
92
 
93
 
94
  class RelayPatchwork(nn.Module):
95
- """The memory-free relay organ: proj -> reconstructive aleph read ->
96
- zero-born squared-ReLU patch head, residual write behind a sigmoid gate."""
97
 
98
  def __init__(self, d: int, spec: RelaySpec | None = None):
99
  super().__init__()
@@ -120,35 +116,36 @@ class RelayPatchwork(nn.Module):
120
 
121
 
122
  class RelayEMA(nn.Module):
123
- """The organ plus zero-born EMA memory taps. Built by widening an organ's
124
- head to 3nD input columns, the added columns zeroed — at birth the forward
125
- equals the organ it came from (shared weights)."""
126
 
127
  def __init__(self, d: int, spec: RelaySpec | None = None):
128
  super().__init__()
129
  self._widen(RelayPatchwork(d, spec))
130
 
131
  @classmethod
132
- def from_organ(cls, organ: RelayPatchwork) -> "RelayEMA":
133
- """Upgrade a (possibly trained) organ in place: shares proj/addr/gate
134
- and the head tail, widens the head's first layer with zeroed columns."""
 
135
  self = cls.__new__(cls)
136
  nn.Module.__init__(self)
137
- self._widen(organ)
138
  return self
139
 
140
- def _widen(self, organ: RelayPatchwork):
141
- self.spec = organ.spec
142
- self.nD = organ.nD
143
- self.proj, self.addr, self.gate = organ.proj, organ.addr, organ.gate
144
- self.n_slots = organ.n_slots
145
- wide = nn.Linear(3 * self.nD, organ.spec.hidden)
146
  with torch.no_grad():
147
- wide.weight[:, :self.nD] = organ.consume[0].weight
148
  wide.weight[:, self.nD:] = 0.0
149
- wide.bias.copy_(organ.consume[0].bias)
150
  self.consume = nn.Sequential(
151
- wide, organ.consume[1], organ.consume[2], organ.consume[3])
152
 
153
  def feats(self, x: torch.Tensor) -> torch.Tensor:
154
  return _feats(self, x)
 
1
+ """RelayPatchwork + RelayEMA — a gated residual patch module over a signed
2
+ address read, and a variant with causal-EMA memory taps.
3
 
4
+ RelayPatchwork (ported from the amoe-lora adapter of the same name,
5
+ github.com/AbstractEyes/amoe-lora, as a native model component):
6
 
7
  slots_t = proj(x_t) (B, n, n_slots, D) orthogonal, no bias
8
  f_t = m_hat(slots_t) flattened the reconstructive signed read
 
11
  y_t = x_t + sigmoid(gate) * consume(f_t)
12
 
13
  consume = Linear(nD -> hidden), ReLU^2, LayerNorm, Linear(hidden -> d) with the
14
+ output layer zero-initialized (weight AND bias), so a fresh module is exactly
15
+ inert: y == x. Gate initialized -3. Reconstructive, never comparative: no
16
+ softmax-over-choices, no argmax, no top-k.
17
 
18
+ RelayEMA adds one mechanism: two fixed-decay causal EMAs of the module's own
19
+ read, fed to the head through input columns that start at zero —
20
 
21
  F1_t = (1 - r1) F1_{t-1} + r1 f_t r1 = 1/16
22
  F2_t = (1 - r2) F2_{t-1} + r2 f_t r2 = 1/64
23
  y_t = x_t + sigmoid(gate) * consume(cat(f_t, F1_t, F2_t))
24
 
25
+ so at birth RelayEMA's forward equals the memory-free RelayPatchwork. Training
26
+ uses the chunked closed-form scan (ema_chunked, renormalized so q^-t never
27
+ overflows); decode carries (F1, F2) state one step at a time — exact, because
28
  the head is position-wise.
29
 
30
+ Defaults are the validated geometry (n_slots 32, K 64, D 4, hidden 256; ~428k
31
+ params at d = 1024). Validation record and trained weights:
32
+ huggingface.co/AbstractPhil/mini-beatrix-2s, arms/btx_e003.
 
 
 
 
 
33
  """
34
  from __future__ import annotations
35
 
 
88
 
89
 
90
  class RelayPatchwork(nn.Module):
91
+ """The memory-free form: proj -> reconstructive address read ->
92
+ zero-initialized squared-ReLU head, residual write behind a sigmoid gate."""
93
 
94
  def __init__(self, d: int, spec: RelaySpec | None = None):
95
  super().__init__()
 
116
 
117
 
118
  class RelayEMA(nn.Module):
119
+ """RelayPatchwork plus the EMA memory taps. Built by widening a patchwork's
120
+ head to 3nD input columns with the added columns zeroed, so at birth the
121
+ forward equals the patchwork it came from (shared weights)."""
122
 
123
  def __init__(self, d: int, spec: RelaySpec | None = None):
124
  super().__init__()
125
  self._widen(RelayPatchwork(d, spec))
126
 
127
  @classmethod
128
+ def from_patchwork(cls, base: RelayPatchwork) -> "RelayEMA":
129
+ """Upgrade a (possibly trained) RelayPatchwork in place: shares its
130
+ proj/addr/gate and head tail, widens the head's first layer with
131
+ zeroed columns."""
132
  self = cls.__new__(cls)
133
  nn.Module.__init__(self)
134
+ self._widen(base)
135
  return self
136
 
137
+ def _widen(self, base: RelayPatchwork):
138
+ self.spec = base.spec
139
+ self.nD = base.nD
140
+ self.proj, self.addr, self.gate = base.proj, base.addr, base.gate
141
+ self.n_slots = base.n_slots
142
+ wide = nn.Linear(3 * self.nD, base.spec.hidden)
143
  with torch.no_grad():
144
+ wide.weight[:, :self.nD] = base.consume[0].weight
145
  wide.weight[:, self.nD:] = 0.0
146
+ wide.bias.copy_(base.consume[0].bias)
147
  self.consume = nn.Sequential(
148
+ wide, base.consume[1], base.consume[2], base.consume[3])
149
 
150
  def feats(self, x: torch.Tensor) -> torch.Tensor:
151
  return _feats(self, x)