REZIRETSA commited on
Commit
df1c27e
·
verified ·
1 Parent(s): cd0ae1b

Consolidated 1B tokenizer program card (vocab profiles, layout, siblings, license)

Browse files
Files changed (1) hide show
  1. README.md +365 -308
README.md CHANGED
@@ -1,309 +1,366 @@
1
- # ASTERIZER Tokenizer
2
-
3
- One **byte-level BPE** tokenizer, **frozen once and reused for ~10 years** across every
4
- model from 100M → 1T params. South-Indian-first (Kannada / Tamil / Telugu / Malayalam),
5
- plus code, math, and broad multilingual coverage. Built only from open, license-audited data.
6
-
7
- Everything lives in a single file: `asterizer.py` (config + all stages + CLI).
8
-
9
- ## Quick start
10
-
11
- ```bash
12
- python3 -m pip install tokenizers datasets "huggingface_hub[hf_transfer]" tiktoken transformers sentencepiece
13
- ```
14
-
15
- ```bash
16
- # interactive (asks vocab size + GB):
17
- python3 asterizer.py
18
- ```
19
-
20
- ```bash
21
- export HF_TOKEN=... # gated permissive code (starcoderdata) - accept the dataset terms on HF first
22
- ```
23
-
24
- ```bash
25
- # -- STEP 1instant config/plan check, NO download (seconds) --
26
- python3 asterizer.py --vocab 8K --gb 1 --dry-run --yes --allow-license-review
27
- ```
28
-
29
- ```bash
30
- # -- STEP 2tiny END-TO-END test (~1 GB, a few min): proves download -> clean -> corpus -> train ->
31
- # eval -> smoke all work and write a real tokenizer dir, with NO errors --
32
- python3 asterizer.py --vocab 8K --gb 1 --yes --allow-license-review
33
- # → if a bucket under-fills on the tiny sample, just bump --gb (e.g. --gb 3) and re-run.
34
- ```
35
-
36
- ```bash
37
- # -- STEP 3 pin source versions, then the PRODUCTION FREEZE (rented high-RAM CPU box): 32K+64K+128K
38
- # from ONE shared corpus, all gates on (~14–24 h, ≥256–512 GB RAM, no GPU) --
39
- python3 asterizer.py --lock
40
- python3 asterizer.py --vocab 32K,64K,128K --gb 240 --yes --require-lock --allow-license-review
41
- ```
42
-
43
- ```bash
44
- # validate / inspect an existing tokenizer:
45
- python3 asterizer.py --smoke runs/128K_240gb/tokenizer/asterizer_128K_v1.json
46
- ```
47
-
48
- ```bash
49
- # FULL held-out fertility + compression vs cl100k / o200k / Llama-3 / Qwen / Gemma / Sarvam:
50
- python3 asterizer.py --eval runs/128K_240gb/tokenizer/asterizer_128K_v1.json
51
- ```
52
-
53
- ```bash
54
- # post-freeze edits:
55
- python3 asterizer.py --promote tok.json --names "<|new_ctrl|>,<|tool2|>" --out tok2.json # size FIXED, sidecars auto-synced
56
- python3 asterizer.py --extend tok.json --new-data new.jsonl --num-new 2000 --out tok2.json # GROWS vocab
57
- ```
58
-
59
- Each build writes a **complete HuggingFace directory**:
60
- `tokenizer.json` + `asterizer_<v>_v1.json` + `tokenizer_config.json` + `special_tokens_map.json`
61
-
62
- `spec_hash.txt` + `fertility_report.json` , with the shared corpus provenance in `manifest.json` .
63
-
64
- ## Frozen design (current spec)
65
-
66
- | Aspect | Decision | Why |
67
- | :--- | :--- | :--- |
68
- | **Algorithm** | byte-level BPE, `unk_token=None` , all 256 bytes seeded | never an UNK in 10 years — any script/emoji/code round-trips |
69
- | **Normalizer** | NFC (never NFKC) | canonical Indic forms; NFKC would destroy x² , full-width, code |
70
- | **Pre-tokenizer** | **GPT-4o (o200k) regex** via `Split(Regex)``ByteLevel(use_regex=False)` | its letter classes include `\p{M}` → Indic vowel-signs/viramas stay glued to the consonant (GPT-2/cl100k/Llama-3 split them) |
71
- | **Digits** | individual ( `\p{N}` ) | stable arithmetic; CamelCase also splits (good for code) |
72
- | **Post-processor** | `ByteLevel(trim_offsets=True)` | correct offsets for training pipelines |
73
- | **Specials** | 32 named + reserved (power-of-two budget) | learned-merge count stays exact; reserved slots are promotable |
74
- | **max_token_length** | 32 bytes (~10 Indic chars) | real Dravidian words form, no giant overfit tokens |
75
- | **min_frequency** | 2 | don't prune rare South-Indian syllable merges |
76
-
77
- ### Vocab profiles ( `vocab_size` = 256 bytes + 32 named + reserved + learned ):
78
-
79
- | profile | vocab_size | reserved | learned | use |
80
- | :--- | :--- | :--- | :--- | :--- |
81
- | 64K | 65,536 | 992 | 64,256 | **1B–4B models** (embedding tax acceptable) |
82
- | 128K | 131,072 | 2,016 | 128,768 | **7B+ models** (flagship; multilingual/code headroom) |
83
-
84
- **Freeze policy (per the review):** use **64K for 1B–4B, 128K for 7B+**. At `d_model=2048` a 131,072 vocab is ~268M tied-embedding params vs ~134M for 64K — a heavy tax on a 1B model.
85
-
86
- **Corpus** (40% South-Indian, scales to `--gb` ): South-Indian 40% · code 17% (StarCoderData, 15 languages, license **review-tagged**) · english 10% · other-Indic 8% (hi/bn/gu/mr/pa/or) · european 5% · more-european 3.5% (el/tr/pl/nl/sv/ka/hy) · SEA 3.5% (th/vi/id/km/my/lo) · cjk 4.5% · semitic 3.8% (ar/fa/ur/he) · cyrillic 2.5% · african 1.5% (sw/am/yo/ha) · coverage 0.5% (bo/si) · math 1.5%. **26 scripts, ~40 languages.** Every bucket is coverage-gated. `--gb N` scales to exactly N GB.
87
-
88
- ## Professor review (2026-06-26) resolution
89
-
90
- | Blocker | Status |
91
- | :--- | :--- |
92
- | Stale 64K artifact, not from current spec | ✅ quarantined ( `STALE_DO_NOT_FREEZE.txt` ); rebuild required |
93
- | Not HF/vLLM/TGI directory-ready; pad/eos None | ✅ full sidecars + bos/eos/pad now emitted |
94
- | Model configs `vocab_size` 64000/128000 65536/131072 | fixed in all 8 FORGE configs |
95
- | Packer uses `uint32` at vocab 65536 (fits uint16) | condition < 65536 → <= 65536 (3 sites in `forge.py`) |
96
- | Corpus not universal | ✅ expanded 12 → 26 scripts, ~25 languages |
97
- | Cleaning strips ZWJ/ZWNJ | now preserved (Indic conjuncts, Persian/Urdu, emoji) |
98
- | Dataset revisions not pinned | ✅ `revision` plumbing + `manifest.json` corpus sha256 anchor |
99
- | License safety asserted, not enforced | ✅ per-source `license` tags + manifest audit |
100
- | `stage_extend` breaks reserved-slot promise | ✅ new `stage_promote` (size FIXED); `extend` clearly labeled vocab-growth |
101
- | Smoke gate masked by `... or True` | ✅ `_smoke_gate` aborts the build on failure |
102
- | No per-language/domain fertility report | ✅ `fertility_report.json` (23 language + domain probes) |
103
- | 64K vs 128K guidance | ✅ documented freeze policy (64K ≤ 4B, 128K ≥ 7B) |
104
- | Rebuild both on one pinned corpus; emit reports | ⌛ run the lock-gated freeze on the rented box ( `--vocab 64K,128K --gb 240 --require-lock` ) |
105
-
106
- ## Professor review #3 (2026-06-26) final hardening
107
-
108
- | Blocker | Status |
109
- | :--- | :--- |
110
- | No built artifact to validate ( `runs/` absent) | ⌛ run the lock-gated freeze on the rented box |
111
- | 45 source revisions unpinned (resolved only post-build) | ✅ `--lock -> sources.lock.json` (60/60 pinned) *before* download; `--require-lock` gates the build |
112
- | Coverage gate only on South-Indian @ 50% | EVERY bucket gated (default 60%, **required 85%**, per-bucket `min_frac` overrides) |
113
- | Code license `mixed-github(review)` | swapped to permissive `bigcode/starcoderdata` (gated, HF_TOKEN); codeparrot kept as a commented dev fallback |
114
- | `stage_promote` leaves sidecars to manual edit | ✅ auto-syncs `tokenizer_config.json` + `special_tokens_map.json` + canonical `tokenizer.json` |
115
- | Eval too small (23 one-sentence probes) | ✅ `--eval` : held-out streamed corpora, per-language bytes/token + tokens/word vs cl100k/o200k/Llama-3/Qwen/Gemma/Sarvam |
116
- | *added:* Urdu absent from corpus | ✅ `urd_Arab` in semitic bucket + eval |
117
- | *added:* ZWJ-emoji only tested non-ZWJ | ✅ ZWJ probe in smoke + eval domains |
118
-
119
- ## Professor review #4 (2026-06-26) resume safety, exact sizing, honest license
120
-
121
- | Finding | Status |
122
- | :--- | :--- |
123
- | Reference corpus 60 GB but sources sum to 60.5 GB ( `--gb 240` → 242) | `REFERENCE_TOTAL_GB` auto-computed from BUCKETS → `--gb N` = exactly N GB |
124
- | `.done` marker written *before* the coverage gate → resume can skip a bad bucket forever | ✅ floor checked *before* the marker; final gate clears markers of under-filled buckets so resume re-downloads (validated with a stubbed streamer) |
125
- | Code tagged `permissive` without a stronger filter | relabeled `permissive(bigcode-filtered; review)` ; comment documents per-file-license filtering for a hard freeze |
126
- | No built artifacts to smoke-test | unchanged run the build on the rented box |
127
-
128
- # CHANGELOG (newest first always appended)
129
-
130
- ## 2026-06-26 Professor-loop pre-freeze review (gpt-5.5 reviewer, auto-logged)
131
-
132
- A two-brain refinement loop hardens `asterizer.py` round by round: **worker** = the build author, **reviewer** = gpt-5.5 via `test1/auto_refine_loop.py` (ARM proxy). Each round sends the summary + full source, gets a JSON verdict, and applies fixes. The reviewer's #1 blocker every round is "no built artifacts exist", so `APPROVED` requires actually running the 240 GB build — the code/gate hardening below is what the loop produced. `test1/professor_review.py` appends each round to the table below automatically (logged here in the CHANGELOG, no separate log files).
133
-
134
- | Round | UTC | Verdict | Issues | Pros |
135
- | :--- | :--- | :--- | :--- | :--- |
136
- | 5 | 2026-06-26T18:18:2Z | NEEDS_WORK | 7 | 6 |
137
- | 4 | 2026-06-26T22:42Z | NEEDS_WORK | 8 | 8 |
138
- | 3 | 2026-06-26T22:34Z | NEEDS_WORK | 11 | 8 |
139
- | 2 | 2026-06-26T22:20Z | NEEDS_WORK | 8 | 8 |
140
- | 1 | 2026-06-26T21:59Z | NEEDS_WORK | 9 | 6 |
141
-
142
- Fixes applied across rounds (all in `asterizer.py` , validated offline):
143
-
144
- * **R1:** `license_gate` (`--allow-license-review`); config-fingerprint checkpoints; exact `_gb_tag` run-dir keys; shuffled sampling + `_sample_digest.json` ; hash-based held-out split written to `raw/heldout/*.jsonl` ; smoke decodes with `skip_special_tokens=False` + special-literal cases; `--extend` gated behind `ASTERIZER_EXPERIMENTAL` .
145
- * **R2 (real bugs caught):** per-bucket `.done` markers store the fingerprint (stale corpus can't be reused); the post-clean gate runs even on resume (was bypassable). Plus per-source coverage floor, eval-threshold freeze gate, whole-dir `SHA256SUMS.txt` , manifest env + `NOTICE.txt` .
146
- * **R3:** `eval-gate-bypass-on-resume` fixed (freeze folded into the tokenizer fingerprint); `run_stage` validates expected outputs exist; vocab-conformance gate; lock inventory check; provenance copied into the tokenizer dir; `promote` writes `promotions.json` + `spec_hash` before checksums.
147
- * **R4 (open):** remaining asks are stricter-enforcement/operational — per-file SPDX, corpus-hash checkpoint verification, holdout-after-cleaning, dependency-version refusal, full source-tuple lock match, and (always) building the real artifacts.
148
-
149
- ## 2026-06-26 (round 4) Resume safety + exact sizing + honest license (review #4)
150
-
151
- ### 1. Coverage gate no longer trappable on resume
152
-
153
- * **Before:** each bucket's `.done` marker was written *before* the coverage gate ran, so an under-filled (e.g. gated/failed) bucket got checkpointed and was skipped on every resume while the gate kept failing — a permanent fail loop.
154
- * **After:** the floor is checked *before* the marker, so an under-filled bucket is never checkpointed; the final gate also clears the marker of any bucket under floor so a resume re-downloads it. Validated with a stubbed streamer (the bad bucket re-downloads and passes on the second run).
155
-
156
- ### 2. Exact corpus sizing
157
-
158
- * **Before:** `REFERENCE_TOTAL_GB = 60` but the source quotas summed to 60.5 (Urdu added +0.5), so `--gb 240` actually scaled to ~242 GB.
159
- * **After:** `REFERENCE_TOTAL_GB` is recomputed as the exact sum of all source quotas, so `--gb N` scales to exactly N GB and never drifts when sources change.
160
-
161
- ### 3. Honest code license tag
162
-
163
- * **Before:** StarCoderData sources were tagged `permissive` an upstream claim, not a filter we ran.
164
- * **After:** tagged `permissive(bigcode-filtered; review)` ; the bucket comment documents that a hard commercial freeze should accept the upstream filter explicitly or filter on a per-file `license` column (e.g. the-stack-dedup). Surfaced in `manifest.json` + `sources.lock.json` .
165
-
166
- ## 2026-06-26 (round 3) — Final hardening (professor review #3)
167
-
168
- ### 1. Pre-resolved source lockfile ( `--lock` `sources.lock.json` )
169
-
170
- * **Before:** dataset commit SHAs were resolved into `manifest.json` *after* the build.
171
- * **After:** `--lock` resolves every source's HF commit SHA + license decision into `sources.lock.json` *before* download; the build pins `load_dataset(revision=...)` from it and `--require-lock` aborts unless it is fully pinned. The 240 GB pull is now reproducible by construction.
172
-
173
- ### 2. Coverage floors on EVERY bucket
174
-
175
- * **Before:** only the South-Indian bucket was gated, at 50% of target.
176
- * **After:** every bucket must hit a floor (default 60%, **required 85%**, low-resource buckets a smaller explicit `min_frac` ) or the build aborts a silent source/auth failure can't gut any script.
177
-
178
- ### 3. Permissive-only code (white-label clean)
179
-
180
- * **Before:** `codeparrot-clean` (Python, mixed GitHub licenses, tagged `mixed-github(review)` ).
181
- * **After:** `bigcode/starcoderdata` (already license-filtered to permissive; 15 languages; gated `HF_TOKEN` ). codeparrot retained as a clearly-commented dev fallback. `the-stack-v2-dedup` stores content as S3 pointers not plain-streamable, so StarCoderData is the practical pick.
182
-
183
- ### 4. `stage_promote` keeps the whole HF dir in lockstep
184
-
185
- * **Before:** it edited the tokenizer JSON and told you to update sidecars by hand.
186
- * **After:** it auto-updates `tokenizer_config.json` + `special_tokens_map.json` and re-saves the canonical `tokenizer.json` — IDs and vocab size still unchanged. Validated 311→311, sidecars synced.
187
-
188
- ### 5. Real eval harness ( `--eval` )
189
-
190
- * **Before:** `fertility_report.json` = 23 one-sentence probes.
191
- * **After:** per-language **held-out** corpora (fresh dataset streams, or local `--evaldir` files) + domain probes (legal/biomed/finance/yaml/url/diff/**ZWJ-emoji**/noisy-web), measured as bytes/token + tokens/word head-to-head against cl100k, o200k, Llama-3, Qwen, Gemma, Sarvam. Runs after each freeze build (non-fatal) and standalone via `--eval` .
192
-
193
- ### 6. Urdu + ZWJ coverage
194
-
195
- * Added `urd_Arab` to the corpus (semitic bucket) and an Urdu probe; added a real ZWJ-emoji family ( 👨‍👩‍👧 ) to smoke + eval so the preserved U+200D is actually exercised.
196
-
197
- ## 2026-06-26 (round 2) Freeze-gate hardening (professor review #2)
198
-
199
- ### 1. Smoke gate now refuses stale / incomplete artifacts
200
-
201
- * **Concept:** a freeze gate that passes a stale artifact is worse than none.
202
- * **Before:** the old 64K artifact still smoke-PASSED despite GPT-2 pretokenization, 24 specials, 1000 reserved, and no sidecars.
203
- * **After:** `stage_smoke` fails if any HF sidecar is missing, a `STALE_*` marker exists in the dir/parent, named specials 32, or reserved count the profile's. Verified: old 64K now FAILS with all 6 reasons; fresh builds still PASS.
204
-
205
- ### 2. Required-bucket coverage gate
206
-
207
- * **Concept:** a silently-failed source must not gut the priority data.
208
- * **Before:** source failures were non-fatal coverage could collapse unnoticed.
209
- * **After:** South-Indian bucket is required ; `stage_download` records actual per-source bytes ( `raw/_download_stats.json` ) and aborts if a required bucket is under `MIN_REQUIRED_FRAC` (50%) of target.
210
-
211
- ### 3. Manifest records actual bytes + resolved dataset commit SHAs
212
-
213
- * **Before:** `revision` plumbing existed but all sources were `None` → no real pinning; no actual bytes.
214
- * **After:** `write_manifest` records `actual_bytes` per source and resolves each dataset's commit SHA via HfApi into `resolved_revision` . Copy `resolved_revision` → a source `revision` to hard-pin a rebuild. Corpus sha256 remains the primary anchor.
215
-
216
- ### 4. Code license (open decision, not a hard blocker)
217
-
218
- * `codeparrot-clean` is Python + mixed GitHub licenses. For a *tokenizer* (a statistical merge table, not redistributed code/weights) mixed-license training data is widely treated as non-infringing (GPT-4/Llama did the same). For maximum white-label cleanliness, set `HF_TOKEN` and swap the code bucket to a permissive subset ( `bigcode/the-stack-v2-dedup` ). The license is tagged `mixed-github(review)` and surfaced in `manifest.json` so it's a conscious choice.
219
-
220
- # 2026-06-26Freeze-readiness (professor review)
221
-
222
- ## 1. Indic ZWJ/ZWNJ preservation
223
-
224
- * **Concept:** zero-width joiners are semantic, not noise.
225
- * **Before:** `ZERO_WIDTH` stripped U+200C (ZWNJ) and U+200D (ZWJ).
226
- * **After:** both preserved; only ZWSP/BOM/WordJoiner/SoftHyphen stripped.
227
- * **Why:** ZWNJ/ZWJ control Indic conjunct formation, Persian/Urdu orthography, and emoji ZWJ-sequences. Stripping them silently corrupts spelling and breaks emoji.
228
-
229
- ## 2. Smoke test is a HARD freeze gate
230
-
231
- * **Concept:** a failed validation must stop the freeze.
232
- * **Before:** `lambda: (stage_smoke(...) or True)` stage marked done even on FAIL.
233
- * **After:** `_smoke_gate()` calls `sys.exit(...)` on failure; stage is not checkpointed.
234
- * **Why:** a frozen-10-year artifact cannot be allowed to ship if round-trip/compat fails.
235
-
236
- ## 3. Reserved-slot promotion vs vocab growth (split)
237
-
238
- * **Concept:** the reserved-slot promise = add control tokens WITHOUT changing IDs or size.
239
- * **Before:** `stage_extend` appended tokens (grew `vocab_size` ), violating the promise.
240
- * **After:** new `stage_promote` renames free `<|reserved_i|>` slots in place (IDs + size UNCHANGED); `stage_extend` kept but loudly labeled as vocab-growth (needs embedding resize + continue-pretrain). New `--promote` / `--extend` CLI.
241
- * **Why:** promoting a reserved slot must never shift a learned-merge ID. Validated: 907 → 907.
242
-
243
- ## 4. Dataset revision pinning + license tags + manifest
244
-
245
- * **Concept:** reproducibility and commercial-safety must be auditable, not asserted.
246
- * **Before:** `load_dataset` streamed by name (no revision); no license metadata.
247
- * **After:** per-source `license` + optional `revision` ; `manifest.json` records every source, license, revision, seed, and the **corpus sha256** (the true reproducibility anchor).
248
- * **Why:** a frozen artifact needs provenance; re-training from the same `corpus.jsonl` is deterministic, so its hash pins the build.
249
-
250
- ## 5. Corpus universality (12 → 26 scripts)
251
-
252
- * **Concept:** "best in every language" needs every major script present so merges form.
253
- * **Before:** 9 buckets, ~12 scripts.
254
- * **After:** 13 buckets, 45 sources, 26 scriptsadded Gujarati/Marathi/Punjabi/Odia, Thai, Vietnamese, Indonesian, Khmer, Burmese, Lao, Greek, Turkish, Polish, Dutch, Swedish, Georgian, Armenian, Swahili, Amharic, Yoruba, Hausa, Tibetan, Sinhala. South-Indian stays 40%.
255
- * **Why:** byte-level guarantees no UNK, but good *fertility* needs the script in the training corpus. Missing-config sources fail non-fatally (logged), so this is safe.
256
-
257
- ## 6. Per-language/script/domain fertility report
258
-
259
- * **Concept:** freeze evidence must be measurable per language and domain.
260
- * **Before:** only an aggregate corpus fertility number.
261
- * **After:** `fertility_report.json` with tokens, bytes/token, tokens/word for 23 probes (all scripts + legal/biomed/finance/social-code-mixed/code-diff).
262
- * **Why:** the review requires held-out fertility per language/script/domain before freeze.
263
-
264
- ## 7. FORGE (cross-repo) exactness
265
-
266
- * **Concept:** vocab size must be identical across tokenizer, configs, packer, model cards.
267
- * **Before:** configs `vocab_size` = 64000/128000; packer `uint16` if vocab < 65536 (so the real 65536 vocab wasted `uint32` ).
268
- * **After:** all 8 configs 65536 / 131072; packer condition <= 65536 (65535 + uint16 max, fits).
269
- * **Why:** a 64000 vs 65536 mismatch corrupts embedding sizing; `uint32` at 64K doubles token-bin storage for nothing.
270
-
271
- ## 8. Stale artifacts quarantined
272
-
273
- * **Before:** `runs/32K_6gb` and `runs/64K_12GB` looked freezable but predate every change.
274
- * **After:** `STALE_DO_NOT_FREEZE.txt` in each; real freeze rebuilds on the rented box.
275
-
276
- # 2026-06-26 — SOTA audit (pre-freeze quality)
277
-
278
- ## A. o200k Indic-aware pre-tokenizer (the critical fix)
279
-
280
- * **Before:** `ByteLevel(use_regex=True)` = GPT-2 regex; `\p{L}+` excludes `\p{M}+` , so Indic marks split off the consonant at the pre-token boundary → BPE cannot merge syllables.
281
- * **After:** **GPT-4o o200k regex** (letter classes include `\p{M}` ) via `Split(Regex)` + `ByteLevel` .
282
- * **Why / proof:** ಕನ್ನಡ 3→1 pre-token, తెలుగు 6→1, ಅತ್ಯಾಧುನಿಕ 9→1; tiny-build fertility Kannada 4.33→1.17, Tamil 7.0→1.80, Telugu 6.6→1.80, Malayalam 8.0→2.50.
283
-
284
- ## B. Special tokens 24 32 (append-only IDs 24–31)
285
-
286
- * Added `<|im_start|>`/`<|im_end|>` (ChatML), `<|endofprompt|>` , `<|repo_name|>`/`<|file_sep|>` (repo-level code), `<|image_start|>`/`<|image_end|>`/`<|image_pad|>` (vision patches).
287
- * Reserved reduced by 8 per profile so **named+reserved** stays a power of two → **learned merges unchanged** (128K still 128,768).
288
-
289
- ## C. Complete HF directory + ByteLevel post-processor
290
-
291
- * Emits `tokenizer.json` (canonical name AutoTokenizer needs), `tokenizer_config.json` , `special_tokens_map.json` with a ChatML `chat_template` ; `unk_token=None` , `bos/eos/pad` declared.
292
- * Compat test now loads the dir via `AutoTokenizer.from_pretrained` and renders the chat template; gates PASS/FAIL.
293
-
294
- # 2026-06-25 — Shared-corpus refactor + UX
295
-
296
- * Download/clean/corpus run **once** into `runs/_data_<gb>gb/` ; 64K and 128K train from the same corpus. `--vocab 64K,128K` comma list. Download progress bar with %/rate/ETA.
297
- * Saturation analysis: tokenizer quality plateaus ~150–240 GB; >300 GB is wasted spend.
298
-
299
- # Build it (rented high-RAM CPU box, no GPU)
300
-
301
- The full 240 GB build needs ~150–200 GB RAM peak (BPE holds word counts in RAM). Rent a CPU box with **≥ 256–386 GB RAM**, ~1 TB disk. Then:
302
-
303
- ```bash
304
- export HF_TOKEN=... # gated permissive code (starcoderdata)
305
- python3 asterizer.py --lock # pin source SHAs -> sources.lock.json (commit it)
306
- python3 asterizer.py --vocab 64K,128K --gb 240 --yes --require-lock
307
- ```
308
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
  Freeze checklist before shipping: `sources.lock.json` fully pinned · every bucket passed its coverage floor · smoke PASS (gate) · `fertility_report.json` reviewed per language *and* vs *baselines* · `manifest.json` licenses audited (all permissive/open) · `spec_hash.txt` recorded · FORGE `vocab_size` matches `tokenizer.get_vocab_size()`.
 
1
+ ---
2
+ license: cc-by-nc-nd-4.0
3
+ tags:
4
+ - tokenizer
5
+ - multilingual
6
+ - bpe
7
+ - corpus
8
+ ---
9
+
10
+ # LUNA-1B Tokenizer — Program & Corpus
11
+
12
+ The single home of the **Asterizer tokenizer** for the LUNA-1B program: one byte-level BPE tokenizer,
13
+ frozen once and reused across every ASTERIZER model from 100M → 1T params. South-Indian-first
14
+ (Kannada / Tamil / Telugu / Malayalam), plus code, math, and broad multilingual coverage.
15
+ Built only from open, license-audited data.
16
+
17
+ This repo consolidates the former `tokeniser` / `LUNA-Tokenizer-Corpus`,
18
+ `LUNA-Tokenizer-Gap-V2`, and the program files of `LUNA-Tokenizer-Corpus-Artifacts`.
19
+
20
+ ## Vocab profiles (pick per model size)
21
+
22
+ | Profile | vocab_size | reserved | learned | use |
23
+ | :--- | :--- | :--- | :--- | :--- |
24
+ | **8K** | 8,192 | — | — | on-device / edge |
25
+ | **32K** | 32,768 | | | small devices, cost-critical |
26
+ | **64K** | 65,536 | 992 | 64,256 | **1B–4B models** |
27
+ | **128K** | 131,072 | 2,016 | 128,768 | **7B+ models** (flagship) |
28
+
29
+ Freeze policy: **64K for 1B–4B, 128K for 7B+**. At `d_model=2048` a 131,072 vocab is ~268M tied-embedding
30
+ params vs ~134M for 64K a heavy tax on a 1B model.
31
+
32
+ ## Layout
33
+
34
+ | Path | What it is |
35
+ | :--- | :--- |
36
+ | `asterizer.py` | The whole pipeline: config + all stages + CLI (download → clean → corpus → train → eval → freeze) |
37
+ | `DATA.7z` | Raw 240 GB source archive (sources pinned in `sources.lock.json`) |
38
+ | `Corpus_Cleaned.7z` | Cleaned 240 GB corpus archive (41.8M docs) |
39
+ | `run_*.sh` · `install_deps.sh` · `requirements.txt` | Reproducible build / freeze commands |
40
+ | `source.lock.json` · `sources.lock.json` | Pinned source revisions (60/60) |
41
+ | `heldout/` | Per-language + per-code held-out eval sets (EN/KN/ML/TA/TE/HI/BN/GU/MR/PA/… + 15 code languages) — the eval corpora behind the ASTERIZER tokenizer benchmarks |
42
+ | `artifacts/` | Build manifests + run info + state + resume notes from the 240 GB checkpointed run |
43
+ | `gap_v2/` | Gap-corpus source links, citations and download plan for the six hard domains (finance numbers, URLs/logs, structured, social chat, OCR-noisy web, mixed-script) |
44
+
45
+ ## Sibling repos
46
+
47
+ - **[LUNA-1B-Tokenizer](https://huggingface.co/ASTERIZER/LUNA-1B-Tokenizer)** — the frozen, ready-to-load tokenizer artifacts (128K / 64K / 8K).
48
+ - **[LUNA-Tokenizer-Corpus-Artifacts](https://huggingface.co/ASTERIZER/LUNA-Tokenizer-Corpus-Artifacts)** — the data store: cleaned 240 GB corpus shards (`clean/`, `corpus_parts/`).
49
+
50
+ ## License
51
+
52
+ CC BY-NC-ND 4.0 compilation. Underlying sources retain their own terms — see `sources.lock.json` and `gap_v2/manifests/CITATIONS.md`.
53
+
54
+ ---
55
+
56
+ # Full specification & build history
57
+
58
+ # ASTERIZER Tokenizer
59
+
60
+ One **byte-level BPE** tokenizer, **frozen once and reused for ~10 years** across every
61
+ model from 100M → 1T params. South-Indian-first (Kannada / Tamil / Telugu / Malayalam),
62
+ plus code, math, and broad multilingual coverage. Built only from open, license-audited data.
63
+
64
+ Everything lives in a single file: `asterizer.py` (config + all stages + CLI).
65
+
66
+ ## Quick start
67
+
68
+ ```bash
69
+ python3 -m pip install tokenizers datasets "huggingface_hub[hf_transfer]" tiktoken transformers sentencepiece
70
+ ```
71
+
72
+ ```bash
73
+ # interactive (asks vocab size + GB):
74
+ python3 asterizer.py
75
+ ```
76
+
77
+ ```bash
78
+ export HF_TOKEN=... # gated permissive code (starcoderdata) - accept the dataset terms on HF first
79
+ ```
80
+
81
+ ```bash
82
+ # -- STEP 1 instant config/plan check, NO download (seconds) --
83
+ python3 asterizer.py --vocab 8K --gb 1 --dry-run --yes --allow-license-review
84
+ ```
85
+
86
+ ```bash
87
+ # -- STEP 2 — tiny END-TO-END test (~1 GB, a few min): proves download -> clean -> corpus -> train ->
88
+ # eval -> smoke all work and write a real tokenizer dir, with NO errors --
89
+ python3 asterizer.py --vocab 8K --gb 1 --yes --allow-license-review
90
+ # → if a bucket under-fills on the tiny sample, just bump --gb (e.g. --gb 3) and re-run.
91
+ ```
92
+
93
+ ```bash
94
+ # -- STEP 3 pin source versions, then the PRODUCTION FREEZE (rented high-RAM CPU box): 32K+64K+128K
95
+ # from ONE shared corpus, all gates on (~14–24 h, ≥256–512 GB RAM, no GPU) --
96
+ python3 asterizer.py --lock
97
+ python3 asterizer.py --vocab 32K,64K,128K --gb 240 --yes --require-lock --allow-license-review
98
+ ```
99
+
100
+ ```bash
101
+ # validate / inspect an existing tokenizer:
102
+ python3 asterizer.py --smoke runs/128K_240gb/tokenizer/asterizer_128K_v1.json
103
+ ```
104
+
105
+ ```bash
106
+ # FULL held-out fertility + compression vs cl100k / o200k / Llama-3 / Qwen / Gemma / Sarvam:
107
+ python3 asterizer.py --eval runs/128K_240gb/tokenizer/asterizer_128K_v1.json
108
+ ```
109
+
110
+ ```bash
111
+ # post-freeze edits:
112
+ python3 asterizer.py --promote tok.json --names "<|new_ctrl|>,<|tool2|>" --out tok2.json # size FIXED, sidecars auto-synced
113
+ python3 asterizer.py --extend tok.json --new-data new.jsonl --num-new 2000 --out tok2.json # GROWS vocab
114
+ ```
115
+
116
+ Each build writes a **complete HuggingFace directory**:
117
+ `tokenizer.json` + `asterizer_<v>_v1.json` + `tokenizer_config.json` + `special_tokens_map.json`
118
+
119
+ `spec_hash.txt` + `fertility_report.json` , with the shared corpus provenance in `manifest.json` .
120
+
121
+ ## Frozen design (current spec)
122
+
123
+ | Aspect | Decision | Why |
124
+ | :--- | :--- | :--- |
125
+ | **Algorithm** | byte-level BPE, `unk_token=None` , all 256 bytes seeded | never an UNK in 10 years any script/emoji/code round-trips |
126
+ | **Normalizer** | NFC (never NFKC) | canonical Indic forms; NFKC would destroy , full-width, code |
127
+ | **Pre-tokenizer** | **GPT-4o (o200k) regex** via `Split(Regex)` → `ByteLevel(use_regex=False)` | its letter classes include `\p{M}` → Indic vowel-signs/viramas stay glued to the consonant (GPT-2/cl100k/Llama-3 split them) |
128
+ | **Digits** | individual ( `\p{N}` ) | stable arithmetic; CamelCase also splits (good for code) |
129
+ | **Post-processor** | `ByteLevel(trim_offsets=True)` | correct offsets for training pipelines |
130
+ | **Specials** | 32 named + reserved (power-of-two budget) | learned-merge count stays exact; reserved slots are promotable |
131
+ | **max_token_length** | 32 bytes (~10 Indic chars) | real Dravidian words form, no giant overfit tokens |
132
+ | **min_frequency** | 2 | don't prune rare South-Indian syllable merges |
133
+
134
+ ### Vocab profiles ( `vocab_size` = 256 bytes + 32 named + reserved + learned ):
135
+
136
+ | profile | vocab_size | reserved | learned | use |
137
+ | :--- | :--- | :--- | :--- | :--- |
138
+ | 64K | 65,536 | 992 | 64,256 | **1B–4B models** (embedding tax acceptable) |
139
+ | 128K | 131,072 | 2,016 | 128,768 | **7B+ models** (flagship; multilingual/code headroom) |
140
+
141
+ **Freeze policy (per the review):** use **64K for 1B–4B, 128K for 7B+**. At `d_model=2048` a 131,072 vocab is ~268M tied-embedding params vs ~134M for 64K — a heavy tax on a 1B model.
142
+
143
+ **Corpus** (40% South-Indian, scales to `--gb` ): South-Indian 40% · code 17% (StarCoderData, 15 languages, license **review-tagged**) · english 10% · other-Indic 8% (hi/bn/gu/mr/pa/or) · european 5% · more-european 3.5% (el/tr/pl/nl/sv/ka/hy) · SEA 3.5% (th/vi/id/km/my/lo) · cjk 4.5% · semitic 3.8% (ar/fa/ur/he) · cyrillic 2.5% · african 1.5% (sw/am/yo/ha) · coverage 0.5% (bo/si) · math 1.5%. **26 scripts, ~40 languages.** Every bucket is coverage-gated. `--gb N` scales to exactly N GB.
144
+
145
+ ## Professor review (2026-06-26) resolution
146
+
147
+ | Blocker | Status |
148
+ | :--- | :--- |
149
+ | Stale 64K artifact, not from current spec | quarantined ( `STALE_DO_NOT_FREEZE.txt` ); rebuild required |
150
+ | Not HF/vLLM/TGI directory-ready; pad/eos None | ✅ full sidecars + bos/eos/pad now emitted |
151
+ | Model configs `vocab_size` 64000/128000 65536/131072 | ✅ fixed in all 8 FORGE configs |
152
+ | Packer uses `uint32` at vocab 65536 (fits uint16) | ✅ condition < 65536 → <= 65536 (3 sites in `forge.py`) |
153
+ | Corpus not universal | expanded 12 26 scripts, ~25 languages |
154
+ | Cleaning strips ZWJ/ZWNJ | now preserved (Indic conjuncts, Persian/Urdu, emoji) |
155
+ | Dataset revisions not pinned | ✅ `revision` plumbing + `manifest.json` corpus sha256 anchor |
156
+ | License safety asserted, not enforced | ✅ per-source `license` tags + manifest audit |
157
+ | `stage_extend` breaks reserved-slot promise | ✅ new `stage_promote` (size FIXED); `extend` clearly labeled vocab-growth |
158
+ | Smoke gate masked by `... or True` | `_smoke_gate` aborts the build on failure |
159
+ | No per-language/domain fertility report | `fertility_report.json` (23 language + domain probes) |
160
+ | 64K vs 128K guidance | ✅ documented freeze policy (64K ≤ 4B, 128K ≥ 7B) |
161
+ | Rebuild both on one pinned corpus; emit reports | ⌛ run the lock-gated freeze on the rented box ( `--vocab 64K,128K --gb 240 --require-lock` ) |
162
+
163
+ ## Professor review #3 (2026-06-26)final hardening
164
+
165
+ | Blocker | Status |
166
+ | :--- | :--- |
167
+ | No built artifact to validate ( `runs/` absent) | ⌛ run the lock-gated freeze on the rented box |
168
+ | 45 source revisions unpinned (resolved only post-build) | ✅ `--lock -> sources.lock.json` (60/60 pinned) *before* download; `--require-lock` gates the build |
169
+ | Coverage gate only on South-Indian @ 50% | ✅ EVERY bucket gated (default 60%, **required 85%**, per-bucket `min_frac` overrides) |
170
+ | Code license `mixed-github(review)` | swapped to permissive `bigcode/starcoderdata` (gated, HF_TOKEN); codeparrot kept as a commented dev fallback |
171
+ | `stage_promote` leaves sidecars to manual edit | auto-syncs `tokenizer_config.json` + `special_tokens_map.json` + canonical `tokenizer.json` |
172
+ | Eval too small (23 one-sentence probes) | ✅ `--eval` : held-out streamed corpora, per-language bytes/token + tokens/word vs cl100k/o200k/Llama-3/Qwen/Gemma/Sarvam |
173
+ | *added:* Urdu absent from corpus | ✅ `urd_Arab` in semitic bucket + eval |
174
+ | *added:* ZWJ-emoji only tested non-ZWJ | ✅ ZWJ probe in smoke + eval domains |
175
+
176
+ ## Professor review #4 (2026-06-26) — resume safety, exact sizing, honest license
177
+
178
+ | Finding | Status |
179
+ | :--- | :--- |
180
+ | Reference corpus 60 GB but sources sum to 60.5 GB ( `--gb 240` 242) | `REFERENCE_TOTAL_GB` auto-computed from BUCKETS → `--gb N` = exactly N GB |
181
+ | `.done` marker written *before* the coverage gateresume can skip a bad bucket forever | floor checked *before* the marker; final gate clears markers of under-filled buckets so resume re-downloads (validated with a stubbed streamer) |
182
+ | Code tagged `permissive` without a stronger filter | ✅ relabeled `permissive(bigcode-filtered; review)` ; comment documents per-file-license filtering for a hard freeze |
183
+ | No built artifacts to smoke-test | ⌛ unchanged — run the build on the rented box |
184
+
185
+ # CHANGELOG (newest first always appended)
186
+
187
+ ## 2026-06-26 — Professor-loop pre-freeze review (gpt-5.5 reviewer, auto-logged)
188
+
189
+ A two-brain refinement loop hardens `asterizer.py` round by round: **worker** = the build author, **reviewer** = gpt-5.5 via `test1/auto_refine_loop.py` (ARM proxy). Each round sends the summary + full source, gets a JSON verdict, and applies fixes. The reviewer's #1 blocker every round is "no built artifacts exist", so `APPROVED` requires actually running the 240 GB build — the code/gate hardening below is what the loop produced. `test1/professor_review.py` appends each round to the table below automatically (logged here in the CHANGELOG, no separate log files).
190
+
191
+ | Round | UTC | Verdict | Issues | Pros |
192
+ | :--- | :--- | :--- | :--- | :--- |
193
+ | 5 | 2026-06-26T18:18:2Z | NEEDS_WORK | 7 | 6 |
194
+ | 4 | 2026-06-26T22:42Z | NEEDS_WORK | 8 | 8 |
195
+ | 3 | 2026-06-26T22:34Z | NEEDS_WORK | 11 | 8 |
196
+ | 2 | 2026-06-26T22:20Z | NEEDS_WORK | 8 | 8 |
197
+ | 1 | 2026-06-26T21:59Z | NEEDS_WORK | 9 | 6 |
198
+
199
+ Fixes applied across rounds (all in `asterizer.py` , validated offline):
200
+
201
+ * **R1:** `license_gate` (`--allow-license-review`); config-fingerprint checkpoints; exact `_gb_tag` run-dir keys; shuffled sampling + `_sample_digest.json` ; hash-based held-out split written to `raw/heldout/*.jsonl` ; smoke decodes with `skip_special_tokens=False` + special-literal cases; `--extend` gated behind `ASTERIZER_EXPERIMENTAL` .
202
+ * **R2 (real bugs caught):** per-bucket `.done` markers store the fingerprint (stale corpus can't be reused); the post-clean gate runs even on resume (was bypassable). Plus per-source coverage floor, eval-threshold freeze gate, whole-dir `SHA256SUMS.txt` , manifest env + `NOTICE.txt` .
203
+ * **R3:** `eval-gate-bypass-on-resume` fixed (freeze folded into the tokenizer fingerprint); `run_stage` validates expected outputs exist; vocab-conformance gate; lock inventory check; provenance copied into the tokenizer dir; `promote` writes `promotions.json` + `spec_hash` before checksums.
204
+ * **R4 (open):** remaining asks are stricter-enforcement/operational — per-file SPDX, corpus-hash checkpoint verification, holdout-after-cleaning, dependency-version refusal, full source-tuple lock match, and (always) building the real artifacts.
205
+
206
+ ## 2026-06-26 (round 4) — Resume safety + exact sizing + honest license (review #4)
207
+
208
+ ### 1. Coverage gate no longer trappable on resume
209
+
210
+ * **Before:** each bucket's `.done` marker was written *before* the coverage gate ran, so an under-filled (e.g. gated/failed) bucket got checkpointed and was skipped on every resume while the gate kept failing — a permanent fail loop.
211
+ * **After:** the floor is checked *before* the marker, so an under-filled bucket is never checkpointed; the final gate also clears the marker of any bucket under floor so a resume re-downloads it. Validated with a stubbed streamer (the bad bucket re-downloads and passes on the second run).
212
+
213
+ ### 2. Exact corpus sizing
214
+
215
+ * **Before:** `REFERENCE_TOTAL_GB = 60` but the source quotas summed to 60.5 (Urdu added +0.5), so `--gb 240` actually scaled to ~242 GB.
216
+ * **After:** `REFERENCE_TOTAL_GB` is recomputed as the exact sum of all source quotas, so `--gb N` scales to exactly N GB and never drifts when sources change.
217
+
218
+ ### 3. Honest code license tag
219
+
220
+ * **Before:** StarCoderData sources were tagged `permissive` an upstream claim, not a filter we ran.
221
+ * **After:** tagged `permissive(bigcode-filtered; review)` ; the bucket comment documents that a hard commercial freeze should accept the upstream filter explicitly or filter on a per-file `license` column (e.g. the-stack-dedup). Surfaced in `manifest.json` + `sources.lock.json` .
222
+
223
+ ## 2026-06-26 (round 3) — Final hardening (professor review #3)
224
+
225
+ ### 1. Pre-resolved source lockfile ( `--lock` `sources.lock.json` )
226
+
227
+ * **Before:** dataset commit SHAs were resolved into `manifest.json` *after* the build.
228
+ * **After:** `--lock` resolves every source's HF commit SHA + license decision into `sources.lock.json` *before* download; the build pins `load_dataset(revision=...)` from it and `--require-lock` aborts unless it is fully pinned. The 240 GB pull is now reproducible by construction.
229
+
230
+ ### 2. Coverage floors on EVERY bucket
231
+
232
+ * **Before:** only the South-Indian bucket was gated, at 50% of target.
233
+ * **After:** every bucket must hit a floor (default 60%, **required 85%**, low-resource buckets a smaller explicit `min_frac` ) or the build aborts — a silent source/auth failure can't gut any script.
234
+
235
+ ### 3. Permissive-only code (white-label clean)
236
+
237
+ * **Before:** `codeparrot-clean` (Python, mixed GitHub licenses, tagged `mixed-github(review)` ).
238
+ * **After:** `bigcode/starcoderdata` (already license-filtered to permissive; 15 languages; gated `HF_TOKEN` ). codeparrot retained as a clearly-commented dev fallback. `the-stack-v2-dedup` stores content as S3 pointers → not plain-streamable, so StarCoderData is the practical pick.
239
+
240
+ ### 4. `stage_promote` keeps the whole HF dir in lockstep
241
+
242
+ * **Before:** it edited the tokenizer JSON and told you to update sidecars by hand.
243
+ * **After:** it auto-updates `tokenizer_config.json` + `special_tokens_map.json` and re-saves the canonical `tokenizer.json` — IDs and vocab size still unchanged. Validated 311→311, sidecars synced.
244
+
245
+ ### 5. Real eval harness ( `--eval` )
246
+
247
+ * **Before:** `fertility_report.json` = 23 one-sentence probes.
248
+ * **After:** per-language **held-out** corpora (fresh dataset streams, or local `--evaldir` files) + domain probes (legal/biomed/finance/yaml/url/diff/**ZWJ-emoji**/noisy-web), measured as bytes/token + tokens/word head-to-head against cl100k, o200k, Llama-3, Qwen, Gemma, Sarvam. Runs after each freeze build (non-fatal) and standalone via `--eval` .
249
+
250
+ ### 6. Urdu + ZWJ coverage
251
+
252
+ * Added `urd_Arab` to the corpus (semitic bucket) and an Urdu probe; added a real ZWJ-emoji family ( 👨‍👩‍👧 ) to smoke + eval so the preserved U+200D is actually exercised.
253
+
254
+ ## 2026-06-26 (round 2) Freeze-gate hardening (professor review #2)
255
+
256
+ ### 1. Smoke gate now refuses stale / incomplete artifacts
257
+
258
+ * **Concept:** a freeze gate that passes a stale artifact is worse than none.
259
+ * **Before:** the old 64K artifact still smoke-PASSED despite GPT-2 pretokenization, 24 specials, 1000 reserved, and no sidecars.
260
+ * **After:** `stage_smoke` fails if any HF sidecar is missing, a `STALE_*` marker exists in the dir/parent, named specials ≠ 32, or reserved count ≠ the profile's. Verified: old 64K now FAILS with all 6 reasons; fresh builds still PASS.
261
+
262
+ ### 2. Required-bucket coverage gate
263
+
264
+ * **Concept:** a silently-failed source must not gut the priority data.
265
+ * **Before:** source failures were non-fatal → coverage could collapse unnoticed.
266
+ * **After:** South-Indian bucket is required ; `stage_download` records actual per-source bytes ( `raw/_download_stats.json` ) and aborts if a required bucket is under `MIN_REQUIRED_FRAC` (50%) of target.
267
+
268
+ ### 3. Manifest records actual bytes + resolved dataset commit SHAs
269
+
270
+ * **Before:** `revision` plumbing existed but all sources were `None` → no real pinning; no actual bytes.
271
+ * **After:** `write_manifest` records `actual_bytes` per source and resolves each dataset's commit SHA via HfApi into `resolved_revision` . Copy `resolved_revision` → a source `revision` to hard-pin a rebuild. Corpus sha256 remains the primary anchor.
272
+
273
+ ### 4. Code license (open decision, not a hard blocker)
274
+
275
+ * `codeparrot-clean` is Python + mixed GitHub licenses. For a *tokenizer* (a statistical merge table, not redistributed code/weights) mixed-license training data is widely treated as non-infringing (GPT-4/Llama did the same). For maximum white-label cleanliness, set `HF_TOKEN` and swap the code bucket to a permissive subset ( `bigcode/the-stack-v2-dedup` ). The license is tagged `mixed-github(review)` and surfaced in `manifest.json` so it's a conscious choice.
276
+
277
+ # 2026-06-26 — Freeze-readiness (professor review)
278
+
279
+ ## 1. Indic ZWJ/ZWNJ preservation
280
+
281
+ * **Concept:** zero-width joiners are semantic, not noise.
282
+ * **Before:** `ZERO_WIDTH` stripped U+200C (ZWNJ) and U+200D (ZWJ).
283
+ * **After:** both preserved; only ZWSP/BOM/WordJoiner/SoftHyphen stripped.
284
+ * **Why:** ZWNJ/ZWJ control Indic conjunct formation, Persian/Urdu orthography, and emoji ZWJ-sequences. Stripping them silently corrupts spelling and breaks emoji.
285
+
286
+ ## 2. Smoke test is a HARD freeze gate
287
+
288
+ * **Concept:** a failed validation must stop the freeze.
289
+ * **Before:** `lambda: (stage_smoke(...) or True)` stage marked done even on FAIL.
290
+ * **After:** `_smoke_gate()` calls `sys.exit(...)` on failure; stage is not checkpointed.
291
+ * **Why:** a frozen-10-year artifact cannot be allowed to ship if round-trip/compat fails.
292
+
293
+ ## 3. Reserved-slot promotion vs vocab growth (split)
294
+
295
+ * **Concept:** the reserved-slot promise = add control tokens WITHOUT changing IDs or size.
296
+ * **Before:** `stage_extend` appended tokens (grew `vocab_size` ), violating the promise.
297
+ * **After:** new `stage_promote` renames free `<|reserved_i|>` slots in place (IDs + size UNCHANGED); `stage_extend` kept but loudly labeled as vocab-growth (needs embedding resize + continue-pretrain). New `--promote` / `--extend` CLI.
298
+ * **Why:** promoting a reserved slot must never shift a learned-merge ID. Validated: 907 → 907.
299
+
300
+ ## 4. Dataset revision pinning + license tags + manifest
301
+
302
+ * **Concept:** reproducibility and commercial-safety must be auditable, not asserted.
303
+ * **Before:** `load_dataset` streamed by name (no revision); no license metadata.
304
+ * **After:** per-source `license` + optional `revision` ; `manifest.json` records every source, license, revision, seed, and the **corpus sha256** (the true reproducibility anchor).
305
+ * **Why:** a frozen artifact needs provenance; re-training from the same `corpus.jsonl` is deterministic, so its hash pins the build.
306
+
307
+ ## 5. Corpus universality (12 → 26 scripts)
308
+
309
+ * **Concept:** "best in every language" needs every major script present so merges form.
310
+ * **Before:** 9 buckets, ~12 scripts.
311
+ * **After:** 13 buckets, 45 sources, 26 scripts — added Gujarati/Marathi/Punjabi/Odia, Thai, Vietnamese, Indonesian, Khmer, Burmese, Lao, Greek, Turkish, Polish, Dutch, Swedish, Georgian, Armenian, Swahili, Amharic, Yoruba, Hausa, Tibetan, Sinhala. South-Indian stays 40%.
312
+ * **Why:** byte-level guarantees no UNK, but good *fertility* needs the script in the training corpus. Missing-config sources fail non-fatally (logged), so this is safe.
313
+
314
+ ## 6. Per-language/script/domain fertility report
315
+
316
+ * **Concept:** freeze evidence must be measurable per language and domain.
317
+ * **Before:** only an aggregate corpus fertility number.
318
+ * **After:** `fertility_report.json` with tokens, bytes/token, tokens/word for 23 probes (all scripts + legal/biomed/finance/social-code-mixed/code-diff).
319
+ * **Why:** the review requires held-out fertility per language/script/domain before freeze.
320
+
321
+ ## 7. FORGE (cross-repo) exactness
322
+
323
+ * **Concept:** vocab size must be identical across tokenizer, configs, packer, model cards.
324
+ * **Before:** configs `vocab_size` = 64000/128000; packer `uint16` if vocab < 65536 (so the real 65536 vocab wasted `uint32` ).
325
+ * **After:** all 8 configs → 65536 / 131072; packer condition <= 65536 (65535 + uint16 max, fits).
326
+ * **Why:** a 64000 vs 65536 mismatch corrupts embedding sizing; `uint32` at 64K doubles token-bin storage for nothing.
327
+
328
+ ## 8. Stale artifacts quarantined
329
+
330
+ * **Before:** `runs/32K_6gb` and `runs/64K_12GB` looked freezable but predate every change.
331
+ * **After:** `STALE_DO_NOT_FREEZE.txt` in each; real freeze rebuilds on the rented box.
332
+
333
+ # 2026-06-26 — SOTA audit (pre-freeze quality)
334
+
335
+ ## A. o200k Indic-aware pre-tokenizer (the critical fix)
336
+
337
+ * **Before:** `ByteLevel(use_regex=True)` = GPT-2 regex; `\p{L}+` excludes `\p{M}+` , so Indic marks split off the consonant at the pre-token boundary → BPE cannot merge syllables.
338
+ * **After:** **GPT-4o o200k regex** (letter classes include `\p{M}` ) via `Split(Regex)` + `ByteLevel` .
339
+ * **Why / proof:** ಕನ್ನಡ 3→1 pre-token, తెలుగు 6→1, ಅತ್ಯಾಧುನಿಕ 9→1; tiny-build fertility Kannada 4.33→1.17, Tamil 7.0→1.80, Telugu 6.6→1.80, Malayalam 8.0→2.50.
340
+
341
+ ## B. Special tokens 24 → 32 (append-only IDs 24–31)
342
+
343
+ * Added `<|im_start|>`/`<|im_end|>` (ChatML), `<|endofprompt|>` , `<|repo_name|>`/`<|file_sep|>` (repo-level code), `<|image_start|>`/`<|image_end|>`/`<|image_pad|>` (vision patches).
344
+ * Reserved reduced by 8 per profile so **named+reserved** stays a power of two → **learned merges unchanged** (128K still 128,768).
345
+
346
+ ## C. Complete HF directory + ByteLevel post-processor
347
+
348
+ * Emits `tokenizer.json` (canonical name AutoTokenizer needs), `tokenizer_config.json` , `special_tokens_map.json` with a ChatML `chat_template` ; `unk_token=None` , `bos/eos/pad` declared.
349
+ * Compat test now loads the dir via `AutoTokenizer.from_pretrained` and renders the chat template; gates PASS/FAIL.
350
+
351
+ # 2026-06-25 — Shared-corpus refactor + UX
352
+
353
+ * Download/clean/corpus run **once** into `runs/_data_<gb>gb/` ; 64K and 128K train from the same corpus. `--vocab 64K,128K` comma list. Download progress bar with %/rate/ETA.
354
+ * Saturation analysis: tokenizer quality plateaus ~150–240 GB; >300 GB is wasted spend.
355
+
356
+ # Build it (rented high-RAM CPU box, no GPU)
357
+
358
+ The full 240 GB build needs ~150–200 GB RAM peak (BPE holds word counts in RAM). Rent a CPU box with **≥ 256–386 GB RAM**, ~1 TB disk. Then:
359
+
360
+ ```bash
361
+ export HF_TOKEN=... # gated permissive code (starcoderdata)
362
+ python3 asterizer.py --lock # pin source SHAs -> sources.lock.json (commit it)
363
+ python3 asterizer.py --vocab 64K,128K --gb 240 --yes --require-lock
364
+ ```
365
+
366
  Freeze checklist before shipping: `sources.lock.json` fully pinned · every bucket passed its coverage floor · smoke PASS (gate) · `fertility_report.json` reviewed per language *and* vs *baselines* · `manifest.json` licenses audited (all permissive/open) · `spec_hash.txt` recorded · FORGE `vocab_size` matches `tokenizer.get_vocab_size()`.