doppler-gpu 0.6.0 → 0.6.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/package.json +8 -2
- package/src/capsule-runtime.d.ts +2 -0
- package/src/capsule-runtime.js +1 -0
- package/src/client/capsule-host.browser.js +1 -0
- package/src/client/capsule-host.d.ts +2 -0
- package/src/client/capsule-host.js +1 -0
- package/src/client/doppler-api.d.ts +2 -0
- package/src/client/doppler-api.js +1 -0
- package/src/client/model-host/model-session.d.ts +1 -0
- package/src/client/model-host/model-session.js +12 -0
- package/src/client/runtime/capsule-operation-adapters.js +15 -14
- package/src/client/runtime/capsule-operation-executor.js +3 -2
- package/src/client/runtime/capsule-program-adapter.js +2 -0
- package/src/client/runtime/capsule-session-execution.js +9 -5
- package/src/client/runtime/composition-root.d.ts +6 -3
- package/src/client/runtime/composition-root.js +13 -5
- package/src/client/runtime/session-controller.d.ts +6 -17
- package/src/client/runtime/session-controller.js +42 -120
- package/src/client/runtime/verified-capsule-artifact-store.js +38 -9
- package/src/config/capsule-loading.d.ts +1 -1
- package/src/config/capsule-loading.schema.json +3 -2
- package/src/config/capsule-operation.js +6 -1
- package/src/config/capsule-operations.json +1 -2
- package/src/config/conversion/diffusiongemma/diffusiongemma-26b-a4b-it-q4k-ehf16-af16.json +3 -3
- package/src/config/conversion/embeddinggemma/google-embeddinggemma-300m-q4k-ehf16-af32.json +1 -1
- package/src/config/conversion/esm/esm2-t12-35m-ur50d-f32-af32.json +32 -14
- package/src/config/conversion/gemma3/gemma-3-1b-it-f16-af32.json +2 -2
- package/src/config/conversion/gemma3/gemma-3-1b-it-q4k-ehf16-af32.json +2 -2
- package/src/config/conversion/gemma3/gemma-3-270m-it-f16-af32.json +2 -2
- package/src/config/conversion/gemma3/gemma-3-270m-it-q4k-ehf16-af16.json +2 -2
- package/src/config/conversion/gemma3/gemma-3-270m-it-q4k-ehf16-af32.json +2 -2
- package/src/config/conversion/gemma3/translategemma-4b-1b-enes-q4k-ehf16-af32.json +2 -2
- package/src/config/conversion/gemma3/translategemma-4b-it-q4k-ehf16-af32.json +2 -2
- package/src/config/conversion/gemma4/gemma-4-12b-it-text-q4k-ehf16-af16.json +3 -3
- package/src/config/conversion/gemma4/gemma-4-12b-it-text-q4k-ehf16-af32.json +3 -3
- package/src/config/conversion/gemma4/gemma-4-12b-it-text-q4k-ehf16-hq4k-af16.json +5 -5
- package/src/config/conversion/gemma4/gemma-4-12b-it-text-w4a16-ct-ehf16-af16.json +2 -2
- package/src/config/conversion/gemma4/gemma-4-31b-it-text-q4k-ehf16-af16.json +3 -3
- package/src/config/conversion/gemma4/gemma-4-31b-it-text-q4k-ehf16-af32.json +3 -3
- package/src/config/conversion/gemma4/gemma-4-e2b-it-q4k-ehf16-af16-int4ple.json +3 -3
- package/src/config/conversion/gemma4/gemma-4-e2b-it-q4k-ehf16-af32-int4ple.json +2 -2
- package/src/config/conversion/gemma4/gemma-4-e2b-it-q4k-ehf16-af32.json +2 -2
- package/src/config/conversion/gemma4/gemma-4-moe-q4k-ehf16-af32.json +2 -2
- package/src/config/conversion/glmocr/glm-ocr-f16-af32.json +1 -1
- package/src/config/conversion/gpt-oss-20b-f16-xmxfp4.json +2 -2
- package/src/config/conversion/janus/janus-pro-1b-text-q4k-ehaf16.json +2 -2
- package/src/config/conversion/lfm2/lfm2.5-1.2b-instruct-q4k-ehf16-af32.json +2 -2
- package/src/config/conversion/minicpm/minicpm4-0-5b-f16-af32.json +2 -2
- package/src/config/conversion/muse-glimmer/muse-glimmer-30b-text-bf16-af32.json +1 -1
- package/src/config/conversion/muse-glimmer/muse-glimmer-30b-text-f16-af32.json +1 -1
- package/src/config/conversion/qwen3/qwen-3-5-0-8b-q4k-ehaf16.json +5 -5
- package/src/config/conversion/qwen3/qwen-3-5-2b-q4k-ehaf16.json +5 -5
- package/src/config/conversion/qwen3/qwen-3-5-9b-q4k-ehaf16.json +5 -5
- package/src/config/conversion/qwen3/qwen-3-6-27b-q4k-eaf16.json +5 -5
- package/src/config/conversion/qwen3/qwen-3-6-27b-q4k-ehaf16.json +5 -5
- package/src/config/conversion/qwen3/qwen-3-embedding-0-6b-q4k-ehf16-af32.json +2 -2
- package/src/config/conversion/qwen3/qwen-3-reranker-0-6b-f16-af32.json +2 -2
- package/src/config/conversion/qwen3/qwen-3-reranker-0-6b-f16-true-logit-af32.json +1 -1
- package/src/config/conversion/qwen3/qwen-3-reranker-0-6b-q4k-ehf16-af32.json +1 -1
- package/src/config/conversion/qwen3/qwen3.8-27b-text-f16-af32.json +3 -3
- package/src/config/conversion/qwen3/qwen3.8-27b-text-q4k-ehaf16.json +3 -3
- package/src/config/generation-contract.d.ts +39 -0
- package/src/config/generation-contract.js +66 -0
- package/src/config/generation-contract.json +32 -0
- package/src/config/kernel-path-loader.d.ts +7 -0
- package/src/config/kernel-path-loader.js +19 -0
- package/src/config/kernels/kernel-ref-digests.js +16 -16
- package/src/config/kernels/registry.json +35 -10
- package/src/config/schema/doppler.schema.js +1 -0
- package/src/config/source-packages/litert/gemma-4-e2b-it.json +2 -2
- package/src/converter/forge-qualification.js +2 -1
- package/src/converter/forge-stages.js +6 -4
- package/src/converter/quantizer.js +18 -4
- package/src/gpu/device-state.js +8 -0
- package/src/gpu/device.js +6 -1
- package/src/gpu/kernels/gelu.d.ts +4 -0
- package/src/gpu/kernels/gelu.js +11 -1
- package/src/gpu/kernels/gelu.wgsl +16 -0
- package/src/gpu/kernels/gelu_f16.wgsl +16 -0
- package/src/gpu/kernels/rep-penalty.js +30 -5
- package/src/gpu/kernels/rep_penalty.wgsl +25 -30
- package/src/gpu/kernels/rep_penalty_f16.wgsl +24 -25
- package/src/gpu/kernels/sample.d.ts +1 -0
- package/src/gpu/kernels/sample.js +31 -16
- package/src/gpu/kernels/sample.wgsl +112 -157
- package/src/gpu/kernels/sample_f16.wgsl +168 -162
- package/src/index.d.ts +2 -0
- package/src/index.js +1 -0
- package/src/inference/pipelines/context.js +6 -2
- package/src/inference/pipelines/structured/json-grammar-mask.d.ts +2 -0
- package/src/inference/pipelines/structured/json-grammar-mask.js +115 -118
- package/src/inference/pipelines/text/ffn/dense-executor.js +5 -0
- package/src/inference/pipelines/text/ffn/dense.js +2 -2
- package/src/inference/pipelines/text/generator/decode-runtime.js +8 -14
- package/src/inference/pipelines/text/generator/decode.js +18 -6
- package/src/inference/pipelines/text/generator/training.js +3 -2
- package/src/inference/pipelines/text/generator-logits-observation.js +5 -2
- package/src/inference/pipelines/text/generator-runtime.js +18 -19
- package/src/inference/pipelines/text/generator-steps.js +15 -8
- package/src/inference/pipelines/text/generator.js +16 -10
- package/src/inference/pipelines/text/linear-attention.js +24 -0
- package/src/inference/pipelines/text/logits/output-transform.js +10 -3
- package/src/inference/pipelines/text/sampling-config.js +22 -113
- package/src/inference/pipelines/text/sampling.d.ts +9 -1
- package/src/inference/pipelines/text/sampling.js +18 -375
- package/src/inference/pipelines/text/types.d.ts +3 -3
- package/src/inference/token-sampling.js +319 -0
- package/src/storage/backends/opfs-store.d.ts +41 -0
- package/src/tooling/node-browser/static-server.js +1 -0
- package/src/tooling-exports/storage.d.ts +2 -0
- package/src/tooling-exports/storage.js +1 -0
- package/src/version.js +1 -1
- package/tests/kernels/browser/test-page.js +1 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
function seededRandom(seed) {
|
|
2
|
+
const x = Math.sin(seed) * 10000;
|
|
3
|
+
return x - Math.floor(x);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
let fallbackRandomState = (Date.now() >>> 0) || 0x6d2b79f5;
|
|
7
|
+
|
|
8
|
+
function unseededRandom() {
|
|
9
|
+
if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
|
|
10
|
+
const values = new Uint32Array(1);
|
|
11
|
+
crypto.getRandomValues(values);
|
|
12
|
+
return values[0] / 4294967296;
|
|
13
|
+
}
|
|
14
|
+
fallbackRandomState = (fallbackRandomState + 0x6d2b79f5) >>> 0;
|
|
15
|
+
return fallbackRandomState / 4294967296;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
export function applyRepetitionPenalty(logits, previousTokens, penalty, windowSize) {
|
|
20
|
+
if (penalty === 1.0) return;
|
|
21
|
+
|
|
22
|
+
const seen = new Set(previousTokens.slice(-windowSize));
|
|
23
|
+
for (const token of seen) {
|
|
24
|
+
if (token >= 0 && token < logits.length) {
|
|
25
|
+
logits[token] = logits[token] > 0
|
|
26
|
+
? logits[token] / penalty
|
|
27
|
+
: logits[token] * penalty;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function applyPresencePenalty(logits, previousTokens, penalty, windowSize) {
|
|
33
|
+
if (!penalty || penalty <= 0) return;
|
|
34
|
+
|
|
35
|
+
const slice = windowSize > 0 ? previousTokens.slice(-windowSize) : previousTokens;
|
|
36
|
+
const seen = new Set(slice);
|
|
37
|
+
for (const token of seen) {
|
|
38
|
+
if (token >= 0 && token < logits.length) {
|
|
39
|
+
logits[token] -= penalty;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
export function softmax(logits) {
|
|
46
|
+
const n = logits.length;
|
|
47
|
+
let max = -Infinity;
|
|
48
|
+
for (let i = 0; i < n; i++) {
|
|
49
|
+
if (logits[i] > max) max = logits[i];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const exps = new Float32Array(n);
|
|
53
|
+
let sum = 0;
|
|
54
|
+
for (let i = 0; i < n; i++) {
|
|
55
|
+
const e = Math.exp(logits[i] - max);
|
|
56
|
+
exps[i] = e;
|
|
57
|
+
sum += e;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const invSum = sum > 0 ? 1 / sum : 0;
|
|
61
|
+
for (let i = 0; i < n; i++) {
|
|
62
|
+
exps[i] *= invSum;
|
|
63
|
+
}
|
|
64
|
+
return exps;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function summarizeLogitHealth(logits) {
|
|
68
|
+
const health = {
|
|
69
|
+
length: logits.length,
|
|
70
|
+
finite: 0,
|
|
71
|
+
nan: 0,
|
|
72
|
+
posInf: 0,
|
|
73
|
+
negInf: 0,
|
|
74
|
+
min: Infinity,
|
|
75
|
+
max: -Infinity,
|
|
76
|
+
};
|
|
77
|
+
for (let i = 0; i < logits.length; i++) {
|
|
78
|
+
const value = logits[i];
|
|
79
|
+
if (Number.isNaN(value)) {
|
|
80
|
+
health.nan += 1;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (value === Infinity) {
|
|
84
|
+
health.posInf += 1;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (value === -Infinity) {
|
|
88
|
+
health.negInf += 1;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (Number.isFinite(value)) {
|
|
92
|
+
health.finite += 1;
|
|
93
|
+
if (value < health.min) health.min = value;
|
|
94
|
+
if (value > health.max) health.max = value;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (health.finite === 0) {
|
|
98
|
+
health.min = null;
|
|
99
|
+
health.max = null;
|
|
100
|
+
}
|
|
101
|
+
return health;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function formatLogitHealth(health) {
|
|
105
|
+
return [
|
|
106
|
+
`len=${health.length}`,
|
|
107
|
+
`finite=${health.finite}`,
|
|
108
|
+
`nan=${health.nan}`,
|
|
109
|
+
`posInf=${health.posInf}`,
|
|
110
|
+
`negInf=${health.negInf}`,
|
|
111
|
+
`min=${health.min === null ? 'n/a' : Number(health.min).toPrecision(6)}`,
|
|
112
|
+
`max=${health.max === null ? 'n/a' : Number(health.max).toPrecision(6)}`,
|
|
113
|
+
].join(',');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function assertFiniteSamplingCandidates(logits, label, beforeMaskHealth) {
|
|
117
|
+
const afterMaskHealth = summarizeLogitHealth(logits);
|
|
118
|
+
if (afterMaskHealth.finite > 0) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
throw new Error(
|
|
122
|
+
`[Sampling] ${label} has no finite candidate logits after masking suppressed tokens. ` +
|
|
123
|
+
'Upstream decode likely produced NaN/Inf or an all-masked distribution. ' +
|
|
124
|
+
`beforeMask={${formatLogitHealth(beforeMaskHealth || afterMaskHealth)}} ` +
|
|
125
|
+
`afterMask={${formatLogitHealth(afterMaskHealth)}}`
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function isHigherPriorityCandidate(candidate, current) {
|
|
130
|
+
return candidate.logit > current.logit
|
|
131
|
+
|| (candidate.logit === current.logit && candidate.token < current.token);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function isLowerPriorityCandidate(candidate, current) {
|
|
135
|
+
return candidate.logit < current.logit
|
|
136
|
+
|| (candidate.logit === current.logit && candidate.token > current.token);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function heapSwap(heap, a, b) {
|
|
140
|
+
const tmp = heap[a];
|
|
141
|
+
heap[a] = heap[b];
|
|
142
|
+
heap[b] = tmp;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function heapPushLowestFirst(heap, candidate) {
|
|
146
|
+
heap.push(candidate);
|
|
147
|
+
let index = heap.length - 1;
|
|
148
|
+
while (index > 0) {
|
|
149
|
+
const parent = Math.floor((index - 1) / 2);
|
|
150
|
+
if (!isLowerPriorityCandidate(heap[index], heap[parent])) {
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
heapSwap(heap, index, parent);
|
|
154
|
+
index = parent;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function heapifyLowestFirst(heap, index) {
|
|
159
|
+
while (true) {
|
|
160
|
+
const left = index * 2 + 1;
|
|
161
|
+
const right = left + 1;
|
|
162
|
+
let smallest = index;
|
|
163
|
+
if (left < heap.length && isLowerPriorityCandidate(heap[left], heap[smallest])) {
|
|
164
|
+
smallest = left;
|
|
165
|
+
}
|
|
166
|
+
if (right < heap.length && isLowerPriorityCandidate(heap[right], heap[smallest])) {
|
|
167
|
+
smallest = right;
|
|
168
|
+
}
|
|
169
|
+
if (smallest === index) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
heapSwap(heap, index, smallest);
|
|
173
|
+
index = smallest;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function selectTopKLogitCandidates(logits, topK) {
|
|
178
|
+
const limit = Math.max(1, Math.floor(topK));
|
|
179
|
+
if (!Number.isFinite(limit) || limit >= logits.length) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const heap = [];
|
|
184
|
+
for (let token = 0; token < logits.length; token++) {
|
|
185
|
+
const logit = logits[token];
|
|
186
|
+
if (!Number.isFinite(logit)) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
const candidate = { token, logit };
|
|
190
|
+
if (heap.length < limit) {
|
|
191
|
+
heapPushLowestFirst(heap, candidate);
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (isHigherPriorityCandidate(candidate, heap[0])) {
|
|
195
|
+
heap[0] = candidate;
|
|
196
|
+
heapifyLowestFirst(heap, 0);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (heap.length === 0) {
|
|
200
|
+
return [];
|
|
201
|
+
}
|
|
202
|
+
return heap.sort((a, b) => b.logit - a.logit || a.token - b.token);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function sampleFromLogitCandidates(candidates, temperature, seed, topP, onCandidates) {
|
|
206
|
+
if (candidates.length === 0) {
|
|
207
|
+
throw new Error(
|
|
208
|
+
'[Sampling] Top-k filtering produced no finite candidates. ' +
|
|
209
|
+
'Upstream decode likely produced NaN/Inf logits.'
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
if (candidates.length === 1) {
|
|
213
|
+
return candidates[0].token;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const invTemperature = 1 / temperature;
|
|
217
|
+
let maxScaled = -Infinity;
|
|
218
|
+
for (const candidate of candidates) {
|
|
219
|
+
const scaled = candidate.logit * invTemperature;
|
|
220
|
+
candidate.scaled = scaled;
|
|
221
|
+
if (scaled > maxScaled) {
|
|
222
|
+
maxScaled = scaled;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
let sum = 0;
|
|
227
|
+
for (const candidate of candidates) {
|
|
228
|
+
const weight = Math.exp(candidate.scaled - maxScaled);
|
|
229
|
+
candidate.prob = weight;
|
|
230
|
+
sum += weight;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (sum > 0) {
|
|
234
|
+
const invSum = 1 / sum;
|
|
235
|
+
for (const candidate of candidates) {
|
|
236
|
+
candidate.prob *= invSum;
|
|
237
|
+
}
|
|
238
|
+
} else {
|
|
239
|
+
const uniformProb = 1.0 / candidates.length;
|
|
240
|
+
for (const candidate of candidates) {
|
|
241
|
+
candidate.prob = uniformProb;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Normalize the retained top-k distribution before nucleus selection.
|
|
246
|
+
if (topP < 1) {
|
|
247
|
+
let cumulative = 0;
|
|
248
|
+
candidates = candidates.filter(candidate => {
|
|
249
|
+
if (cumulative >= topP) return false;
|
|
250
|
+
cumulative += candidate.prob;
|
|
251
|
+
return true;
|
|
252
|
+
});
|
|
253
|
+
const retained = candidates.reduce((total, candidate) => total + candidate.prob, 0);
|
|
254
|
+
for (const candidate of candidates) candidate.prob /= retained;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
onCandidates?.(candidates);
|
|
258
|
+
|
|
259
|
+
const r = seed !== undefined ? seededRandom(seed) : unseededRandom();
|
|
260
|
+
let cumProb = 0;
|
|
261
|
+
for (const candidate of candidates) {
|
|
262
|
+
cumProb += candidate.prob;
|
|
263
|
+
if (r < cumProb) return candidate.token;
|
|
264
|
+
}
|
|
265
|
+
return candidates[candidates.length - 1].token;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
export function sample(logits, opts) {
|
|
270
|
+
const { temperature, topP, topK, padTokenId, seed, suppressTokenIds, onCandidates } = opts;
|
|
271
|
+
const beforeMaskHealth = summarizeLogitHealth(logits);
|
|
272
|
+
|
|
273
|
+
if (Number.isInteger(padTokenId) && padTokenId >= 0 && padTokenId < logits.length) {
|
|
274
|
+
logits[padTokenId] = -Infinity;
|
|
275
|
+
}
|
|
276
|
+
if (Array.isArray(suppressTokenIds)) {
|
|
277
|
+
for (const tokenId of suppressTokenIds) {
|
|
278
|
+
if (Number.isInteger(tokenId) && tokenId >= 0 && tokenId < logits.length) {
|
|
279
|
+
logits[tokenId] = -Infinity;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
assertFiniteSamplingCandidates(logits, 'Logits', beforeMaskHealth);
|
|
285
|
+
|
|
286
|
+
// Greedy (argmax) when temperature = 0
|
|
287
|
+
if (temperature === 0) {
|
|
288
|
+
let maxIdx = -1;
|
|
289
|
+
let maxVal = -Infinity;
|
|
290
|
+
for (let i = 0; i < logits.length; i++) {
|
|
291
|
+
const value = logits[i];
|
|
292
|
+
if (!Number.isFinite(value)) {
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
if (value > maxVal) {
|
|
296
|
+
maxVal = value;
|
|
297
|
+
maxIdx = i;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (maxIdx < 0) {
|
|
301
|
+
throw new Error(
|
|
302
|
+
'[Sampling] Greedy sampling could not find a finite candidate logit. ' +
|
|
303
|
+
'Upstream decode likely produced NaN/Inf.'
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
onCandidates?.([{ token: maxIdx, logit: maxVal, prob: 1 }]);
|
|
307
|
+
return maxIdx;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
let candidates = topK > 0 ? selectTopKLogitCandidates(logits, topK) : null;
|
|
311
|
+
if (candidates === null) {
|
|
312
|
+
candidates = [];
|
|
313
|
+
for (let token = 0; token < logits.length; token++) {
|
|
314
|
+
if (Number.isFinite(logits[token])) candidates.push({ token, logit: logits[token] });
|
|
315
|
+
}
|
|
316
|
+
candidates.sort((a, b) => b.logit - a.logit || a.token - b.token);
|
|
317
|
+
}
|
|
318
|
+
return sampleFromLogitCandidates(candidates, temperature, seed, topP, onCandidates);
|
|
319
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface OpfsStoreConfig {
|
|
2
|
+
opfsRootDir: string;
|
|
3
|
+
useSyncAccessHandle: boolean;
|
|
4
|
+
maxConcurrentHandles: number;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface OpfsWriteStream {
|
|
8
|
+
write(chunk: Uint8Array | ArrayBuffer): Promise<void>;
|
|
9
|
+
close(): Promise<void>;
|
|
10
|
+
abort(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface OpfsWriteStreamOptions {
|
|
14
|
+
append?: boolean;
|
|
15
|
+
expectedOffset?: number | null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface OpfsStore {
|
|
19
|
+
init(): Promise<void>;
|
|
20
|
+
openModel(modelId: string, options?: { create?: boolean }): Promise<FileSystemDirectoryHandle>;
|
|
21
|
+
getCurrentModelId(): string | null;
|
|
22
|
+
getFileSize(filename: string): Promise<number>;
|
|
23
|
+
readFile(filename: string): Promise<ArrayBuffer>;
|
|
24
|
+
readFileRange(filename: string, offset?: number, length?: number | null): Promise<ArrayBuffer>;
|
|
25
|
+
readFileRangeStream(
|
|
26
|
+
filename: string,
|
|
27
|
+
offset?: number,
|
|
28
|
+
length?: number | null,
|
|
29
|
+
options?: { chunkBytes?: number }
|
|
30
|
+
): AsyncIterable<Uint8Array>;
|
|
31
|
+
readText(filename: string): Promise<string | null>;
|
|
32
|
+
writeFile(filename: string, data: Uint8Array | ArrayBuffer): Promise<void>;
|
|
33
|
+
createWriteStream(filename: string, options?: OpfsWriteStreamOptions): Promise<OpfsWriteStream>;
|
|
34
|
+
deleteFile(filename: string): Promise<boolean>;
|
|
35
|
+
listFiles(): Promise<string[]>;
|
|
36
|
+
listModels(): Promise<string[]>;
|
|
37
|
+
deleteModel(modelId: string): Promise<boolean>;
|
|
38
|
+
cleanup(): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function createOpfsStore(config: OpfsStoreConfig): OpfsStore;
|
|
@@ -10,6 +10,7 @@ const SERVER_HOSTS = Object.freeze(['127.0.0.1', 'localhost', '0.0.0.0']);
|
|
|
10
10
|
const MIME_BY_EXTENSION = Object.freeze({
|
|
11
11
|
'.html': 'text/html; charset=utf-8',
|
|
12
12
|
'.js': 'text/javascript; charset=utf-8',
|
|
13
|
+
'.mjs': 'text/javascript; charset=utf-8',
|
|
13
14
|
'.json': 'application/json; charset=utf-8',
|
|
14
15
|
'.css': 'text/css; charset=utf-8',
|
|
15
16
|
'.map': 'application/json; charset=utf-8',
|
|
@@ -23,6 +23,8 @@ export { listStorageInventory, deleteStorageEntry } from '../storage/inventory.j
|
|
|
23
23
|
export { formatBytes, getQuotaInfo } from '../storage/quota.js';
|
|
24
24
|
export { exportModelToDirectory } from '../storage/export.js';
|
|
25
25
|
export { ensureModelCached, ensureModelCachedSource } from '../tooling/opfs-cache.js';
|
|
26
|
+
export { createOpfsStore } from '../storage/backends/opfs-store.js';
|
|
27
|
+
export type { OpfsStore, OpfsStoreConfig } from '../storage/backends/opfs-store.js';
|
|
26
28
|
export {
|
|
27
29
|
buildManifestVersionSet,
|
|
28
30
|
inspectModelDownloadResume,
|
|
@@ -27,6 +27,7 @@ export { listStorageInventory, deleteStorageEntry } from '../storage/inventory.j
|
|
|
27
27
|
export { formatBytes, getQuotaInfo } from '../storage/quota.js';
|
|
28
28
|
export { exportModelToDirectory } from '../storage/export.js';
|
|
29
29
|
export { ensureModelCached, ensureModelCachedSource } from '../tooling/opfs-cache.js';
|
|
30
|
+
export { createOpfsStore } from '../storage/backends/opfs-store.js';
|
|
30
31
|
export {
|
|
31
32
|
buildManifestVersionSet,
|
|
32
33
|
inspectModelDownloadResume,
|
package/src/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const DOPPLER_VERSION = '0.6.
|
|
1
|
+
export const DOPPLER_VERSION = '0.6.1';
|
|
2
2
|
export const DOPPLER_PROVIDER_VERSION = DOPPLER_VERSION;
|
|
@@ -1721,6 +1721,7 @@ const testHarness = {
|
|
|
1721
1721
|
const tokenId = await sampleKernel.runGPUSample(logitsBuf, logits.length, {
|
|
1722
1722
|
temperature,
|
|
1723
1723
|
topK,
|
|
1724
|
+
topP: 1,
|
|
1724
1725
|
randomSeed: randomValue * 10000, // Convert to seed
|
|
1725
1726
|
logitsDtype: 'f32',
|
|
1726
1727
|
padTokenId: null,
|