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.
- 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 +68 -2
- 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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present onmax
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,97 @@
|
|
|
1
|
-
|
|
1
|
+
<h1>
|
|
2
|
+
<img src="https://gpu-engine.dev/banner.svg" alt="gpu-engine: small neural networks you train from scratch and run locally" width="100%">
|
|
3
|
+
</h1>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
gpu-engine is a TypeScript library for tiny models you define, train and ship yourself. You list the layers of a small neural network in a model file, train it on your own data on a laptop in seconds to minutes, tune it against a dev set while a sealed test set stays locked until promotion, and ship the int6 weights (a few kilobytes up to about 1 MB) inside your own package, which runs on the CPU or WebGPU with zero runtime dependencies. A model reads short text and tags its tokens, labels or scores the whole input, or ranks the rows of a table; your own plain code turns that into a result. The API is low-level and written for coding agents: `net` is always an explicit list, and there are no presets. The docs are at [gpu-engine.dev](https://gpu-engine.dev), and [SPEC.md](./SPEC.md) is the source of truth.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- Node 24 or later for the CLI and the harness (training, the dev loop, promote, build).
|
|
10
|
+
- A built model package is one ES2023 module with no imports. It runs in Node and in browsers with ES2023 (Chrome 110, Firefox 115, Safari 16 or later), in pages and in workers.
|
|
11
|
+
- The CPU is the v0.1 runtime. WebGPU is experimental: it runs where `navigator.gpu` exists, or in Node with the `webgpu` package, and `backend: 'auto'` picks the CPU for every model trained so far ([runtime.md](./docs/runtime.md#the-threshold)).
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npx gpu-engine@latest new my-model --head tag # a model package with a tag head
|
|
17
|
+
cd my-model
|
|
18
|
+
npm install
|
|
19
|
+
npx gpu-engine doctor # static checks, each finding with its fix
|
|
20
|
+
npx gpu-engine loop --log "starter" # generate data, train, print the dev table, log the try
|
|
21
|
+
npx gpu-engine promote # the one command that reads the test set
|
|
22
|
+
npm run build # gpu-engine build: dist/index.mjs and dist/index.d.mts
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The package holds the model file, the eval file (data generators, training options, a rule baseline, the gate), `src/decode.ts` and an `AGENTS.md` for the agent that tunes it. The model file of the tag starter:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
// The model: what it reads, its layers and its head. SPEC.md says what it is for; a change to that lands there first.
|
|
29
|
+
import { defineModel, features as f, heads as h, int6, layers as l } from 'gpu-engine'
|
|
30
|
+
|
|
31
|
+
export default defineModel({
|
|
32
|
+
name: 'my-model',
|
|
33
|
+
input: f.tokens({ max: 16, rows: [f.shape(), f.hash({ buckets: 256, k: 2 })] }),
|
|
34
|
+
net: [l.embed({ size: 16 }), l.conv({ taps: 3 }), l.dense({ size: 16, activation: 'relu' })],
|
|
35
|
+
head: h.tag({ labels: ['count', 'item', 'other'] }),
|
|
36
|
+
quant: int6({ qatFrom: 0.7 }),
|
|
37
|
+
budgets: { brotliBytes: 8_000, macsPerToken: 2_000 },
|
|
38
|
+
})
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`loop` trains it and prints the dev table: the model, the rule baseline, and the oracle (the gold run through your decode step):
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
dev main (120)
|
|
45
|
+
model 0.750
|
|
46
|
+
baseline rules 0.375
|
|
47
|
+
oracle 1.000
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The starter leaves room to tune: part of its data needs words farther away than `conv` reaches, as the package's `SPEC.md` says. Change one thing, run `loop` again and keep the change or revert it; the [skill](./skills/gpu-engine/SKILL.md) is the tuning guide. To train on rows you already have, see [data.md](./docs/data.md).
|
|
51
|
+
|
|
52
|
+
## Use it in an app
|
|
53
|
+
|
|
54
|
+
`npm run build` writes `dist/index.mjs` with the runtime, the weights and your decode step, and its types in `dist/index.d.mts`. Pack the model package and install it in the app:
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
npm pack # in my-model: my-model-0.0.0.tgz
|
|
58
|
+
cd ../my-app && npm install ../my-model/my-model-0.0.0.tgz
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { load } from 'my-model'
|
|
63
|
+
|
|
64
|
+
const model = await load({ backend: 'cpu' })
|
|
65
|
+
const [error, result] = await model.run('Ana bought 3 pens') // { count: 3, item: 'pens' }
|
|
66
|
+
if (error) console.error(error.code, error.fix)
|
|
67
|
+
await model.destroy()
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`run` never throws: it returns `[error, undefined]` or `[undefined, result]`. [apps.md](./docs/apps.md) covers bundlers, Node with WebGPU, workers and browser support.
|
|
71
|
+
|
|
72
|
+
## Status
|
|
73
|
+
|
|
74
|
+
- Pre-release on npm (`gpu-engine`, 0.0.x): the API can still change between releases.
|
|
75
|
+
- Three examples are promoted, each with parity on a software adapter (llvmpipe) and a report CI verifies. On their test sets: [examples/tag](./examples/tag/RESULTS.md) 0.418 against 0.093 for its rule baseline (the second attempt; [both attempts](./examples/tag/SPEC.md#attempt-2)), [examples/pooled](./examples/pooled/RESULTS.md) 0.688 against 0.521, [examples/retrieve](./examples/retrieve/RESULTS.md) 0.877 against 0.610.
|
|
76
|
+
- The WGSL tests, `parity` and the `auto` threshold ran on a software adapter (llvmpipe) through Dawn in Node. One real GPU in a real browser: [examples/browser-demo](./examples/browser-demo) in Chrome 155 on an Apple M1 (Metal 3) matched the CPU within 5.72e-6 and decoded the same on 40 of 40 dev inputs ([measurement](./docs/measurements/real-gpu-2026-11-22.md)); Safari 17.4 has no WebGPU. The `auto` threshold is a placeholder until someone measures real devices ([measurements](./docs/measurements/auto-threshold.md)).
|
|
77
|
+
- Level 3 of the sealed test set is built and tested but not switched on for an example.
|
|
78
|
+
|
|
79
|
+
## Develop
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
pnpm install
|
|
83
|
+
pnpm check # format and lint
|
|
84
|
+
pnpm typecheck
|
|
85
|
+
pnpm test
|
|
86
|
+
pnpm test:gpu # WGSL tests; needs a WebGPU adapter (lavapipe works)
|
|
87
|
+
pnpm validate # build and check the packed package
|
|
88
|
+
pnpm milestones # one pass or fail line per milestone
|
|
89
|
+
pnpm leak # banned names; reads GPU_ENGINE_LEAK_PATTERN or ~/.config/gpu-engine/leak-pattern
|
|
90
|
+
pnpm examples # retrain the playground examples
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The site's playground runs [examples/recipe-quantities](./examples/recipe-quantities) and [examples/command-search](./examples/command-search) on the CPU through [playground/render.ts](./playground/render.ts).
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
[MIT](./LICENSE)
|