gpu-engine 0.0.0 → 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.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +96 -2
  3. package/SPEC.md +988 -0
  4. package/THIRD_PARTY_NOTICES.md +29 -0
  5. package/dist/cli.d.mts +1 -0
  6. package/dist/cli.mjs +4 -0
  7. package/dist/harness.d.mts +132 -0
  8. package/dist/harness.mjs +1 -0
  9. package/dist/index.d.mts +98 -0
  10. package/dist/index.mjs +1 -0
  11. package/dist/load-o_thEAKC.mjs +258 -0
  12. package/dist/scaffold-CY5xhy-V.mjs +106 -0
  13. package/dist/types-BwigqFwr.d.mts +868 -0
  14. package/docs/apps.md +108 -0
  15. package/docs/cli.md +126 -0
  16. package/docs/data.md +101 -0
  17. package/docs/diagnostics.md +509 -0
  18. package/docs/harness.md +191 -0
  19. package/docs/layers.md +249 -0
  20. package/docs/measurements/auto-threshold.json +335 -0
  21. package/docs/measurements/auto-threshold.md +56 -0
  22. package/docs/measurements/real-gpu-2026-11-22.json +4718 -0
  23. package/docs/measurements/real-gpu-2026-11-22.md +75 -0
  24. package/docs/runtime.md +112 -0
  25. package/docs/sealed-test-set.md +107 -0
  26. package/docs/weights-format.md +138 -0
  27. package/llms.txt +24 -0
  28. package/package.json +68 -2
  29. package/skills/gpu-engine/SKILL.md +117 -0
  30. package/templates/common/AGENTS.md +27 -0
  31. package/templates/common/github/workflows/ci.yml +35 -0
  32. package/templates/common/gitignore +3 -0
  33. package/templates/common/package.template.json +27 -0
  34. package/templates/common/tsconfig.template.json +17 -0
  35. package/templates/pooled/NEW_MODEL_NAME.eval.ts +93 -0
  36. package/templates/pooled/NEW_MODEL_NAME.model.ts +11 -0
  37. package/templates/pooled/SPEC.md +31 -0
  38. package/templates/pooled/src/decode.ts +10 -0
  39. package/templates/pooled/src/index.ts +44 -0
  40. package/templates/pooled/src/weights.ts +4 -0
  41. package/templates/retrieve/NEW_MODEL_NAME.eval.ts +149 -0
  42. package/templates/retrieve/NEW_MODEL_NAME.model.ts +12 -0
  43. package/templates/retrieve/SPEC.md +33 -0
  44. package/templates/retrieve/data/table.jsonl +16 -0
  45. package/templates/retrieve/src/decode.ts +9 -0
  46. package/templates/retrieve/src/index.ts +45 -0
  47. package/templates/retrieve/src/table.ts +21 -0
  48. package/templates/retrieve/src/weights.ts +4 -0
  49. package/templates/tag/NEW_MODEL_NAME.eval.ts +114 -0
  50. package/templates/tag/NEW_MODEL_NAME.model.ts +11 -0
  51. package/templates/tag/SPEC.md +31 -0
  52. package/templates/tag/src/decode.ts +25 -0
  53. package/templates/tag/src/index.ts +44 -0
  54. package/templates/tag/src/weights.ts +4 -0
package/docs/apps.md ADDED
@@ -0,0 +1,108 @@
1
+ # Use a model in an app
2
+
3
+ A model package made by `gpu-engine new` ships one file an app imports: `dist/index.mjs`, written by `npm run build` (`gpu-engine build`, [cli.md](./cli.md#build)). It holds the promoted weights, the gpu-engine runtime (minified) and your decode step, imports nothing, and starts with a comment carrying the MIT notices of the code it bundles. `dist/index.d.mts` declares its exports. The model package has no `dependencies`, and the app needs none for the model.
4
+
5
+ Build after every `promote`: until then `dist/` holds the old weights, and `doctor` reports `SHIP_BUILD_STALE`.
6
+
7
+ ## Install it in the app
8
+
9
+ The model package is `"private": true`, so it does not go to a registry as it is. Pack it and install the tarball:
10
+
11
+ ```sh
12
+ npm run build && npm pack # in the model package: my-model-0.0.0.tgz
13
+ cd ../my-app && npm install ../my-model/my-model-0.0.0.tgz
14
+ ```
15
+
16
+ In a monorepo, add it as a workspace dependency instead. Either way the app imports `my-model`, which resolves to `dist/index.mjs` and its types through the package's `exports`.
17
+
18
+ ## Load and run
19
+
20
+ ```ts
21
+ import { load } from 'my-model'
22
+ import type { Result } from 'my-model'
23
+
24
+ const model = await load({ backend: 'cpu' })
25
+ const [error, result] = await model.run('Ana bought 3 pens')
26
+ if (error) console.error(error.code, error.message, error.fix)
27
+ else console.log(result satisfies Result) // { count: 3, item: 'pens' }
28
+ model.inspect() // { backend: 'cpu', reason, bytes, macs, inputMax: 16, head: 'tag' }
29
+ await model.destroy()
30
+ ```
31
+
32
+ The shipped entry is the package's own `src/index.ts`, so you can change what it exports. The one `new` writes exports:
33
+
34
+ | Export | What it is |
35
+ | ------------- | ------------------------------------------------------------------------------------------------------------------------ |
36
+ | `load` | `load({ backend, gpu? })`: loads the promoted weights once (a `retrieve` model also encodes its table) and never rejects |
37
+ | `LoadOptions` | `backend` (`'cpu'`, `'webgpu'` or `'auto'`, required) and `gpu` (a WebGPU entry point where `navigator.gpu` is missing) |
38
+ | `Loaded` | `run(text)`, `inspect()` and `destroy()` |
39
+ | `Result` | what your decode step returns, the `result` of a `run` |
40
+
41
+ - `run(text)` never throws. It returns `[error, undefined]` or `[undefined, result]`, where `error` is `{ code, message, why, fix }` with a run code (`RUN_*` or `WEIGHTS_*`, [runtime.md](./runtime.md#results)). A model that failed to load returns its load error from every `run`, and `inspect().reason` names it.
42
+ - Load once and keep the model: loading decodes the weights and, on WebGPU, opens a device and compiles the pipelines. Runs may overlap, so `Promise.all(inputs.map((text) => model.run(text)))` works.
43
+ - Text longer than the model's `input.max` tokens (`inspect().inputMax`) runs on its first `max` tokens; the rest get no output.
44
+ - `await model.destroy()` when the model is no longer needed, such as when a component that loaded it unmounts. It frees the WebGPU buffers and device once the runs already called finish, never rejects, and every later `run` returns `RUN_MODEL_DESTROYED`. On the CPU it frees nothing but still ends the model's runs.
45
+
46
+ ## Pick a backend
47
+
48
+ There is no default backend: `load` needs one.
49
+
50
+ | `backend` | Runs on |
51
+ | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
52
+ | `'cpu'` | The CPU, everywhere. The v0.1 runtime |
53
+ | `'webgpu'` | WebGPU, experimental. Without `navigator.gpu` (or the `gpu` option) or an adapter, every `run` returns `RUN_BACKEND_UNAVAILABLE` |
54
+ | `'auto'` | The CPU or WebGPU by the rules in [runtime.md](./runtime.md#backends). For every model trained so far that is the CPU, without opening a device, as `inspect().reason` says |
55
+
56
+ WebGPU results so far come from a software adapter (llvmpipe) through Dawn in Node, and from one real GPU in a real browser: Chrome on an Apple M1 matched the CPU within 5.72e-6, with the CPU 6 to 14 times faster per run on these small models ([measurement](./measurements/real-gpu-2026-11-22.md)). Use `'cpu'` unless you are measuring WebGPU on your devices.
57
+
58
+ ## A bundler app
59
+
60
+ Vite, webpack, esbuild and other bundlers take `dist/index.mjs` as it is: it imports nothing, touches no WebGPU global at import time and needs no plugin. Import `load` where the model is first needed. The module carries its weights, so they are part of your bundle; `npm run build` prints its bytes and Brotli bytes, and the eval's `ship.brotliBytes` caps them (`SHIP_SIZE_EXCEEDED`).
61
+
62
+ ## Node
63
+
64
+ On the CPU, import and load as above. For WebGPU in Node, install the `webgpu` package (Dawn; pin `^0.6.2`, since 0.3.8 crashes) in the app and pass its entry point:
65
+
66
+ ```ts
67
+ import { create } from 'webgpu'
68
+ import { load } from 'my-model'
69
+
70
+ const gpu = create([]) // keep this referenced while the model lives
71
+ const model = await load({ backend: 'webgpu', gpu })
72
+ ```
73
+
74
+ On Linux without a GPU it needs a Vulkan driver: `apt-get install mesa-vulkan-drivers` gives the lavapipe software adapter, which `inspect().reason` names as llvmpipe.
75
+
76
+ ## A worker
77
+
78
+ A run is synchronous CPU work between awaits, so a long input or many inputs can hold the main thread. Load the model in a module worker and send it text:
79
+
80
+ ```ts
81
+ // model-worker.ts
82
+ import { load } from 'my-model'
83
+
84
+ const model = await load({ backend: 'cpu' })
85
+ self.onmessage = async (event: MessageEvent<string>) => {
86
+ self.postMessage(await model.run(event.data))
87
+ }
88
+ ```
89
+
90
+ ```ts
91
+ // main thread
92
+ const worker = new Worker(new URL('./model-worker.ts', import.meta.url), { type: 'module' })
93
+ worker.onmessage = (event) => {
94
+ const [error, result] = event.data
95
+ }
96
+ worker.postMessage('Ana bought 3 pens')
97
+ ```
98
+
99
+ The `[error, result]` pair is plain data, so it crosses `postMessage` as it is. Browsers expose `navigator.gpu` in dedicated workers too, so `'webgpu'` works there where it works on the page.
100
+
101
+ ## Browser support
102
+
103
+ - The module is ES2023 (it uses `Array.prototype.toSorted`): Chrome and Edge 110, Firefox 115, Safari 16 or later, and every bundler that targets them. Code you add to `src/` sets its own floor.
104
+ - WebGPU needs `navigator.gpu`, which only some browsers expose, on some systems and only in secure contexts (HTTPS or localhost). Where it is missing, `'cpu'` still runs and `'auto'` falls back to the CPU.
105
+
106
+ ## TypeScript
107
+
108
+ `dist/index.d.mts` declares every export with every type it uses, gpu-engine's types included, so an app that installs only the model package typechecks with `strict` and `skipLibCheck: false`. The declarations name no WebGPU or DOM type (the `gpu` option is typed by its one method, `requestAdapter`), so a Node app with `lib: ["es2023"]` and no `@webgpu/types` typechecks too.
package/docs/cli.md ADDED
@@ -0,0 +1,126 @@
1
+ # CLI
2
+
3
+ `gpu-engine <command> [arguments]`. Seven commands. Every command but `new` runs in a model package: the working directory, or the folder `--dir` names. `gpu-engine --help` lists the commands, `gpu-engine <command> --help` the flags of one, and `gpu-engine --version` (or `-v`) prints the version.
4
+
5
+ Exit codes: 0 when the command did what it says, 1 on any finding or failure. Every failure prints its diagnostic code with a why and a fix ([diagnostics.md](./diagnostics.md)). An unknown command is `CLI_COMMAND_UNKNOWN`; an unknown flag, a missing value, a missing argument, a flag given twice, or a flag the command would ignore or cannot combine is `CLI_FLAG_INVALID`, and nothing runs. Flags take their value as the next argument or after `=`, such as `--head=tag`. A next argument that is itself a flag (it starts with `--`, or is `-h`) is `CLI_FLAG_INVALID`, so `loop --log --fail` stops instead of logging `--fail` as the idea; write `--log=--fail` for that text. Every argument after a lone `--` is a positional, so `gpu-engine inspect -- "--help me"` inspects that text.
6
+
7
+ | Command | Reads the test set | Writes |
8
+ | ------------------ | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
9
+ | `new` | no | a new package folder |
10
+ | `loop` | no (digest only) | missing data sets (`--regenerate`: the named train or dev files), `data.lock.json` entries, `.gpu-engine/`, one `tries.jsonl` row, the digest row in `reads.jsonl` |
11
+ | `loop --fail` | no (digest only) | what the data step writes, the digest row in `reads.jsonl`; no try |
12
+ | `loop --mark` | no | the `status` of the last row of `tries.jsonl` |
13
+ | `promote` | yes, once, counted | the digest row in `reads.jsonl`, and the `examples` row unless a dev, budget or data gate line failed first; on a pass weights, `src/weights.ts`, `gate.json`, `report.json`, `MODEL_CARD.md`, `RESULTS.md` |
14
+ | `promote --verify` | no (digest only) | nothing but the digest row in `reads.jsonl` |
15
+ | `promote --seal` | no (digest only) | sealed test files, the key file outside the tree, lock, `gate.json`, a promote workflow, two digest rows in `reads.jsonl` |
16
+ | `promote --scan` | no (digest only) | the files the promote workflow commits, repaired when they hold a test input; one digest row in `reads.jsonl` |
17
+ | `parity` | no | `parity.json`, `MODEL_CARD.md` |
18
+ | `inspect` | no | nothing |
19
+ | `doctor` | no (digest only) | nothing but the digest row in `reads.jsonl` |
20
+ | `build` | no | `dist/index.mjs`, `dist/index.d.mts`, and `src/table.ts` for a `retrieve` head |
21
+
22
+ A digest returns hashes, counts and fingerprints of the test set, never its text ([sealed-test-set.md](./sealed-test-set.md)).
23
+
24
+ ## new
25
+
26
+ ```sh
27
+ gpu-engine new <name> --head tag|pooled|retrieve [--dir <path>]
28
+ ```
29
+
30
+ Writes a model package into `<dir>/<name>` from the starter of the head kind: the model and eval files with a seeded generator per set and a rule baseline, `src/decode.ts`, `src/index.ts`, `src/weights.ts`, `AGENTS.md`, `SPEC.md`, the skill, a CI workflow, `package.json` with `gpu-engine`, `typescript` and `@types/node` as devDependencies and the `build` (`gpu-engine build`) and `typecheck` (`tsc -p .`) scripts. It writes no data and no data folder: the generators run on the first `loop`, which writes `data/train/`, `data/dev/` and `data/test/`. The first `loop` of a starter trains three seeds in a few seconds, beats the rule baseline on dev and leaves room to tune: the starter's `SPEC.md` names the layer its data needs.
31
+
32
+ It then prints the next steps: `cd` into the package, install gpu-engine, `npx gpu-engine doctor` and `npx gpu-engine loop --log "starter"`. Without gpu-engine installed anywhere, run it through npx; the whole quick start:
33
+
34
+ ```sh
35
+ npx gpu-engine@latest new my-model --head tag
36
+ cd my-model
37
+ npm install
38
+ npx gpu-engine doctor
39
+ npx gpu-engine loop --log "starter"
40
+ npx gpu-engine promote
41
+ npm run build
42
+ ```
43
+
44
+ | Flag | Value | What it does |
45
+ | -------- | ----------------------------- | -------------------------------------------------- |
46
+ | `--head` | `tag`, `pooled` or `retrieve` | Required. The head kind of the starter |
47
+ | `--dir` | a path | Where to create the package (default: working dir) |
48
+
49
+ The name must match `^[a-z][a-z0-9-]{0,63}$` (`NEW_NAME_INVALID`). It never overwrites: a target folder holding any file is `NEW_TARGET_EXISTS`.
50
+
51
+ ## loop
52
+
53
+ ```sh
54
+ gpu-engine loop [--log "<idea>"] [--status kept|dropped] [--regenerate train|dev|train,dev] [--dir <path>]
55
+ gpu-engine loop --fail [--set <name>] [--dir <path>]
56
+ gpu-engine loop --mark kept|dropped [--dir <path>]
57
+ ```
58
+
59
+ One try: level 1 scan, data step, training, dev table with baselines and oracle, gate lines, candidate in `.gpu-engine/`, one row in `tries.jsonl`. Exit 1 when a check or a gate line fails. While it trains it prints one line per finished seed: `train: seed 2 done (2/3), best dev 0.917 at epoch 9, 420 steps, 3.1 s, stopped by epochs`.
60
+
61
+ | Flag | Value | What it does |
62
+ | -------------- | ----------------------------- | --------------------------------------------------------------------------------------------------------------------- |
63
+ | `--log` | the idea, quoted | What this try changes, written to the try's `idea` |
64
+ | `--status` | `kept` or `dropped` | Marks this try before it runs; `--mark` records it after |
65
+ | `--regenerate` | `train`, `dev` or `train,dev` | Rewrite those generated files from their generators and drop their lock entries, then run the try; never the test set |
66
+ | `--fail` | | Train nothing; list every dev example the candidate gets wrong |
67
+ | `--set` | a dev set name | With `--fail`, only that dev set |
68
+ | `--mark` | `kept` or `dropped` | Train nothing; record the decision on the last try, once |
69
+ | `--dir` | a path | The model package folder |
70
+
71
+ `--set` needs `--fail`. `--fail` takes neither `--log`, `--status` nor `--regenerate`, since it appends no try. `--mark` takes no other flag but `--dir`.
72
+
73
+ ## promote
74
+
75
+ ```sh
76
+ gpu-engine promote [--dir <path>]
77
+ gpu-engine promote --verify [--dir <path>]
78
+ gpu-engine promote --seal [--key-out <path>] [--dir <path>]
79
+ gpu-engine promote --scan [--dir <path>]
80
+ ```
81
+
82
+ `promote` alone needs a fresh candidate from `loop`, gates dev, the budgets and the data before it reads anything, then reads the test set once, scores and gates it, and on a pass writes the promoted model. `--verify` is the CI gate: it checks the committed promotion without reading test data. `--seal` turns on level 3: it encrypts the test set so only CI can read it. `--scan` checks the files the promote workflow commits for test inputs and repairs them; it exits 0 when they were clean and 3 after a repair, and the workflow commits only after one of those two.
83
+
84
+ | Flag | Value | What it does |
85
+ | ----------- | ------ | ------------------------------------------------------------------------------------------------------ |
86
+ | `--verify` | | Check the committed promotion without reading test data |
87
+ | `--seal` | | Encrypt the test set and require CI and the key for every later `promote` |
88
+ | `--key-out` | a path | With `--seal`, where to write the key (default `~/.gpu-engine/keys/<name>.key`, outside the tree) |
89
+ | `--scan` | | Scan the files the promote workflow commits for test inputs and repair them (needs the key at level 3) |
90
+ | `--dir` | a path | The model package folder |
91
+
92
+ `--verify` takes neither `--seal` nor `--key-out`, `--scan` takes none of `--verify`, `--seal` and `--key-out`, and `--key-out` needs `--seal`. `--seal` refuses while the eval file declares a test generator (`SEAL_GENERATOR_FOUND`).
93
+
94
+ At level 3, `promote` refuses outside CI (`PROMOTE_OUTSIDE_CI`) and without the key in `GPU_ENGINE_TEST_KEY` (`SEAL_KEY_MISSING`, `SEAL_KEY_INVALID`).
95
+
96
+ ## parity
97
+
98
+ ```sh
99
+ gpu-engine parity [--dir <path>]
100
+ ```
101
+
102
+ Compares the promoted weights on the trainer's forward pass, the CPU runtime and WGSL, on every dev input and four edge inputs, and writes `parity.json`. Needs `report.json` and the `webgpu` package as a devDependency of the model package with a Vulkan driver (`PARITY_ADAPTER_MISSING`). Flags: `--dir`.
103
+
104
+ ## inspect
105
+
106
+ ```sh
107
+ gpu-engine inspect "<text>" [--dir <path>]
108
+ ```
109
+
110
+ Tokens, feature rows, the weights file and the definition hash it carries, raw logits, head output, decoded result, backend and reason for one input, on the weights trained from the model file as it is now: the last candidate when it was, else the promoted weights. Every flag is off. Flags: `--dir`.
111
+
112
+ ## doctor
113
+
114
+ ```sh
115
+ gpu-engine doctor [--dir <path>]
116
+ ```
117
+
118
+ Every check that needs no training and no test read, each finding with its code, why and fix. Exit 1 on any finding. Flags: `--dir`.
119
+
120
+ ## build
121
+
122
+ ```sh
123
+ gpu-engine build [--dir <path>]
124
+ ```
125
+
126
+ What the package ships, run by `npm run build`. For a `retrieve` head it first writes `src/table.ts` from the table the eval names (`table`), the one the harness evaluated. Then it bundles `src/index.ts`, the gpu-engine runtime (minified when gpu-engine was packed) and the weights into `dist/index.mjs`, one ES module that imports nothing and starts with a `/*! ... */` comment holding the MIT notices of the code it bundles, and writes `dist/index.d.mts`, the declarations of every export with every type they use, so an app with `strict` and `skipLibCheck: false` typechecks against the package alone. It reads imports with a tokenizer, so comments, strings and templates that mention `import` are left alone. It prints each file with its bytes and Brotli bytes. Exit 1 with `BUILD_SOURCE_UNSUPPORTED` (a dynamic `import()`, a JSON import, a Node built-in, a cycle, an exported `let` or `var`, a top-level `await`, or declarations that would not typecheck), `BUILD_IMPORT_UNRESOLVED` (a missing file or package) or `BUILD_TYPES_FAILED` (no TypeScript, a type error, or an export it cannot declare), before anything in `dist/` is written. Flags: `--dir`.
package/docs/data.md ADDED
@@ -0,0 +1,101 @@
1
+ # Bring your own data
2
+
3
+ A package from `gpu-engine new` generates its three sets from seeded generators in the eval file. This page is for rows you already have: logs, a labelled export, sentences you wrote. [harness.md](./harness.md#data) is the reference for the data step, and [SPEC.md](../SPEC.md) sections 6 and 7 the normative text.
4
+
5
+ ## Where rows live
6
+
7
+ ```
8
+ data/train/*.jsonl what the model learns from
9
+ data/dev/*.jsonl what the loop tunes against, as often as you like
10
+ data/test/*.jsonl sealed: only `promote` reads it, once per promotion
11
+ ```
12
+
13
+ The eval file points at them with `sets: { train: 'data/train/*.jsonl', dev: 'data/dev/*.jsonl', test: sealed('data/test/*.jsonl') }`. Every set needs at least one file (`DATA_SET_MISSING`). One file is one named set: `data/dev/main.jsonl` and `data/dev/support.jsonl` are two dev sets, scored in two columns of every table, and the dev score is their mean. `data.minSize` is the least number of rows in each file (`DATA_SET_TOO_SMALL`).
14
+
15
+ ## A row
16
+
17
+ One JSON object per line:
18
+
19
+ ```json
20
+ {
21
+ "input": "Ana bought 3 pens",
22
+ "gold": ["other", "other", "count", "item"],
23
+ "group": "shop-receipts",
24
+ "vocab": ["Ana"]
25
+ }
26
+ ```
27
+
28
+ | Field | Required | What it holds |
29
+ | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------ |
30
+ | `input` | yes | The text, or `{ "text": "...", "flags": { "<name>": [true, false, ...] } }` when the model declares `features.flag` rows |
31
+ | `gold` | yes | The right answer in the shape of the head (below) |
32
+ | `expect` | no | The decoded result to score against, when it is not `decode(gold)` |
33
+ | `group` | no | Where the row came from: a source, a site, a sentence frame, a time window. No two sets may share one |
34
+ | `vocab` | no | Words no two sets may share, such as the item names when the test items must be unseen |
35
+
36
+ `gold` by head:
37
+
38
+ | Head | `gold` |
39
+ | ----------------------- | -------------------------------------------------------------------------------- |
40
+ | `tag` | One label per token of `tokenize(input)`, every label one of the head's `labels` |
41
+ | `pooled` with `labels` | One label |
42
+ | `pooled` with `outputs` | An array of `outputs` finite numbers |
43
+ | `retrieve` | An array of at least one table row id, no repeats, the best row first |
44
+
45
+ A `tag` row needs as many labels as the tokenizer gives tokens, so count them with the tokenizer, not by splitting on spaces. `tokenize` from `gpu-engine` splits text into runs of letters, runs of digits and each other character that is not a space: `"3.5kg"` is four tokens, `3`, `.`, `5` and `kg`. A flag list has one boolean per token the same way. Labels for tokens past `input.max` are checked and then dropped with their tokens.
46
+
47
+ A row of the wrong shape is `DATA_ROW_INVALID`, and a label the head does not have is `DATA_LABEL_UNKNOWN`. Both name the file and the count of rows, never a row.
48
+
49
+ A `retrieve` head also needs the table it ranks: `table` in the eval file names a JSONL file of `{ "id": "...", "text": "..." }` rows outside the set folders, such as `data/table.jsonl`. Every gold id in train and dev must name one of its rows.
50
+
51
+ ## Without generators
52
+
53
+ Write the files, then leave the sets you wrote out of `generate`, or drop `generate`:
54
+
55
+ ```ts
56
+ data: defineDataset<Result>({
57
+ seed: 1,
58
+ minSize: { train: 600, dev: 120, test: 120 },
59
+ }),
60
+ ```
61
+
62
+ `seed` stays required, and seeds the generators you keep. A set with a generator is generated only into an empty folder, so a mix works: generate train, and write dev and test from real rows.
63
+
64
+ Keep a conversion script that writes the test set outside the package, or delete it once it ran. The level 1 scan fails `doctor` and `loop` on any code file in the package that names the test folder (`DATA_TEST_READ`); only the `sealed(...)` call in the eval file may.
65
+
66
+ ## Splitting
67
+
68
+ Split by group, not by row. If dev and test hold rows from the sources train learned, such as the same sentence frames, the same users or the same week, a model that memorised those sources scores well and generalises to nothing. Give each set its own groups, and declare them in `group` so the check holds you to it (`DATA_GROUP_SHARED`).
69
+
70
+ - Logs over time: split by time. Train on the earlier windows, dev on a later one, test on the latest, with the window as `group`.
71
+ - Words the model must handle without having seen them, such as names or product words: list them in `vocab`, give each set its own, and `DATA_VOCAB_SHARED` catches a word that leaked across sets.
72
+ - The same input in two sets, after lowercasing and collapsing whitespace, is `DATA_SPLIT_OVERLAP`. Drop duplicates before you split.
73
+ - Write a rule baseline in `baselines` that a plain heuristic would reach. A model that does not beat it on dev is not worth its bytes.
74
+
75
+ The checks read the test set through a digest of hashes, counts and fingerprints, never its text, so they run on every `loop` without counting a read ([sealed-test-set.md](./sealed-test-set.md)).
76
+
77
+ ## The lock
78
+
79
+ The first `loop` whose checks all pass records each set in `data.lock.json`: every file's SHA-256 and row count, and the test set's fingerprints. A retrieve table gets an entry under `table`. Commit the lock with the data.
80
+
81
+ From then on a changed, added or removed file is `DATA_HASH_CHANGED` on every command, and nothing trains. To accept a change you made by hand, delete that set's entry from `data.lock.json` and run `loop`; the change then shows in the diff. Never delete an entry to hide a change.
82
+
83
+ ## Changing generated data
84
+
85
+ A generator writes only into an empty folder, so `loop` runs the train and dev generators again in memory and compares their output with the generated file (`main.jsonl`). After you edit one, `loop` stops with `DATA_GENERATOR_CHANGED`. Accept the edit with:
86
+
87
+ ```sh
88
+ npx gpu-engine loop --regenerate train --log "<the data change>" # or dev, or train,dev
89
+ ```
90
+
91
+ It rewrites the generated file of each named set (the folder's other files stay), drops their lock entries and trains, and the data step records the new hashes. A changed dev set moves every dev score, so compare tries only within one dev set; a promoted floor measured on the old dev set may now fail. Rows you write by hand go in another file of the set, never in the generated one.
92
+
93
+ ## Changing the test set
94
+
95
+ The test set is never regenerated, and `--regenerate test` is refused. Changing it means a new test set:
96
+
97
+ 1. Write new rows in new groups, by someone or something that has not seen the model's errors.
98
+ 2. Replace the files, delete the `test` entry from `data.lock.json`, and run `loop` to record it.
99
+ 3. Say in the package's `SPEC.md` that the earlier set was retired and why. Scores on the two sets do not compare.
100
+
101
+ Do the same when the test set was seen. Before `promote --seal` turns on level 3, remove the test generator: with it and `seed`, anyone could rebuild the sealed rows (`SEAL_GENERATOR_FOUND`).