@tryhamster/gerbil 1.10.0 → 1.10.2

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 (47) hide show
  1. package/dist/cli.mjs +7 -7
  2. package/dist/cli.mjs.map +1 -1
  3. package/dist/frameworks/express.mjs +1 -1
  4. package/dist/frameworks/fastify.mjs +1 -1
  5. package/dist/frameworks/hono.mjs +1 -1
  6. package/dist/frameworks/next.d.mts +2 -2
  7. package/dist/frameworks/next.mjs +1 -1
  8. package/dist/frameworks/trpc.mjs +1 -1
  9. package/dist/gerbil-IqsK32DM.mjs +4 -0
  10. package/dist/{gerbil-CSk3AHNN.d.mts → gerbil-PEAdJdsH.d.mts} +2 -2
  11. package/dist/{gerbil-CSk3AHNN.d.mts.map → gerbil-PEAdJdsH.d.mts.map} +1 -1
  12. package/dist/{gerbil-DtREprR_.mjs → gerbil-sQ7eqzn3.mjs} +2 -2
  13. package/dist/{gerbil-DtREprR_.mjs.map → gerbil-sQ7eqzn3.mjs.map} +1 -1
  14. package/dist/gpu/hooks.d.mts +1 -1
  15. package/dist/gpu/index.d.mts +1 -1
  16. package/dist/gpu/index.mjs +2 -2
  17. package/dist/{gpu-NPdk7pmr.mjs → gpu-Ps1eQaXG.mjs} +88 -17
  18. package/dist/gpu-Ps1eQaXG.mjs.map +1 -0
  19. package/dist/{index-B56xBiR2.d.mts → index-CJux7zbV.d.mts} +15 -1
  20. package/dist/{index-B56xBiR2.d.mts.map → index-CJux7zbV.d.mts.map} +1 -1
  21. package/dist/index.d.mts +2 -2
  22. package/dist/index.mjs +4 -4
  23. package/dist/integrations/ai-sdk.mjs +1 -1
  24. package/dist/integrations/langchain.mjs +1 -1
  25. package/dist/integrations/llamaindex.mjs +1 -1
  26. package/dist/integrations/mcp.d.mts +2 -2
  27. package/dist/integrations/mcp.mjs +4 -4
  28. package/dist/{mcp-XU4quJ9w.mjs → mcp-BX-ryGGJ.mjs} +3 -3
  29. package/dist/{mcp-XU4quJ9w.mjs.map → mcp-BX-ryGGJ.mjs.map} +1 -1
  30. package/dist/{moonshine-stt-BYbYwSz2.mjs → moonshine-stt-BKeD6OYF.mjs} +59 -7
  31. package/dist/moonshine-stt-BKeD6OYF.mjs.map +1 -0
  32. package/dist/moonshine-stt-DKC0PHF_.mjs +4 -0
  33. package/dist/{one-liner-1WoJGLlZ.mjs → one-liner-m6NjYWMg.mjs} +2 -2
  34. package/dist/{one-liner-1WoJGLlZ.mjs.map → one-liner-m6NjYWMg.mjs.map} +1 -1
  35. package/dist/outetts-CAL3_K3j.d.mts.map +1 -1
  36. package/dist/{repl-B41yROa-.mjs → repl-hN4jSHrb.mjs} +3 -3
  37. package/dist/skills/index.d.mts +15 -15
  38. package/dist/skills/index.d.mts.map +1 -1
  39. package/dist/skills/index.mjs +3 -3
  40. package/dist/{skills-C9RgR8qU.mjs → skills-DZ5OITy0.mjs} +2 -2
  41. package/dist/{skills-C9RgR8qU.mjs.map → skills-DZ5OITy0.mjs.map} +1 -1
  42. package/dist/tune/index.mjs +1 -1
  43. package/package.json +1 -1
  44. package/dist/gerbil-DrV6iNcD.mjs +0 -4
  45. package/dist/gpu-NPdk7pmr.mjs.map +0 -1
  46. package/dist/moonshine-stt-BRTnAoQ8.mjs +0 -4
  47. package/dist/moonshine-stt-BYbYwSz2.mjs.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { i as resolveDefaultRepo, n as OUTETTS_ASSETS, r as OUTETTS_PRESET_VOICES, t as DEFAULT_MODELS } from "./defaults-C_bJK9zs.mjs";
2
2
  import { E as GEMMA4_VIS_KEYS, S as DEFAULT_GROUP_SIZE, T as DTYPE_BYTES, _ as kaniCosTensor, c as KANI_END_OF_HUMAN, d as buildKaniLayerCosSin, f as computeKaniPositions, g as kaniAttentionLayerIndices, h as generateNanoCodecDecoderGraph, l as KANI_START_OF_HUMAN, m as generateKaniTtsGraph, u as audioTokensToCodes, v as kaniLayerAlpha, w as CANONICAL_KEYS, x as parseKaniConfig, y as kaniSinTensor } from "./architectures-BHkqQ9xp.mjs";
3
- import { C as destroyBuffers, E as verifyGPU, S as createUniformBuffer, T as initGPU, _ as KERNEL_REGISTRY, a as loadModel, b as createBindGroup, c as loadParlerTTS, d as remapPrunedToken, g as Executor, h as fetchAdapter, i as loadKaniTTS, l as quantizeBackboneInt4, m as buildLoRADeltas, r as createKeyMapperForArch, s as loadOuteTTS, u as quantizeKaniBackbone, v as MATMUL_BIAS_F16C_SPEC, w as getOrCreatePipeline, x as createStorageBuffer, y as clearPipelineCache } from "./moonshine-stt-BYbYwSz2.mjs";
3
+ import { C as destroyBuffers, E as verifyGPU, S as createUniformBuffer, T as initGPU, _ as KERNEL_REGISTRY, a as loadModel, b as createBindGroup, c as loadParlerTTS, d as remapPrunedToken, g as Executor, h as fetchAdapter, i as loadKaniTTS, l as quantizeBackboneInt4, m as buildLoRADeltas, r as createKeyMapperForArch, s as loadOuteTTS, u as quantizeKaniBackbone, v as MATMUL_BIAS_F16C_SPEC, w as getOrCreatePipeline, x as createStorageBuffer, y as clearPipelineCache } from "./moonshine-stt-BKeD6OYF.mjs";
4
4
 
5
5
  //#region src/gpu/architectures/gemma4_vision.ts
6
6
  /**
@@ -806,7 +806,7 @@ function nucleusSample$1(probs, ids, topP) {
806
806
  * In-place top-k filter over a probability array: keep only the `k` highest, zero
807
807
  * the rest, and renormalize. No-op when k <= 0 or k >= length (keep everything).
808
808
  */
809
- function applyTopK$1(scores, k) {
809
+ function applyTopK(scores, k) {
810
810
  const n = scores.length;
811
811
  if (k <= 0 || k >= n) return;
812
812
  const order = Array.from({ length: n }, (_, i) => i).sort((a, b) => scores[b] - scores[a]);
@@ -1065,7 +1065,7 @@ var KaniTTS = class KaniTTS {
1065
1065
  scores[i] = s / p.temperature;
1066
1066
  }
1067
1067
  softmaxInPlace$1(scores);
1068
- applyTopK$1(scores, p.topK);
1068
+ applyTopK(scores, p.topK);
1069
1069
  return nucleusSample$1(scores, ids, p.topP);
1070
1070
  }
1071
1071
  /**
@@ -2880,16 +2880,6 @@ function softmaxInPlace(scores) {
2880
2880
  }
2881
2881
  for (let i = 0; i < scores.length; i++) scores[i] /= sum;
2882
2882
  }
2883
- /** In-place top-k filter: keep the k highest, zero the rest, renormalize. */
2884
- function applyTopK(scores, k) {
2885
- const n = scores.length;
2886
- if (k <= 0 || k >= n) return;
2887
- const order = Array.from({ length: n }, (_, i) => i).sort((a, b) => scores[b] - scores[a]);
2888
- let keepSum = 0;
2889
- for (let r = 0; r < k; r++) keepSum += scores[order[r]];
2890
- for (let r = k; r < n; r++) scores[order[r]] = 0;
2891
- if (keepSum > 0) for (let i = 0; i < n; i++) scores[i] /= keepSum;
2892
- }
2893
2883
  /** Top-p nucleus sample from a softmaxed prob array over `ids`. */
2894
2884
  function nucleusSample(probs, ids, topP) {
2895
2885
  const n = probs.length;
@@ -2913,6 +2903,81 @@ function nucleusSample(probs, ids, topP) {
2913
2903
  return ids[order[0]];
2914
2904
  }
2915
2905
  /**
2906
+ * Select the `k` highest-scoring token ids in a single O(n·logk) pass (bounded
2907
+ * min-heap), applying the repetition penalty to `previous` tokens inline so a
2908
+ * penalized token can drop out of the shortlist. Returns the kept ids and their
2909
+ * (penalized, pre-temperature) logits, unsorted.
2910
+ *
2911
+ * This replaces the two full-vocab `Array.from(...).sort(...)` passes the sampler
2912
+ * ran PER TOKEN over OuteTTS's ~157k vocab (the top-k filter + the nucleus sort):
2913
+ * a codec-LM emits hundreds-to-thousands of tokens per utterance, so those two
2914
+ * O(n·logn) sorts — plus their two fresh 157k-element allocations every step —
2915
+ * dominated host-side decode and made the browser SPEECH tab look stalled
2916
+ * ("SYNTHESIZING…" for minutes). Restricting the softmax + nucleus to the kept
2917
+ * top-k is distribution-identical to the old full-vocab path (softmax is
2918
+ * monotonic and the discarded tail is renormalized away either way).
2919
+ */
2920
+ function selectTopKPenalized(logits, k, penalized, penalty) {
2921
+ const n = logits.length;
2922
+ const cap = Math.min(k, n);
2923
+ const heapVal = new Float32Array(cap);
2924
+ const heapId = new Int32Array(cap);
2925
+ let size = 0;
2926
+ const penalize = (i, v) => {
2927
+ if (penalized?.has(i)) return v > 0 ? v / penalty : v * penalty;
2928
+ return v;
2929
+ };
2930
+ const siftDown$1 = () => {
2931
+ let root = 0;
2932
+ for (;;) {
2933
+ let smallest = root;
2934
+ const l = 2 * root + 1;
2935
+ const r = 2 * root + 2;
2936
+ if (l < size && heapVal[l] < heapVal[smallest]) smallest = l;
2937
+ if (r < size && heapVal[r] < heapVal[smallest]) smallest = r;
2938
+ if (smallest === root) break;
2939
+ const tv = heapVal[root];
2940
+ const ti = heapId[root];
2941
+ heapVal[root] = heapVal[smallest];
2942
+ heapId[root] = heapId[smallest];
2943
+ heapVal[smallest] = tv;
2944
+ heapId[smallest] = ti;
2945
+ root = smallest;
2946
+ }
2947
+ };
2948
+ const siftUp = (node0) => {
2949
+ let node = node0;
2950
+ while (node > 0) {
2951
+ const parent = node - 1 >> 1;
2952
+ if (heapVal[parent] <= heapVal[node]) break;
2953
+ const tv = heapVal[node];
2954
+ const ti = heapId[node];
2955
+ heapVal[node] = heapVal[parent];
2956
+ heapId[node] = heapId[parent];
2957
+ heapVal[parent] = tv;
2958
+ heapId[parent] = ti;
2959
+ node = parent;
2960
+ }
2961
+ };
2962
+ for (let i = 0; i < n; i++) {
2963
+ const v = penalize(i, logits[i]);
2964
+ if (size < cap) {
2965
+ heapVal[size] = v;
2966
+ heapId[size] = i;
2967
+ size++;
2968
+ siftUp(size - 1);
2969
+ } else if (v > heapVal[0]) {
2970
+ heapVal[0] = v;
2971
+ heapId[0] = i;
2972
+ siftDown$1();
2973
+ }
2974
+ }
2975
+ return {
2976
+ ids: heapId.subarray(0, size),
2977
+ vals: heapVal.subarray(0, size)
2978
+ };
2979
+ }
2980
+ /**
2916
2981
  * Resample interleaved-or-mono PCM to mono at `targetRate` via linear interpolation.
2917
2982
  * Audio is assumed already mono (Float32 [-1,1]); if `srcRate === targetRate` the
2918
2983
  * input is returned as-is. Linear resampling is sufficient for codec conditioning
@@ -3145,9 +3210,16 @@ var OuteTTS = class OuteTTS {
3145
3210
  */
3146
3211
  sampleToken(logits, p) {
3147
3212
  const n = logits.length;
3213
+ const prev = p.repetitionPenalty !== 1 ? new Set(p.previous) : null;
3214
+ if (p.topK > 0 && p.topK < n) {
3215
+ const { ids: kIds, vals: kVals } = selectTopKPenalized(logits, p.topK, prev, p.repetitionPenalty);
3216
+ const scores$1 = new Float32Array(kVals.length);
3217
+ for (let i = 0; i < kVals.length; i++) scores$1[i] = kVals[i] / p.temperature;
3218
+ softmaxInPlace(scores$1);
3219
+ return nucleusSample(scores$1, Int32Array.from(kIds), p.topP);
3220
+ }
3148
3221
  const ids = new Int32Array(n);
3149
3222
  const scores = new Float32Array(n);
3150
- const prev = p.repetitionPenalty !== 1 ? new Set(p.previous) : null;
3151
3223
  for (let i = 0; i < n; i++) {
3152
3224
  ids[i] = i;
3153
3225
  let s = logits[i];
@@ -3155,7 +3227,6 @@ var OuteTTS = class OuteTTS {
3155
3227
  scores[i] = s / p.temperature;
3156
3228
  }
3157
3229
  softmaxInPlace(scores);
3158
- applyTopK(scores, p.topK);
3159
3230
  return nucleusSample(scores, ids, p.topP);
3160
3231
  }
3161
3232
  /**
@@ -6159,7 +6230,7 @@ var WebGPUEngine = class WebGPUEngine {
6159
6230
  let mmLogicalPos = inputIds.length;
6160
6231
  const keepPlan = this.config.vocabKeepPlan;
6161
6232
  const remapTok = keepPlan ? (i) => remapPrunedToken(i, keepPlan) : (i) => i;
6162
- if (isGreedy && !this.executor.needsMultiEncoder && !mmDecode && !this.executor.hasRuntimeAdapter) {
6233
+ if (isGreedy && !this.executor.needsMultiEncoder && !mmDecode) {
6163
6234
  const firstToken = remapTok(sampleToken(logits, sampling, [...inputIds, ...generatedIds]));
6164
6235
  if (!consumeToken(firstToken)) {
6165
6236
  const depth = Executor.PIPELINE_DEPTH;
@@ -7272,4 +7343,4 @@ var WebGPUEngine = class WebGPUEngine {
7272
7343
 
7273
7344
  //#endregion
7274
7345
  export { dequantizeGemma4VisionProjection as A, audioTokensToDacCodes as C, parseOuteTtsConfig as D, generateOuteTtsBackboneGraph as E, generateGemma4VisionGraph as M, patchGemma4VisionClips as N, KaniTTS as O, resolveGemma4VisionInfo as P, loadOuteSpeaker as S, generateDacSpeechDecoderGraph as T, smartResize as _, buildGemma4PosEmbeds as a, OuteTTS as b, buildMRoPECosSin as c, buildPositionIds as d, buildRotaryCosSin as f, preprocessImageGemma4 as g, preprocessImage as h, buildGemma4PoolMatrix as i, dequantizeMLXProjection as j, generateQwen3_5VisionGraph as k, buildMRoPEPositionIds as l, mropeFreqDims as m, GEMMA4_IMAGE_PROCESSOR as n, buildGemma4RotaryCosSin as o, buildVisionPositionTensors as p, QWEN3_5_IMAGE_PROCESSOR as r, buildGemma4VisionPositionTensors as s, WebGPUEngine as t, buildPosEmbeds as u, VisionExecutor as v, dacOutputLength as w, buildOutePromptString as x, ParlerTTS as y };
7275
- //# sourceMappingURL=gpu-NPdk7pmr.mjs.map
7346
+ //# sourceMappingURL=gpu-Ps1eQaXG.mjs.map