runntime 0.1.0 → 0.2.0
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/README.md +12 -4
- package/dist/{classifier-ByH6OI6h.mjs → classifier-C6ZR3cyJ.mjs} +38576 -22654
- package/dist/{config-UyxIidZc.d.mts → config-DZyZ2TdH.d.mts} +21 -8
- package/dist/zoo/index.d.mts +206 -63
- package/dist/zoo/index.mjs +2217 -473
- package/dist/zoo/transformers/index.d.mts +10 -10
- package/dist/zoo/transformers/index.mjs +14 -16
- package/package.json +13 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as Yolo26Variant } from "../../config-
|
|
1
|
+
import { t as Yolo26Variant } from "../../config-DZyZ2TdH.mjs";
|
|
2
2
|
import { TgpuRoot } from "typegpu";
|
|
3
3
|
import { PreTrainedModel, PretrainedConfig } from "@huggingface/transformers";
|
|
4
4
|
//#region src/zoo/transformers/registry.d.ts
|
|
@@ -13,13 +13,13 @@ export declare function registerRunntimeBackend(opts?: RegisterRunntimeBackendOp
|
|
|
13
13
|
export declare function unregisterRunntimeBackend(): void;
|
|
14
14
|
//#endregion
|
|
15
15
|
//#region src/zoo/transformers/init.d.ts
|
|
16
|
-
/** One-call plugin setup: creates the WebGPU device,
|
|
17
|
-
* and patches transformers.js. Requests subgroups
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
16
|
+
/** One-call plugin setup: creates the WebGPU device, runs the models on it
|
|
17
|
+
* and patches transformers.js. Requests `subgroups`, which makes matmul and
|
|
18
|
+
* attention faster, and `shader-f16`, which the YOLO26 and DepthART models
|
|
19
|
+
* need and the others use when present. A device without them still loads
|
|
20
|
+
* every model that runs in f32. Options go straight to
|
|
21
|
+
* registerRunntimeBackend(), so `models` and `fallbackToOnnx` work here too.
|
|
22
|
+
* Returns the root for apps that also use TypeGPU directly. */
|
|
23
23
|
export declare function initRunntimeBackend(opts?: RegisterRunntimeBackendOpts): Promise<TgpuRoot>;
|
|
24
24
|
//#endregion
|
|
25
25
|
//#region src/zoo/transformers/runntimeModel.d.ts
|
|
@@ -51,8 +51,8 @@ export declare function yolo26Loader(weightsUrl?: string, opts?: {
|
|
|
51
51
|
//#endregion
|
|
52
52
|
//#region src/zoo/transformers/depthart/loader.d.ts
|
|
53
53
|
/** `weightsUrl`: a safetensors export of a Fengxue93/DepthART relative
|
|
54
|
-
* checkpoint
|
|
55
|
-
*
|
|
54
|
+
* checkpoint. Defaults to the hosted export for the hub id. The variant is
|
|
55
|
+
* read from the file. */
|
|
56
56
|
export declare function depthartLoader(weightsUrl?: string, opts?: {
|
|
57
57
|
onProgress?: (name: string, doneBytes: number, totalBytes: number) => void;
|
|
58
58
|
}): RunntimeModelLoader;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { At as defaultRoot, D as MINILM_BUCKETS, E as MinilmModel, L as models, Nt as RunntimeError, Pt as isRunntimeError, Q as bufferSource, R as createOpfsCache, S as configFromCheckpoint, T as V2_NER_CLASS_NAMES, X as inGpuErrorScopes, at as toArray, b as MOONSHINE_TINY, c as createDetector, et as fromSafetensors, i as MOBILENETV4_CONV_S, it as initRunntime, j as MINILM_L6, jt as supportsF16, k as fillBucketInputs, l as createTranscriber, s as createEstimator, t as createClassifier, tt as httpRangeSource, w as loadPrivacyFilterModel, x as assertConfigMatches, y as MOONSHINE_BASE, z as createReplayCache } from "../../classifier-C6ZR3cyJ.mjs";
|
|
2
2
|
import tgpu from "typegpu";
|
|
3
3
|
import { AutoConfig, PreTrainedModel, Tensor } from "@huggingface/transformers";
|
|
4
4
|
//#region src/zoo/transformers/minilm/model.ts
|
|
@@ -138,7 +138,7 @@ async function loadCachedWeights(url, key) {
|
|
|
138
138
|
//#region src/zoo/transformers/minilm/loader.ts
|
|
139
139
|
/** The hosted f16 export; loadStateDict fuses qkv and folds the token-type
|
|
140
140
|
* embedding while loading it. */
|
|
141
|
-
const MINILM_WEIGHTS_URL = models.
|
|
141
|
+
const MINILM_WEIGHTS_URL = models.embedding.ALL_MINILM_L6_V2.DEFAULT.modelPath;
|
|
142
142
|
const MINILM_MODEL_IDS = ["Xenova/all-MiniLM-L6-v2", "sentence-transformers/all-MiniLM-L6-v2"];
|
|
143
143
|
function minilmLoader(weightsUrl = MINILM_WEIGHTS_URL) {
|
|
144
144
|
return { async load(_modelId, config) {
|
|
@@ -296,13 +296,11 @@ function moonshinePreset(config) {
|
|
|
296
296
|
cfg
|
|
297
297
|
};
|
|
298
298
|
}
|
|
299
|
+
/** The hub tokenizer decodes the text, so the transcriber's text stays empty. */
|
|
299
300
|
function idsOnlyTokenizer(cfg) {
|
|
300
301
|
return {
|
|
301
|
-
version: 0,
|
|
302
|
-
bosId: cfg.bos,
|
|
303
302
|
eosId: cfg.eos,
|
|
304
|
-
|
|
305
|
-
vocab: new Array(cfg.vocab).fill("")
|
|
303
|
+
decode: () => ""
|
|
306
304
|
};
|
|
307
305
|
}
|
|
308
306
|
function moonshineLoader(weightsUrl, opts = {}) {
|
|
@@ -589,8 +587,8 @@ const DEPTHART_WEIGHTS_URLS = {
|
|
|
589
587
|
};
|
|
590
588
|
const DEPTHART_MODEL_IDS = Object.keys(DEPTHART_WEIGHTS_URLS);
|
|
591
589
|
/** `weightsUrl`: a safetensors export of a Fengxue93/DepthART relative
|
|
592
|
-
* checkpoint
|
|
593
|
-
*
|
|
590
|
+
* checkpoint. Defaults to the hosted export for the hub id. The variant is
|
|
591
|
+
* read from the file. */
|
|
594
592
|
function depthartLoader(weightsUrl, opts = {}) {
|
|
595
593
|
return { async load(modelId, config) {
|
|
596
594
|
const root = defaultRoot();
|
|
@@ -630,7 +628,7 @@ function registerRunntimeBackend(opts = {}) {
|
|
|
630
628
|
const config = await AutoConfig.from_pretrained(modelId, options);
|
|
631
629
|
return await loader.load(modelId, config);
|
|
632
630
|
} catch (e) {
|
|
633
|
-
if (!fallbackToOnnx) throw new
|
|
631
|
+
if (!fallbackToOnnx) throw new RunntimeError(isRunntimeError(e) ? e.code : "LOAD_FAILED", `runntime backend: loading '${modelId}' failed. Pass fallbackToOnnx: true to load it on ONNX instead.`, { cause: e });
|
|
634
632
|
console.warn(`runntime backend: loading '${modelId}' failed, falling back to ONNX`, e);
|
|
635
633
|
}
|
|
636
634
|
else if (!fallbackToOnnx) {
|
|
@@ -650,13 +648,13 @@ function unregisterRunntimeBackend() {
|
|
|
650
648
|
}
|
|
651
649
|
//#endregion
|
|
652
650
|
//#region src/zoo/transformers/init.ts
|
|
653
|
-
/** One-call plugin setup: creates the WebGPU device,
|
|
654
|
-
* and patches transformers.js. Requests subgroups
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
*
|
|
658
|
-
*
|
|
659
|
-
*
|
|
651
|
+
/** One-call plugin setup: creates the WebGPU device, runs the models on it
|
|
652
|
+
* and patches transformers.js. Requests `subgroups`, which makes matmul and
|
|
653
|
+
* attention faster, and `shader-f16`, which the YOLO26 and DepthART models
|
|
654
|
+
* need and the others use when present. A device without them still loads
|
|
655
|
+
* every model that runs in f32. Options go straight to
|
|
656
|
+
* registerRunntimeBackend(), so `models` and `fallbackToOnnx` work here too.
|
|
657
|
+
* Returns the root for apps that also use TypeGPU directly. */
|
|
660
658
|
async function initRunntimeBackend(opts = {}) {
|
|
661
659
|
const root = await tgpu.init({ device: { optionalFeatures: ["subgroups", "shader-f16"] } });
|
|
662
660
|
initRunntime(root);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "runntime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "AI models on the web, built with TypeGPU.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -45,14 +45,19 @@
|
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "tsdown",
|
|
47
47
|
"typecheck": "tsc --noEmit",
|
|
48
|
-
"prepack": "node ../../scripts/sync-readme.mjs && pnpm run build"
|
|
48
|
+
"prepack": "node ../../scripts/sync-readme.mjs && pnpm run build",
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"test:unit": "vitest run --project unit",
|
|
51
|
+
"test:gpu": "vitest run --project gpu",
|
|
52
|
+
"bench:ab": "node bench/cli.ts"
|
|
49
53
|
},
|
|
50
54
|
"dependencies": {
|
|
55
|
+
"@huggingface/tokenizers": "^0.1.3",
|
|
51
56
|
"js-tiktoken": "^1.0.20"
|
|
52
57
|
},
|
|
53
58
|
"peerDependencies": {
|
|
54
|
-
"
|
|
55
|
-
"
|
|
59
|
+
"@huggingface/transformers": "^4.2.0",
|
|
60
|
+
"typegpu": "^0.12.5"
|
|
56
61
|
},
|
|
57
62
|
"peerDependenciesMeta": {
|
|
58
63
|
"@huggingface/transformers": {
|
|
@@ -62,9 +67,12 @@
|
|
|
62
67
|
"devDependencies": {
|
|
63
68
|
"@huggingface/transformers": "^4.2.0",
|
|
64
69
|
"@types/node": "^25.9.2",
|
|
70
|
+
"@vitest/browser-playwright": "^5.0.4",
|
|
65
71
|
"@webgpu/types": "^0.1.60",
|
|
72
|
+
"playwright": "^1.64.0",
|
|
66
73
|
"tsdown": "^0.23.0",
|
|
74
|
+
"typegpu": "^0.12.5",
|
|
67
75
|
"unplugin-typegpu": "^0.12.3",
|
|
68
|
-
"
|
|
76
|
+
"vitest": "^5.0.4"
|
|
69
77
|
}
|
|
70
78
|
}
|