amer224 commited on
Commit
39cb2ee
·
verified ·
1 Parent(s): d142123

Add brains/sovereign-v3/README.md

Browse files
Files changed (1) hide show
  1. brains/sovereign-v3/README.md +101 -0
brains/sovereign-v3/README.md ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SOVEREIGN v3 — the rival architect's brain
2
+
3
+ A **~272M-param dense, return-conditioned spatial policy** for
4
+ **territorial.io (last-survivor elimination)** — built to be trained by
5
+ the shared pipeline on `amer224/territorial-bot-data → rl/shards_v2/` and
6
+ judged on **win-rate + mean rank vs 9 mixed bots** against the rival
7
+ TeacherV2/StudentV2 blueprint.
8
+
9
+ > Straight talk (read me before training): SOVEREIGN wins by converting
10
+ > more of a 0-win farmer buffer into legal, timing-correct, strategic
11
+ > behavior. Its real weapons: **return conditioning (RPO)**,
12
+ > **opponent-intent mirrors** and **one-step dynamics** (trained on
13
+ > labels the shards already contain), a **win-probability critic**, a
14
+ > **multi-scale attention cortex**, and an optional **GRU memory**. It is
15
+ > not a planner — search is the documented roadmap, not a promise.
16
+
17
+ ---
18
+
19
+ ## Files
20
+
21
+ | File | What |
22
+ |---|---|
23
+ | `model.py` | the whole model, torch-only. Run `python model.py` for the CPU smoke test (prints exact per-module params + shape checks). |
24
+ | `data_adapters.py` | shard → training samples: RTG, AWR weights, intent-mirror masks, next-frame labels, win labels, sequence windows. `python data_adapters.py` smoke-tests it. |
25
+ | `ARCHITECTURE.md` | design reasoning, module table, memory math, citations. |
26
+ | `train_notes.md` | the exact recipe: Stage A (return-conditioned filtered BC + dynamics), Stage B (RPO with KL guard, league-lite), Stage C (eval + wake-sleep distill), ablations, risks. |
27
+ | `sovereign_v3_init.pt` | optional random-init checkpoint (seed 0), exported by the upload script. |
28
+
29
+ ## Input/output contract (the pipeline's fair-play rule)
30
+
31
+ ```
32
+ IN : rgb (B,3,256,256) float [0,1] + nums (B,8) [+ rtg (B,) + state]
33
+ OUT: click heatmap ≥16×16 (native 256×256, pooled via grid=32)
34
+ kind logits (B,3) · pct (B,) ∈[0,1] · value (B,)
35
+ ```
36
+
37
+ - `forward(rgb, nums, mask=None, grid=32, return_all=False)` returns
38
+ `(click, kind_logits, pct, value)` — the **same 4-tuple order** as
39
+ `TeacherV2/StudentV2`; `click` is the kind-marginal logsumexp of the
40
+ per-kind heatmaps pooled to the grid. Any wrapper sampling a flat cell
41
+ vector works unchanged.
42
+ - `act(rgb, nums, mask=None, rtg=None, state=None)` returns
43
+ `{kind, cell, yx, pct, logprob, value, win_prob, entropy, state}` with
44
+ the correct `p(kind)·p(cell|kind)·p(pct|kind,cell)` factorization.
45
+ - `lab` is **supervision only** (gate/seg/dynamics heads) during
46
+ pretraining — never a play-time input.
47
+ - External legality masks remain supported (log-summed on top of the
48
+ learned gate).
49
+
50
+ ## Quickstart (training machine, 2× T4)
51
+
52
+ ```bash
53
+ # 1. smoke tests (CPU)
54
+ python model.py --fast
55
+ python data_adapters.py
56
+
57
+ # 2. upload this brain to the HF model repo (or use the site's browser
58
+ # uploader — paste token, click once, same result)
59
+ HF_TOKEN="hf_..." python upload_to_hf.py # code + docs
60
+ HF_TOKEN="hf_..." python upload_to_hf.py --with-weights # + init checkpoint
61
+
62
+ # 3. Stage A / B / C training — per train_notes.md, run by the shared
63
+ # pipeline on the same shards + PPO recipe as the rival.
64
+ ```
65
+
66
+ ## For the other agent (the pipeline owner)
67
+
68
+ 1. **Pull**: `huggingface_hub.snapshot_download("amer224/botfromdeep", allow_patterns="brains/sovereign-v3/*")`
69
+ 2. **Wrap**: env wrapper calls `act()` per tick; if memory mode is
70
+ enabled, carry `a["state"]` (sketch in train_notes.md §B.1).
71
+ 3. **RTG**: during PPO pass the rollout's actual RTG into `act(rtg=...)`;
72
+ the critic is rtg-conditioned — this is RPO, not an option.
73
+ 4. **Judge**: Stage C, 100+ episodes, 9 mixed bots, fixed seeds,
74
+ win-rate + mean rank. Save best on rank.
75
+ 5. If anything looks off, the ablation table (train_notes.md) isolates
76
+ every new mechanism one knob at a time.
77
+
78
+ ## Sizing / memory (why 272M is not reckless)
79
+
80
+ fp16, bs 16/GPU: weights 1.09 GB + grads 1.09 GB + Adam 2.18 GB +
81
+ activations ≈4 GB + ctx ≈1 GB ≈ **9.4 GB of 16 GB** per T4.
82
+ Play speed <30 ms/frame vs 560 ms ticks. Trim knobs (keeps >200M):
83
+ `head_hidden`, `cortex_layers`, `enc_ch`, `grad_ckpt=True`.
84
+
85
+ ## Honest expectations
86
+
87
+ - **Should win the imitation stage**: AWR weighting + legality gate +
88
+ intent mirrors convert more of the weak buffer than uniform BC into a
89
+ flat 16×16 head.
90
+ - **Should win the PPO-stability war**: 100% of 272M active per step
91
+ (rival's MoE activates ~45M and never applies its load-balance loss),
92
+ rtg-consistent critic, KL anchor, league-lite self-play.
93
+ - **Honest ceiling**: without search it is a strong reactive policy with
94
+ opponent modeling — the dynamics head is the seed of future MCTS.
95
+ - If the shared PPO recipe is weak, both brains plateau; this one is
96
+ engineered to plateau higher, and the ablations prove exactly why.
97
+
98
+ ## Safety / scope
99
+
100
+ No live-site automation. No Kaggle fleet use. HF token read from
101
+ `$HF_TOKEN` only — never stored in any file.