gpu-engine 0.0.0-stage → 0.0.1
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.
- package/LICENSE +21 -0
- package/README.md +96 -2
- package/SPEC.md +988 -0
- package/THIRD_PARTY_NOTICES.md +29 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +4 -0
- package/dist/harness.d.mts +132 -0
- package/dist/harness.mjs +1 -0
- package/dist/index.d.mts +98 -0
- package/dist/index.mjs +1 -0
- package/dist/load-o_thEAKC.mjs +258 -0
- package/dist/scaffold-CY5xhy-V.mjs +106 -0
- package/dist/types-BwigqFwr.d.mts +868 -0
- package/docs/apps.md +108 -0
- package/docs/cli.md +126 -0
- package/docs/data.md +101 -0
- package/docs/diagnostics.md +509 -0
- package/docs/harness.md +191 -0
- package/docs/layers.md +249 -0
- package/docs/measurements/auto-threshold.json +335 -0
- package/docs/measurements/auto-threshold.md +56 -0
- package/docs/measurements/real-gpu-2026-11-22.json +4718 -0
- package/docs/measurements/real-gpu-2026-11-22.md +75 -0
- package/docs/runtime.md +112 -0
- package/docs/sealed-test-set.md +107 -0
- package/docs/weights-format.md +138 -0
- package/llms.txt +24 -0
- package/package.json +73 -3
- package/skills/gpu-engine/SKILL.md +117 -0
- package/templates/common/AGENTS.md +27 -0
- package/templates/common/github/workflows/ci.yml +35 -0
- package/templates/common/gitignore +3 -0
- package/templates/common/package.template.json +27 -0
- package/templates/common/tsconfig.template.json +17 -0
- package/templates/pooled/NEW_MODEL_NAME.eval.ts +93 -0
- package/templates/pooled/NEW_MODEL_NAME.model.ts +11 -0
- package/templates/pooled/SPEC.md +31 -0
- package/templates/pooled/src/decode.ts +10 -0
- package/templates/pooled/src/index.ts +44 -0
- package/templates/pooled/src/weights.ts +4 -0
- package/templates/retrieve/NEW_MODEL_NAME.eval.ts +149 -0
- package/templates/retrieve/NEW_MODEL_NAME.model.ts +12 -0
- package/templates/retrieve/SPEC.md +33 -0
- package/templates/retrieve/data/table.jsonl +16 -0
- package/templates/retrieve/src/decode.ts +9 -0
- package/templates/retrieve/src/index.ts +45 -0
- package/templates/retrieve/src/table.ts +21 -0
- package/templates/retrieve/src/weights.ts +4 -0
- package/templates/tag/NEW_MODEL_NAME.eval.ts +114 -0
- package/templates/tag/NEW_MODEL_NAME.model.ts +11 -0
- package/templates/tag/SPEC.md +31 -0
- package/templates/tag/src/decode.ts +25 -0
- package/templates/tag/src/index.ts +44 -0
- package/templates/tag/src/weights.ts +4 -0
package/docs/harness.md
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
# Harness
|
|
2
|
+
|
|
3
|
+
The harness takes a model from definition to release: data, training, the dev loop, the sealed test set, promotion, parity and ship checks. It runs in Node, from the `gpu-engine` CLI or the `gpu-engine/harness` entry. [SPEC.md](../SPEC.md) sections 6 to 8 and 10 are the normative text; [cli.md](./cli.md) lists every command and flag.
|
|
4
|
+
|
|
5
|
+
## The model package
|
|
6
|
+
|
|
7
|
+
`gpu-engine new <name> --head tag|pooled|retrieve` writes one. Every command runs in its folder (or `--dir`) and finds exactly one `*.model.ts` and one `*.eval.ts`.
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
<name>.model.ts defineModel: input, net, head, quant, budgets
|
|
11
|
+
<name>.eval.ts defineEval(model, ...): sets, data, train, decode, metric, baselines, gate, parity, ship
|
|
12
|
+
src/decode.ts your decode step, shared by the eval and the shipped entry
|
|
13
|
+
src/index.ts the shipped entry: load({ backend, gpu? }), then run(text), inspect() and destroy()
|
|
14
|
+
src/weights.ts the promoted weights as lowercase hex, written by promote
|
|
15
|
+
src/table.ts retrieve only: the eval's table as a module, written by gpu-engine build
|
|
16
|
+
dist/ not committed: index.mjs and index.d.mts, written by gpu-engine build
|
|
17
|
+
data/train/*.jsonl data/dev/*.jsonl data/test/*.jsonl one file is one named set
|
|
18
|
+
data.lock.json file hashes, row counts and test fingerprints
|
|
19
|
+
tries.jsonl one row per loop try, dev scores only
|
|
20
|
+
reads.jsonl every touch of the test set
|
|
21
|
+
gate.json level and the promoted scores
|
|
22
|
+
report.json what the last promotion measured
|
|
23
|
+
MODEL_CARD.md RESULTS.md generated from report.json
|
|
24
|
+
parity.json the last parity run
|
|
25
|
+
weights/<name>.bin the promoted weights file
|
|
26
|
+
.gpu-engine/ not committed: the candidate and checkpoints from the last loop
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The CLI loads the two files with Node's own type stripping, so they use erasable TypeScript only and `.ts` extensions in relative imports. Their `import ... from 'gpu-engine'` resolves to the built package.
|
|
30
|
+
|
|
31
|
+
## The eval file
|
|
32
|
+
|
|
33
|
+
Nothing in `defineEval` has a default: the data, the training run, the gate and parity are always written out.
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import model from './my-model.model.ts'
|
|
37
|
+
|
|
38
|
+
export default defineEval(model, {
|
|
39
|
+
sets: { train: 'data/train/*.jsonl', dev: 'data/dev/*.jsonl', test: sealed('data/test/*.jsonl') },
|
|
40
|
+
data: defineDataset<Result>({
|
|
41
|
+
seed: 1,
|
|
42
|
+
minSize: { train: 600, dev: 120, test: 120 },
|
|
43
|
+
generate: { train, dev, test },
|
|
44
|
+
}),
|
|
45
|
+
train: { seeds: [1, 2], epochs: 12, batch: 16, learningRate: 0.02, warmup: 0.1, budgetSeconds: 30 },
|
|
46
|
+
decode,
|
|
47
|
+
metric: (pred, gold) => (pred.count === gold.count && pred.item === gold.item ? 1 : 0),
|
|
48
|
+
baselines: { rules },
|
|
49
|
+
gate: { floors: 'promoted', noise: 0.03 },
|
|
50
|
+
parity: { tolerance: 1e-3 },
|
|
51
|
+
ship: { brotliBytes: 40_000, files: ['dist/index.mjs', 'dist/index.d.mts'] },
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
- The model comes first, so the eval needs no type arguments: `decode` gets the head output the model's head gives (`ModelOutput<typeof model>`) and the input (`EvalInput<typeof model>`, the text for a model without flag rows), and what it returns types `metric` and the baselines. Without `decode` the result is the head output. Write `decode` before `metric`: TypeScript infers the result from the first of them it reads. `defineEval({ ... })` without the model is `DEFINE_EVAL_MODEL`.
|
|
56
|
+
- `defineEval` checks every option when the file loads and throws a `DEFINE_*` code naming the first bad one: `DEFINE_DATA_INVALID` (`seed`, `minSize`, `generate`), `DEFINE_TRAIN_INVALID` (`seeds` non-empty and distinct integers, positive integer `epochs` and `batch`, finite `learningRate` and `budgetSeconds` above 0, `warmup` from 0 up to 1, positive integer `negatives`), `DEFINE_GATE_INVALID` (finite `noise` of at least 0), `DEFINE_PARITY_INVALID` (finite `tolerance` of at least 0), `DEFINE_SHIP_INVALID` and `DEFINE_EVAL_INVALID` (`metric`, `decode`, `baselines`). The model's `name` must be lowercase letters, digits and `-`, starting with a letter (`DEFINE_NAME_INVALID`), since it names `weights/<name>.bin`.
|
|
57
|
+
- `sets` must point inside `data/train/`, `data/dev/` and `data/test/` (`DEFINE_SET_FOLDER`). The test set is wrapped in `sealed(...)`, the only place code may name its folder.
|
|
58
|
+
- `train.seeds` run one after another; the budget `budgetSeconds` is split across them. A `retrieve` head also needs `train.negatives`.
|
|
59
|
+
- `baselines` are plain functions from input to result, scored beside the model. Write at least one rule baseline: a model that does not beat it is not worth its bytes.
|
|
60
|
+
- `table` (retrieve heads only) is a JSONL file of `{ "id", "text" }` rows outside the set folders.
|
|
61
|
+
|
|
62
|
+
## Data
|
|
63
|
+
|
|
64
|
+
A row is one JSON object per line:
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{ "input": "Ana bought 3 pens", "gold": ["other", "other", "count", "item"], "group": "train-bought", "vocab": ["Ana"] }
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`input` is text or `{ text, flags }`. `gold` is one label per token for a `tag` head, one label for a `pooled` class head, an array of numbers for a values head, an array of table ids for a `retrieve` head. `expect` (optional) is the decoded result to score against, when it is not `decode(gold)`. `group` names where the row came from, such as a sentence frame or a domain; `vocab` lists words no two sets may share.
|
|
71
|
+
|
|
72
|
+
Every command that trains runs the data step first:
|
|
73
|
+
|
|
74
|
+
1. Generate. Each `generate.<set>` is `(random) => rows`, seeded from `data.seed`. It runs only when the set's folder holds no file, and never rewrites a file, so an existing test set is never touched. Each generator is optional. Before `promote --seal`, remove `generate.test` (`SEAL_GENERATOR_FOUND`): with it and the seed, anyone could rebuild the sealed rows.
|
|
75
|
+
2. Compare. The train and dev generators run again in memory, and a generated file that is not what its generator writes now is `DATA_GENERATOR_CHANGED`, so an edited generator is never silently ignored. Accept the edit with `loop --regenerate train`, `dev` or `train,dev`: it rewrites those files and drops their lock entries, which the data step records again. The test generator is never run again. `doctor` runs no generator and skips this check.
|
|
76
|
+
3. Check. The section 7 checks: every set exists and meets `minSize`, rows fit the head, no example is in two sets after normalising case and whitespace, no `group` or `vocab` word is shared by sets, and every file matches its hash in `data.lock.json`. Each failure names files and counts, never examples.
|
|
77
|
+
4. Record. A set without an entry in `data.lock.json` gets one once every check passes.
|
|
78
|
+
|
|
79
|
+
The lock is never rewritten, except that `loop --regenerate` drops the entries of the sets it rewrites. To accept a changed file you wrote by hand, delete that set's entry by hand and rerun `loop`; the change then shows in the diff.
|
|
80
|
+
|
|
81
|
+
Split by group, not by row: if dev and test hold sentences from the frames train learned, a model that memorised the frames scores well and generalises to nothing. Give each set its own groups, and its own `vocab` when the model must handle words it never saw.
|
|
82
|
+
|
|
83
|
+
## Scores
|
|
84
|
+
|
|
85
|
+
Every score table has one column per set and one row per method:
|
|
86
|
+
|
|
87
|
+
| Row | Score of each example |
|
|
88
|
+
| ------------- | ------------------------------------------ |
|
|
89
|
+
| model | `metric(decode(output, input), reference)` |
|
|
90
|
+
| each baseline | `metric(baseline(input), reference)` |
|
|
91
|
+
| oracle | `metric(decode(gold, input), reference)` |
|
|
92
|
+
|
|
93
|
+
The reference is `expect` when the row has one, else `decode(gold, input)`. The oracle is the ceiling the decode step allows: when it is below 1, the decode loses information and no model can fix that. The model is always scored on its quantized weights; a float score is never reported.
|
|
94
|
+
|
|
95
|
+
## Loop
|
|
96
|
+
|
|
97
|
+
`gpu-engine loop --log "<idea>"` runs one try: the level 1 scan, the data step, training on train with dev as the scorer, then the dev table and the gate. It writes the candidate to `.gpu-engine/` and appends one row to `tries.jsonl`. It exits 0 when every gate line passes, 1 otherwise; the candidate and the try are written either way. `train.budgetSeconds` caps the training time; keep a try under a minute so you can run many.
|
|
98
|
+
|
|
99
|
+
`gpu-engine loop --fail [--set <name>]` trains nothing. It scores the candidate on dev and prints every dev example where the model scores below the oracle, with its input, reference and result. It never touches the test set.
|
|
100
|
+
|
|
101
|
+
`gpu-engine loop --mark kept|dropped` trains nothing either. Once you have read a try's dev score and kept or reverted the change, it records that decision as the `status` of the last row of `tries.jsonl`. It refuses (`CLI_FLAG_INVALID`) when there is no try or the last try already has a status.
|
|
102
|
+
|
|
103
|
+
### Tries log
|
|
104
|
+
|
|
105
|
+
`tries.jsonl` is append-only, one JSON row per line and one row per try (shown across lines here):
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"at": "2026-11-21T17:52:30.334Z",
|
|
110
|
+
"commit": "none",
|
|
111
|
+
"dirty": false,
|
|
112
|
+
"idea": "starter",
|
|
113
|
+
"status": null,
|
|
114
|
+
"definition": "877fc88ef32374fd",
|
|
115
|
+
"seeds": [1, 2],
|
|
116
|
+
"dev": { "main": 1 },
|
|
117
|
+
"devScore": 1,
|
|
118
|
+
"devSpread": 0.008,
|
|
119
|
+
"brotliBytes": 3409,
|
|
120
|
+
"macsPerToken": 944,
|
|
121
|
+
"trainSeconds": 1.26,
|
|
122
|
+
"gate": "pass"
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
`idea` is `--log`, `status` is `kept` or `dropped` from `--status` or a later `loop --mark` (null until then), `definition` the model's hash, `devScore` the mean over dev sets, `devSpread` the best minus the worst seed's dev score, `dirty` whether the git working tree had uncommitted changes (the harness's own `tries.jsonl` and `reads.jsonl` do not count). A line that is not a tries row, such as half a line a killed `loop` left, stops `loop` and `loop --mark` with `PROJECT_STATE_INVALID`; so does a `.gpu-engine/candidate.json` that does not parse, which the next `loop` replaces. A try where a seed's loss stopped being finite adds `diverged`, the seed to the step, such as `{ "2": 14 }`, and `loop` prints one `note: training diverged ...` line; when no checkpoint of a seed stayed finite, `loop` exits 1 with `TRAIN_DIVERGED`. The key list is closed and any key matching `/test/i` is refused, so a try never carries a test score.
|
|
127
|
+
|
|
128
|
+
## Gate
|
|
129
|
+
|
|
130
|
+
`gate.json` is `{ level, promoted }`; `promoted` stays null until the first promotion. Each gate line passes or fails with a code:
|
|
131
|
+
|
|
132
|
+
| Line | Passes when | Code |
|
|
133
|
+
| ------ | ---------------------------------------------------------------- | ------------------------ |
|
|
134
|
+
| Floor | Each set scores at least the promoted score minus `gate.noise` | `GATE_FLOOR_FAILED` |
|
|
135
|
+
| Budget | The weights file's Brotli bytes are within `budgets.brotliBytes` | `BUDGET_BYTES_EXCEEDED` |
|
|
136
|
+
| Budget | `macsPerToken` is within `budgets.macsPerToken` | `DEFINE_BUDGET_EXCEEDED` |
|
|
137
|
+
| Data | Every data file matches `data.lock.json` | `DATA_HASH_CHANGED` |
|
|
138
|
+
|
|
139
|
+
`loop` gates dev; `promote` gates dev and test. On the first promotion every floor passes. A set that was promoted and has no score now fails, so removing a set cannot skip its floor. The floor line prints the seed spread next to `noise`: a spread wider than `noise` means the floor sits inside seed-to-seed variation, so add seeds or raise `noise` with that number as the reason.
|
|
140
|
+
|
|
141
|
+
## Promote
|
|
142
|
+
|
|
143
|
+
`gpu-engine promote` turns the candidate into the promoted model, without training. It refuses a missing or stale candidate (`PROMOTE_CANDIDATE_MISSING`, `PROMOTE_CANDIDATE_STALE`: run `loop`), then reads the test set once, counted in `reads.jsonl`, scores dev and test, and runs the gate. On a pass it writes `weights/<name>.bin`, `src/weights.ts`, `gate.json`, `report.json`, `MODEL_CARD.md` and `RESULTS.md`. On a failure it prints the tables and the gate and writes nothing.
|
|
144
|
+
|
|
145
|
+
The test set leaves `promote` as per-set aggregates only. Every string it prints or writes is first scanned for test inputs (`DATA_TEST_PRINTED`), and the package's own output is muted from the read on: `console` and `process.stdout` and `process.stderr`, references saved when the package loaded and output deferred to a microtask, `process.nextTick` or a zero-delay timer included. Any attempt is `DATA_TEST_PRINTED`, and the `gpu-engine` process stays muted until it exits. [sealed-test-set.md](./sealed-test-set.md) explains the levels and `promote --seal`.
|
|
146
|
+
|
|
147
|
+
`report.json` holds the date, commit, definition hash, the weights' SHA-256, bytes and Brotli bytes, parameters, multiply-adds, the training run (seeds, chosen seed, steps, seconds, dev score per seed), the data hashes (a retrieve head's table included), the dev and test tables, the gate lines, `testReads` and the level. `MODEL_CARD.md` and `RESULTS.md` are rendered from it by pure functions and must not be edited by hand.
|
|
148
|
+
|
|
149
|
+
## Verify
|
|
150
|
+
|
|
151
|
+
`gpu-engine promote --verify` is the CI gate. It reads no test data. It checks the level 1 scan, the data checks and hashes against the report, the model file's hash, the weights file, a fresh dev score against the report's dev table, `gate.json`, the budgets and dev floors, the read count in `reads.jsonl`, and that `MODEL_CARD.md`, `RESULTS.md` and `src/weights.ts` regenerate byte-identical. Any difference exits 1 with its code (`VERIFY_*`, `DATA_HASH_CHANGED`, `WEIGHTS_DEFINITION_MISMATCH`, `GATE_FLOOR_FAILED`, the budget codes).
|
|
152
|
+
|
|
153
|
+
After a promotion, a changed model file fails verify with `WEIGHTS_DEFINITION_MISMATCH` until the tuned model is promoted. That is expected while tuning: promote once when the tuning is done.
|
|
154
|
+
|
|
155
|
+
Verify cannot re-measure test scores without a read, so it checks that the report, `gate.json` and the generated files agree on them. An edit to all of them together shows only in the repository history.
|
|
156
|
+
|
|
157
|
+
## Doctor
|
|
158
|
+
|
|
159
|
+
`gpu-engine doctor` runs every check that needs no training and no test read: the model and eval files load with their definition checks, the level 1 scan, the data checks with a digest of the test set, `gate.json`, the promoted weights against the byte budget, the report against the package, the ship checks when `dist/` exists, and the level 3 checks when sealed. It prints each finding with its code, why and fix, a `pass` or `note` line for every clean check, and exits 1 on any finding. It writes no data and runs no function the package supplies. A fresh package from `new` passes. A model file changed after the promotion is a note, not a finding: it is the normal state while tuning, and the note says that `promote --verify` fails until you promote once.
|
|
160
|
+
|
|
161
|
+
## Inspect
|
|
162
|
+
|
|
163
|
+
`gpu-engine inspect "<text>"` shows what the model does with one input: the tokens with offsets, the feature rows of each token, the weights file it runs and the definition hash that file carries, the raw logits, the head output and the decoded result, the backend and the reason it was chosen. It runs the weights trained from the model file as it is now: the last candidate when it was, else the promoted weights, with a note saying which and why. When neither was, it exits 1 with `WEIGHTS_DEFINITION_MISMATCH`. A `retrieve` table is checked by the data step's rules (`DATA_SET_MISSING`, `DATA_ROW_INVALID`). It never touches the test set.
|
|
164
|
+
|
|
165
|
+
## Parity
|
|
166
|
+
|
|
167
|
+
`gpu-engine parity` compares the promoted weights on three paths: the trainer's forward pass, the CPU runtime and the WGSL runtime. The fixtures are every dev input plus four edge inputs: empty text, one token, exactly `input.max` tokens and `input.max + 3` tokens. Never the test set.
|
|
168
|
+
|
|
169
|
+
1. Trainer and CPU must be bitwise identical.
|
|
170
|
+
2. CPU and WGSL must decode to the same result on every fixture (`PARITY_DECODE_DIFFERS`) and stay within `eval.parity.tolerance` on every logit (`PARITY_TOLERANCE_EXCEEDED`).
|
|
171
|
+
|
|
172
|
+
WGSL needs the `webgpu` package as a devDependency of the model package and a Vulkan driver (`PARITY_ADAPTER_MISSING` names the install). On a pass it writes `parity.json` with the adapter name, the tolerance, the fixture count and the largest difference, and regenerates `MODEL_CARD.md`. Parity in this repository's CI runs on a software adapter (llvmpipe), so `parity.json` records `realGpu: "not run"`. Parity runs in Node, so the model card says `Real browser: not run`; an older `parity.json` with a `realBrowser` field still reads. Parity destroys the models it loads, so no GPU device outlives the command. On an adapter whose name is not a software rasterizer's, parity records its CPU and WGSL result as `realGpu` and prints it as the real GPU line.
|
|
173
|
+
|
|
174
|
+
## Ship
|
|
175
|
+
|
|
176
|
+
`npm run build` runs `gpu-engine build` ([cli.md](./cli.md#build)): it bundles `src/index.ts` with the gpu-engine runtime and the hex weights into `dist/index.mjs`, one ES module that imports nothing with the MIT notices in its first comment, and declares its exports in `dist/index.d.mts`. A `retrieve` head's `src/table.ts` is rewritten first from the table the eval names, so the package ships the table the harness evaluated. `npm run typecheck` runs `tsc -p .` on the package. When `dist/` exists, `doctor` also runs the ship checks. They look at the package the way npm would publish it (`npm pack --dry-run`) and write nothing:
|
|
177
|
+
|
|
178
|
+
| Check | Code |
|
|
179
|
+
| --------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
|
|
180
|
+
| `package.json` parses and `npm pack --dry-run --json` lists the packed files | `SHIP_PACKAGE_INVALID` |
|
|
181
|
+
| No `dependencies` (or peer, optional, bundled) field, and no packed script imports anything | `SHIP_DEPENDENCY_FOUND` |
|
|
182
|
+
| Once `weights/<name>.bin` exists, a packed file holds it as lowercase hex, so the build has the promoted model | `SHIP_BUILD_STALE` |
|
|
183
|
+
| A `retrieve` head's packed files hold every row of the eval's table, and the table still has the hash `report.json` records | `SHIP_BUILD_STALE` |
|
|
184
|
+
| Every packed file is `package.json` or a path in `eval.ship.files` | `SHIP_FILE_NOT_ALLOWED` |
|
|
185
|
+
| The packed files' Brotli bytes, summed, are within `eval.ship.brotliBytes` | `SHIP_SIZE_EXCEEDED` |
|
|
186
|
+
|
|
187
|
+
Without `ship` in the eval file the last two checks do not run, and doctor says so. The scaffolded `.github/workflows/ci.yml` builds, runs `doctor`, then `promote --verify` once `report.json` exists, every step under `set -euo pipefail`. After a `promote` or a table change, run `npm run build` again: until then the build holds the old weights or table (`SHIP_BUILD_STALE`).
|
|
188
|
+
|
|
189
|
+
## Diagnostics
|
|
190
|
+
|
|
191
|
+
Every code, its why and its fix: [diagnostics.md](./diagnostics.md). Messages name files and counts, never examples.
|
package/docs/layers.md
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# Layers
|
|
2
|
+
|
|
3
|
+
The layer catalog is closed: `embed`, `conv`, `biScan`, `dense`, then one head, `tag`, `pooled` or `retrieve`. A model is `featurize -> net -> head -> decode`: `net` is an explicit list that starts with one `embed`, the head comes last, and your decode step turns the head's output into your result. Each section says what the layer does, what it costs in bytes and multiply-adds, when it helps and when it does not.
|
|
4
|
+
|
|
5
|
+
Each section starts with its builder. Every builder from `gpu-engine` (`features`, `layers`, `heads`, `int6`) takes one options object named after the fields it writes, such as `layers.dense({ size: 16, activation: 'relu' })`, and returns that plain object with its `kind`: `{ kind: 'dense', size: 16, activation: 'relu' }`, which is what the weights file hashes. Nothing is defaulted.
|
|
6
|
+
|
|
7
|
+
Widths are per token: `in` is the width the layer reads, `out` the width it writes, `n` the token count. Bytes are for int6 weights (6 bits per parameter, packed per tensor) before Brotli; the [weights file](./weights-format.md) adds the definition and a small record per tensor. The formulas are what `plan(definition)` from `gpu-engine/harness` computes; a test in this repository (`test/docs.test.ts`) evaluates every formula on this page and compares it with `plan()`.
|
|
8
|
+
|
|
9
|
+
| Op | Output width | Parameters | Multiply-adds per token | Sees other tokens |
|
|
10
|
+
| ---------- | ------------ | -------------------------- | -------------------------- | -------------------------- |
|
|
11
|
+
| `embed` | `size` | `rows * size + size` | `slots * size` | no |
|
|
12
|
+
| `conv` | `in` | `taps * in + in` | `taps * in` | `(taps - 1) / 2` each side |
|
|
13
|
+
| `biScan` | `2 * size` | `4 * size * in + 4 * size` | `4 * size * in + 2 * size` | all, both sides |
|
|
14
|
+
| `dense` | `size` | `size * in + size` | `size * in` | no |
|
|
15
|
+
| `tag` | `labels` | `labels * in + labels` | `in * labels` | no |
|
|
16
|
+
| `pooled` | `out` | `out * 2 * in + out` | `2 * in + 2 * in * out` | all, by pooling |
|
|
17
|
+
| `retrieve` | `size` | `size * 2 * in + size` | `2 * in + 2 * in * size` | all, by pooling |
|
|
18
|
+
|
|
19
|
+
A model's totals are the sums over its ops: `loop` prints its multiply-adds per token and the Brotli bytes of the trained weights, and `defineModel` throws `DEFINE_BUDGET_EXCEEDED` when the layers already exceed `budgets`. In a small model the `embed` table is most of the bytes; hashed rows that no training token reaches stay zero and Brotli shrinks them to almost nothing, so the trained file is usually well under the packed size.
|
|
20
|
+
|
|
21
|
+
The contract every layer implements (forward, backward, WGSL bindings, numeric rules) is at the top of `src/kit/ops.ts` in this repository.
|
|
22
|
+
|
|
23
|
+
## embed
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
layers.embed({ size }) // must be the first layer, once
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
What it does: turns each token's feature rows into one vector. The featurizer gives every token `slots` embedding row indices (`-1` for an empty slot); `embed` adds the matching rows of a `[rows, size]` table to a bias of length `size`: `y[t] = b + sum of table[r]` over the token's filled slots. `in = slots`, `out = size`. A row that fills two slots, or two tokens, is added each time. `rows` and `slots` come from `features.tokens({ rows })` (SPEC.md section 5, Feature rows). It sees one token at a time.
|
|
30
|
+
|
|
31
|
+
| Cost | Formula |
|
|
32
|
+
| ----------------------- | ------------------------------------------------ |
|
|
33
|
+
| Parameters | `rows * size + size` |
|
|
34
|
+
| Bytes (int6, packed) | `ceil(6 * rows * size / 8) + ceil(6 * size / 8)` |
|
|
35
|
+
| Multiply-adds per token | `slots * size` (additions: no multiplies) |
|
|
36
|
+
|
|
37
|
+
For example `embed({ size: 20 })` over `features.shape()` and `features.hash({ buckets: 2048, k: 2 })` (2061 rows, 4 slots): 41,240 parameters, 30,930 bytes, 80 multiply-adds per token. The table is nearly all of a small model's bytes, while its compute is the cheapest of any layer.
|
|
38
|
+
|
|
39
|
+
Initial values: the table starts at zero and the bias uniform in `±0.1`. A row that no training token reaches, such as a hash bucket only unseen words land in, stays zero, so it adds nothing at run time and Brotli shrinks it to almost nothing. The bias is not zero because an all-zero `embed` sends zeros forward: a `relu` layer after it then sits at its kink, passes no gradient, and the table never learns.
|
|
40
|
+
|
|
41
|
+
When it helps:
|
|
42
|
+
|
|
43
|
+
- Always: it is the only way in. Every model starts with one `embed`.
|
|
44
|
+
- A wider `size` gives every later layer more channels to work with, and costs `rows` parameters per channel. Raise it when dev scores improve with depth but plateau early.
|
|
45
|
+
|
|
46
|
+
When it does not:
|
|
47
|
+
|
|
48
|
+
- Bytes grow with `rows * size`. More hash buckets cut collisions between words but each bucket costs `size` parameters; on a small training set most buckets are never reached, so past a few times the training vocabulary they mostly add rows that stay zero.
|
|
49
|
+
- `k` hash rows per token make collisions rarer for the same bucket count, at `k * size` more additions per token. Two is usually enough.
|
|
50
|
+
- It adds no context and no non-linearity: two words that share no rows look unrelated, and a token's vector ignores its neighbours. Follow it with `conv` or `biScan`.
|
|
51
|
+
|
|
52
|
+
WGSL: one pass, one invocation per (token, output channel), `ceil(n * size / 64)` workgroups of 64; binding 2 is the featurizer's rows as `array<i32>`. Matches the CPU within 1e-5 on the software adapter (llvmpipe) for `n` = 1, 2 and the maximum token count (`test/gpu/embed.test.ts`). Real GPU: not run. Real browser: not run.
|
|
53
|
+
|
|
54
|
+
## conv
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
layers.conv({ taps }) // taps: odd, 1, 3, 5, ...
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
What it does: mixes each token with its neighbours, channel by channel. With `h = (taps - 1) / 2`, `y[t, i] = tanh(b[i] + sum over j of kernel[j, i] * x[t + j - h, i])`: tap `h` is the token itself, taps below it the tokens before, taps above it the tokens after. Tokens past either end read as zero. It is depthwise: channel `i` reads only channel `i` of its neighbours, so it never mixes channels. `out = in`.
|
|
61
|
+
|
|
62
|
+
| Cost | Formula |
|
|
63
|
+
| ----------------------- | -------------------------------------------- |
|
|
64
|
+
| Parameters | `taps * in + in` |
|
|
65
|
+
| Bytes (int6, packed) | `ceil(6 * taps * in / 8) + ceil(6 * in / 8)` |
|
|
66
|
+
| Multiply-adds per token | `taps * in` |
|
|
67
|
+
|
|
68
|
+
For example `conv({ taps: 3 })` after a 20-wide `embed`: 80 parameters, 60 bytes, 60 multiply-adds per token.
|
|
69
|
+
|
|
70
|
+
Initial values: the centre tap starts at 1 and the other taps uniform in `±0.1`, the bias at zero, so a new `conv` starts close to `tanh(x)`, passing each token through, and learns how much of its neighbours to mix in.
|
|
71
|
+
|
|
72
|
+
When it helps:
|
|
73
|
+
|
|
74
|
+
- When a token's label depends on the words right next to it ("to" before a unit, a number after "in"). Three taps see one word each side for 60 bytes, which a `dense` of any size cannot.
|
|
75
|
+
- Before `biScan`, to give the scan local features (word pairs) it would otherwise have to build up in its state.
|
|
76
|
+
- Cheap context: its cost grows with `taps * in`, not `in * in`, so it is the smallest layer that looks at other tokens.
|
|
77
|
+
|
|
78
|
+
When it does not:
|
|
79
|
+
|
|
80
|
+
- Context farther than `h` tokens away. Stacking `conv` layers widens the reach by `h` each time, but a `biScan` sees the whole input in both directions for a similar cost once the reach you need passes a few tokens.
|
|
81
|
+
- It never combines channels, so it cannot build a feature from two different features of the same token. Put a `dense` or a `biScan` after it for that.
|
|
82
|
+
- With `taps: 1` it is a per-channel scale and `tanh`, no context; it rarely earns its bytes.
|
|
83
|
+
- Positions near the ends see zeros for the missing neighbours. On inputs of one or two tokens most taps read nothing, so a wide kernel helps little there.
|
|
84
|
+
|
|
85
|
+
WGSL: one pass, one invocation per (token, channel), `ceil(n * in / 64)` workgroups of 64; only the first `n` tokens are read, whatever the buffer holds after them. Matches the CPU within 1e-5 on the software adapter (llvmpipe) for 1, 3, 5 and 7 taps with `n` = 1, 2 and the maximum token count (`test/gpu/conv.test.ts`). Real GPU: not run. Real browser: not run.
|
|
86
|
+
|
|
87
|
+
## dense
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
layers.dense({ size, activation }) // activation: 'relu' | 'tanh' | 'none'
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
What it does: a fully connected layer applied to each token on its own. For token `t`, `y[t] = act(W x[t] + b)` with `W` of shape `[size, in]` and `b` of length `size`. `out = size`. It mixes the channels of one token and never looks at other tokens.
|
|
94
|
+
|
|
95
|
+
| Cost | Formula |
|
|
96
|
+
| ----------------------- | ---------------------------------------------- |
|
|
97
|
+
| Parameters | `size * in + size` |
|
|
98
|
+
| Bytes (int6, packed) | `ceil(6 * size * in / 8) + ceil(6 * size / 8)` |
|
|
99
|
+
| Multiply-adds per token | `size * in` |
|
|
100
|
+
|
|
101
|
+
For example `dense({ size: 20, activation: 'relu' })` after a 40-wide `biScan`: 820 parameters, 615 bytes, 800 multiply-adds per token.
|
|
102
|
+
|
|
103
|
+
Initial values: weights uniform in `±sqrt(6 / in)` for `relu` (He) and `±sqrt(6 / (in + size))` for `tanh` and `none` (Glorot); biases zero.
|
|
104
|
+
|
|
105
|
+
When it helps:
|
|
106
|
+
|
|
107
|
+
- Between the sequence layers and the head, to combine what `conv` and `biScan` found into features the head can separate. One `dense` with `relu` or `tanh` gives the head a non-linear boundary instead of a linear one.
|
|
108
|
+
- To change width cheaply: shrink a wide `biScan` output (`2 * size`) before the head, which cuts the head's cost.
|
|
109
|
+
|
|
110
|
+
When it does not:
|
|
111
|
+
|
|
112
|
+
- It adds no context. If a token's label depends on its neighbours, add `conv` or `biScan`; a wider or deeper `dense` will not find what it cannot see.
|
|
113
|
+
- Its cost grows with `size * in`, the fastest-growing term in a small model. Two stacked `dense` layers rarely beat one wider one at the same byte budget on short inputs; try one first.
|
|
114
|
+
- `none` right before the head is a linear map the head already is (the head is linear too), so it only adds bytes. Use `relu` or `tanh` there, or drop the layer.
|
|
115
|
+
- `relu` units can die (stay at zero for every input) when the learning rate is high; if dev scores stall, try `tanh`.
|
|
116
|
+
|
|
117
|
+
WGSL: one pass, one invocation per (token, output channel), `ceil(n * size / 64)` workgroups of 64. Matches the CPU within 1e-5 on the software adapter (llvmpipe) for `n` = 1, 2 and the maximum token count (`test/gpu/dense.test.ts`). Real GPU: not run. Real browser: not run.
|
|
118
|
+
|
|
119
|
+
## biScan
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
layers.biScan({ size })
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
What it does: a bidirectional gated scan over the tokens. Each direction keeps `size` channels of state. For channel `d` at token `t`, `gate = sigmoid(Wg x[t] + bg)`, `candidate = (1 - gate) * tanh(Wc x[t] + bc)` and `state[t] = gate * state[t-1] + candidate`, with the state at 0 before the first token. The forward direction runs left to right, the backward direction right to left, and the output for token `t` is the forward states followed by the backward states, so `out = 2 * size`. Because of the `(1 - gate)` factor each state is a weighted mix of the previous state and a value in (-1, 1), so it stays in (-1, 1) at any length. A gate near 1 keeps what the channel holds; a gate near 0 replaces it with the current token.
|
|
126
|
+
|
|
127
|
+
| Cost | Formula |
|
|
128
|
+
| ----------------------- | ------------------------------------------------------ |
|
|
129
|
+
| Parameters | `4 * size * in + 4 * size` |
|
|
130
|
+
| Bytes (int6, packed) | `4 * ceil(6 * size * in / 8) + 4 * ceil(6 * size / 8)` |
|
|
131
|
+
| Multiply-adds per token | `4 * size * in + 2 * size` |
|
|
132
|
+
|
|
133
|
+
For example `biScan({ size: 20 })` after a 32-wide `conv`: 2640 parameters, 1980 bytes, 2600 multiply-adds per token, output 40 wide.
|
|
134
|
+
|
|
135
|
+
Initial values: gate and candidate weights uniform in `±sqrt(6 / (in + size))` (Glorot); gate biases spread evenly from 0 to 3 across the channels, so at the start some channels forget within a step (gate 0.5) and others keep a token for about twenty steps (gate 0.95); candidate biases zero.
|
|
136
|
+
|
|
137
|
+
When it helps:
|
|
138
|
+
|
|
139
|
+
- When a token's label depends on tokens far away, on either side: "12 kg to pounds" needs to know that "pounds" follows "to", and the first word of a long phrase may decide the last one. `conv` sees only its taps; `biScan` sees the whole input in both directions.
|
|
140
|
+
- When inputs vary a lot in length. The cost is linear in the token count and the state stays bounded, so long inputs behave like short ones.
|
|
141
|
+
- Stacked twice, the second scan reads both directions of the first and can combine left and right context per token. Try one first; a second scan doubles the cost.
|
|
142
|
+
|
|
143
|
+
When it does not:
|
|
144
|
+
|
|
145
|
+
- When only the immediate neighbours matter. A `conv` with 3 or 5 taps costs `taps * in` per token, far less than `4 * size * in`, and trains faster.
|
|
146
|
+
- Its cost grows with `size * in`. A wide input (a large `embed`) makes it expensive; put a narrow `dense` or keep `embed` small before it.
|
|
147
|
+
- The scan is sequential over tokens: on the WGSL path one invocation walks all `n` tokens, so it parallelises over channels only. With few channels and long inputs it is the slowest op on a GPU.
|
|
148
|
+
|
|
149
|
+
WGSL: one pass, one invocation per (direction, channel), `ceil(2 * size / 64)` workgroups of 64, each looping over the `n` tokens in its direction. Matches the CPU within 1e-5 on the software adapter (llvmpipe) for `n` = 1, 2 and the maximum token count (`test/gpu/biscan.test.ts`). Real GPU: not run. Real browser: not run.
|
|
150
|
+
|
|
151
|
+
## tag head
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
head: heads.tag({ labels: ['amount', 'from', 'to', 'none'] })
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
What it does: a linear step from the last layer to one logit per label for every token, `logits[t] = W x[t] + b` with `W` of shape `[labels, in]`. `run` decodes each token to the label with the largest logit (the first label on a tie). Softmax is not part of the forward pass; training uses softmax cross-entropy per token, averaged over the tokens. Gold is one label per token of the tokenized text; labels for tokens cut at `input.max` are dropped with them.
|
|
158
|
+
|
|
159
|
+
| Cost | Formula |
|
|
160
|
+
| ----------------------- | -------------------------------------------------- |
|
|
161
|
+
| Parameters | `labels * in + labels` |
|
|
162
|
+
| Bytes (int6, packed) | `ceil(6 * labels * in / 8) + ceil(6 * labels / 8)` |
|
|
163
|
+
| Multiply-adds per token | `in * labels` |
|
|
164
|
+
|
|
165
|
+
For example four labels after `dense({ size: 20, activation: 'relu' })`: 84 parameters, 63 bytes, 80 multiply-adds per token.
|
|
166
|
+
|
|
167
|
+
Initial values: weights uniform in `±sqrt(6 / (in + labels))` (Glorot); biases zero.
|
|
168
|
+
|
|
169
|
+
When it helps:
|
|
170
|
+
|
|
171
|
+
- When the output is one label per token: spans (start, inside, none), roles of words in a phrase, or which tokens to keep.
|
|
172
|
+
|
|
173
|
+
When it does not:
|
|
174
|
+
|
|
175
|
+
- When the output is one answer for the whole input. Use the `pooled` head; tagging every token and voting wastes bytes and loses the input-level context.
|
|
176
|
+
- It is linear: put `dense` with `relu` or `tanh` before it when labels need a non-linear boundary.
|
|
177
|
+
|
|
178
|
+
WGSL: one pass, one invocation per (token, label), `ceil(n * labels / 64)` workgroups of 64. Argmax and decode stay on the CPU. Matches the CPU within 1e-5 on the software adapter (llvmpipe) for `n` = 1, 2 and the maximum token count, with the same decoded labels (`test/gpu/tag.test.ts`). Real GPU: not run. Real browser: not run.
|
|
179
|
+
|
|
180
|
+
## pooled head
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
head: heads.pooled({ labels: ['question', 'request', 'statement'] }) // class form
|
|
184
|
+
head: heads.pooled({ outputs: 2 }) // values form
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
What it does: one output for the whole input. It pools the last layer over the tokens, mean then max per channel, into a vector of `2 * in`, then takes one linear step to `out` logits: `logits = W pooled + b` with `W` of shape `[out, 2 * in]`. `out` is the label count in the class form and `outputs` in the values form. An empty input pools to zeros, so it returns the bias. The class form decodes to the label with the largest logit (the first on a tie) and trains with softmax cross-entropy; gold is one label. The values form returns the logits as numbers and trains with mean squared error over the outputs; gold is an array of `outputs` numbers.
|
|
188
|
+
|
|
189
|
+
In the backward pass the mean half spreads its gradient evenly over the tokens and the max half sends all of it to the token holding the max (the first such token on a tie), so a channel's max learns from one token per input.
|
|
190
|
+
|
|
191
|
+
| Cost | Formula |
|
|
192
|
+
| ----------------------- | ---------------------------------------------------------- |
|
|
193
|
+
| Parameters | `out * 2 * in + out` |
|
|
194
|
+
| Bytes (int6, packed) | `ceil(6 * out * 2 * in / 8) + ceil(6 * out / 8)` |
|
|
195
|
+
| Multiply-adds per token | `2 * in + 2 * in * out` (the plan's count, an upper bound) |
|
|
196
|
+
|
|
197
|
+
The plan counts the linear step per token, an upper bound: it runs once per input, so a run costs about `2 * in` per token for the pool plus `2 * in * out` once. For example three labels after `dense({ size: 20, activation: 'relu' })`: 123 parameters, 93 bytes, 160 multiply-adds per token in the plan.
|
|
198
|
+
|
|
199
|
+
Initial values: weights uniform in `±sqrt(6 / (2 * in + out))` (Glorot); biases zero.
|
|
200
|
+
|
|
201
|
+
When it helps:
|
|
202
|
+
|
|
203
|
+
- When the answer is one class or a few numbers for the whole input: the kind of a note, a language, a score, a date as numbers.
|
|
204
|
+
- Mean pooling sees how much of something the input holds (a share of words); max pooling sees whether something appears anywhere, wherever it is. The head gets both, so a marker word at any position counts the same.
|
|
205
|
+
|
|
206
|
+
When it does not:
|
|
207
|
+
|
|
208
|
+
- When the answer belongs to tokens, such as spans or roles of words. Use the `tag` head.
|
|
209
|
+
- Pooling drops order: "dog bites man" and "man bites dog" pool to the same vector after `embed`. Put `conv` or `biScan` before the head when order decides the answer.
|
|
210
|
+
- It is linear after the pool: put `dense` with `relu` or `tanh` before it when the classes need a non-linear boundary. The values form has no activation, so it can return any number; clamp or round in your decode step.
|
|
211
|
+
|
|
212
|
+
WGSL: two passes. The pool is one invocation per channel, `ceil(in / 64)` workgroups of 64, each looping over the `n` tokens and writing mean and max to `temp`; the linear step is one invocation per output, `ceil(out / 64)` workgroups. A model with `input.max` 1, whose buffers cannot hold `2 * in` floats, runs only the linear step on the one token. Argmax and decode stay on the CPU. Matches the CPU within 1e-5 on the software adapter (llvmpipe) for both forms with `n` = 1, 2 and the maximum token count, and for a one-token model (`test/gpu/pooled.test.ts`). Real GPU: not run. Real browser: not run.
|
|
213
|
+
|
|
214
|
+
## retrieve head
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
head: heads.retrieve({ size: 16 })
|
|
218
|
+
// eval: table: 'data/table.jsonl', train: { ..., negatives: 8 }
|
|
219
|
+
// app: loadModel(weights, { backend: 'auto', table: [{ id: 'dark-mode', text: 'toggle dark mode' }] })
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
What it does: scores the input against every row of a table of `{ id, text }` rows and ranks them. There is one tower, used twice: the `net`, then the head's op, which is the `pooled` pool and linear step with `out = size`, turns any text into a vector of `size` floats. The table's rows go through the same tower once, at load, and each input's score against row `r` is the dot product of the two vectors. `run` returns one `{ id, score }` per row, the highest score first (table order on a tie); the table's ids type `id`.
|
|
223
|
+
|
|
224
|
+
Training: gold is the array of ids of the rows that answer the input. Each example is compared with its gold rows and `negatives` other rows drawn from the seed's stream, with softmax cross-entropy over those candidates' scores, every gold row counted as right. The score step's backward pass sends gradient to the input's side and to every candidate row's side, and both walk back through the same weights, so the tower learns from both. A step costs one tower pass per candidate, `2 + negatives` for one gold row.
|
|
225
|
+
|
|
226
|
+
| Cost | Formula |
|
|
227
|
+
| ----------------------- | --------------------------------------------------------------------------- |
|
|
228
|
+
| Parameters | `size * 2 * in + size` |
|
|
229
|
+
| Bytes (int6, packed) | `ceil(6 * size * 2 * in / 8) + ceil(6 * size / 8)` |
|
|
230
|
+
| Multiply-adds per token | `2 * in + 2 * in * size` (the plan's count, an upper bound) |
|
|
231
|
+
| Score step, per run | `rows * size` multiply-adds, not in the plan's count; no parameters |
|
|
232
|
+
| At load | one tower pass per table row; `rows * size` floats kept, uploaded to WebGPU |
|
|
233
|
+
|
|
234
|
+
For example `size` 16 after `dense({ size: 16, activation: 'tanh' })`: 528 parameters, 396 bytes, 544 multiply-adds per token in the plan, and 960 multiply-adds per run for a table of 60 rows.
|
|
235
|
+
|
|
236
|
+
Initial values: weights uniform in `±sqrt(6 / (2 * in + size))` (Glorot); biases zero.
|
|
237
|
+
|
|
238
|
+
When it helps:
|
|
239
|
+
|
|
240
|
+
- When the answer is one of a known list that changes more often than the model: commands, help articles, settings. The list is data, not labels, so a row can be added or reworded without retraining, and a row the model never trained on still gets a score.
|
|
241
|
+
- When the list is long or its rows share words: the scores rank every row, so the decode step can show the top few.
|
|
242
|
+
|
|
243
|
+
When it does not:
|
|
244
|
+
|
|
245
|
+
- When the list is short and fixed. A `pooled` class head with one label per row is smaller and needs no table.
|
|
246
|
+
- When the input and the rows share no tokens, such as a misspelt word: a token no training text holds reaches only the embedding bias, so it adds the same vector to every input and can pull the query away from its row. On a synthetic task (`test/heads/retrieve.test.ts`, 20 rows of three made-up words, queries are noisy copies) held-out recall at 1 is 0.925 against 0.04 for the untrained tower, 1 on queries without a misspelt word, and every miss has one. Train on the misspellings and paraphrases users type, or add a rule baseline for exact matches.
|
|
247
|
+
- It pools, so order is lost unless `conv` or `biScan` comes before the head.
|
|
248
|
+
|
|
249
|
+
WGSL: the tower runs the `pooled` passes. The score step is one pass, one invocation per table row, `ceil(rows / 64)` workgroups, reading the input's vector from the tower's output and the row vectors from the weights buffer, where they follow the model's parameters. Ranking stays on the CPU. The score step matches the CPU within 1e-5 for 1, 20 and 130 rows, the head op for `n` = 1, 2 and the maximum token count, and a whole retrieve model's scores against 100 rows within 1e-3 on 30 inputs, all on the software adapter (llvmpipe) (`test/gpu/retrieve.test.ts`). Real GPU: not run. Real browser: not run.
|