jev-web 0.7.2 → 0.8.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/src/config.mjs CHANGED
@@ -1,65 +1,65 @@
1
- // jev-web — model defaults, backend resolution, and model-side config.
2
- //
3
- // Defaults point at the reference ONNX export of com-kotobalabs/open-jev-
4
- // deberta-v3-large (Apache-2.0), pinned by revision for reproducibility. Any
5
- // repo with the same typed-decision graph layout works: pass `model` and
6
- // optionally `revision`.
7
-
8
- export const DEFAULT_MODEL = "onnx-community/open-jev-deberta-v3-large-ONNX";
9
- export const DEFAULT_REVISION = "7c79f25b5ac496089f448a969c801872ad59d31c";
10
- export const DEFAULT_TEMPERATURE = 1.05;
11
- export const DEFAULT_MARKERS = ["[STATE]", "[Q]", "[OPT]"];
12
- export const DEFAULT_MAX_STATE_TOKENS = 256;
13
- export const DEFAULT_MAX_LEN = 512;
14
-
15
- const HF_BASE = "https://huggingface.co";
16
-
17
- export function resolveDevice({ device = "auto", webgpu = false } = {}) {
18
- if (device && device !== "auto") return device;
19
- return webgpu ? "webgpu" : "wasm";
20
- }
21
-
22
- // Quantized WebGPU kernels are f16-friendly (q4f16); WASM wants the
23
- // non-f16 q4 build. fp32/fp16/q8 stay explicit opt-ins.
24
- export function resolveDtype(device, dtype = "auto") {
25
- if (dtype && dtype !== "auto") return dtype;
26
- return device === "webgpu" ? "q4f16" : "q4";
27
- }
28
-
29
- export async function detectWebGPU(scope = globalThis) {
30
- try {
31
- if (!scope?.navigator?.gpu?.requestAdapter) return false;
32
- return !!(await scope.navigator.gpu.requestAdapter());
33
- } catch {
34
- return false;
35
- }
36
- }
37
-
38
- // Read the model's own calibration/marker config when the repo ships one
39
- // (open_jev_config.json), else fall back to the published reference values.
40
- export async function loadModelConfig({ model = DEFAULT_MODEL, revision = DEFAULT_REVISION, fetchImpl = fetch } = {}) {
41
- const fallback = {
42
- temperature: DEFAULT_TEMPERATURE,
43
- markers: [...DEFAULT_MARKERS],
44
- maxStateTokens: DEFAULT_MAX_STATE_TOKENS,
45
- maxLen: DEFAULT_MAX_LEN,
46
- pool: "span",
47
- source: "defaults",
48
- };
49
- const url = `${HF_BASE}/${model}/resolve/${revision ? `${revision}/` : ""}open_jev_config.json`;
50
- try {
51
- const res = await fetchImpl(url, { cache: "no-store" });
52
- if (!res.ok) return fallback;
53
- const cfg = await res.json();
54
- return {
55
- temperature: Number.isFinite(Number(cfg.temperature)) ? Number(cfg.temperature) : fallback.temperature,
56
- markers: Array.isArray(cfg.markers) && cfg.markers.length === 3 ? cfg.markers.map(String) : fallback.markers,
57
- maxStateTokens: Number.isFinite(Number(cfg.max_state_tokens)) ? Number(cfg.max_state_tokens) : fallback.maxStateTokens,
58
- maxLen: Number.isFinite(Number(cfg.max_len)) ? Number(cfg.max_len) : fallback.maxLen,
59
- pool: typeof cfg.pool === "string" ? cfg.pool : fallback.pool,
60
- source: "model",
61
- };
62
- } catch {
63
- return fallback;
64
- }
65
- }
1
+ // jev-web — model defaults, backend resolution, and model-side config.
2
+ //
3
+ // Defaults point at the reference ONNX export of com-kotobalabs/open-jev-
4
+ // deberta-v3-large (Apache-2.0), pinned by revision for reproducibility. Any
5
+ // repo with the same typed-decision graph layout works: pass `model` and
6
+ // optionally `revision`.
7
+
8
+ export const DEFAULT_MODEL = "onnx-community/open-jev-deberta-v3-large-ONNX";
9
+ export const DEFAULT_REVISION = "7c79f25b5ac496089f448a969c801872ad59d31c";
10
+ export const DEFAULT_TEMPERATURE = 1.05;
11
+ export const DEFAULT_MARKERS = ["[STATE]", "[Q]", "[OPT]"];
12
+ export const DEFAULT_MAX_STATE_TOKENS = 256;
13
+ export const DEFAULT_MAX_LEN = 512;
14
+
15
+ const HF_BASE = "https://huggingface.co";
16
+
17
+ export function resolveDevice({ device = "auto", webgpu = false } = {}) {
18
+ if (device && device !== "auto") return device;
19
+ return webgpu ? "webgpu" : "wasm";
20
+ }
21
+
22
+ // Quantized WebGPU kernels are f16-friendly (q4f16); WASM wants the
23
+ // non-f16 q4 build. fp32/fp16/q8 stay explicit opt-ins.
24
+ export function resolveDtype(device, dtype = "auto") {
25
+ if (dtype && dtype !== "auto") return dtype;
26
+ return device === "webgpu" ? "q4f16" : "q4";
27
+ }
28
+
29
+ export async function detectWebGPU(scope = globalThis) {
30
+ try {
31
+ if (!scope?.navigator?.gpu?.requestAdapter) return false;
32
+ return !!(await scope.navigator.gpu.requestAdapter());
33
+ } catch {
34
+ return false;
35
+ }
36
+ }
37
+
38
+ // Read the model's own calibration/marker config when the repo ships one
39
+ // (open_jev_config.json), else fall back to the published reference values.
40
+ export async function loadModelConfig({ model = DEFAULT_MODEL, revision = DEFAULT_REVISION, fetchImpl = fetch } = {}) {
41
+ const fallback = {
42
+ temperature: DEFAULT_TEMPERATURE,
43
+ markers: [...DEFAULT_MARKERS],
44
+ maxStateTokens: DEFAULT_MAX_STATE_TOKENS,
45
+ maxLen: DEFAULT_MAX_LEN,
46
+ pool: "span",
47
+ source: "defaults",
48
+ };
49
+ const url = `${HF_BASE}/${model}/resolve/${revision ? `${revision}/` : ""}open_jev_config.json`;
50
+ try {
51
+ const res = await fetchImpl(url, { cache: "no-store" });
52
+ if (!res.ok) return fallback;
53
+ const cfg = await res.json();
54
+ return {
55
+ temperature: Number.isFinite(Number(cfg.temperature)) ? Number(cfg.temperature) : fallback.temperature,
56
+ markers: Array.isArray(cfg.markers) && cfg.markers.length === 3 ? cfg.markers.map(String) : fallback.markers,
57
+ maxStateTokens: Number.isFinite(Number(cfg.max_state_tokens)) ? Number(cfg.max_state_tokens) : fallback.maxStateTokens,
58
+ maxLen: Number.isFinite(Number(cfg.max_len)) ? Number(cfg.max_len) : fallback.maxLen,
59
+ pool: typeof cfg.pool === "string" ? cfg.pool : fallback.pool,
60
+ source: "model",
61
+ };
62
+ } catch {
63
+ return fallback;
64
+ }
65
+ }