Code: LR_STEP_OFFSET/LR_TOTAL_STEPS resume fix, runner/push/launch scripts, generation research, TRAINING_LOG Oct 13-17
Browse files- docs/GENERATION_SURGERY.md +162 -0
- docs/TRAINING_LOG.md +7 -0
- scripts/atom_runner.py +4 -2
- scripts/fast4gpu_atom.py +4 -2
- scripts/gen_block.py +109 -0
- scripts/gen_surgery2.py +85 -0
- scripts/launch8.sh +7 -0
- scripts/manual_push.py +23 -0
- scripts/push_good.py +79 -0
docs/GENERATION_SURGERY.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Generation surgery: block-mode inference with carried state (Fractus CTE-Atom)
|
| 2 |
+
|
| 3 |
+
Checkpoint: HF `thefinalboss/fractus-cte-atom` `checkpoints/atom_latest` (step_00770000, 2,454,777,856 ids, ema_tf 0.484), CPU fp32, mmap load, eval, no weight changes. Script: `scripts/gen_block.py`. Raw results: `/workspace/gb1.jsonl`, `gb2.jsonl`, `gb3.jsonl` (verbatim outputs + ids).
|
| 4 |
+
|
| 5 |
+
## How training drives the model (mirrored)
|
| 6 |
+
`scripts/fast4gpu_atom.py`: SEQ=128 per chunk, B=16 lanes, `tick_chunk_train_ce` per chunk; carry
|
| 7 |
+
(`thought_state`, per-block `attn_S`, `attn_z`, `kuramoto_phases`; 49 batch-sized keys in the ckpt) persists
|
| 8 |
+
across chunks and is zeroed per lane only when the chunk contains BOS (257). `thought_state` is added only at
|
| 9 |
+
position 0 of the next chunk. Inference uses `tick_chunk` (same per-block core; verified identical CE to
|
| 10 |
+
`tick_chunk_train_ce`, and `FRACTUS_ATTN_IMPL=chunked` vs `cumsum` gives identical numbers).
|
| 11 |
+
|
| 12 |
+
## Modes
|
| 13 |
+
- **A (block tick)**: each step feeds the last C ids as one chunk and keeps the resulting carry.
|
| 14 |
+
- **B (regen block)**: carry committed at chunk boundaries; each step restores the committed carry, re-runs the pending block (C/2..C ids), takes the last-position id; at C ids the first C/2 are committed.
|
| 15 |
+
- Start states: `warm` = lane-0 carry stored in the ckpt (no BOS); `cold` = BOS reset; `primer` = BOS + 256 ids of an in-corpus document head (reasoning__syllogisms) committed in C-sized chunks, then the prompt.
|
| 16 |
+
|
| 17 |
+
## Teacher-forced diagnostics (CE nats/id, chunk 128)
|
| 18 |
+
- lanes.i16 (older eval slice): warm 6.9, 6.2, 4.5, 5.0, 5.5, 5.8; cold 100, 29, 9.0, 7.4, 7.3, 5.3.
|
| 19 |
+
- In-corpus document (syllogisms), 30 chunks: cold-from-BOS 22.6, 1.47, 0.69, 4.65, 2.2, 0.39, 0.18 ... mostly 0.1-2.5; lane-0 warm is worse (4.0, 3.2, 2.6 ...). So for in-corpus text, BOS reset + ≥1 chunk of document is the correct regime; the stored lane-0 carry does not help unrelated text.
|
| 20 |
+
- Short novel prompts (prompt TF): warm 8.9-17.7; primer 6.2-14; the in-corpus continuation tail after the primer: **0.97**.
|
| 21 |
+
|
| 22 |
+
## Generation results (N=120 unless noted, unique@40, ids/s on loaded 8-core CPU)
|
| 23 |
+
| config | unique@40 | ids/s | note |
|
| 24 |
+
|---|---|---|---|
|
| 25 |
+
| B:128 greedy warm | 0.35-0.40 | 0.75 | pseudo-word salad |
|
| 26 |
+
| B:32 T0.8 k40 rp1.1 primer | 0.40-0.525 | 1.1 | salad, some primer-domain words |
|
| 27 |
+
| A:128 T0.8 k40 rp1.1 primer | 0.40 | 0.66 | worse: re-fed overlap corrupts carry |
|
| 28 |
+
| B:128 greedy primer, in-corpus continuation | 0.375 | 0.92 | ~20 correct ids then drift |
|
| 29 |
+
| B:128 greedy primer, "The capital of France is" | 0.45 | 1.28 | salad |
|
| 30 |
+
|
| 31 |
+
Verbatim samples:
|
| 32 |
+
- B:128 greedy primer, continue in-corpus doc: `'ioner looking to to deepenging.\n\n**Derition.** Systesidece ice w oing precting e ececesing watedefr acesands ofr th'`
|
| 33 |
+
- B:128 greedy warm, "The capital of France is": `'rompureriplespaces- ticaliticationgr tical dingrs teses tonator thecad diuprcaprescesioratioration d he pan en ner'`
|
| 34 |
+
- B:32 T0.8 primer, "The capital of France is": `'leterepepatioog acior atizineriting atier uatier loong tinemer anerditing\nederlying tengcuertton. Det s athef dis pl'`
|
| 35 |
+
- A:128 T0.8 primer, "Bonjour, je m'appelle": `'rid ctsd ctnndstete-ctitbityctyycathtastitharabisryrystherathithere are r re r io frathe a t ta p as aun th l as das'`
|
| 36 |
+
|
| 37 |
+
## What works / what does not
|
| 38 |
+
- Works: Mode B at C=128 reproduces the training forward exactly; the carry mechanics are correct (in-corpus TF 0.1-2 after one chunk; continuation TF 0.97).
|
| 39 |
+
- Does not work: free-running generation in any mode/config. Even on in-corpus text with low TF loss, greedy output holds for ~20 ids and then decays into morpheme salad (unique@40 0.35-0.53). Mode A is strictly worse than B (re-feeding overlapping context writes duplicates into attn_S/attn_z).
|
| 40 |
+
- Prompts outside the corpus distribution have TF 6-17 nats/id regardless of start state; a 256-id primer does not fix that.
|
| 41 |
+
|
| 42 |
+
## Reason for remaining failure
|
| 43 |
+
Inference driving is not the bottleneck: Mode B is the training forward. The model's low ema_tf (0.48) is local next-byte prediction on in-corpus text, which degrades as soon as the input is its own samples (exposure bias), and it does not generalize to short novel prompts. Fixing this needs a training-side change (e.g. scheduled sampling / SS_RATE>0, more diverse data), not an inference change.
|
| 44 |
+
|
| 45 |
+
## Addendum (gb3)
|
| 46 |
+
- A:128 greedy primer, in-corpus continuation: unique@40 0.275, 1.0 ids/s: `'io.\n**** at bat cte The pllyindsstnduly ing ly- prng ting plionthecusthe p p ts the tas thass sss bs bs athorathon'`
|
| 47 |
+
- A:128 greedy primer, France: unique@40 0.325.
|
| 48 |
+
- B:128 T0.8 k40 rp1.1 primer, continuation: unique@40 0.475, 1.21 ids/s: `'iong tionery.\n\n*Drefion.** Slesdedatiice ongiceasing ing wea expe eds or heds ped atefctey wtit nnef acthelt men,f'`
|
| 49 |
+
- B:128 T0.8 k40 rp1.1 primer, France: unique@40 0.50, 1.4 ids/s.
|
| 50 |
+
Confirms B > A. Even the best B config degrades into salad.
|
| 51 |
+
|
| 52 |
+
## Addendum 2 (gb4: bf16 weights, N=80, 3 prompts; fp32 mmap thrashed the page cache, so bf16 was used: ~2.2-3.1 ids/s)
|
| 53 |
+
| config | unique@40 (Bonjour / France / Il était) | ids/s | prompt TF |
|
| 54 |
+
|---|---|---|---|
|
| 55 |
+
| A:32:0:1:1.0:primer | 0.35 / 0.375 / 0.25 | 2.83 | [] / [] / [] |
|
| 56 |
+
| A:32:0.8:40:1.1:primer | 0.55 / 0.275 / 0.45 | 2.77 | [] / [] / [] |
|
| 57 |
+
| B:128:0:1:1.0:cold | 0.375 / 0.3 / 0.425 | 2.44 | [200.0] / [57.75] / [113.5] |
|
| 58 |
+
| B:128:0.8:40:1.1:cold | 0.475 / 0.5 / 0.45 | 2.5 | [200.0] / [55.25] / [114.5] |
|
| 59 |
+
| B:128:0:1:1.0:primer | 0.425 / 0.375 / 0.5 | 2.51 | [11.438] / [7.031] / [14.188] |
|
| 60 |
+
| B:128:0.8:40:1.1:primer | 0.375 / 0.475 / 0.475 | 2.8 | [11.688] / [6.75] / [13.812] |
|
| 61 |
+
|
| 62 |
+
Verbatim (all in gb4.jsonl):
|
| 63 |
+
- A:32:0:1:1.0:primer, "Bonjour, je m'appelle": `'z aind x thhherncctcte.cbpepepeeecelecenceelllllis.... un bbs v varnrwrwrwrwrw'`
|
| 64 |
+
- A:32:0:1:1.0:primer, 'The capital of France is': `'penedume/tt. sthDhe bs bisca ca in an n e telseestme,terotrort.tid tid a '`
|
| 65 |
+
- A:32:0:1:1.0:primer, 'Il était une fois': `' wlddeng/neeeeeneteatetataan.. d d p p bn cn c b Thaaaaaaaaaaraanaeaereeeeee'`
|
| 66 |
+
- A:32:0.8:40:1.1:primer, "Bonjour, je m'appelle": `'zid s a ctxathhhen. ct pupplplececicastcastcakisinisisec\x04-w,t�tcero&KRdiog'`
|
| 67 |
+
- A:32:0.8:40:1.1:primer, 'The capital of France is': `'lenwling outhods..s th t r is a cenameanestssststtttttthtant,,,,iniiiiii'`
|
| 68 |
+
- A:32:0.8:40:1.1:primer, 'Il était une fois': `'zg d pte binthe thon. rsts aus ce te deateatin wind, thepngppr- thorere Q'`
|
| 69 |
+
- B:128:0:1:1.0:cold, "Bonjour, je m'appelle": `'it nrgh sisssstt phio list lisest, listtraivillew proh ofppoati atorlp tat'`
|
| 70 |
+
- B:128:0:1:1.0:cold, 'The capital of France is': `'onditon.wf atstsA is ssonatin antpe tinervessnd oneatrtnvevsov soend sest tep'`
|
| 71 |
+
- B:128:0:1:1.0:cold, 'Il était une fois': `'t deltisatiora poin iorg to ocaevenerete an dapt che vore commiston dereta('`
|
| 72 |
+
- B:128:0.8:40:1.1:cold, "Bonjour, je m'appelle": `'it rgnr bhoossaplatiplin. ts pling troFaisis-(v�ute a a-th ambkes deteasap-pi'`
|
| 73 |
+
- B:128:0.8:40:1.1:cold, 'The capital of France is': `'wom and isabteg hhit clovise, form aungerthano y.\nIpoan ler yas blingepoh.* a'`
|
| 74 |
+
- B:128:0.8:40:1.1:cold, 'Il était une fois': `'g lhe cstin usting deraing ite te walpyine reath manaingo ferom a pe.hPronun'`
|
| 75 |
+
- B:128:0:1:1.0:primer, "Bonjour, je m'appelle": `'zer catinit aorion ated wr iprenepring acortiooeineing tithetingeraly ong\n\n'`
|
| 76 |
+
- B:128:0:1:1.0:primer, 'The capital of France is': `'speplenentize foripurs atipliooonene denerstatindeng. Setitine we terlengetle'`
|
| 77 |
+
- B:128:0:1:1.0:primer, 'Il était une fois': `' ze apriprineng tlortzioo atinener tineratinering tlyintoo�� uryiaceiu. The i'`
|
| 78 |
+
- B:128:0.8:40:1.1:primer, "Bonjour, je m'appelle": `'zizKt as for acin ing cule ateormepkit, writen wredipengate tepiatiatingyione'`
|
| 79 |
+
- B:128:0.8:40:1.1:primer, 'The capital of France is': `"suponedepriplyizes aces ong ineringriplesatotothe atine' ceintinendernt ur"`
|
| 80 |
+
- B:128:0.8:40:1.1:primer, 'Il était une fois': `'ierprong szen apptot ze ippacinerinesti tienenderace Ding tintiwederlyinouqu'`
|
| 81 |
+
|
| 82 |
+
Findings: Mode A at block 32 collapses into letter runs (unique@40 0.25-0.55). Plain BOS reset gives prompt TF 55-200 per id (the first chunk after a reset is far out of distribution) and output similar to primer runs. Primer and plain-BOS starts have similar unique@40 (0.3-0.5). No config produces coherent text; the conclusion above holds.
|
| 83 |
+
|
| 84 |
+
## Carry surgery round (bf16, N=80; scripts/gen_surgery2.py; raw: /workspace/gs2.jsonl, gs3.jsonl, gs2_ref.json)
|
| 85 |
+
|
| 86 |
+
### 1. Carry norms: generation vs teacher-forced (TF) reference
|
| 87 |
+
The reference is TF over one in-corpus document starting at BOS, in 128-id chunks (27 clean chunks; chunk 28 contains BOS and resets). In the reference, attn_S Frobenius (mean over 16 blocks) grows about linearly, ~2.7e9 per chunk (3.7e9 after 1 chunk, 2.5e10 after 10, 7.4e10 after 27), and attn_z grows ~1.5e7 per chunk. Nothing decays (as in DISCOVERY_LOG §7.2). Past 27 chunks the reference is extrapolated linearly. thought_state L2 in TF stays at ~600-1300.
|
| 88 |
+
|
| 89 |
+
| config (prompt: Bonjour) | gen pos | carry ticks | S_fro mean/max | ref S_fro mean/max | z_l2 mean/max | ref z mean/max | thought L2 (ref) | phases L2 mean/max |
|
| 90 |
+
|---|---|---|---|---|---|---|---|---|
|
| 91 |
+
| B:128:0:1:1.0:cold:none:0 | 0 | 0 | 0/0 | 3.73e+09/4.72e+10 | 0/0 | 1.27e+07/1.5e+08 | 0 (1317) | 0.0/0.0 |
|
| 92 |
+
| B:128:0:1:1.0:cold:none:0 | 10 | 0 | 0/0 | 3.73e+09/4.72e+10 | 0/0 | 1.27e+07/1.5e+08 | 0 (1317) | 0.0/0.0 |
|
| 93 |
+
| B:128:0:1:1.0:cold:none:0 | 20 | 0 | 0/0 | 3.73e+09/4.72e+10 | 0/0 | 1.27e+07/1.5e+08 | 0 (1317) | 0.0/0.0 |
|
| 94 |
+
| B:128:0:1:1.0:cold:none:0 | 40 | 0 | 0/0 | 3.73e+09/4.72e+10 | 0/0 | 1.27e+07/1.5e+08 | 0 (1317) | 0.0/0.0 |
|
| 95 |
+
| B:128:0:1:1.0:cold:none:0 | 79 | 0 | 0/0 | 3.73e+09/4.72e+10 | 0/0 | 1.27e+07/1.5e+08 | 0 (1317) | 0.0/0.0 |
|
| 96 |
+
| B:128:0:1:1.0:cold:none:0 | 80 | 0 | 0/0 | 3.73e+09/4.72e+10 | 0/0 | 1.27e+07/1.5e+08 | 0 (1317) | 0.0/0.0 |
|
| 97 |
+
| B:128:0:1:1.0:primer:none:0 | 0 | 2 | 5.88e+09/7.18e+10 | 5.87e+09/7.18e+10 | 2.68e+07/2.99e+08 | 2.68e+07/2.99e+08 | 827 (831) | 163.719/166.563 |
|
| 98 |
+
| B:128:0:1:1.0:primer:none:0 | 10 | 2 | 5.88e+09/7.18e+10 | 5.87e+09/7.18e+10 | 2.68e+07/2.99e+08 | 2.68e+07/2.99e+08 | 827 (831) | 163.719/166.563 |
|
| 99 |
+
| B:128:0:1:1.0:primer:none:0 | 20 | 2 | 5.88e+09/7.18e+10 | 5.87e+09/7.18e+10 | 2.68e+07/2.99e+08 | 2.68e+07/2.99e+08 | 827 (831) | 163.719/166.563 |
|
| 100 |
+
| B:128:0:1:1.0:primer:none:0 | 40 | 2 | 5.88e+09/7.18e+10 | 5.87e+09/7.18e+10 | 2.68e+07/2.99e+08 | 2.68e+07/2.99e+08 | 827 (831) | 163.719/166.563 |
|
| 101 |
+
| B:128:0:1:1.0:primer:none:0 | 79 | 2 | 5.88e+09/7.18e+10 | 5.87e+09/7.18e+10 | 2.68e+07/2.99e+08 | 2.68e+07/2.99e+08 | 827 (831) | 163.719/166.563 |
|
| 102 |
+
| B:128:0:1:1.0:primer:none:0 | 80 | 2 | 5.88e+09/7.18e+10 | 5.87e+09/7.18e+10 | 2.68e+07/2.99e+08 | 2.68e+07/2.99e+08 | 827 (831) | 163.719/166.563 |
|
| 103 |
+
| A:128:0:1:1.0:cold:none:0 | 0 | 0 | 0/0 | 3.73e+09/4.72e+10 | 0/0 | 1.27e+07/1.5e+08 | 0 (1317) | 0.0/0.0 |
|
| 104 |
+
| A:128:0:1:1.0:cold:none:0 | 10 | 10 | 1.21e+09/1.63e+10 | 2.52e+10/2.81e+11 | 2.61e+06/3.62e+07 | 1.46e+08/1.49e+09 | 4909 (914) | 79.967/82.565 |
|
| 105 |
+
| A:128:0:1:1.0:cold:none:0 | 20 | 20 | 1.55e+09/2.14e+10 | 5.47e+10/5.95e+11 | 3.48e+06/4.79e+07 | 2.98e+08/2.97e+09 | 3829 (704) | 92.137/95.562 |
|
| 106 |
+
| A:128:0:1:1.0:cold:none:0 | 40 | 40 | 1.89e+09/2.53e+10 | 1.09e+11/1.18e+12 | 5.26e+06/7.13e+07 | 5.98e+08/5.93e+09 | 2265 (643) | 112.559/116.117 |
|
| 107 |
+
| A:128:0:1:1.0:cold:none:0 | 79 | 79 | 4.02e+09/5.53e+10 | 2.16e+11/2.34e+12 | 8.72e+06/1.17e+08 | 1.18e+09/1.17e+10 | 2159 (643) | 144.061/147.072 |
|
| 108 |
+
| A:128:0:1:1.0:cold:none:0 | 80 | 80 | 4.05e+09/5.57e+10 | 2.19e+11/2.37e+12 | 8.81e+06/1.18e+08 | 1.2e+09/1.19e+10 | 2267 (643) | 144.578/147.298 |
|
| 109 |
+
| A:128:0:1:1.0:primer:none:0 | 0 | 2 | 5.88e+09/7.18e+10 | 5.87e+09/7.18e+10 | 2.68e+07/2.99e+08 | 2.68e+07/2.99e+08 | 814 (831) | 163.785/166.67 |
|
| 110 |
+
| A:128:0:1:1.0:primer:none:0 | 10 | 12 | 2.62e+10/3.46e+11 | 3.17e+10/3.56e+11 | 5.54e+07/6.33e+08 | 1.76e+08/1.79e+09 | 2587 (660) | 84.248/92.778 |
|
| 111 |
+
| A:128:0:1:1.0:primer:none:0 | 20 | 22 | 4.73e+10/6.19e+11 | 6.39e+10/7.07e+11 | 9.12e+07/1.08e+09 | 3.28e+08/3.27e+09 | 2077 (748) | 99.638/112.516 |
|
| 112 |
+
| A:128:0:1:1.0:primer:none:0 | 40 | 42 | 8.49e+10/1.09e+12 | 1.15e+11/1.24e+12 | 1.9e+08/2.34e+09 | 6.28e+08/6.23e+09 | 1527 (643) | 115.808/131.591 |
|
| 113 |
+
| A:128:0:1:1.0:primer:none:0 | 79 | 81 | 1.77e+11/2.31e+12 | 2.22e+11/2.4e+12 | 4.97e+08/6.12e+09 | 1.21e+09/1.2e+10 | 1281 (643) | 143.602/156.769 |
|
| 114 |
+
| A:128:0:1:1.0:primer:none:0 | 80 | 82 | 1.81e+11/2.36e+12 | 2.24e+11/2.43e+12 | 5.06e+08/6.24e+09 | 1.23e+09/1.22e+10 | 1286 (643) | 144.371/158.854 |
|
| 115 |
+
|
| 116 |
+
Findings:
|
| 117 |
+
- **No attn_S inflation in generation.** In Mode A (one carry tick per generated id), S_fro after 80 ticks is at or below the TF reference for the same number of chunks: primer start 1.8-2.2e11 vs ref 2.2e11; plain BOS 3-4e9 vs ref 2.2e11. In Mode A, attn_z *undershoots*: 5e8 vs ref 1.2e9 (primer), 9e6 vs 1.2e9 (BOS). So the S/z ratio in generation is ~2x the reference (primer) and ~20x (plain BOS).
|
| 118 |
+
- **thought_state is inflated in Mode A**: 1300-4900 vs 640-910 in TF (2-7x).
|
| 119 |
+
- **In Mode B the carry is frozen during 80 ids.** With block 128 and a short prompt, the pending block never reaches 128 ids, so there is no commit (ticks stay at 0 for BOS, 2 for primer). Its carry equals the TF carry exactly. The failure in Mode B therefore does not come from the carry.
|
| 120 |
+
|
| 121 |
+
### 2-3. Partial carry reset and inference-side scheduled sampling (unique@40: Bonjour / France / Il était; ids/s mean)
|
| 122 |
+
|
| 123 |
+
| config | unique@40 | ids/s |
|
| 124 |
+
|---|---|---|
|
| 125 |
+
| B:128:0:1:1.0:cold:none:0 | 0.4 / 0.35 / 0.4 | 2.27 |
|
| 126 |
+
| B:128:0:1:1.0:primer:none:0 | 0.4 / 0.275 / 0.375 | 2.23 |
|
| 127 |
+
| B:128:0:1:1.0:primer:none:0 (rerun) | 0.35 / 0.5 / 0.35 | 2.12 |
|
| 128 |
+
| A:128:0:1:1.0:cold:none:0 | 0.425 / 0.475 / 0.425 | 2.31 |
|
| 129 |
+
| A:128:0:1:1.0:cold:none:0 (rerun) | 0.4 / 0.275 / 0.425 | 2.39 |
|
| 130 |
+
| A:128:0:1:1.0:primer:none:0 | 0.275 / 0.3 / 0.225 | 2.24 |
|
| 131 |
+
| A:128:0:1:1.0:primer:none:0 (rerun) | 0.3 / 0.3 / 0.325 | 2.38 |
|
| 132 |
+
| A:128:0:1:1.0:primer:half:0 | 0.5 / 0.475 / 0.4 | 2.11 |
|
| 133 |
+
| A:128:0.8:40:1.1:primer:half:0 | 0.45 / 0.425 / 0.275 | 2.5 |
|
| 134 |
+
| A:128:0:1:1.0:primer:clamp:0 | 0.325 / 0.275 / 0.275 | 2.48 |
|
| 135 |
+
| A:128:0.8:40:1.1:primer:clamp:0 | 0.225 / 0.325 / 0.225 | 2.57 |
|
| 136 |
+
| B:128:0:1:1.0:primer:half:0 | 0.425 / 0.4 / 0.375 | 2.61 |
|
| 137 |
+
| B:128:0.8:40:1.1:primer:half:0 | 0.425 / 0.55 / 0.425 | 2.51 |
|
| 138 |
+
| B:128:0:1:1.0:primer:clamp:0 | 0.35 / 0.4 / 0.375 | 2.53 |
|
| 139 |
+
| B:128:0.8:40:1.1:primer:clamp:0 | 0.375 / 0.5 / 0.5 | 2.68 |
|
| 140 |
+
| B:128:0:1:1.0:primer:none:0.2 | 0.525 / 0.4 / 0.35 | 0.97 |
|
| 141 |
+
| B:128:0.8:40:1.1:primer:none:0.2 | 0.4 / 0.475 / 0.425 | 2.64 |
|
| 142 |
+
| B:128:0.8:40:1.1:primer:none:0 | 0.45 / 0.5 / 0.525 | 2.61 |
|
| 143 |
+
| A:128:0.8:40:1.1:primer:none:0 | 0.25 / 0.3 / 0.325 | 2.53 |
|
| 144 |
+
|
| 145 |
+
Notes:
|
| 146 |
+
- In Mode B the half/clamp fixes never trigger within 80 ids, because no block boundary is crossed. B half/clamp rows are therefore effectively baseline reruns. Identical baseline configs run twice gave different greedy outputs (bf16 CPU nondeterminism under load), e.g. B:128 greedy primer France 0.275 vs 0.50. Unique@40 differences of about ±0.15 are noise.
|
| 147 |
+
- Mode A x0.5 (half) raises greedy unique@40 from 0.275/0.30/0.225-0.325 to 0.50/0.475/0.40. The output is still not words. Clamping to the reference norm changes nothing (0.275-0.325), since the generated S/z are already at or below the reference.
|
| 148 |
+
- Inference SS (20% of generated positions in the fed block replaced by prompt ids, Mode B): unique@40 0.35-0.525, no change in quality. The ids/s values of 0.13/0.40 come from box contention.
|
| 149 |
+
- The B:128 T0.8 primer baseline and A:128 T0.8 primer baseline in this round were not completed (run stalled >7 min and was killed); see gb4 for B:128 T0.8 primer (0.375/0.475/0.475).
|
| 150 |
+
|
| 151 |
+
Verbatim (Mode A half, greedy, primer):
|
| 152 |
+
- "Bonjour, je m'appelle": `'caisss tn znusentudetderbr inte fo vntevee. f weroe sexpkalerssir m ting t to'`
|
| 153 |
+
- 'The capital of France is': `' plewtkcon dinglevewt cewt frend ceriviliung ohe the uakit pl ce. tanoly is d'`
|
| 154 |
+
- 'Il était une fois': `' pzesedevencesiwrg alyesyes fesingaer undexait he t the coranclio ghe re un'`
|
| 155 |
+
Verbatim (Mode B T0.8 primer + 20% inference SS):
|
| 156 |
+
- "Bonjour, je m'appelle": `'zericzatorr a ce aens weipe ile- upt fplicacucacapitiniongation. aainiroert'`
|
| 157 |
+
- 'The capital of France is': `"speronediprbcteotipeselyinanondezi ule\neLitinivie aloduatog mr'deing teeder "`
|
| 158 |
+
- 'Il était une fois': `' wrg wle tgernt prtrone acndhoncteedinrzipeizaeni ing tedinpttertye racn-nton'`
|
| 159 |
+
|
| 160 |
+
Verdict: none of the carry fixes or inference SS makes this checkpoint generate coherent text. The carry is not inflated relative to TF. In Mode B it is identical to TF, so the remaining failure comes from the model's own next-id predictions on its sampled inputs and on out-of-corpus prompts, not from the inference driving.
|
| 161 |
+
|
| 162 |
+
Trainer check (scripts/fast4gpu_atom.py): `SS_RATE` exists, default 1.0 (`SS_PROB_START` 0.2 -> `SS_PROB_END` 0.5 over `SS_RAMP_TOKENS` 5e7). The current run logs an SS pass on only some steps (`ss=`/`ema_ss` ~1.17 present on a subset of log lines; SS takes ~17% of wall time), so the run's effective SS_RATE is <1.0. Per-lane carry reset at BOS already exists (`reset_rows` on any chunk containing 257, applied to thought_state, attn_S, attn_z, kuramoto_phases).
|
docs/TRAINING_LOG.md
CHANGED
|
@@ -70,3 +70,10 @@ tf = teacher-forced loss. SGD tf ≈ 3.2-3.3 regardless of LR.
|
|
| 70 |
- **Clipping.** `clip_grad_norm_(..., 1.0)` was active in both runs (it already existed in the script); it did not prevent the divergences.
|
| 71 |
- **Guarded restart** from the 409.6M checkpoint: LR 1e-4 cosine to 1e-5, 500-step warmup, spike guard (skip when gn > max(300, 10 x EMA)), rollback request after 50 consecutive skipped steps or ema_tf > 4.0 for 1,000 steps (runner restarts from the last good checkpoint at half LR, max 3 times), rotating step checkpoints with a `good/` copy (ema_tf < 3.0, no skip in the last 2,000 steps), and a push loop that uploads only `good/`. Healthy checkpoint archived in `checkpoints/atom_409M_good/`.
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
- **Clipping.** `clip_grad_norm_(..., 1.0)` was active in both runs (it already existed in the script); it did not prevent the divergences.
|
| 71 |
- **Guarded restart** from the 409.6M checkpoint: LR 1e-4 cosine to 1e-5, 500-step warmup, spike guard (skip when gn > max(300, 10 x EMA)), rollback request after 50 consecutive skipped steps or ema_tf > 4.0 for 1,000 steps (runner restarts from the last good checkpoint at half LR, max 3 times), rotating step checkpoints with a `good/` copy (ema_tf < 3.0, no skip in the last 2,000 steps), and a push loop that uploads only `good/`. Healthy checkpoint archived in `checkpoints/atom_409M_good/`.
|
| 72 |
|
| 73 |
+
|
| 74 |
+
## 2026-10-13/17: guarded run, rollbacks, LR offset fix, resume at 2.485B ids
|
| 75 |
+
|
| 76 |
+
- **Rollbacks.** The guarded run rolled back twice to the last `good/` checkpoint at half LR: on Oct 13 and on Oct 14 (00:57 UTC, 51 consecutive skipped steps at 877.8M ids; LR 5e-5 to 2.5e-5, min 2.5e-6).
|
| 77 |
+
- **LR offset fix.** A runner restart reset the cosine schedule to step 0. `scripts/fast4gpu_atom.py` now reads `LR_STEP_OFFSET` and `LR_TOTAL_STEPS` and computes `t = (n + LR_STEP_OFFSET) / LR_TOTAL_STEPS`, so a resume continues the schedule instead of restarting it. The runner (`scripts/atom_runner.py`) stores both values in its state file.
|
| 78 |
+
- **Resume.** On Oct 15 (17:22 UTC) the run resumed from the `good/` checkpoint at 2.485B ids with `WARMUP_STEPS=0`, `LR_STEP_OFFSET=785000`, `LR_TOTAL_STEPS=1725158`, 940,158 steps left. Guards (spike skip, rollback request, `good/` checkpoints, push of `good/` only) unchanged.
|
| 79 |
+
- **Status (Oct 16).** ~3.61B ids, ~11.3k ids/s wall (TF 82%, SS 17%), LR ~5.2e-6, mem peak 29.3 GB. Expected to finish around Oct 17.
|
scripts/atom_runner.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
"""
|
| 2 |
with half the LR when the trainer exits with code 42 (rollback request)."""
|
| 3 |
import json, os, subprocess, sys, time
|
| 4 |
from pathlib import Path
|
|
@@ -22,7 +22,8 @@ while True:
|
|
| 22 |
STATE.write_text(json.dumps(st, indent=1))
|
| 23 |
env = dict(os.environ, **BASE, LR=str(st["lr"]), LR_MIN=str(st["lr_min"]),
|
| 24 |
WARMUP_STEPS=str(st["warmup"]), CKPT_IN=st["ckpt_in"],
|
| 25 |
-
START_TOKEN=str(st["start_token"]), MAX_STEPS=str(st["steps_left"])
|
|
|
|
| 26 |
log("launch", json.dumps(st))
|
| 27 |
with open("/workspace/train.log", "a") as f:
|
| 28 |
p = subprocess.Popen([sys.executable, "-u", "scripts/fast4gpu_atom.py"], cwd="/workspace/repo",
|
|
@@ -41,6 +42,7 @@ while True:
|
|
| 41 |
if good.exists():
|
| 42 |
st["ckpt_in"] = str(good)
|
| 43 |
st["steps_left"] = max(1, st["steps_left"] - int(rb["step_in_run"]))
|
|
|
|
| 44 |
st["start_token"] = int(rb["start_token_next"]) # data keeps moving forward
|
| 45 |
st["lr"] /= 2; st["lr_min"] /= 2
|
| 46 |
log("rollback", rb, "->", st["ckpt_in"], "lr", st["lr"])
|
|
|
|
| 1 |
+
"""Runner for the Atom resume: restarts the trainer from the last GOOD checkpoint
|
| 2 |
with half the LR when the trainer exits with code 42 (rollback request)."""
|
| 3 |
import json, os, subprocess, sys, time
|
| 4 |
from pathlib import Path
|
|
|
|
| 22 |
STATE.write_text(json.dumps(st, indent=1))
|
| 23 |
env = dict(os.environ, **BASE, LR=str(st["lr"]), LR_MIN=str(st["lr_min"]),
|
| 24 |
WARMUP_STEPS=str(st["warmup"]), CKPT_IN=st["ckpt_in"],
|
| 25 |
+
START_TOKEN=str(st["start_token"]), MAX_STEPS=str(st["steps_left"]),
|
| 26 |
+
LR_STEP_OFFSET=str(st.get("lr_step_offset", 0)), LR_TOTAL_STEPS=str(st.get("lr_total_steps", 0)))
|
| 27 |
log("launch", json.dumps(st))
|
| 28 |
with open("/workspace/train.log", "a") as f:
|
| 29 |
p = subprocess.Popen([sys.executable, "-u", "scripts/fast4gpu_atom.py"], cwd="/workspace/repo",
|
|
|
|
| 42 |
if good.exists():
|
| 43 |
st["ckpt_in"] = str(good)
|
| 44 |
st["steps_left"] = max(1, st["steps_left"] - int(rb["step_in_run"]))
|
| 45 |
+
if st.get("lr_total_steps"): st["lr_step_offset"] = st.get("lr_step_offset", 0) + int(rb["step_in_run"])
|
| 46 |
st["start_token"] = int(rb["start_token_next"]) # data keeps moving forward
|
| 47 |
st["lr"] /= 2; st["lr_min"] /= 2
|
| 48 |
log("rollback", rb, "->", st["ckpt_in"], "lr", st["lr"])
|
scripts/fast4gpu_atom.py
CHANGED
|
@@ -311,8 +311,10 @@ def main() -> None:
|
|
| 311 |
# Overrides whatever lr a loaded optimizer state carried, every step.
|
| 312 |
f = min(1.0, (n + 1) / warmup_steps) if warmup_steps > 0 else 1.0
|
| 313 |
cur = lr
|
| 314 |
-
|
| 315 |
-
|
|
|
|
|
|
|
| 316 |
cur = lr_min + 0.5 * (lr - lr_min) * (1.0 + math.cos(math.pi * t))
|
| 317 |
cur *= f
|
| 318 |
_lr_now["lr"] = cur
|
|
|
|
| 311 |
# Overrides whatever lr a loaded optimizer state carried, every step.
|
| 312 |
f = min(1.0, (n + 1) / warmup_steps) if warmup_steps > 0 else 1.0
|
| 313 |
cur = lr
|
| 314 |
+
_off = int(os.environ.get("LR_STEP_OFFSET", "0"))
|
| 315 |
+
_tot = int(os.environ.get("LR_TOTAL_STEPS", "0")) or max_steps
|
| 316 |
+
if lr_sched == "cosine" and _tot > 0:
|
| 317 |
+
t = min(1.0, (n + _off) / _tot)
|
| 318 |
cur = lr_min + 0.5 * (lr - lr_min) * (1.0 + math.cos(math.pi * t))
|
| 319 |
cur *= f
|
| 320 |
_lr_now["lr"] = cur
|
scripts/gen_block.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Block-mode generation for Fractus CTE-Atom with warm carried state.
|
| 2 |
+
Mirrors fast4gpu_atom.py: chunk forward via the same per-block core, carry
|
| 3 |
+
(thought_state, attn_S, attn_z, kuramoto_phases) passed between chunks, reset only at BOS.
|
| 4 |
+
Modes:
|
| 5 |
+
A 'block tick' : every step feed the last C ids as one chunk, keep the resulting carry.
|
| 6 |
+
B 'regen block' : carry is committed at chunk boundaries; every step restores the
|
| 7 |
+
committed carry and re-runs the whole pending block (C/2..C ids),
|
| 8 |
+
takes the next id from the last position. When the pending block
|
| 9 |
+
reaches C ids, its first C/2 ids are committed (carry advanced).
|
| 10 |
+
Usage: CKPT=... CONFIGS=... python3 scripts/gen_block.py > out.jsonl
|
| 11 |
+
"""
|
| 12 |
+
import sys,os,time,json,gc,resource,torch,torch.nn.functional as F
|
| 13 |
+
sys.path.insert(0,os.path.join(os.path.dirname(__file__),'..'))
|
| 14 |
+
from fractus.atom_tokenizer import VOCAB_SIZE,AtomFractusTokenizer
|
| 15 |
+
from fractus.continuous_engine import ContinuousThoughtEngine
|
| 16 |
+
torch.set_num_threads(int(os.environ.get('THREADS','6')))
|
| 17 |
+
CK=os.environ.get('CKPT','/workspace/ckpt_new/checkpoints/atom_latest/fractus_atom_1b_gpu0.bin')
|
| 18 |
+
ck=torch.load(CK,map_location='cpu',weights_only=False,mmap=True)
|
| 19 |
+
cfg=ck['config']; sd=ck['model_state']
|
| 20 |
+
keys=['d_model','n_heads','d_head','n_levels','n_oscillators','coupling_rank','n_experts','top_k','expert_d_ff','siren_rank','n_layers']
|
| 21 |
+
with torch.device('meta'): eng=ContinuousThoughtEngine(vocab_size=VOCAB_SIZE,**{k:cfg[k] for k in keys})
|
| 22 |
+
msd=eng.state_dict(); bad=[k for k in sd if sd[k].shape!=msd[k].shape] # batch-sized stream-state keys
|
| 23 |
+
LANE=int(os.environ.get('LANE','0'))
|
| 24 |
+
saved={k:sd[k][LANE:LANE+1].float().clone() for k in bad}
|
| 25 |
+
for k in bad: sd[k]=torch.zeros(msd[k].shape)
|
| 26 |
+
DT=getattr(torch,os.environ.get('DTYPE','float32'))
|
| 27 |
+
if DT!=torch.float32: # materialize one tensor at a time as bf16 (half the RSS, no mmap thrash)
|
| 28 |
+
for k in list(sd): sd[k]=sd[k].to(DT) if sd[k].is_floating_point() else sd[k]
|
| 29 |
+
saved={k:v.to(DT) for k,v in saved.items()}
|
| 30 |
+
eng.load_state_dict(sd,strict=True,assign=True); del sd,ck; gc.collect()
|
| 31 |
+
for b in eng.blocks: b.moe.temperature=float(cfg['gate_temp'])
|
| 32 |
+
eng.eval(); SEQ=int(cfg.get('seq',128)); NB=len(eng.blocks)
|
| 33 |
+
print(json.dumps({'ckpt':CK,'ids_processed':cfg.get('ids_processed'),'seq':SEQ,'n_state_keys':len(bad)}),flush=True)
|
| 34 |
+
tok=AtomFractusTokenizer()
|
| 35 |
+
def get():
|
| 36 |
+
return (eng.thought_state.clone(),[(b.attn_S.clone(),b.attn_z.clone(),b.kuramoto_phases.clone()) for b in eng.blocks])
|
| 37 |
+
def put(s):
|
| 38 |
+
eng.thought_state=s[0].clone()
|
| 39 |
+
for b,(a,z,k) in zip(eng.blocks,s[1]): b.attn_S,b.attn_z,b.kuramoto_phases=a.clone(),z.clone(),k.clone()
|
| 40 |
+
def warm():
|
| 41 |
+
put((saved['thought_state'],[(saved[f'blocks.{i}.attn_S'],saved[f'blocks.{i}.attn_z'],saved[f'blocks.{i}.kuramoto_phases']) for i in range(NB)]))
|
| 42 |
+
def cold():
|
| 43 |
+
eng.reset_thought(1)
|
| 44 |
+
if DT!=torch.float32:
|
| 45 |
+
eng.thought_state=eng.thought_state.to(DT)
|
| 46 |
+
for b in eng.blocks: b.attn_S,b.attn_z,b.kuramoto_phases=b.attn_S.to(DT),b.attn_z.to(DT),b.kuramoto_phases.to(DT)
|
| 47 |
+
def tick(ids):
|
| 48 |
+
if 257 in ids: cold() # training: reset at any chunk containing BOS
|
| 49 |
+
return eng.tick_chunk(torch.tensor([ids]))[0]
|
| 50 |
+
def pick(lg,hist,T,k,rp):
|
| 51 |
+
lg=lg.float().clone(); lg[256]=-1e9; lg[257]=-1e9
|
| 52 |
+
if rp!=1.0:
|
| 53 |
+
for i in set(hist[-64:]): lg[i]=lg[i]/rp if lg[i]>0 else lg[i]*rp
|
| 54 |
+
if T<=0: return int(lg.argmax())
|
| 55 |
+
v,i=torch.topk(lg/T,k); return int(i[torch.multinomial(torch.softmax(v,-1),1)])
|
| 56 |
+
def prime(ids,C,keep):
|
| 57 |
+
"""commit prompt in chunks of C, leave >=keep ids pending; returns pending + TF losses"""
|
| 58 |
+
tf=[]; pend=list(ids)
|
| 59 |
+
while len(pend)-keep>=1 and len(pend)>C:
|
| 60 |
+
c=min(C,len(pend)-keep); ch=pend[:c]
|
| 61 |
+
lg=tick(ch)
|
| 62 |
+
if len(pend)>c: tf.append(round(float(F.cross_entropy(lg,torch.tensor(pend[1:c+1]))),3))
|
| 63 |
+
pend=pend[c:]
|
| 64 |
+
return pend,tf
|
| 65 |
+
PRIMER_FILE=os.environ.get('PRIMER','/workspace/lmsys/ref/atom_corpus/reasoning__syllogisms.i16')
|
| 66 |
+
def primer_ids(n=256):
|
| 67 |
+
import numpy as np
|
| 68 |
+
p=np.fromfile(PRIMER_FILE,dtype=np.int16,count=4096).astype(np.int64).tolist()
|
| 69 |
+
i=p.index(257); return p[i:i+n]
|
| 70 |
+
def gen(prompt,mode,C,T,k,rp,N,state):
|
| 71 |
+
warm() if state=='warm' else cold()
|
| 72 |
+
if state=='primer': # BOS-led in-distribution document head, committed in C-sized chunks
|
| 73 |
+
P=primer_ids();
|
| 74 |
+
with torch.inference_mode():
|
| 75 |
+
for j in range(0,len(P),C): tick(P[j:j+C])
|
| 76 |
+
if prompt=='<CONT>': # continue the primer document itself (in-distribution check)
|
| 77 |
+
P=primer_ids(256+int(os.environ.get('CONT_TAIL','64'))); ids=P[256:]
|
| 78 |
+
else:
|
| 79 |
+
ids,_=tok.encode_open(prompt if state=='cold' else "\n\n"+prompt)
|
| 80 |
+
ids=list(ids) if state=='cold' else list(ids)[1:] # cold keeps BOS (resets), warm drops it
|
| 81 |
+
out=[]; hist=list(ids)
|
| 82 |
+
with torch.inference_mode():
|
| 83 |
+
if mode=='B':
|
| 84 |
+
pend,tf=prime(ids,C,C//2)
|
| 85 |
+
s=get(); lg=tick(pend);
|
| 86 |
+
if len(pend)>1: tf.append(round(float(F.cross_entropy(lg[:-1],torch.tensor(pend[1:]))),3))
|
| 87 |
+
put(s)
|
| 88 |
+
for _ in range(N):
|
| 89 |
+
s=get(); lg=tick(pend)[-1]; put(s)
|
| 90 |
+
n=pick(lg,hist,T,k,rp); out.append(n); hist.append(n); pend.append(n)
|
| 91 |
+
if len(pend)>=C:
|
| 92 |
+
tick(pend[:C//2]); pend=pend[C//2:]
|
| 93 |
+
else: # A
|
| 94 |
+
pend,tf=prime(ids,C,0); tf=tf # prompt fully committed except tail
|
| 95 |
+
ctx=list(hist)
|
| 96 |
+
for _ in range(N):
|
| 97 |
+
lg=tick(ctx[-C:])[-1]
|
| 98 |
+
n=pick(lg,hist,T,k,rp); out.append(n); hist.append(n); ctx.append(n)
|
| 99 |
+
return out,tf
|
| 100 |
+
PROMPTS=os.environ['PROMPTS'].split('|') if os.environ.get('PROMPTS') else ["Bonjour, je m'appelle","The capital of France is","Q: What is 2+2?\nA:","Il était une fois"]
|
| 101 |
+
if __name__=='__main__':
|
| 102 |
+
N=int(os.environ.get('N','120'))
|
| 103 |
+
for c in os.environ.get('CONFIGS','B:128:0:1:1.0:warm').split(','):
|
| 104 |
+
mode,C,T,k,rp,state=c.split(':'); C=int(C);T=float(T);k=int(k);rp=float(rp)
|
| 105 |
+
for p in PROMPTS:
|
| 106 |
+
torch.manual_seed(0); t=time.time(); out,tf=gen(p,mode,C,T,k,rp,N,state); dt=time.time()-t
|
| 107 |
+
last=out[-40:]
|
| 108 |
+
print(json.dumps({'cfg':c,'prompt':p,'output':tok.decode(out),'ids':out,'ids_s':round(N/dt,2),
|
| 109 |
+
'unique40':round(len(set(last))/len(last),3),'prompt_tf':tf,'rss_gb':round(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss/1e6,2)},ensure_ascii=False),flush=True)
|
scripts/gen_surgery2.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Carry-norm measurement + partial carry reset + inference-side scheduled sampling.
|
| 2 |
+
PHASE=ref|gen ; CONFIGS=mode:C:T:k:rp:state:fix:ss fix in none|half|clamp ; ss = fraction (0..1)
|
| 3 |
+
Appends one JSON line per prompt to OUT."""
|
| 4 |
+
import sys,os,json,time,random
|
| 5 |
+
sys.argv=['x']; sys.path.insert(0,os.path.dirname(__file__))
|
| 6 |
+
from gen_block import *
|
| 7 |
+
import numpy as np
|
| 8 |
+
OUT=os.environ.get('OUT','/workspace/gs2.jsonl'); REF='/workspace/gs2_ref.json'
|
| 9 |
+
def norms():
|
| 10 |
+
S=[float(b.attn_S.float().norm()) for b in eng.blocks]; Smx=[float(b.attn_S.float().abs().max()) for b in eng.blocks]
|
| 11 |
+
z=[float(b.attn_z.float().norm()) for b in eng.blocks]; zmx=[float(b.attn_z.float().abs().max()) for b in eng.blocks]
|
| 12 |
+
ph=[float(b.kuramoto_phases.float().norm()) for b in eng.blocks]
|
| 13 |
+
th=float(eng.thought_state.float().norm())
|
| 14 |
+
m=lambda v:(round(sum(v)/len(v),3),round(max(v),3))
|
| 15 |
+
return {'S_fro':m(S),'S_max':m(Smx),'z_l2':m(z),'z_max':m(zmx),'ph_l2':m(ph),'thought_l2':round(th,3),'_S':S,'_z':z}
|
| 16 |
+
def emit(r):
|
| 17 |
+
with open(OUT,'a') as f: f.write(json.dumps(r,ensure_ascii=False)+'\n')
|
| 18 |
+
if os.environ.get('PHASE')=='ref':
|
| 19 |
+
d=np.fromfile(PRIMER_FILE,dtype=np.int16,count=200000).astype(np.int64).tolist(); i=d.index(257); d=d[i:]
|
| 20 |
+
cold(); ref=[]
|
| 21 |
+
with torch.inference_mode():
|
| 22 |
+
for j in range(int(os.environ.get('NREF','40'))):
|
| 23 |
+
x=d[j*128:j*128+129]
|
| 24 |
+
if 257 in x[1:]: print('BOS at chunk',j)
|
| 25 |
+
lg=tick(x[:-1]); n=norms(); n['tf']=round(float(F.cross_entropy(lg.float(),torch.tensor(x[1:]))),3); n['chunks']=j+1; ref.append(n)
|
| 26 |
+
print(j+1,n['tf'],n['S_fro'],n['z_l2'],n['thought_l2'],flush=True)
|
| 27 |
+
json.dump(ref,open(REF,'w')); sys.exit()
|
| 28 |
+
ref=json.load(open(REF))
|
| 29 |
+
ref=ref[:27] # chunk 28 contains BOS (reset); keep one clean document
|
| 30 |
+
def refat(t):
|
| 31 |
+
if t<=len(ref): return ref[t-1]
|
| 32 |
+
r=ref[-1]; f=t/len(ref) # S,z grow ~linearly with chunks in TF; extrapolate
|
| 33 |
+
return {'S_fro':[x*f for x in r['S_fro']],'z_l2':[x*f for x in r['z_l2']],'thought_l2':r['thought_l2'],'_S':[x*f for x in r['_S']],'_z':[x*f for x in r['_z']]}
|
| 34 |
+
TICKS=[0]
|
| 35 |
+
def tk(ids):
|
| 36 |
+
TICKS[0]+=1; return tick(ids)
|
| 37 |
+
def fixcarry(fix):
|
| 38 |
+
if fix=='half':
|
| 39 |
+
for b in eng.blocks: b.attn_S=b.attn_S*0.5; b.attn_z=b.attn_z*0.5
|
| 40 |
+
elif fix=='clamp':
|
| 41 |
+
r=refat(TICKS[0])
|
| 42 |
+
for i,b in enumerate(eng.blocks):
|
| 43 |
+
for name,key in (('attn_S','_S'),('attn_z','_z')):
|
| 44 |
+
t=getattr(b,name); n=float(t.float().norm()); lim=r[key][i]
|
| 45 |
+
if n>lim>0: setattr(b,name,t*(lim/n))
|
| 46 |
+
def run(prompt,mode,C,T,k,rp,state,fix,ss,N,rng):
|
| 47 |
+
TICKS[0]=0; cold()
|
| 48 |
+
with torch.inference_mode():
|
| 49 |
+
if state=='primer':
|
| 50 |
+
P=primer_ids()
|
| 51 |
+
for j in range(0,len(P),C): tk(P[j:j+C])
|
| 52 |
+
if state=='primer': ids=list(tok.encode_open("\n\n"+prompt)[0])[1:]
|
| 53 |
+
else: ids=list(tok.encode_open(prompt)[0])
|
| 54 |
+
pool=[x for x in ids if x<256] or ids
|
| 55 |
+
hist=list(ids); out=[]; log={}
|
| 56 |
+
def feed(block,start): # inference SS: replace ss fraction of generated positions by prompt ids
|
| 57 |
+
if ss<=0: return block
|
| 58 |
+
b=list(block); g0=len(hist)-len(out)
|
| 59 |
+
for j in range(len(b)):
|
| 60 |
+
if start+j>=g0 and rng.random()<ss: b[j]=rng.choice(pool)
|
| 61 |
+
return b
|
| 62 |
+
if mode=='B':
|
| 63 |
+
pend=list(ids); base=0
|
| 64 |
+
while len(pend)>C: tk(pend[:C//2]); fixcarry(fix); pend=pend[C//2:]; base+=C//2
|
| 65 |
+
for p in range(N):
|
| 66 |
+
if p in (0,10,20,40,80) or p==N-1:
|
| 67 |
+
n=norms(); n.pop('_S'); n.pop('_z'); rr=refat(max(TICKS[0],1)); log[p]={'ticks':TICKS[0],**n,'ref_S_fro':rr['S_fro'],'ref_z_l2':rr['z_l2'],'ref_thought':rr['thought_l2']}
|
| 68 |
+
if mode=='B':
|
| 69 |
+
s=get(); lg=tick(feed(pend,len(hist)-len(pend)))[-1]; put(s)
|
| 70 |
+
else:
|
| 71 |
+
ctx=hist[-C:]; lg=tk(feed(ctx,len(hist)-len(ctx)))[-1]; fixcarry(fix)
|
| 72 |
+
n_=pick(lg,hist,T,k,rp); out.append(n_); hist.append(n_)
|
| 73 |
+
if mode=='B':
|
| 74 |
+
pend.append(n_)
|
| 75 |
+
if len(pend)>=C: tk(pend[:C//2]); fixcarry(fix); pend=pend[C//2:]
|
| 76 |
+
n=norms(); n.pop('_S'); n.pop('_z'); rr=refat(max(TICKS[0],1)); log[N]={'ticks':TICKS[0],**n,'ref_S_fro':rr['S_fro'],'ref_z_l2':rr['z_l2'],'ref_thought':rr['thought_l2']}
|
| 77 |
+
return out,log
|
| 78 |
+
N=int(os.environ.get('N','80'))
|
| 79 |
+
for c in os.environ['CONFIGS'].split(','):
|
| 80 |
+
mode,C,T,k,rp,state,fix,ss=c.split(':'); C=int(C);T=float(T);k=int(k);rp=float(rp);ss=float(ss)
|
| 81 |
+
for p in PROMPTS:
|
| 82 |
+
torch.manual_seed(0); rng=random.Random(0); t=time.time()
|
| 83 |
+
out,log=run(p,mode,C,T,k,rp,state,fix,ss,N,rng); dt=time.time()-t; last=out[-40:]
|
| 84 |
+
emit({'cfg':c,'prompt':p,'output':tok.decode(out),'ids':out,'ids_s':round(N/dt,2),'unique40':round(len(set(last))/len(last),3),'carry':log})
|
| 85 |
+
print(c,p,round(len(set(last))/len(last),3),flush=True)
|
scripts/launch8.sh
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
cd /workspace
|
| 2 |
+
mkdir -p /workspace/ckpt_full
|
| 3 |
+
nohup python -u /workspace/run8.py > /workspace/run8.out 2>&1 </dev/null &
|
| 4 |
+
echo $! > /workspace/train.pid
|
| 5 |
+
nohup python -u /workspace/push_good.py > /workspace/push.log 2>&1 </dev/null &
|
| 6 |
+
echo $! > /workspace/push.pid
|
| 7 |
+
echo launched
|
scripts/manual_push.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# manual one-shot push mirroring push_good.py v2 push() (own stage dir, real copy snapshot)
|
| 2 |
+
import os, json, shutil, time, subprocess
|
| 3 |
+
for l in open("/workspace/hf.env"):
|
| 4 |
+
k,_,v=l.strip().partition("=")
|
| 5 |
+
if k=="HF_TOKEN": os.environ["HF_TOKEN"]=v
|
| 6 |
+
from huggingface_hub import HfApi
|
| 7 |
+
REPO="thefinalboss/fractus-cte-atom"; G="/workspace/ckpt_full/good"; LOG="/workspace/train.log"
|
| 8 |
+
s="/workspace/manual_push_stage"; shutil.rmtree(s,ignore_errors=True); os.makedirs(s)
|
| 9 |
+
names={"fractus_atom_1b_gpu0.pt":"fractus_atom_1b_gpu0.bin","fractus_atom_1b_gpu0.opt":"fractus_atom_1b_gpu0.opt.bin",
|
| 10 |
+
"RESUME_MANIFEST_atom_gpu0.json":"RESUME_MANIFEST_atom_gpu0.json","GOOD.json":"GOOD.json"}
|
| 11 |
+
info=json.load(open(G+"/GOOD.json"))
|
| 12 |
+
for a,b in names.items(): shutil.copy2(f"{G}/{a}",f"{s}/{b}")
|
| 13 |
+
man=json.load(open(s+"/RESUME_MANIFEST_atom_gpu0.json")); g2=json.load(open(s+"/GOOD.json"))
|
| 14 |
+
assert man["ids_processed"]==g2["ids_processed"]==info["ids_processed"], "snapshot inconsistent"
|
| 15 |
+
assert os.path.getsize(s+"/fractus_atom_1b_gpu0.bin")==os.path.getsize(G+"/fractus_atom_1b_gpu0.pt")
|
| 16 |
+
os.system(f"tail -n 300 {LOG} > {s}/train_tail.log")
|
| 17 |
+
print("snapshot ok",info,time.ctime(),flush=True)
|
| 18 |
+
api=HfApi()
|
| 19 |
+
for p in ("checkpoints/atom","checkpoints/atom_latest"):
|
| 20 |
+
r=api.upload_folder(folder_path=s,repo_id=REPO,path_in_repo=p,
|
| 21 |
+
commit_message="atom good ckpt %d ids (ema_tf %.3f) -> %s [manual]"%(info["ids_processed"],info["ema_tf"],p))
|
| 22 |
+
print("committed",p,r.oid if hasattr(r,"oid") else r,time.ctime(),flush=True)
|
| 23 |
+
print("DONE",time.ctime(),flush=True)
|
scripts/push_good.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# push_good v2: relaxed "good" watcher + pusher (does not touch the trainer)
|
| 2 |
+
import os, re, time, shutil, json, traceback, glob
|
| 3 |
+
for l in open('/workspace/hf.env'):
|
| 4 |
+
k,_,v=l.strip().partition('=')
|
| 5 |
+
if k=='HF_TOKEN': os.environ['HF_TOKEN']=v
|
| 6 |
+
from huggingface_hub import HfApi
|
| 7 |
+
REPO='thefinalboss/fractus-cte-atom'; OUT='/workspace/ckpt_full'; G=OUT+'/good'
|
| 8 |
+
LOG='/workspace/train.log'; STATE='/workspace/push_good_state.json'
|
| 9 |
+
INTERVAL=int(os.environ.get('PUSH_INTERVAL','36000'))
|
| 10 |
+
EMA_MAX=float(os.environ.get('RELAX_EMA_MAX','3.0'))
|
| 11 |
+
WIN=int(os.environ.get('RELAX_WINDOW_STEPS','2000')); MAX_SKIPS=int(os.environ.get('RELAX_MAX_SKIPS','20'))
|
| 12 |
+
IDS_PER_STEP=2048
|
| 13 |
+
api=HfApi()
|
| 14 |
+
st={'last_key':None,'last_t':0.0}
|
| 15 |
+
if os.path.exists(STATE): st.update(json.load(open(STATE)))
|
| 16 |
+
def save_state(): json.dump(st,open(STATE,'w'))
|
| 17 |
+
RE_LINE=re.compile(r'^GPU 0:\s+([\d,]+) tf=.*?gn_ema=([\d.]+) skips=(\d+)')
|
| 18 |
+
RE_SAVED=re.compile(r'saved -> .*\(([\d,]+) ids\)')
|
| 19 |
+
RE_CK=re.compile(r'ckpt (step_\d+): ema_tf=([\d.]+)')
|
| 20 |
+
def scan():
|
| 21 |
+
lines=open(LOG,errors='replace').read().splitlines()
|
| 22 |
+
m=max(i for i,l in enumerate(lines) if 'lr schedule=cosine' in l) # current trainer segment only
|
| 23 |
+
pts=[]; cks=[]; last_ids=None
|
| 24 |
+
for l in lines[m:]:
|
| 25 |
+
a=RE_LINE.match(l)
|
| 26 |
+
if a: pts.append((int(a[1].replace(',','')),float(a[2]),int(a[3]))); continue
|
| 27 |
+
a=RE_SAVED.search(l)
|
| 28 |
+
if a: last_ids=int(a[1].replace(',','')); continue
|
| 29 |
+
a=RE_CK.search(l)
|
| 30 |
+
if a and last_ids: cks.append((a[1],float(a[2]),last_ids))
|
| 31 |
+
out=[]
|
| 32 |
+
for name,ema,ids in cks:
|
| 33 |
+
before=[p for p in pts if p[0]<=ids]; start=[p for p in pts if p[0]<=ids-WIN*IDS_PER_STEP]
|
| 34 |
+
if not before or not start: continue
|
| 35 |
+
out.append(dict(step_dir=name,ids_processed=ids,ema_tf=ema,gn_ema_tf=before[-1][1],
|
| 36 |
+
skips_total=before[-1][2],skips_window=before[-1][2]-start[-1][2]))
|
| 37 |
+
return out
|
| 38 |
+
def complete(d,ids):
|
| 39 |
+
try:
|
| 40 |
+
man=json.load(open(d+'/RESUME_MANIFEST_atom_gpu0.json'))
|
| 41 |
+
return man['ids_processed']==ids and os.path.exists(d+'/fractus_atom_1b_gpu0.pt') and os.path.exists(d+'/fractus_atom_1b_gpu0.opt')
|
| 42 |
+
except Exception: return False
|
| 43 |
+
def promote(c):
|
| 44 |
+
d=f"{OUT}/{c['step_dir']}"; tmp=OUT+'/good.relaxed.tmp'; shutil.rmtree(tmp,ignore_errors=True); os.makedirs(tmp)
|
| 45 |
+
for f in ('fractus_atom_1b_gpu0.pt','fractus_atom_1b_gpu0.opt','RESUME_MANIFEST_atom_gpu0.json'): os.link(f'{d}/{f}',f'{tmp}/{f}')
|
| 46 |
+
if not complete(tmp,c['ids_processed']): shutil.rmtree(tmp,ignore_errors=True); return False
|
| 47 |
+
man=json.load(open(tmp+'/RESUME_MANIFEST_atom_gpu0.json'))
|
| 48 |
+
info=dict(c,start_token_next=man['start_token_next'],ts=man['ts'],criterion=f'relaxed: ema_tf<{EMA_MAX}, skips in last {WIN} steps<{MAX_SKIPS}, no ROLLBACK.json')
|
| 49 |
+
json.dump(info,open(tmp+'/GOOD.json','w'),indent=1)
|
| 50 |
+
old=OUT+'/good.old'; shutil.rmtree(old,ignore_errors=True)
|
| 51 |
+
if os.path.exists(G): os.replace(G,old)
|
| 52 |
+
os.replace(tmp,G); shutil.rmtree(old,ignore_errors=True)
|
| 53 |
+
print('promoted to good/',info,time.ctime(),flush=True); return True
|
| 54 |
+
def push(info):
|
| 55 |
+
s='/workspace/push_stage_good'; shutil.rmtree(s,ignore_errors=True); os.makedirs(s)
|
| 56 |
+
names={'fractus_atom_1b_gpu0.pt':'fractus_atom_1b_gpu0.bin','fractus_atom_1b_gpu0.opt':'fractus_atom_1b_gpu0.opt.bin',
|
| 57 |
+
'RESUME_MANIFEST_atom_gpu0.json':'RESUME_MANIFEST_atom_gpu0.json','GOOD.json':'GOOD.json'}
|
| 58 |
+
for a,b in names.items():
|
| 59 |
+
if os.path.exists(f'{G}/{a}'): os.link(f'{G}/{a}',f'{s}/{b}')
|
| 60 |
+
os.system(f'tail -n 300 {LOG} > {s}/train_tail.log')
|
| 61 |
+
for p in ('checkpoints/atom','checkpoints/atom_latest'):
|
| 62 |
+
api.upload_folder(folder_path=s,repo_id=REPO,path_in_repo=p,
|
| 63 |
+
commit_message=f"atom good ckpt {info['ids_processed']} ids (ema_tf {info['ema_tf']:.3f}) -> {p}")
|
| 64 |
+
shutil.rmtree(s,ignore_errors=True); print('pushed good',info,time.ctime(),flush=True)
|
| 65 |
+
while True:
|
| 66 |
+
try:
|
| 67 |
+
if not glob.glob(OUT+'/ROLLBACK*.json') or True:
|
| 68 |
+
cur=json.load(open(G+'/GOOD.json')) if os.path.exists(G+'/GOOD.json') else {'ids_processed':0}
|
| 69 |
+
if not os.path.exists(OUT+'/ROLLBACK.json'):
|
| 70 |
+
for c in sorted(scan(),key=lambda c:-c['ids_processed']):
|
| 71 |
+
if c['ids_processed']<=cur['ids_processed']: break
|
| 72 |
+
if c['ema_tf']<EMA_MAX and c['skips_window']<MAX_SKIPS and complete(f"{OUT}/{c['step_dir']}",c['ids_processed']):
|
| 73 |
+
promote(c); break
|
| 74 |
+
if os.path.exists(G+'/GOOD.json'):
|
| 75 |
+
info=json.load(open(G+'/GOOD.json')); key=[info['ids_processed'],info['ts']]
|
| 76 |
+
if key!=st['last_key'] and time.time()-st['last_t']>=INTERVAL:
|
| 77 |
+
push(info); st['last_key']=key; st['last_t']=time.time(); save_state()
|
| 78 |
+
except Exception: traceback.print_exc()
|
| 79 |
+
time.sleep(60)
|