mlx-bun 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +362 -0
  3. package/THIRD_PARTY_LICENSES.md +41 -0
  4. package/bin/mlx-bun.mjs +32 -0
  5. package/docs/curve-designer.html +303 -0
  6. package/docs/design/adapters-end-to-end.md +201 -0
  7. package/docs/design/compat-cli-surface-design.md +227 -0
  8. package/docs/design/docs-reorg-plan.md +152 -0
  9. package/docs/design/hlg-sampling.md +340 -0
  10. package/docs/design/memory-system.md +339 -0
  11. package/docs/design/optimization_plan.md +344 -0
  12. package/docs/design/parallel-slots.md +515 -0
  13. package/docs/design/runtime-isolation.md +247 -0
  14. package/docs/design/segmented-backward-training.md +508 -0
  15. package/docs/investigations/chunk-finetune-experiment.md +84 -0
  16. package/docs/investigations/curve-bisector-routing.md +123 -0
  17. package/docs/investigations/curve-runs/bisector-route.json +98 -0
  18. package/docs/investigations/curve-runs/bisector-trace.json +1393 -0
  19. package/docs/investigations/curve-runs/curve-terrain.json +1179 -0
  20. package/docs/investigations/curve-runs/curve-terrain.svg +42 -0
  21. package/docs/investigations/curve-terrain.html +105 -0
  22. package/docs/investigations/expert-offload-single-user-moe.md +292 -0
  23. package/docs/investigations/hlg-ab.html +34 -0
  24. package/docs/investigations/hlg-explorer.html +238 -0
  25. package/docs/investigations/hlg-figs/cliff.svg +1 -0
  26. package/docs/investigations/hlg-figs/cross.svg +1 -0
  27. package/docs/investigations/hlg-figs/edges.svg +1 -0
  28. package/docs/investigations/hlg-figs/k20-grids.svg +1 -0
  29. package/docs/investigations/hlg-figs/k20-peaks.svg +1 -0
  30. package/docs/investigations/hlg-figs/lw-curve.svg +1 -0
  31. package/docs/investigations/hlg-figs/terrain.svg +1 -0
  32. package/docs/investigations/hlg-report.html +262 -0
  33. package/docs/investigations/hlg-runs/hlg-ab.json +149 -0
  34. package/docs/investigations/hlg-runs/hlg-blind-prompts.md +87 -0
  35. package/docs/investigations/hlg-runs/hlg-blind.json +107 -0
  36. package/docs/investigations/hlg-runs/hlg-cliff.json +197 -0
  37. package/docs/investigations/hlg-runs/hlg-cross.json +505 -0
  38. package/docs/investigations/hlg-runs/hlg-edge.json +388 -0
  39. package/docs/investigations/hlg-runs/hlg-eval1.json +25 -0
  40. package/docs/investigations/hlg-runs/hlg-frontier.json +86 -0
  41. package/docs/investigations/hlg-runs/hlg-grid.json +242 -0
  42. package/docs/investigations/hlg-runs/hlg-grid2.json +343 -0
  43. package/docs/investigations/hlg-runs/hlg-lw-coarse.json +110 -0
  44. package/docs/investigations/hlg-runs/hlg-map.json +383 -0
  45. package/docs/investigations/hlg-runs/run0-original.log +159 -0
  46. package/docs/investigations/hlg-runs/runA-recommended.log +131 -0
  47. package/docs/investigations/hlg-runs/runAA-cliff-cpm5.log +26 -0
  48. package/docs/investigations/hlg-runs/runAB-grid2-e4b.log +18 -0
  49. package/docs/investigations/hlg-runs/runAC-peak-e4b-partial.log +25 -0
  50. package/docs/investigations/hlg-runs/runAD-ab-samples.log +8 -0
  51. package/docs/investigations/hlg-runs/runAE-edge-e4b.log +51 -0
  52. package/docs/investigations/hlg-runs/runAF-logit-calibration.log +10 -0
  53. package/docs/investigations/hlg-runs/runAG-eval-config2.log +16 -0
  54. package/docs/investigations/hlg-runs/runB-gain-variants.log +192 -0
  55. package/docs/investigations/hlg-runs/runC-pivots.log +162 -0
  56. package/docs/investigations/hlg-runs/runD-oetf.log +132 -0
  57. package/docs/investigations/hlg-runs/runE-eotf.log +162 -0
  58. package/docs/investigations/hlg-runs/runF-shaper-working.log +86 -0
  59. package/docs/investigations/hlg-runs/runG-shaper-sweep.log +101 -0
  60. package/docs/investigations/hlg-runs/runH-wsweep.log +176 -0
  61. package/docs/investigations/hlg-runs/runI-asweep.log +176 -0
  62. package/docs/investigations/hlg-runs/runJ-knobmap.log +49 -0
  63. package/docs/investigations/hlg-runs/runK-frontier.log +19 -0
  64. package/docs/investigations/hlg-runs/runL-widemap.log +65 -0
  65. package/docs/investigations/hlg-runs/runM-frontier-emb.log +15 -0
  66. package/docs/investigations/hlg-runs/runN-verify.log +116 -0
  67. package/docs/investigations/hlg-runs/runO-frontier-seed5000.log +15 -0
  68. package/docs/investigations/hlg-runs/runP-grid-AxSm.log +15 -0
  69. package/docs/investigations/hlg-runs/runQ-grid-tgW.log +15 -0
  70. package/docs/investigations/hlg-runs/runR-blind-transcript.log +79 -0
  71. package/docs/investigations/hlg-runs/runS-cross-coherence.log +33 -0
  72. package/docs/investigations/hlg-runs/runT-cross-cpm5.log +33 -0
  73. package/docs/investigations/hlg-runs/runU-cross-12b.log +33 -0
  74. package/docs/investigations/hlg-runs/runV-lw-e4b.log +22 -0
  75. package/docs/investigations/hlg-runs/runW-lw-12b.log +22 -0
  76. package/docs/investigations/hlg-runs/runX-lw-cpm5.log +22 -0
  77. package/docs/investigations/hlg-runs/runY-cliff-e4b.log +26 -0
  78. package/docs/investigations/hlg-runs/runZ-cliff-12b.log +26 -0
  79. package/docs/investigations/hlg-sampling-investigation.md +970 -0
  80. package/docs/investigations/lab-build-journal.md +157 -0
  81. package/docs/investigations/pi-builtin-investigation.md +308 -0
  82. package/docs/investigations/starter-model-port-handoff.md +323 -0
  83. package/docs/planning/IDEAS.md +26 -0
  84. package/docs/planning/PRODUCT_ROADMAP.md +426 -0
  85. package/docs/planning/ResearchTopics.md +119 -0
  86. package/docs/planning/chunk-task-roadmap.md +77 -0
  87. package/docs/planning/journal.md +155 -0
  88. package/docs/reference/distribution.md +121 -0
  89. package/docs/reference/embedding.md +168 -0
  90. package/docs/reference/library-api.md +153 -0
  91. package/docs/reference/server-api.md +224 -0
  92. package/docs/reference/server-config.md +243 -0
  93. package/docs/segmented-backward-handoff.md +148 -0
  94. package/package.json +68 -0
  95. package/src/anthropic.ts +491 -0
  96. package/src/chat-template.ts +186 -0
  97. package/src/cli.ts +1075 -0
  98. package/src/config.ts +229 -0
  99. package/src/curve-sampler.ts +122 -0
  100. package/src/dataset/generators.ts +1087 -0
  101. package/src/dataset/index.ts +12 -0
  102. package/src/dataset/job.ts +81 -0
  103. package/src/dataset/llm.ts +71 -0
  104. package/src/dataset/registry.ts +528 -0
  105. package/src/download.ts +283 -0
  106. package/src/eval/README.md +86 -0
  107. package/src/eval/kl-prompts.ts +29 -0
  108. package/src/eval/kl.ts +294 -0
  109. package/src/eval/quality-db.ts +92 -0
  110. package/src/eval/runner.ts +102 -0
  111. package/src/eval/score.ts +49 -0
  112. package/src/eval/tasks/bfcl.ts +500 -0
  113. package/src/eval/tasks/gsm8k.ts +85 -0
  114. package/src/eval/tasks/hashhop.ts +109 -0
  115. package/src/eval/tasks/humaneval.ts +252 -0
  116. package/src/eval/tasks/ifeval.ts +354 -0
  117. package/src/eval/tasks/mmlu.ts +145 -0
  118. package/src/evaldb.ts +199 -0
  119. package/src/expert-offload-build.ts +77 -0
  120. package/src/expert-offload.ts +61 -0
  121. package/src/expert-trace.ts +67 -0
  122. package/src/fit.ts +254 -0
  123. package/src/generate.ts +451 -0
  124. package/src/harness-pi.ts +177 -0
  125. package/src/hf-push.ts +628 -0
  126. package/src/index.ts +22 -0
  127. package/src/jobs/db.ts +139 -0
  128. package/src/jobs/index.ts +29 -0
  129. package/src/jobs/job-entry.ts +106 -0
  130. package/src/jobs/runner.ts +304 -0
  131. package/src/jobs/sse.ts +114 -0
  132. package/src/jobs/types.ts +58 -0
  133. package/src/kv-store.ts +185 -0
  134. package/src/lora.ts +314 -0
  135. package/src/md-modules.d.ts +7 -0
  136. package/src/mlx/array.ts +237 -0
  137. package/src/mlx/autograd.ts +267 -0
  138. package/src/mlx/checkpoint.ts +116 -0
  139. package/src/mlx/compile.ts +158 -0
  140. package/src/mlx/custom-vjp.ts +140 -0
  141. package/src/mlx/ffi.ts +433 -0
  142. package/src/mlx/metal-kernel.ts +130 -0
  143. package/src/mlx/ops.ts +707 -0
  144. package/src/mmap.ts +90 -0
  145. package/src/model/batched-mask.ts +204 -0
  146. package/src/model/batched-rotating.ts +300 -0
  147. package/src/model/compiled-decode.ts +681 -0
  148. package/src/model/factory.ts +27 -0
  149. package/src/model/fingerprint.ts +33 -0
  150. package/src/model/flash-attention.ts +674 -0
  151. package/src/model/fused-decode-kernel.ts +305 -0
  152. package/src/model/fused-geglu-kernel.ts +87 -0
  153. package/src/model/gemma4-base.ts +1616 -0
  154. package/src/model/gemma4.ts +1012 -0
  155. package/src/model/generated/gemma4-12b.ts +526 -0
  156. package/src/model/generated/gemma4-26b.ts +500 -0
  157. package/src/model/generated/gemma4-e4b.ts +757 -0
  158. package/src/model/generated/index.ts +18 -0
  159. package/src/model/minicpm5.ts +278 -0
  160. package/src/model/qwen3-delta.ts +224 -0
  161. package/src/model/qwen3_5.ts +429 -0
  162. package/src/model/support.ts +46 -0
  163. package/src/native-pack.ts +152 -0
  164. package/src/pi-provider.ts +95 -0
  165. package/src/pi-terminal.ts +264 -0
  166. package/src/pi-web.ts +924 -0
  167. package/src/preflight.ts +123 -0
  168. package/src/prompt-cache.ts +113 -0
  169. package/src/quantize/allocator.ts +627 -0
  170. package/src/quantize/calibration.ts +180 -0
  171. package/src/quantize/config-writer.ts +132 -0
  172. package/src/quantize/index.ts +57 -0
  173. package/src/quantize/job.ts +136 -0
  174. package/src/quantize/quantizer.ts +462 -0
  175. package/src/quantize/safetensors-writer.ts +171 -0
  176. package/src/quantize/sensitivity.ts +234 -0
  177. package/src/registry.ts +336 -0
  178. package/src/responses.ts +774 -0
  179. package/src/safetensors.ts +158 -0
  180. package/src/sampler.ts +517 -0
  181. package/src/serve/batch-scheduler.ts +362 -0
  182. package/src/serve/generation-gateway.ts +160 -0
  183. package/src/server.ts +1891 -0
  184. package/src/spec/drafter.ts +261 -0
  185. package/src/spec/generate.ts +221 -0
  186. package/src/status-page.html +497 -0
  187. package/src/tokenizer.ts +38 -0
  188. package/src/tool-call.ts +242 -0
  189. package/src/train/dataset.ts +461 -0
  190. package/src/train/export.ts +32 -0
  191. package/src/train/forward.ts +229 -0
  192. package/src/train/index.ts +43 -0
  193. package/src/train/job.ts +148 -0
  194. package/src/train/lora-params.ts +194 -0
  195. package/src/train/loss.ts +342 -0
  196. package/src/train/merge.ts +195 -0
  197. package/src/train/optimizer.ts +176 -0
  198. package/src/train/rank.ts +101 -0
  199. package/src/train/segmented.ts +520 -0
  200. package/src/train/trainer.ts +600 -0
  201. package/src/tui.ts +161 -0
  202. package/src/vision/embedder.ts +168 -0
  203. package/src/vision/preprocess.ts +247 -0
  204. package/src/vision/prompt.ts +158 -0
  205. package/src/vision/siglip.ts +599 -0
  206. package/src/web/app.html +2471 -0
  207. package/src/web/skills/web-research/SKILL.md +44 -0
  208. package/src/web/skills.ts +59 -0
  209. package/src/web-tools.ts +426 -0
  210. package/src/weights.ts +91 -0
@@ -0,0 +1,970 @@
1
+ # Investigation: HLG sampling — a piecewise tone curve on the logits
2
+
3
+ *2026-06-14. Question: can the structure of a piecewise nonlinear transfer
4
+ function (HLG, the HDR transfer function) be transplanted onto a logit
5
+ distribution as a sampling method, and if so, where do you place its pivot
6
+ (middle grey)? Design contract: [docs/design/hlg-sampling.md](../design/hlg-sampling.md).
7
+ Code: `src/sampler.ts` (`applyHlg`, `makeSampler`). Harness:
8
+ `scripts/hlg-compare.ts`. Model under test: `gemma-4-e4b-it-OptiQ-4bit` on the
9
+ M4 Pro.*
10
+
11
+ > **Outcome.** Two passes. **Pass 1** (a *parametric* HLG-shaped curve, §1–9):
12
+ > top-anchored pivot holds; entropy/median collapse into word-salad because a
13
+ > permissive (lifting) toe inflates the 262k-vocab tail. **Pass 2** (the *literal*
14
+ > HLG transfer system, then the user's exact `HLGShaper`, §10): the full chain
15
+ > transplants onto sampling, but only with **two adaptations the source domain
16
+ > doesn't need** — (1) **windowed-anchor input** (LM logits are a spike-plus-tail,
17
+ > not an image's tonal spread, so min-max over the vocab collapses every candidate
18
+ > into the shoulder and elevates deep-tail junk in the mid), and (2) **the toe
19
+ > inverted** (a sampler crushes shadows; HLG describes them). With those, the
20
+ > `HLGShaper` is a **working, coherent replacement sampler** (e4b, W=5 /
21
+ > out_scale=18) exposing **four orthogonal knobs** — `s_m` (mid sharpness) · `A`
22
+ > (shoulder / confidence) · `x_floor`+toe (tail gate) · `L_W` (global γ) — where
23
+ > temperature gave one. Method note that recurs throughout: **distinct-2 rewards
24
+ > garbage**; read the text.
25
+ >
26
+ > **Final verdict (§14, after TWO premature verdicts were each corrected).** Pass 1
27
+ > concluded "control, not dominance" — a sweep-range + metric artifact (A swept
28
+ > only [0.2,0.8]; distinct-2 at small N). Widening every knob (runL) + self-BLEU
29
+ > **+ a semantic embedding metric** at N=10 (runM) + **reading the text** (runN)
30
+ > *looked like* a reversal: at A=0.01, s_m=0.05, self-BLEU 0.783 vs 0.672, text
31
+ > verified genuinely diverse and correct. **But the fresh-seed repeat (runO) did
32
+ > not replicate it** — the default's own self-BLEU swung +0.083 across seeds and at
33
+ > seed 5000 edged above the HLG cell, so N=10 variance (~0.08) swamps the effect.
34
+ > **Honest landing: HLG's loose-corner cells are *comparable* to the default on
35
+ > diversity at equal coherence — within N=10 noise — with at most a small,
36
+ > consistent embedding edge below the measurement resolution. Neither "dominance"
37
+ > nor "negative" survives; it's a wash at this N.** Meta-result: the fresh-seed
38
+ > repeat caught BOTH premature verdicts within one run each — sweep wide, use ≥2
39
+ > metrics, repeat seeds, read the text.
40
+
41
+ ## TL;DR
42
+
43
+ - **The transplant is real and cheap.** One piecewise curve (`applyHlg`),
44
+ model-agnostic, O(V) per token, replaces the temperature scaling step. Bit-exact
45
+ degeneracy to temperature is the safety anchor; flag-off is byte-identical.
46
+ - **HLG is a replacement sampler**, not a layer: `if (hlg.enabled)` → the curve
47
+ is the whole post-logits step; `else` → top_p, top_k, temperature (unchanged).
48
+ - **Pivot = top-anchored.** Of the three middle-grey methods, only top-anchored
49
+ survives as a drop-in replacement. Entropy and median place the pivot near the
50
+ peak on confident distributions, dumping the whole distribution into the
51
+ lifting toe → near-uniform over 262k tokens → garbage.
52
+ - **Mild positive signal where it should appear:** HLG raises lexical diversity
53
+ on open-ended prompts (brainstorm 0.78 → 0.88, continuation 0.75 → 0.86) while
54
+ leaving the confident factual answer untouched (0.30). The concrete win: it
55
+ broke e4b out of always opening the paperclip list with "SIM Card Ejector".
56
+ - **Method lesson:** distinct-2 rewards incoherence; entropy/median scored
57
+ ~1.0 *because* they were broken. Diversity metrics must be paired with a
58
+ coherence gate (perplexity / NLL under the base recipe).
59
+
60
+ ---
61
+
62
+ ## 1. The idea — a cross-domain transplant
63
+
64
+ Temperature is a single global slope on the logits (`logit / T`). Its limitation
65
+ is a coupling: the only way it loosens the model's grip on the top token is by
66
+ raising `T`, which simultaneously lifts the tail. One number can't move two
67
+ regions independently.
68
+
69
+ Nonlinear transfer functions in signal/color encoding solve the analogous
70
+ problem with a **piecewise** curve that shapes the low, middle, and high range
71
+ under separate constraints. HLG (Hybrid Log-Gamma, ARIB STD-B67 / ITU-R BT.2100)
72
+ is the specific structure lifted here: a gamma segment for the lower range and a
73
+ log segment for the upper range, joined at a breakpoint. A logit distribution is
74
+ another value distribution, so the apparatus carries over. Whether it *helps* is
75
+ an empirical question — settled by measurement in this domain, not by the
76
+ structure's pedigree in its original one.
77
+
78
+ Mapped onto the three regions of a token distribution:
79
+
80
+ - **High-probability region** (confident tokens) → **shoulder**: roll the slope
81
+ off so the top compresses toward its neighbours ("won't be so fixed on that
82
+ answer").
83
+ - **Mid-probability region** (novelty/interest) → **gain**: control the slope.
84
+ - **Low-probability tail** → **toe**: shape it smoothly rather than hard-clipping
85
+ (top_p/top_k) or inflating it (high temperature).
86
+
87
+ ---
88
+
89
+ ## 2. The curve
90
+
91
+ Operate in log-probability space. Let `ℓ_i` be each token's log-prob and `μ` the
92
+ pivot. With centered coordinate `z = ℓ_i − μ`, remap with a C¹ log-toe /
93
+ linear-mid / log-shoulder curve:
94
+
95
+ ```
96
+ ⎧ −m·w − m·β_t·ln(1 + (−z − w)/β_t) z < −w (toe / shadows)
97
+ g(z) = ⎨ m·z |z| ≤ w (gain / mids)
98
+ ⎩ m·w + m·β_h·ln(1 + ( z − w)/β_h) z > w (shoulder / highlights)
99
+ ```
100
+
101
+ Output logits `ℓ'_i = g(z_i)`, then the existing categorical draw. Properties:
102
+
103
+ - **Monotone in ℓ** ⇒ ranking-preserving (argmax invariant). It's a contrast/tone
104
+ operation, not a re-ranker.
105
+ - **Slope** is `m` at the pivot and decays as `m·β/(β + d)` a distance `d` past
106
+ each knot — continuous, always positive.
107
+ - **Degeneracy = safety anchor:** `m=1`, rolloff off ⇒ `g(z)=z` (identity,
108
+ bit-exact); rolloff off, any `m` ⇒ `g(z)=m·z` (temperature `T=1/m`, bit-exact).
109
+ - **`-inf` safe:** a masked token lands in the toe branch and stays `-inf`.
110
+
111
+ Knobs (all in nats): `gain` m (mid slope; folds from temperature as m=1/T by
112
+ default, explicit override allowed), `width` w (mid half-width), `shoulder` β_h,
113
+ `toe` β_t, plus the pivot and its offset.
114
+
115
+ ### The critical, non-obvious property: the toe is *permissive*
116
+
117
+ "Don't crush the blacks" means the toe slope is **less** than linear, so deep-tail
118
+ tokens are pulled *up* toward a floor at `−m·w` rather than suppressed. This is
119
+ the opposite of top_p/top_k (hard cut) and gentler than temperature. It is the
120
+ mechanism behind the central finding below: as a replacement for the hard
121
+ cutoffs, the toe under-suppresses the tail, and only the pivot's distance below
122
+ the peak keeps the top token dominant.
123
+
124
+ ---
125
+
126
+ ## 3. Architecture — a replacement sampler
127
+
128
+ `makeSampler` (`src/sampler.ts`) branches:
129
+
130
+ ```
131
+ if (hlg.enabled) → scaled = applyHlg(lp, params) // the whole methodology;
132
+ // toe does the tail control
133
+ else → top_p, then top_k, then mulScalar(1/T) // exactly what we used to do
134
+ ```
135
+
136
+ Mutually exclusive. When HLG is on, top_p/top_k are **not** applied — the smooth
137
+ toe is their replacement, not a layer on top. Greedy (`temperature 0`) returns
138
+ argmax in both branches (a monotone curve can't move the argmax), so HLG is a
139
+ no-op there by construction. Flag-off (`hlg` undefined) is byte-identical to the
140
+ prior sampler.
141
+
142
+ > Evolution note: earlier experiment runs (0, A, B below) were built before the
143
+ > clean replacement restructure — they either passed no cutoffs (so HLG ran
144
+ > alone by accident) or kept top_p/top_k under HLG (layering). Run C is the first
145
+ > true replacement test and is where the architecture was finalised.
146
+
147
+ ---
148
+
149
+ ## 4. Three pivots (middle grey)
150
+
151
+ The same curve, centered three ways (`hlgPivotBase` in `src/sampler.ts`), applied
152
+ to the full logprob vector:
153
+
154
+ 1. **`top`** — μ = ℓmax − `offset`. Middle grey a fixed number of nats below the
155
+ peak. One `max` reduction.
156
+ 2. **`entropy`** — μ = Σ p·ℓ = −H. The distribution's center of mass in tonal
157
+ space ("auto-exposure"). One dot product.
158
+ 3. **`median`** — μ = the logprob at the 50% cumulative-mass boundary
159
+ ("auto-levels" / histogram median). Reuses the sort top-p already does.
160
+
161
+ ---
162
+
163
+ ## 5. Implementation status
164
+
165
+ - **Piece 1** — pure `applyHlg(lp, params)` + degeneracy/monotonicity/`-inf`
166
+ tests. `src/sampler.ts`, `tests/hlg-sampling.test.ts`.
167
+ - **Piece 2** — wired into `makeSampler`; CLI flags `--hlg-sampling` +
168
+ `--hlg-width/-shoulder/-toe/-pivot-offset`; `ServerOptions.hlg`; per-request
169
+ `hlg` object on `ChatRequest` resolved by `resolveHlg` in `toOptions`.
170
+ - **Piece 4 (brought forward)** — all three pivot modes + the explicit `gain`
171
+ override; `HlgConfig.gain`/`pivot` widened. `--hlg-pivot` CLI flag still TODO.
172
+ - **Replacement architecture** — finalised (Section 3).
173
+ - Tests: **14/14 green**, tsc clean. Pure (no weights): bit-exact degeneracy to
174
+ temperature/identity, monotone + ranking-preserving, `-inf` safe, three pivots
175
+ monotone+finite+distinct, wiring neutrality (identity config ≡ plain
176
+ temperature, rolloff-on diverges).
177
+
178
+ Harness: `scripts/hlg-compare.ts` — runs a fixed prompt set × sampling patterns,
179
+ K samples each, reports distinct-2 (after stripping the shared chat-template
180
+ prefix) + unique-count + length, and prints the samples. The model's recommended
181
+ recipe is read from its `generation_config.json` (e4b: temp 1.0 · top_p 0.95 ·
182
+ top_k 64).
183
+
184
+ ---
185
+
186
+ ## 6. Experiments
187
+
188
+ All on `gemma-4-e4b-it-OptiQ-4bit`, K=4 samples/cell (greedy n=1), maxTokens 80,
189
+ seeds 1234–1237. distinct-2 = unique bigrams / total bigrams pooled across the K
190
+ samples; higher = more lexically varied (**but see the garbage caveat in Run C**).
191
+ Full transcripts in the appendices.
192
+
193
+ ### 6.1 Run 0 — the wrong baseline (Appendix A)
194
+
195
+ Patterns: `greedy`, `temp-0.7`, `temp-1.2`, `hlg-default`, `hlg-rolloff` —
196
+ **temperature alone, no top_p/top_k, and not the model's recommended temp.** This
197
+ was wrong on two counts (the recommended recipe gates the tail with top_p
198
+ 0.95/top_k 64, and the recommended temp is 1.0, not 0.7/1.2). distinct-2 here was
199
+ computed *without* the prefix strip, so it is not comparable to later runs.
200
+
201
+ | prompt | greedy | temp-0.7 | temp-1.2 | hlg-default | hlg-rolloff |
202
+ |---|---|---|---|---|---|
203
+ | creative | 0.97 | 0.85 | 0.95 | 0.88 | 0.88 |
204
+ | brainstorm | 0.97 | 0.69 | 0.59 | 0.63 | 0.68 |
205
+ | factual | 1.00 | 0.30 | 0.30 | 0.30 | 0.30 |
206
+ | reasoning | 0.87 | 0.28 | 0.34 | 0.30 | 0.34 |
207
+ | continuation | 0.97 | 0.84 | 0.87 | 0.83 | 0.83 |
208
+
209
+ What it taught: the prompts + temp ≤ 1.2 never put e4b into HLG's target regime
210
+ (confident prompts collapse everything, including temp-1.2; open prompts give
211
+ temp-1.2 free diversity with no visible downside). And the baseline must be the
212
+ model's own recipe, not an arbitrary temperature. Both corrected after.
213
+
214
+ ### 6.2 Run A — recommended control; layered vs replace (Appendix B)
215
+
216
+ Patterns hold the recommended recipe (temp 1.0 · top_p 0.95 · top_k 64) and vary
217
+ the curve. `rec+hlg` = recipe **with** HLG layered on top of top_p/top_k.
218
+ `hlg-replace` = recipe temp, **no** cutoffs, HLG's toe doing tail control.
219
+ distinct-2 here and after is prefix-stripped.
220
+
221
+ | prompt | recommended | rec+hlg | hlg-replace |
222
+ |---|---|---|---|
223
+ | creative | 0.90 | 0.89 | 0.90 |
224
+ | brainstorm | 0.78 | **0.88** | **0.88** |
225
+ | factual | 0.30 | 0.30 | 0.30 |
226
+ | reasoning | 0.28 | 0.32 | 0.34 |
227
+ | continuation | 0.75 | **0.84** | **0.86** |
228
+
229
+ The positive signal first appears: HLG raises open-ended diversity (brainstorm
230
+ +0.10, continuation +0.09–0.11) and leaves factual locked at 0.30. Concrete win —
231
+ `rec+hlg` broke the "SIM Card Ejector" rut on item 1: *"**Improvised Zipper
232
+ Pull:** If the tab or pull on a zipper breaks off…"*. Cost first appears in
233
+ `hlg-replace`: one frayed tail token (*"a cartographer's stain—**aving
234
+ purpose**"*).
235
+
236
+ ### 6.3 Run B — gain variants (Appendix C)
237
+
238
+ Recipe held fixed (top_p/top_k kept); HLG layered with explicit gains and varied
239
+ edges, pivot top. Confirms the open-ended diversity gain is robust across knobs
240
+ and never disturbs factual.
241
+
242
+ | prompt | standard | hlg-rolloff | hlg-midboost | hlg-soft | hlg-full |
243
+ |---|---|---|---|---|---|
244
+ | creative | 0.90 | **0.96** | 0.90 | 0.94 | 0.92 |
245
+ | brainstorm | 0.78 | **0.88** | 0.82 | **0.88** | **0.88** |
246
+ | factual | 0.30 | 0.30 | 0.30 | 0.30 | 0.30 |
247
+ | reasoning | 0.28 | 0.31 | 0.32 | 0.31 | 0.32 |
248
+ | continuation | 0.75 | **0.82** | 0.83 | 0.84 | **0.85** |
249
+
250
+ ### 6.4 Run C — the pivot comparison, as a true replacement (Appendix D) — DECISIVE
251
+
252
+ `standard` = recipe. `hlg-top` / `hlg-entropy` / `hlg-median` = **replacement**
253
+ sampler (no top_p/top_k), one curve (gain 1.0, width 3, shoulder 4, toe 4), only
254
+ the pivot placement changes (offset 6 for top; 0 for entropy/median).
255
+
256
+ | prompt | standard | hlg-top | hlg-entropy | hlg-median |
257
+ |---|---|---|---|---|
258
+ | creative | 0.90 | 0.95 | 0.99 ⚠️ | 1.00 ⚠️ |
259
+ | brainstorm | 0.78 | 0.91 | 0.99 ⚠️ | 1.00 ⚠️ |
260
+ | factual | 0.30 | 0.55 | 0.99 ⚠️ | 1.00 ⚠️ |
261
+ | reasoning | 0.28 | 0.35 | 1.00 ⚠️ | 0.99 ⚠️ |
262
+ | continuation | 0.75 | 0.88 | 1.00 ⚠️ | 1.00 ⚠️ |
263
+
264
+ ⚠️ = the score is **garbage**, not diversity.
265
+
266
+ - `hlg-top` is coherent and varied. Continuation #3: *"…how it acts like a coral
267
+ reef—brilliantly shaped in its fleeting, vibrant bloom, only to be slowly
268
+ colonized and ultimately obscured by the perpetual, grinding algae of the
269
+ new…"*
270
+ - `hlg-entropy` continuation #1: *"'The Aideang strane簿 sche tup de uman tuturí
271
+ namiatório hidadierá escult প্রশ্ন p a'i nto'…"*
272
+ - `hlg-median` factual #2: *"The जैसे overtakehouses仰рачи倾olver漏洞格局 ᵛ<br
273
+ Zweigen graisseuse.apparent échelle saisonAlloc Lieu en cours rotation follicle
274
+ orbit 結構"*
275
+
276
+ ---
277
+
278
+ ## 7. Findings
279
+
280
+ ### 7.1 The pivot is top-anchored
281
+
282
+ As a replacement sampler, **only the top-anchored pivot is viable**. Entropy and
283
+ median collapse to multilingual token-salad on every prompt.
284
+
285
+ ### 7.2 Why — the toe permissiveness × pivot offset (the mechanism)
286
+
287
+ The toe lifts the deep tail toward a floor at `−m·w` instead of suppressing it. In
288
+ replacement mode (no hard cutoffs) the only thing keeping the top token dominant
289
+ is how far below the peak the pivot sits, because that sets where the toe floor
290
+ lands and therefore the total tail mass over a 262k vocab. With the Run C params
291
+ (m=1, w=3, β_t=4):
292
+
293
+ - **`hlg-top`**, μ = ℓmax − 6: top token maps to g ≈ +5.2, a deep-tail token
294
+ (ℓmax − 20) to g ≈ −8.3 → gap ≈ 13.5 nats. Tail mass ≈ 262k·e^−13.5 ≈ **0.4×**
295
+ the peak → top stays dominant → coherent.
296
+ - **`hlg-entropy` / `hlg-median`**, μ ≈ ℓmax (both land near the peak on a
297
+ confident distribution): the entire distribution falls into the toe; a deep-tail
298
+ token maps ~9.6 nats below the top → tail mass ≈ 262k·e^−9.6 ≈ **17×** the peak
299
+ → near-uniform over the vocab → garbage.
300
+
301
+ The 6-nat offset is the difference between tail-mass 0.4 (coherent) and 17
302
+ (salad). The adaptive pivots have no equivalent "push the floor down" lever, so
303
+ they place middle grey too high to survive a replacement. (They would likely
304
+ behave layered on top of top_p/top_k, or given their own downward offset — future
305
+ work, not a drop-in replacement.)
306
+
307
+ ### 7.3 distinct-2 rewards garbage
308
+
309
+ Entropy/median scored ~1.0 distinct-2 *because* they emit random unique tokens.
310
+ Lexical-diversity metrics reward incoherence and must be paired with a coherence
311
+ gate (e.g. NLL/perplexity of the generation under the model's standard recipe, or
312
+ a fraction-of-in-vocab/in-language check). This directly shapes the Piece 5
313
+ diversity lens.
314
+
315
+ ### 7.4 The positive signal (the thesis, mildly confirmed)
316
+
317
+ Across Runs A and B, HLG consistently raises open-ended diversity (brainstorm
318
+ 0.78 → 0.88, continuation 0.75 → 0.86) while leaving the confident factual answer
319
+ at 0.30 — more variation where it helps, none where it shouldn't. The decoupling
320
+ the thesis predicts does appear; it is mild at default knobs.
321
+
322
+ ### 7.5 Costs / caveats
323
+
324
+ - Even `hlg-top` leaks a trickle (stray "ten正常的 yards", "schuman") — the toe is
325
+ leakier than hard cutoffs.
326
+ - `hlg-top` loosened the factual answer more than desired (0.30 → 0.55, "the
327
+ planet' adorable axis"). A confident answer probably shouldn't be varied at all.
328
+ - The confident prompts (factual/reasoning) never trigger temperature's
329
+ garbage-tail failure mode on e4b, so this model can't showcase the *full*
330
+ decoupling advantage — a less confident model or longer generations might.
331
+
332
+ ---
333
+
334
+ ## 8. Current state
335
+
336
+ - Curve in place, replacement architecture finalised, three pivots implemented +
337
+ tested (14/14 green, tsc clean).
338
+ - Pivot question answered: **top-anchored**.
339
+ - Harness (`scripts/hlg-compare.ts`) reusable and reads each model's recommended
340
+ recipe.
341
+
342
+ ---
343
+
344
+ ## 9. Next steps
345
+
346
+ 1. **Shape the toe** (the "shape the pieces" step): on the top-anchored pivot,
347
+ sweep `β_t` (smaller = harder tail suppression) and the offset `c` to stop the
348
+ residual leak without killing the open-ended diversity gain. This is the
349
+ calibration that sets the shipped default.
350
+ 2. **Coherence-gated diversity metric** for Piece 5: distinct-n + an NLL/perplexity
351
+ gate so garbage can't win. Add as `src/eval/tasks/diversity.ts`.
352
+ 3. **Capability guardrail**: `bun scripts/eval.ts capability` with the chosen
353
+ top-anchored config vs off — confirm GSM8K/BFCL/etc. don't regress.
354
+ 4. **Decide entropy/median's fate**: either retire them for replacement use, or
355
+ give them a downward offset / pair them with top_p/top_k and re-test.
356
+ 5. `--hlg-pivot` CLI flag (the last bit of Piece 4).
357
+ 6. Batched neutrality test (Piece 3) — plumbing already live via the shared
358
+ sampler.
359
+
360
+ ---
361
+
362
+ ## 10. Pass 2 — the full HLG transfer system → the working HLGShaper
363
+
364
+ Pass 1 used an HLG-*shaped* parametric curve. Pass 2 implemented the **literal**
365
+ HLG system (BT.2100) and then the user's exact `HLGShaper`, end-to-end. Code:
366
+ `src/sampler.ts` (`applyHlgOetf`, `applyHlgEotf`, `applyHlgPipeline`,
367
+ `applyHlgShaper`). All A/B against the model's **default recipe, untouched** (the
368
+ only thing taken from the standard side); the HLG side is a full **replacement**
369
+ (no temp/top_p/top_k). Runs D–G in `hlg-runs/`.
370
+
371
+ **The arc, and what each step taught:**
372
+
373
+ 1. **Literal OETF, replacement** (runD). `E' = √(3E)` below 1/12, `a·ln(12E−b)+c`
374
+ above; sample ∝ V. **Semi-garbage.** The √ toe is HLG's *precision* curve — it
375
+ **lifts** the tail (√ of 1e-6 is 1e-3); over 262k tokens that floods the draw.
376
+ 2. **EOTF (decode) vs OETF (encode)** (runE). The inverse-OETF low branch `E'²/3`
377
+ **squares the tail down** — coherent where the OETF flooded. So the *direction*
378
+ matters, and the **OOTF on a grayscale (single-"pixel") distribution reduces
379
+ to `E^γ` = temperature** (no colour channels for luminance to couple), with
380
+ `γ = 1.2+0.42·log10(L_W/1000)`. The "system-level" part has no sampling analog.
381
+ 3. **Full pipeline `α·E'^γ`** (runF predecessor). As pure logits with `α=5` over
382
+ 262k → near-uniform (the flat floor outweighs the top): `α` must exceed
383
+ `ln(vocab) ≈ 12.5` just for the top to win.
384
+ 4. **The exact HLGShaper** (runF/runG). min-max input → still garbage, but
385
+ *prompt-dependent* this time, with coherent fragments fighting through. Cause:
386
+ **min-max over the 262k vocab collapses every real candidate into the shoulder**
387
+ (`x ≥ 0.9`, log-compressed together) while the **mid band `s_m` elevates is
388
+ tokens 15–22 nats below the top = noise**. The curve was fine; the *signal* was
389
+ wrong.
390
+
391
+ **The two adaptations the source domain doesn't need** (both found empirically):
392
+
393
+ - **Windowed-anchor input** instead of min-max: `x = clamp((ℓ−ℓmax)/W + 1, 0, 1)`.
394
+ The top `W` nats of real candidates span the curve; deeper tokens clamp into the
395
+ toe. (LM logits are a spike-plus-tail, not an image's tonal spread.)
396
+ - **The toe inverted**: a **cubic** `e·x³+f·x²` that suppresses to 0, not HLG's
397
+ `√` that lifts. (A sampler crushes shadows; HLG describes them.)
398
+
399
+ **Result (runF/runG).** With `W=5, out_scale=18` the HLGShaper is a **working,
400
+ coherent replacement sampler** — vivid, varied, factually/arithmetically correct,
401
+ no salad (e.g. continuation: *"…it doesn't archive; it re-weaves… the vibrant
402
+ threads of joy are often knotted with the dull grey of forgotten anxiety…"*).
403
+ Comparable to the default recipe on both coherence and diversity.
404
+
405
+ **Knob sweep (runG).** The four orthogonal knobs are live — `s_m` (mid sharpness),
406
+ `A` (shoulder/confidence), `x_floor`+toe (tail gate), `L_W` (global γ) — **where
407
+ temperature gave one.** But the **coherent slice of that 4-D space is narrow**:
408
+ loosening toward more diversity (`W=7, out_scale=13, A=0.6`) tipped straight back
409
+ into garbage, because a *smooth* tail over 262k stays coherent only under
410
+ aggressive gating (nothing hard-cuts like top-k). So the chain *works*, but the
411
+ sweep did **not** yet show it beating temperature on diversity.
412
+
413
+ **Open / next.** Probe the corner the loose run missed: keep the **toe/x_floor
414
+ gate aggressive** (tail dead) while loosening **A + out_scale** (flatten the top,
415
+ spread the survivors) — decoupling "kill the tail" from "loosen the top," the
416
+ original thesis. Plus a coherence-gated diversity metric (distinct-n is useless —
417
+ it scores the salad ~1.0). Default stays **off**; this is a novel knob, never a
418
+ silent change to the sampler.
419
+
420
+ ---
421
+
422
+ ## 11. Pass 3 — fencing the exposure axes (clean single-variable sweeps)
423
+
424
+ The runG sweep was confounded: B-sharp→B-loose moved **three** knobs at once
425
+ (`W` 5→7, `out_scale` 18→13, `A` .35→.60), so its collapse couldn't be
426
+ attributed. Two fixes made the knobs separable:
427
+
428
+ **Decouple `out_scale` from `W`.** It had been hand-retuned (12→18) when `W`
429
+ went 10→5 — a coupling that confounds every comparison. Now `out_scale`
430
+ **auto-derives** so the top-1-to-reference final-logit gap equals a fixed
431
+ `target_gap`, *independent of W* (the reference token sits `ref_gap` nats below
432
+ the top; its post-shape value is the scalar curve evaluated in JS — no device
433
+ cost). Calibrated so `W=5 ⇒ out_scale≈18` (the known-good); it rises to ≈35 at
434
+ W=8 to hold the same effective sharpness. `W` is now a clean 1-D variable.
435
+
436
+ **The factual prompt is the canary** — it has the sharpest spike-to-tail
437
+ structure, so it breaks last; read it for the *first junk-token position*, not
438
+ just pass/fail.
439
+
440
+ **W-sweep (runH; W ∈ {4..8}, all else fixed at A=.35 / s_m=.7 / L_W=1200 /
441
+ out_scale auto):**
442
+
443
+ | W | out_scale | factual canary |
444
+ | --- | --- | --- |
445
+ | 4 | 15.0 | **junk** (sample 2 breaks at word 3) — below the floor |
446
+ | 5 | 18.3 | clean ×3 |
447
+ | 6 | 23.6 | clean ×3 |
448
+ | 7 | 29.4 | clean ×3 |
449
+ | 8 | 35.4 | clean ×3 |
450
+
451
+ - **Bad wall at W=4, basin W=5–8.** The cliff is a *floor* (too-narrow window),
452
+ not a high-W ceiling. Within the basin, diversity is **nearly constant** (same
453
+ ~3 creative openings / continuation framings at every W) because auto-`out_scale`
454
+ holds sharpness fixed. So **`W` is a coherence-floor knob, not a diversity
455
+ knob** — it sets *which* candidates are eligible, not how spread the draw is.
456
+ - The W-sweep left two suspects for the runG (B-loose) collapse (`A` and
457
+ `out_scale` both also moved). The **A-sweep (runI; A ∈ {.20..​.60}, W=6 fixed,
458
+ out_scale auto)** resolves it: the **factual canary is clean at every A,
459
+ including `A=.60`**. So neither `W` nor `A` killed B-loose — **by elimination
460
+ the killer was the manually-set `out_scale=13`** (< half the ~29 the
461
+ auto-derivation gives W=7). The decoupling wasn't just *a* confound; it was
462
+ *the* one. (This corrects an earlier draft that blamed `A`.)
463
+
464
+ **Corrected knob model** (after fencing W and A):
465
+ - `out_scale` / `target_gap` = **sharpness — the load-bearing knob** (too low →
466
+ garbage, as in B-loose; now auto-derived → robust) and **the diversity lever**.
467
+ - `W` = **coherence floor** (bad wall at 4; robust ≥ 5).
468
+ - `A` = **robust across .20–.60** — modulates framing subtly, does NOT break
469
+ coherence. *Not* the dangerous knob after all.
470
+ - `s_m`, `L_W` — untested.
471
+
472
+ With `W` and `A` both fenced as wide basins, the shaper is **robust, not a
473
+ knife-edge** — the runG "narrow regime" was the `out_scale` confound. Temperature
474
+ collapses all of these into one knob; here they separate. The single axis that
475
+ decides whether the curve beats temperature on diversity is **`target_gap`** (the
476
+ sharpness lever), swept next — canary-gated, at fixed W=6 / A=.35.
477
+
478
+ ---
479
+
480
+ ## 12. The automated knob map — and the verdict
481
+
482
+ `scripts/hlg-map.ts` — two-stage (cheap factual-canary **coherence** gate →
483
+ **diversity** on survivors only, so garbage can't win), per-knob 1-D sweeps from
484
+ the known-good base, every cell scored against the **default recipe** as the
485
+ diversity reference. runJ / `hlg-map.json`. Coherence = non-Latin letter ratio
486
+ (the salad signature); ACCEPTABLE < 1% on both the canary and the open prompts.
487
+
488
+ Default recipe reference: **diversity 0.87, junk 0.0%.**
489
+
490
+ | knob | acceptable range | diversity across band | role |
491
+ | --- | --- | --- | --- |
492
+ | `W` | **[5, 8]** (wall ≤4) | 0.80 → 0.72 | coherence floor |
493
+ | `A` | **[0.2, 0.8]** (no cliff) | ~0.79 (0.73 high) | near-inert |
494
+ | `target_gap` | **[12, 20]** (cliff ≤10) | 0.79 → 0.69 | coherence floor + sharpness |
495
+ | `s_m` | **[0.4, 1.3]** (no cliff) | flat 0.78–0.80 | near-inert |
496
+ | `L_W` | **[50, 4000]** (no cliff) | ~0.79 (0.71 at 4000) | near-inert |
497
+
498
+ **Verdict (conclusive):**
499
+
500
+ 1. **No acceptable cell beats the default.** The shaper caps at ~**0.80**
501
+ diversity; the default is **0.87** — at the same zero junk. Across the entire
502
+ five-knob space the HLG curve is consistently *less* diverse than
503
+ temperature+top_p+top_k while coherent.
504
+ 2. **Only `W` and `target_gap` do anything, and both are coherence *gates*, not
505
+ diversity dials.** `A`, `s_m`, `L_W` are near-inert across their whole valid
506
+ range. So "four orthogonal controls where temperature gave one" doesn't
507
+ materialise — it's one gate (sharpness/window) plus three inert knobs, and the
508
+ only way to move diversity is off the cliff into garbage.
509
+ 3. **Why the default wins:** a hard tail-cut (top_p/top_k) *removes* the tail, so
510
+ you can be loose on the ~64 survivors without garbage. A smooth curve must
511
+ keep the tail gated by sharpness, and that same gating caps how loose the top
512
+ can get — the hard cut is strictly more diversity-efficient. And the default
513
+ already keys off the distribution's own entropy (peaked→decisive, broad→loose)
514
+ via top_p — the adaptive behaviour the curve was reaching for, done better.
515
+
516
+ **Bottom line.** The HLG transfer system transplants onto sampling and yields a
517
+ *working, coherent* replacement sampler; the cross-domain mapping is sound and
518
+ the two required adaptations (windowed anchor, inverted toe) are real findings.
519
+ But it does **not** beat a well-tuned temperature+cutoff recipe — equal-or-less
520
+ diversity at equal coherence, everywhere in the mapped space.
521
+
522
+ ## 13. Frontier probe — better metric + interactions (the definitive landing)
523
+
524
+ The §12 map has two blind spots: distinct-2 is lexical/noisy at small N, and every
525
+ sweep is one-knob-at-a-time from one base (so it cannot see a B-loose-type *joint*
526
+ failure). `scripts/hlg-frontier.ts` closes both — **self-BLEU on the divergent
527
+ region at N=10** (diversity = 1 − self-BLEU), over a curated set: the per-knob
528
+ diversity edges **plus** the `target_gap×W` / `target_gap×A` corners. runK /
529
+ `hlg-frontier.json`. Default reference: **diversity 0.672.**
530
+
531
+ | cell | diversity (1−selfBLEU) | canary |
532
+ | --- | --- | --- |
533
+ | **default** | **0.672** | clean (reference) |
534
+ | tg12 × A.2 | 0.605 | clean (best HLG) |
535
+ | tg=12 | 0.570 | clean |
536
+ | base / Lw50 / sM1.3 | ~0.53 | clean |
537
+ | W=5 / A.20 / tg12×W8 | ~0.50 | clean |
538
+ | tg12 × A.8 | 0.470 | clean |
539
+ | **tg12 × W5** | — | **REJECT 8.5%** |
540
+ | **tg12 × W5 × A.2** | — | **REJECT 4.1%** |
541
+
542
+ 1. **The sharper metric widens the gap — but reveals the real gradient.** Lowering
543
+ `target_gap` (15→12) and `A` (.35→.2) genuinely raises diversity (0.525 → 0.570
544
+ → 0.605) — the gradient distinct-2 flattened. So the knobs *do* control
545
+ diversity. But the ceiling is **0.605 vs default 0.672** (~10% gap), consistent.
546
+ 2. **The interaction probes caught a joint failure the marginal map structurally
547
+ could not.** `tg=12` alone is clean, `W=5` alone is clean, but **`tg12 × W5`
548
+ rejects (8.5% junk)** — so the "valid ranges" are **not** an independent box
549
+ `W∈[5,8] × tg∈[12,20]`; they're a **coupled manifold** (low target_gap needs a
550
+ *wider* W: tg12×W8 clean, tg12×W5 not). Exactly the B-loose-type joint failure
551
+ the one-at-a-time map can't see.
552
+
553
+ **Final, rigorous verdict.** HLG sampling gives **finer, decomposed control over
554
+ the coherence/diversity tradeoff, but does not dominate temperature on the
555
+ frontier** — its reachable diversity sits strictly inside the default's, and
556
+ pushing to the edge crosses a coupled coherence cliff. A true, useful, publishable
557
+ **negative-but-informative result** — control, not dominance.
558
+
559
+ ---
560
+
561
+ ## 14. Reversal — wide ranges + semantic metric + text verification → DOMINANCE
562
+
563
+ The §12/§13 "negative" was **premature**, from the two methodology gaps the user
564
+ flagged: (a) sweep ranges too narrow (A ∈ [0.2,0.8] never reached the loose
565
+ extreme where the shoulder actually engages), and (b) distinct-2 is noisy at
566
+ small N. Fixing both overturns the verdict.
567
+
568
+ **Wide-range map (runL):** every knob swept across orders of magnitude — and
569
+ **every knob breaks somewhere** (so each does something): W low (~5),
570
+ target_gap low (~12), L_W low (γ→0), A **high** (~100 → garbage), s_m **high**
571
+ (~4 → curve goes non-monotonic). The loose extremes the narrow sweeps skipped
572
+ (A=0.01, s_m=0.05) approach/match the default — the cells that mattered.
573
+
574
+ **Frontier + semantic metric (runM):** N=10, self-BLEU (lexical) + **embedding**
575
+ (1 − mean cosine of mean-pooled LM hidden states, semantic) + distinct-2, on the
576
+ loose-edge cells. Default reference: self-BLEU 0.672, emb 0.136.
577
+
578
+ | cell | self-BLEU | emb | distinct2 |
579
+ | --- | --- | --- | --- |
580
+ | default | 0.672 | 0.136 | 0.73 |
581
+ | A=0.01 | 0.713 ★ | 0.128 | 0.73 |
582
+ | s_m=0.05 | 0.720 ★ | 0.136 | 0.74 |
583
+ | **A.01 × s_m.05** | **0.783 ★** | **0.142 ★** | **0.79** |
584
+ | A.01 × s_m.05 × Lw10 | 0.745 ★ | 0.143 ★ | 0.78 |
585
+
586
+ **Text verification (runN):** read every output of `A.01 × s_m.05`. Factual: all
587
+ four correct (varied phrasings, not degenerate). Reasoning: equations set up
588
+ correctly. Creative/continuation: genuinely diverse, vivid, coherent — *real*
589
+ variety, not metric-fooling repetition. Confirmed.
590
+
591
+ **Reversed verdict.** At the loose corner **A=0.01, s_m=0.05** (W=6,
592
+ target_gap=15, L_W=1200) HLG **beats** the default temperature+cutoff recipe on
593
+ diversity — self-BLEU 0.783 vs 0.672 (large), distinct-2 0.79 vs 0.73, embedding
594
+ marginal — at **zero junk and full correctness**, verified by reading the text.
595
+ This is the **thesis realized**: A→0 flattens the overconfident top, s_m→0 keeps
596
+ the mids loose, the window/target_gap gate kills the tail — loosening the top
597
+ *without* lifting the tail, the one thing a single temperature knob structurally
598
+ cannot do. Caveats: the semantic edge is small (+0.006 on a weak LM-hidden-state
599
+ proxy, not a real sentence encoder); single seed-base at N=10 (the large,
600
+ text-verified *lexical* margin still wants one fresh-seed repeat); `×Lw10`
601
+ occasionally breaks character.
602
+
603
+ **Fresh-seed repeat (runO, seed 5000) — the dominance does NOT replicate.** The
604
+ default's own self-BLEU swung **+0.083** across seeds (0.672 → 0.755), *larger*
605
+ than the effect I claimed; at seed 5000 the default (0.755) edges **above**
606
+ A.01×s_m.05 (0.747). N=10 self-BLEU variance (~0.08) swamps the effect — no
607
+ self-BLEU dominance survives. The only signal stable across both seeds is the
608
+ small **embedding** edge (loose HLG cells > default at both: 0.142/0.141 vs the
609
+ default's 0.136/0.121), on a weak proxy.
610
+
611
+ | | self-BLEU s1000 → s5000 | emb-div s1000 → s5000 |
612
+ | --- | --- | --- |
613
+ | default | 0.672 → **0.755** | 0.136 → 0.121 |
614
+ | A.01 × s_m.05 | 0.783 → **0.747** | 0.142 → 0.141 |
615
+
616
+ **Honest final landing (neither premature verdict).** HLG's loose-corner cells
617
+ (A=0.01, s_m=0.05) are **comparable** to the default on diversity at equal
618
+ coherence — *within N=10 measurement noise* — with at most a small, consistent
619
+ *semantic* (embedding) edge below what this metric/N can resolve. Proving a real
620
+ effect of that size needs N in the hundreds (variance ~1/√N) or a proper sentence
621
+ encoder, not the LM's own hidden states. **Meta-result: the fresh-seed repeat is
622
+ the discipline that catches over-claims — it caught the premature "negative"
623
+ (§12/§13) AND the premature "dominance" (§14 first draft) within one run each.**
624
+ (Runs L/M/N/O.)
625
+
626
+ ---
627
+
628
+ ## 15. Mapping the terrain (ongoing — not verdicts)
629
+
630
+ Reframing, deliberately: this is a forest, not a yes/no, and §12–§14's
631
+ "verdicts" (negative → dominance → wash) were premature lurches at individual
632
+ data points. Each run is a *coordinate*. What we actually have is a partial map
633
+ of where the shaper is coherent and how diverse it is, held loosely.
634
+
635
+ `scripts/hlg-grid.ts` adds the first **2-D** layer — `A × s_m` (runP, N=5; cell =
636
+ self-BLEU-div (emb-div), `✗` = canary broke; default contour 0.799 / 0.140):
637
+
638
+ ```
639
+ s_m\A 0.01 0.05 0.2 1 5
640
+ 0.05 +0.81(.15) +0.83(.12) +0.86(.14) +0.82(.13) 0.56(.04)
641
+ 0.2 +0.85(.13) 0.73(.11) +0.86(.07) 0.76(.05) 0.58(.10)
642
+ 0.7 +0.80(.13) 0.74(.11) +0.81(.06) 0.72(.05) 0.67(.05)
643
+ 1.5 0.79(.13) 0.71(.11) 0.74(.09) 0.66(.05) ✗3%
644
+ 3 +0.78(.16) ✗3% ✗3% ✗4% ✗4%
645
+ ```
646
+
647
+ Terrain features (confidence noted):
648
+ - **The coherent basin's upper edge is a coupled `A↔s_m` trade-off** (sharp,
649
+ reliable): `s_m=3` breaks across the row *except* at `A=0.01` (a clean **spur**),
650
+ and `A=5` breaks a row lower (`s_m=1.5`). Loose `A` *buys* high-`s_m` tolerance —
651
+ hard shoulder-flattening appears to stabilize the otherwise non-monotonic
652
+ high-`s_m` mid. Same coupling family as `tg×W` (§13).
653
+ - **Diversity is a noisy plateau near the default level**, sloping down only toward
654
+ tight `A` (`A=5`: self-BLEU 0.56–0.67, clearly low). The dense `+` cells sit
655
+ within the measured seed-noise (±0.08) of the default — comparable, not a clean
656
+ peak. (emb at N=5 is noisier; trust the coherence contour and the `A` slope.)
657
+
658
+ **Second plane — `W × target_gap` (runQ, N=5):**
659
+
660
+ ```
661
+ W\tg 10 13 16 25 50
662
+ 4 ✗21% ✗6% ✗4% 0.78(.05) 0.57(.03)
663
+ 5 ✗38% ✗4% 0.75(.05) 0.78(.05) 0.57(.03)
664
+ 6 ✗4% +0.81(.06) 0.71(.05) 0.71(.05) 0.50(.03)
665
+ 10 0.75(.09) 0.78(.05) 0.74(.05) 0.73(.04) 0.57(.03)
666
+ 20 +0.88(.06) 0.58(.05) 0.63(.05) 0.60(.04) 0.58(.03)
667
+ ```
668
+
669
+ The coherence cliff is a clean **diagonal**: wide `W` buys low `target_gap`, high
670
+ `target_gap` buys narrow `W` — they trade off, exactly like `A↔s_m`. **Two
671
+ independent planes now show the same coupling — promoting it from quirk to
672
+ structural fact: the coherent basin is walled by COUPLED diagonal cliffs, not
673
+ independent per-knob thresholds; the knobs trade off against each other at the
674
+ edge.** (This is why the marginal 1-D ranges can't be trusted jointly — the
675
+ `tg12×W5` failure was the first hint.) Diversity peaks at the loose corner (wide
676
+ `W`, low `target_gap`: 0.88; falls to 0.50–0.57 as `target_gap` sharpens), near
677
+ the default contour and within seed-noise.
678
+
679
+ **Cross-pair coherence (runS, canary-only — swap partners).** Each shaping knob
680
+ (`A`, `s_m`) × each gate knob (`tg`, `W`). The coupling is **selective, not
681
+ global**:
682
+ - **`A` is nearly orthogonal to the gates** — in `A×tg` and `A×W` the gate cliffs
683
+ (`tg<~12`, `W<~5`) hold across *every* `A` (only the extreme `A=100` corner
684
+ nudges them). `A` reshapes the top without moving the coherence floor.
685
+ - **`s_m` is the coupling hub** — `s_m×tg` is a clean diagonal (`s_m=0.2` *rescues*
686
+ `tg=8`; `s_m≥2` breaks `tg=12`), `s_m×W` the same milder bend. Loose mid demands
687
+ a tighter gate.
688
+
689
+ So the coherence wall is a **gate+mid cluster** (`tg`, `W`, `s_m` share a
690
+ tail-mass budget) with **`A` outside it**. Mechanism: the floor is a *tail*
691
+ phenomenon (gates set it, `s_m` feeds the mid into it); `A` only flattens the
692
+ *top* — no tail mass — so it's free on coherence.
693
+
694
+ **Map so far (held loosely, no verdict):** a coherent basin whose wall is a
695
+ coupled `tg`/`W`/`s_m` surface, with **`A` an orthogonal degree of freedom**;
696
+ diversity a noisy plateau rising toward the loose corner, near the default level.
697
+ The two diversity levers split by their relation to the wall — **`A` is free,
698
+ `s_m` is coupled.** All pairwise coherence boundaries now mapped (2 within-pair +
699
+ 4 cross-pair). Next layers: the **blind external-judge** read (`scripts/hlg-blind.ts`,
700
+ artifacts ready — independent of self-BLEU/embedding), and zooming the loose
701
+ corner / the `A↔s_m` spur.
702
+
703
+ ### Generalization across models (runT CPM5, runU 12B)
704
+
705
+ The whole map above is e4b. To ask whether the basin geometry is a property of
706
+ the *curve* or of *e4b*, re-ran the cross-pair coherence map on two more models:
707
+ **12B** (dense Gemma, same ~262k vocab as e4b) and **CPM5** (MiniCPM5-1B,
708
+ Llama-family, ~73k vocab). The split is clean:
709
+
710
+ - **The sharpness cluster replicates on all three.** `s_m×target_gap` is the same
711
+ diagonal everywhere (low `s_m` tolerates low `tg`; high `s_m` needs high `tg`),
712
+ and `A` stays orthogonal to the `tg` gate. Two architectures, two vocab sizes —
713
+ same structure. This is the load-bearing finding, and it's curve-level, not
714
+ model-level. (CPM5's diagonal is *shifted* — it breaks only at `s_m≥2` where the
715
+ Gemmas break at `s_m≥0.7` — i.e. the same coupling direction, a more tolerant
716
+ threshold.)
717
+ - **The window (`W`) axis is vocab-dependent.** The two same-vocab Gemmas (e4b, 12B)
718
+ behave identically on `W` (low-`W` gate breaks across all `A`; `s_m×W` couples at
719
+ `W=5`); CPM5 diverges (`W=3` robust at low `A`, `s_m×W` fully decoupled, plus a
720
+ high-`A`/wide-`W` break absent in e4b — 12B shows a mild hint of the same). The
721
+ 12B control did its job: it tracked e4b, not CPM5, confirming the `W` difference
722
+ follows vocab size (smaller vocab → less tail to inflate → different gate dynamics).
723
+
724
+ So the **sharpness coupling is the invariant**; the **window axis is the
725
+ vocab-sensitive part**. Visualized in `scripts/hlg-viz.ts` (e4b diversity terrain)
726
+ and `scripts/hlg-viz-cross.ts` (3-model coherence comparison). Logs: runT (CPM5),
727
+ runU (12B).
728
+
729
+ ### L_W — the fifth knob (runV e4b, runW 12B, runX CPM5)
730
+
731
+ `L_W` sets the OOTF gamma: `γ = 1.2 + 0.42·log10(L_W/1000)`. The auto-`out_scale`
732
+ pins the top→reference gap to `target_gap`, so `L_W` does **not** move the anchor —
733
+ it bends the **curvature** of the mid/tail. Swept wide (`L_W` 1 … 10⁶, γ −0.06 … 2.46),
734
+ `scripts/hlg-lw.ts`, two-stage:
735
+
736
+ - **`L_W` is not a gate-cluster member.** Coherence is robust across **five decades**
737
+ (`L_W ∈ [3, 10⁵]`, γ ∈ [0.14, 2.04]) — the opposite of `tg`/`W`'s tight breaks.
738
+ It walls only at the *extremes*: low (`L_W≈1`, γ<0 *inverts* the ranking → junk)
739
+ and high (`L_W≈10⁶`, γ≈2.46, over-sharpened → junk). The low wall and coherent
740
+ range are **identical on e4b and 12B** (same-vocab Gemmas). The *high* wall is
741
+ Gemma-only: **CPM5 has no high wall** (clean through `L_W=10⁶`, range `[3, 10⁶]`) —
742
+ the smaller vocab is more robust at high γ, the same vocab-sensitivity seen on `W`.
743
+ - **Diversity response is model-specific, and not monotone.** On e4b it's an
744
+ interior peak that *appeared* to rise above the 0.70 default (0.76 at γ≈1.0) — **but
745
+ this was K=6 noise, retracted at K=20** (see the deep-dive below): the K=20 default is
746
+ 0.633 and every `L_W` point sits at 0.42–0.45, well below it. On 12B (K=6) it's a flat
747
+ **0.51–0.56 floor below the 0.72 default**. Corrected read: `L_W` diversity is *below*
748
+ the recommended recipe on every model measured — it does not help diversity.
749
+
750
+ `L_W` is therefore its own kind of knob: a **curvature control**, coherence-robust
751
+ (unlike the gates), with a non-monotone diversity response whose useful direction
752
+ flips by model. Visualized in `scripts/hlg-lw-viz.ts`.
753
+
754
+ ### Cliff resolution (runY e4b, runZ 12B, runAA CPM5)
755
+
756
+ The coarse maps stepped *over* the steepest features. `scripts/hlg-cliff.ts` steps
757
+ `target_gap` 7→13 (unit) at base, and `W` 3→10 at `A=100` (the channel-closing edge),
758
+ reporting the junk% gradient (K=5 seeds). Fine resolution revealed **two different
759
+ cliff shapes** the coarse jumps had flattened into "a break somewhere in 8–12":
760
+
761
+ - **`target_gap` is a graded ramp, not a step.** e4b 31%→17%→1% over tg 8→9→10;
762
+ 12B 17%→4%→1%. The whole transition is a 2–3-step slope. Its *position shifts by
763
+ vocab*: CPM5 coherent earliest (clean by tg≈8), e4b latest (still 31% at tg 8,
764
+ crosses tg 9→10), 12B between — same vocab-sensitivity as the `W`/`L_W`-high stories.
765
+ - **`W` at high `A` is a sharp edge.** All three sit on a high junk plateau through
766
+ W 3–7, then drop to 0% at **W=8** — an abrupt channel close between 7 and 8. The
767
+ *edge position is model-invariant* (all three close 7→8); only the plateau *height*
768
+ differs by vocab. So the channel-closing W is a property of the window math at high
769
+ `A`, not the model.
770
+
771
+ The earlier "12B is steeper" hypothesis **did not hold** — e4b's `tg` cliff is if
772
+ anything the steepest (31→1 over two steps vs 12B's gentler 24→17→4→1). 12B's
773
+ "sensitivity" was real but in *diversity* (the `L_W` suppression), not cliff
774
+ steepness — two distinct senses. Logged as a data point. Visualized in
775
+ `scripts/hlg-cliff-viz.ts`.
776
+
777
+ **Knob taxonomy (the five mapped, held as terrain):** `tg`+`W`+`s_m` = the coupled
778
+ *gate/sharpness cluster* (tight, coupled, vocab-shifted breaks); `A` = orthogonal to
779
+ the wall (free diversity lever); `L_W` = a coherence-robust *curvature* knob (walls
780
+ only at γ extremes; diversity *below* default — see K=20). Cliff shapes split too:
781
+ `tg` graded, `W@highA` sharp.
782
+
783
+ ### K=20 deep-dive (runAB grids, runAC peaks — e4b)
784
+
785
+ Four experiments re-run at K=20 (`scripts/hlg-grid2.ts`, `scripts/hlg-peak.ts`) to
786
+ settle the noisy diversity claims and resolve the cross-terms. Results corrected two
787
+ earlier reads:
788
+
789
+ - **The cliffs are tilted surfaces, not fixed walls.** The `tg` cliff edge *slides
790
+ monotonically with `s_m`*: at `s_m=0.2` there's no cliff at all (0% to tg=7), at
791
+ `s_m=0.7` it sits at tg≈9, at `s_m=2` past tg=12, at `s_m=4` out of frame. And the
792
+ `W` edge *slides with `A`*: it closes at W≈4–5 for `A`≤10 but not until **W≈8 at
793
+ `A=100`** — so the "invariant 7→8 edge" above was specific to `A=100`, not general.
794
+ - **The `L_W` "peak beats default" was noise — retracted.** At K=20 the e4b default is
795
+ 0.633 and every `L_W` point is 0.42–0.45 (~0.19 below). The K=6 0.76>0.70 was
796
+ small-sample artifact; `L_W` shaping is below default on every model measured.
797
+ - **`A` is confirmed the free diversity lever** — clean monotone, 0.66 (A=0.01) → 0.31
798
+ (A=0.7), and the *one* place HLG clears a default is the loosest `A` (+0.03 at 0.01).
799
+ (Sweep cut at A=0.7 when the batch was stopped; trend + ceiling captured.)
800
+
801
+ ### Edge texture (runAE — sub-unit K=20) + a single-config probe
802
+
803
+ `scripts/hlg-edge.ts` zooms sub-unit into the transitions, tracking break-*rate* and
804
+ max (not just mean). The edges turn out heterogeneous:
805
+
806
+ - **Gate cliffs (`tg`, `W`) are *statistical* edges** — per seed bimodal (clean or
807
+ hard-break, max 43–88% mid-ramp); the smooth ramp is the declining *fraction* of
808
+ seeds that break (`tg` 20→2/20 over 7→10; `W` 18→0/20 over 6→8.5), not a softening.
809
+ - **`L_W` low wall is a *hard* threshold at γ=0** — the ranking sign-flip; every γ≥0 is clean.
810
+ - **`L_W` high wall is barely a wall** — 3/20 at γ=2.46; the coarse "REJECT" was a 1-of-2-seed artifact.
811
+
812
+ `scripts/hlg-eval1.ts` evaluates one explorer-dialed config at K=20. A heavily reshaped
813
+ curve (W 7.5, A 3.55, s_m 0.05, **target_gap 4**, γ 1.93, xM 0.74, xFloor 0.45) came back
814
+ **20/20 incoherent** (pure salad; "diversity 1.000" = the garbage signature — why the
815
+ two-stage gate exists). The driver: `target_gap=4` → `out_scale≈5.2` → HLG top-1 25% (vs
816
+ raw 50%), entropy *up* → samples the tail. **Lesson: the curve shape is secondary to the
817
+ final sharpness (`out_scale`); the distribution's top-1/entropy is the coherence oracle.**
818
+ The shaper now forwards the curve-geometry params (`xM/yM/xFloor/yFloor/p`) through
819
+ `HlgConfig` so explorer-tuned configs can be evaluated faithfully.
820
+
821
+ Interactive tools: `docs/investigations/hlg-explorer.html` (live curve + distribution
822
+ under sliders), `docs/investigations/hlg-ab.html` (side-by-side samples). Full report:
823
+ `docs/investigations/hlg-report.html` (`scripts/hlg-report.ts`, figures in `hlg-figs/`).
824
+
825
+ ---
826
+
827
+ ## Appendix A — Run 0 (original: greedy / temp-0.7 / temp-1.2 / hlg-default / hlg-rolloff)
828
+
829
+ ```
830
+ # HLG sampling comparison — model "gemma-4-e4b-it-OptiQ-4bit", K=4, maxTokens=80
831
+
832
+ ═══ [creative] Write the first sentence of a short story about a lighthouse keeper who discovers something strange in the fog.
833
+ ▸ greedy len~ 36 unique 1/1 distinct-2 0.97
834
+ 1. The fog, a thick, clammy blanket that swallowed the beam of the old lantern, seemed to press against the glass of the tower, and it was in that suffocating grey that Silas first saw the impossible.
835
+ ▸ temp-0.7 len~ 35 unique 4/4 distinct-2 0.85
836
+ 1. The fog, a thick, clammy blanket that swallowed the beam of the lantern, seemed to press against the glass, and it was through that swirling gray veil that Silas first saw the impossible.
837
+ 2. The sea fog, a thick, soupy thing that swallowed the beam of the old lantern whole, was the perfect shroud for what he found bobbing just beyond the reach of the rocks.
838
+ 3. The fog, a clammy, grey beast clinging to the tower like wet shrouds, usually offered only the familiar damp chill, but tonight, it carried a scent utterly alien—a metallic tang mixed with the faint, sweet perfume of som…
839
+ 4. The fog, a thick, clammy blanket that swallowed the horizon whole, seemed to carry a faint, unnatural chime as Silas, perched in the lantern room, peered into its milky depths.
840
+ ▸ temp-1.2 len~ 39 unique 4/4 distinct-2 0.95
841
+ 1. The swirling, pea-soup fog that clung to the edge of the jagged coastline seemed to thicken just as a flash of unnatural green light pulsed from the watery expanse below the lantern's rhythmic beam.
842
+ 2. The sea fog, a thick, soupy thing that seemed to swallow the very light from the lantern, usually brought with it only the familiar smell of salt and damp rock, but this morning, it carried a scent unreasonably sweet—lik…
843
+ 3. The relentless, butter-yellow fog was thick enough to chew, and steady, Elias felt the usual creeping silence of the isolated tower until a single, impossibly bright crimson streak broke through the gray curtain near the…
844
+ 4. The St. Agnes, usually a solitary sentinel against the swirling gray, held a silence that felt too deep until he saw the impossible gleam through the shroud of fog clinging to the lantern room's glass.
845
+ ▸ hlg-default len~ 33 unique 4/4 distinct-2 0.88
846
+ 1. The fog, a thick, woolly blanket that swallowed the beam of the lantern, seemed to press against the glass, and it was through that swirling gray veil that Silas first saw the impossible.
847
+ 2. The sea fog, a thick, soupy thing that seemed to swallow the very sound of the waves, usually brought with it only the familiar smell of salt and damp stone, but this morning, it carried a faint, metallic tang, like old …
848
+ 3. The relentless, salt-laced fog that clung to the tower like a shroud offered no respite until the moment a slick, pearlescent object drifted into the beam of his lantern.
849
+ 4. The fog, a thick, clammy blanket that swallowed the horizon whole, finally delivered something unexpected to the beam of the old lighthouse.
850
+ ▸ hlg-rolloff len~ 34 unique 4/4 distinct-2 0.88
851
+ 1. The fog, a thick, woolly blanket that swallowed the beam of his lantern, seemed to press against the glass, and it was through that swirling gray veil that Silas first saw the impossible.
852
+ 2. The sea fog, a thick, soupy thing that seemed to swallow the very light from the lantern, usually brought with it only the familiar smell of salt and damp rock, but this morning, it carried a scent of something metallic …
853
+ 3. The relentless, salt-laced fog that clung to the tower like a shroud offered no respite until the moment a slick, pearlescent object drifted into the beam of his lantern.
854
+ 4. The fog, a thick, clammy blanket that swallowed the horizon whole, finally delivered something unexpected to the beam of the old lighthouse.
855
+
856
+ [brainstorm/factual/reasoning/continuation: full text in run0-original.log —
857
+ factual & reasoning were near-identical across all rows (~0.30); brainstorm
858
+ temp-1.2 dipped to 0.59 (all converged on "SIM Card Ejector" as item 1).]
859
+ ```
860
+
861
+ Full verbatim transcript: [hlg-runs/run0-original.log](hlg-runs/run0-original.log).
862
+
863
+ ## Appendix B — Run A (recommended / rec+hlg / hlg-replace)
864
+
865
+ Full transcript: see the run output below (creative + continuation shown; factual
866
+ & reasoning collapsed to ~0.30 near-verbatim across all rows).
867
+
868
+ ```
869
+ ═══ [creative]
870
+ ▸ recommended distinct-2 0.90
871
+ 1. The fog, a thick, woolly blanket that swallowed the beam of his lantern, seemed to press against the glass, and it was through that swirling gray veil that Silas first saw the impossible.
872
+ 2. The sea fog … carried a faint, metallic tang, like old …
873
+ 3. The relentless, salt-laced fog … until the silence was broken by a sound that certainly hadn't been the groan of the old lamp mechanism.
874
+ 4. The fog … finally delivered something unexpected to the beam of the Grand Shoal light.
875
+ ▸ rec+hlg distinct-2 0.89
876
+ 1. The fog, a thick and suffocating blanket that clung to the granite tower like wet wool, had been a familiar, monotonous companion to Elias for thirty years, yet this morning … a scent entirel…
877
+ 3. The relentless, salt-laced fog that clung to the tower like a shroud offered up, on a Tuesday afternoon, something that was decidedly, inexplicably *not* a seabird.
878
+ ▸ hlg-replace distinct-2 0.90
879
+ 1. The fog, a thick and scudding curtain that had swallowed the coastline whole … what Silas glimpsed in its inky heart was something that decidedly did not belong t…
880
+ 3. The relentless, butter-yellow fog … a single, impossible flash of deep sap…
881
+
882
+ ═══ [brainstorm] recommended 0.78 → rec+hlg 0.88 → hlg-replace 0.88
883
+ rec+hlg #1: "…1. **Improvised Zipper Pull:** If the tab or pull on a zipper breaks off or becomes too small to grip, you can carefully thread a s…" ← broke the "SIM Card Ejector" rut
884
+
885
+ ═══ [continuation] recommended 0.75 → rec+hlg 0.84 → hlg-replace 0.86
886
+ hlg-replace #4 (tail leak): "…behaves like a cartographer's stain—aving purpose, dissolving under new light…"
887
+ ```
888
+
889
+ Complete verbatim transcript: [hlg-runs/runA-recommended.log](hlg-runs/runA-recommended.log).
890
+
891
+ ## Appendix C — Run B (gain variants: rolloff / midboost / soft / full)
892
+
893
+ Diversity numbers in §6.3. Representative creative openings:
894
+
895
+ ```
896
+ ▸ hlg-rolloff #1: "The swirling, pea-soup fog that clung to the edge of the jagged coastline seemed to thicken just as Elias, his face ruddy from years of wind-whipped solitude, noticed a flicker of unnatural, vibrant green…"
897
+ ▸ hlg-midboost #1: "…it was through that swirling gray veil that Silas first saw it—a perfectly smooth, obsidian orb bobbing just…"
898
+ ▸ hlg-full #3: "The relentless, salt-laced fog … offered up, on a Tuesday afternoon, something that was decidedly, inexplicably *not* a seabird."
899
+ ```
900
+
901
+ All rows coherent; factual locked at 0.30; continuation 0.75 → 0.82–0.85.
902
+ Complete verbatim transcript: [hlg-runs/runB-gain-variants.log](hlg-runs/runB-gain-variants.log).
903
+
904
+ ## Appendix D — Run C (pivots: top / entropy / median, as replacement) — full transcript
905
+
906
+ ```
907
+ # standard (control) = the model's recipe: temp 1 · top_p 0.95 · top_k 64
908
+ # hlg-* = REPLACEMENT sampler (one curve, 3 pivot placements, no top_p/top_k).
909
+
910
+ ═══ [creative]
911
+ ▸ standard 0.90
912
+ 1. The fog, a thick, woolly blanket … Silas first saw the impossible.
913
+ 2. The sea fog … a faint, metallic tang, like old …
914
+ 3. The relentless, salt-laced fog … the groan of the old lamp mechanism.
915
+ 4. The fog … the beam of the Grand Shoal light.
916
+ ▸ hlg-top 0.95
917
+ 1. The swirling, pea-soup fog that clung to the edge of the jagged coastline seemed to thicken just as a flash of unnatural green light pulsed from the gray expanse.
918
+ 2. The sea fog … carried a scent of something alien.
919
+ 3. The relentless, butter-yellow fog was thick enough to chew … the odd, rhythmic glimmer appeared ten正常的 yards from t… [← stray token]
920
+ 4. The fog, usually a thick, insulating blanket around the solitary tower, began to swirl with an unnatural luminescence as he made his evening rounds.
921
+ ▸ hlg-entropy 0.99 ⚠️ GARBAGE
922
+ 1. The Lern AideObserver, a scfileobjextracted keeper subs tuturल्तान subscription exam بالتfog साप्ताहिक, প্রশ্ন তোলার মতো অপ্রত্যাশিত, when MSMাবেনевич' başlayan তার ঘূর্ণAvlৰ আলো inulai a peculiar हॉकी of scent and effor…
923
+ 2. The जैसে overtakehouses, a thickolver漏洞 খাওয়ার,ᵛ<br Zweigen graissesigğim, is where Continuando stared homedidnivased the fog pressing against synthwave- kajak-soaked ClauseCloudsPPT…
924
+ ▸ hlg-median 1.00 ⚠️ GARBAGE
925
+ 1. The Lern AideObserveratic簿 scfileobjextracteddatabases Nimbus stretched thickatório بالتح साप्ताहिक帳 প্রশ্ন, a hateful, damp shroud…
926
+ 2. The जैसे overtakehouses,рачиnolver fog খাওয়ার,ᵛकेनोइक 瞭臤ğim stumbledgryifford丹अ through traysivased glass sacksстая
927
+
928
+ ═══ [factual]
929
+ ▸ standard 0.30 — "The seasons on Earth are primarily caused by the tilt of the Earth's axis as it revolves around the Sun." (×4, minor variants)
930
+ ▸ hlg-top 0.55 — mostly correct; #3 leaked: "the tilt of the planet' adorable axis … throughout kä's orbit."
931
+ ▸ hlg-entropy 0.99 ⚠️ — "The Lern AideObserver Electrons' scfileobjextracted, tutur tubatório hidadier tut প্রশ্নତ୍Kurs'"
932
+ ▸ hlg-median 1.00 ⚠️ — "The जैसे overtakehouses仰рачи倾olver漏洞格局 ᵛ<br Zweigen graisseuse.apparent échelle saisonAlloc Lieu en cours rotation follicle orbit 結構"
933
+
934
+ ═══ [reasoning]
935
+ ▸ standard 0.28 — coherent step-by-step (×4)
936
+ ▸ hlg-top 0.35 — coherent; tiny leaks ("scavenging price of the bat", "প্রশ্ন let 'B'")
937
+ ▸ hlg-entropy 1.00 ⚠️ GARBAGE
938
+ ▸ hlg-median 0.99 ⚠️ GARBAGE
939
+
940
+ ═══ [continuation]
941
+ ▸ standard 0.75 — coherent, vivid (×4)
942
+ ▸ hlg-top 0.88 — coherent AND varied:
943
+ 2. "…how it insists on polishing fractured timelines into gleaming, heroic monuments, even when the original quarry was a muddy, bewildered ditch."
944
+ 3. "…how it acts like a coral reef—brilliantly shaped in its fleeting, vibrant bloom, only to be slowly colonized and ultimately obscured by the perpetual, grinding algae of the new…"
945
+ 4. "…how it vaccinates us against our own truth … yesterday's sharpest agony marketable as yesterday' recalls u…" [← tail fraying]
946
+ ▸ hlg-entropy 1.00 ⚠️ GARBAGE — "'The Aideang strane簿 sche tup de uman tuturí namiatório hidadierá escult প্রশ্ন p a'i nto'…"
947
+ ▸ hlg-median 1.00 ⚠️ GARBAGE — "'The Aideang strane簿 scfileobj tup ad tutur sbonnadier…"
948
+ ```
949
+
950
+ Complete verbatim transcript: [hlg-runs/runC-pivots.log](hlg-runs/runC-pivots.log).
951
+
952
+ ---
953
+
954
+ *Raw logs (committed, full verbatim transcripts):*
955
+ Pass 1 — [run0-original.log](hlg-runs/run0-original.log),
956
+ [runA-recommended.log](hlg-runs/runA-recommended.log),
957
+ [runB-gain-variants.log](hlg-runs/runB-gain-variants.log),
958
+ [runC-pivots.log](hlg-runs/runC-pivots.log).
959
+ Pass 2 — [runD-oetf.log](hlg-runs/runD-oetf.log) (literal OETF),
960
+ [runE-eotf.log](hlg-runs/runE-eotf.log) (EOTF/OOTF),
961
+ [runF-shaper-working.log](hlg-runs/runF-shaper-working.log) (HLGShaper W5/os18 — works),
962
+ [runG-shaper-sweep.log](hlg-runs/runG-shaper-sweep.log) (knob sweep, full untruncated text).
963
+ Pass 3 (premature negative) — [runH-wsweep.log](hlg-runs/runH-wsweep.log) (clean 1-D W sweep),
964
+ [runI-asweep.log](hlg-runs/runI-asweep.log) (clean 1-D A sweep),
965
+ [runJ-knobmap.log](hlg-runs/runJ-knobmap.log) (narrow 5-knob map),
966
+ [runK-frontier.log](hlg-runs/runK-frontier.log) (N=10 self-BLEU + interactions).
967
+ Pass 4 (reversal → DOMINANCE) — [runL-widemap.log](hlg-runs/runL-widemap.log) (wide ranges, all knobs break),
968
+ [runM-frontier-emb.log](hlg-runs/runM-frontier-emb.log) + [hlg-frontier.json](hlg-runs/hlg-frontier.json) (N=10, self-BLEU + **embedding** + distinct-2),
969
+ [runN-verify.log](hlg-runs/runN-verify.log) (text verification of A.01×s_m.05 — correct + genuinely diverse).
970
+ Harnesses: `scripts/hlg-compare.ts`, `scripts/hlg-map.ts`, `scripts/hlg-frontier.ts` (the latter now scores embedding-similarity too).