Views
No views yet
TL;DR: RealignR = ARP Optimizer (training) + ARP Memory (inference) + Substrate (future) — each works alone or together.
1import torch
2
3class ARP(torch.optim.Optimizer):
4 def __init__(self, params, lr=1e-3, alpha=1e-2, mu=1e-3):
5 defaults = dict(lr=lr, alpha=alpha, mu=mu)
6 super().__init__(params, defaults)
7
8 @torch.no_grad()
9 def step(self):
10 for group in self.param_groups:
11 lr, alpha, mu = group['lr'], group['alpha'], group['mu']
12 for p in group['params']:
13 if p.grad is None:
14 continue
15 state = self.state.setdefault(p, {})
16 G = state.get('G', torch.zeros_like(p.data))
17 g = p.grad
18 # Conductance dynamics
19 G.add_(alpha * g.abs() - mu * G)
20 state['G'] = G
21 # Resistance‑aware update (example scaling)
22 p.addcdiv_(g, (1.0 + G), value=-lr)1# attn_scores: [B, H, Q, K]
2# memory_vec: [B, 1, 1, K] accumulated per‑key "pressure"
3def apply_arp_memory(attn_scores, memory_vec, beta=0.2):
4 return attn_scores + beta * memory_vec1model = ...
2opt = ARP(model.parameters(), lr=1e-3, alpha=1e-2, mu=1e-3)
3
4for x, y in loader:
5 opt.zero_grad(set_to_none=True)
6 out = model(x)
7 loss = loss_fn(out, y)
8 loss.backward()
9 opt.step()1memory_vec = None
2for tokens in stream():
3 logits, attn_scores = model.forward_with_scores(tokens)
4 pressure = attn_scores.abs().mean(dim=(0,1,2), keepdim=True)
5 memory_vec = pressure if memory_vec is None else 0.9 * memory_vec + 0.1 * pressure
6 attn_scores = apply_arp_memory(attn_scores, memory_vec, beta=0.2)
7 # continue generation…| Dataset | Top‑1 Acc. |
|---|---|
| CIFAR‑10 | 96.0%+ |
| CIFAR‑100 | 85.0%+ |
| SVHN | 94.5%+ |
RealignR.py — main pretrain and ARP‑continue script with dataset switching and CPR logic.arp_optimizer.py — Adaptive Resistance Principle optimizer (PyTorch).dataset_schedule.json — JSON file specifying when to switch datasets during training.switcher/ — module providing load_dataset, load_dataset_schedule, and get_current_dataset functions for dataset switching.watcher.py — optional live controller that uses TensorBoard metrics and GPT feedback to adjust alpha/mu and trigger CPR resets.beta to avoid instability.alpha=1e-2, mu=1e-3 for a stable baseline.G_mean and GradNorm; keep G_mean bounded.G_{ij} states for smooth domain switching.@software{realignr_2025,
author = {Ryan McKenna},
title = {RealignR: A Lifelong Adaptive Optimization System},
year = {2025},
url = {https://huggingface.co/RealignR/RealignR},
note = {ARP optimizer + inference‑time memory}
}RealignR is more than an optimizer — it’s a new way to think about intelligence.