@tryhamster/gerbil 1.2.2 → 1.3.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.
Files changed (88) hide show
  1. package/README.md +6 -6
  2. package/dist/architectures-Ol7yUmKf.mjs.map +1 -1
  3. package/dist/browser/index.d.ts +68 -2
  4. package/dist/browser/index.d.ts.map +1 -1
  5. package/dist/cli.mjs +7 -7
  6. package/dist/cli.mjs.map +1 -1
  7. package/dist/defaults-CudhglS1.mjs +47 -0
  8. package/dist/defaults-CudhglS1.mjs.map +1 -0
  9. package/dist/frameworks/express.d.mts +2 -1
  10. package/dist/frameworks/express.d.mts.map +1 -1
  11. package/dist/frameworks/express.mjs +1 -1
  12. package/dist/frameworks/fastify.d.mts +2 -1
  13. package/dist/frameworks/fastify.d.mts.map +1 -1
  14. package/dist/frameworks/fastify.mjs +1 -1
  15. package/dist/frameworks/hono.d.mts +2 -1
  16. package/dist/frameworks/hono.d.mts.map +1 -1
  17. package/dist/frameworks/hono.mjs +1 -1
  18. package/dist/frameworks/next.d.mts +4 -3
  19. package/dist/frameworks/next.d.mts.map +1 -1
  20. package/dist/frameworks/next.mjs +1 -1
  21. package/dist/frameworks/react.d.mts +2 -1
  22. package/dist/frameworks/react.d.mts.map +1 -1
  23. package/dist/frameworks/trpc.d.mts +2 -1
  24. package/dist/frameworks/trpc.d.mts.map +1 -1
  25. package/dist/frameworks/trpc.mjs +1 -1
  26. package/dist/{gerbil-DkilSf1Q.d.mts → gerbil-4Xid85_Z.d.mts} +31 -6
  27. package/dist/gerbil-4Xid85_Z.d.mts.map +1 -0
  28. package/dist/gerbil-BikD0xFU.mjs +4 -0
  29. package/dist/{gerbil-BMZ5wnM_.mjs → gerbil-Du-1M2Wq.mjs} +52 -14
  30. package/dist/gerbil-Du-1M2Wq.mjs.map +1 -0
  31. package/dist/gpu/hooks.d.mts +51 -3
  32. package/dist/gpu/hooks.d.mts.map +1 -1
  33. package/dist/gpu/hooks.mjs +130 -2
  34. package/dist/gpu/hooks.mjs.map +1 -1
  35. package/dist/gpu/index.d.mts +3 -2
  36. package/dist/gpu/index.mjs +4 -4
  37. package/dist/{gpu-BZHJDas1.mjs → gpu-BECDib8p.mjs} +2085 -217
  38. package/dist/gpu-BECDib8p.mjs.map +1 -0
  39. package/dist/{index-HVS7yeLx.d.mts → index-C4kJrqs1.d.mts} +99 -5
  40. package/dist/index-C4kJrqs1.d.mts.map +1 -0
  41. package/dist/{index-Dgmb2kE3.d.mts → index-CRDf-nS4.d.mts} +2 -2
  42. package/dist/{index-Dgmb2kE3.d.mts.map → index-CRDf-nS4.d.mts.map} +1 -1
  43. package/dist/index.d.mts +6 -5
  44. package/dist/index.d.mts.map +1 -1
  45. package/dist/index.mjs +5 -5
  46. package/dist/integrations/ai-sdk.d.mts +2 -1
  47. package/dist/integrations/ai-sdk.d.mts.map +1 -1
  48. package/dist/integrations/ai-sdk.mjs +1 -1
  49. package/dist/integrations/langchain.d.mts +2 -1
  50. package/dist/integrations/langchain.d.mts.map +1 -1
  51. package/dist/integrations/langchain.mjs +1 -1
  52. package/dist/integrations/llamaindex.d.mts +2 -1
  53. package/dist/integrations/llamaindex.d.mts.map +1 -1
  54. package/dist/integrations/llamaindex.mjs +1 -1
  55. package/dist/integrations/mcp.d.mts +4 -3
  56. package/dist/integrations/mcp.d.mts.map +1 -1
  57. package/dist/integrations/mcp.mjs +4 -4
  58. package/dist/{mcp-D1laYce-.mjs → mcp-4imtBQLX.mjs} +3 -3
  59. package/dist/{mcp-D1laYce-.mjs.map → mcp-4imtBQLX.mjs.map} +1 -1
  60. package/dist/memory/index.d.mts +2 -2
  61. package/dist/{moonshine-stt-Bj1zJfZg.mjs → moonshine-stt-BO5gZ_D6.mjs} +300 -30
  62. package/dist/moonshine-stt-BO5gZ_D6.mjs.map +1 -0
  63. package/dist/moonshine-stt-fVw-UB4s.mjs +4 -0
  64. package/dist/{one-liner-qLcYdOfH.mjs → one-liner-X5vMbWzs.mjs} +2 -2
  65. package/dist/{one-liner-qLcYdOfH.mjs.map → one-liner-X5vMbWzs.mjs.map} +1 -1
  66. package/dist/outetts-DmR0NfSG.d.mts +219 -0
  67. package/dist/outetts-DmR0NfSG.d.mts.map +1 -0
  68. package/dist/{repl-RdQ2vKRz.mjs → repl-CGadrKcY.mjs} +3 -3
  69. package/dist/skills/index.d.mts +6 -5
  70. package/dist/skills/index.d.mts.map +1 -1
  71. package/dist/skills/index.mjs +3 -3
  72. package/dist/{skills-_q7U_ySm.mjs → skills-BFGAXYkm.mjs} +2 -2
  73. package/dist/{skills-_q7U_ySm.mjs.map → skills-BFGAXYkm.mjs.map} +1 -1
  74. package/dist/{types-LlyYILII.d.mts → types-Cpf-aOxX.d.mts} +25 -3
  75. package/dist/types-Cpf-aOxX.d.mts.map +1 -0
  76. package/dist/{types-DQBe2lFo.d.mts → types-Dqv4m0vo.d.mts} +1 -1
  77. package/dist/{types-DQBe2lFo.d.mts.map → types-Dqv4m0vo.d.mts.map} +1 -1
  78. package/package.json +2 -2
  79. package/dist/defaults-bJcmOaRG.mjs +0 -24
  80. package/dist/defaults-bJcmOaRG.mjs.map +0 -1
  81. package/dist/gerbil-BMZ5wnM_.mjs.map +0 -1
  82. package/dist/gerbil-BWKJtIYj.mjs +0 -4
  83. package/dist/gerbil-DkilSf1Q.d.mts.map +0 -1
  84. package/dist/gpu-BZHJDas1.mjs.map +0 -1
  85. package/dist/index-HVS7yeLx.d.mts.map +0 -1
  86. package/dist/moonshine-stt-Bj1zJfZg.mjs.map +0 -1
  87. package/dist/moonshine-stt-Eei7fh3N.mjs +0 -4
  88. package/dist/types-LlyYILII.d.mts.map +0 -1
@@ -1088,6 +1088,28 @@ fn main(
1088
1088
  function cdiv(a, b) {
1089
1089
  return Math.ceil(a / b);
1090
1090
  }
1091
+ /**
1092
+ * Spread a flat workgroup count over a 2D grid so neither dimension exceeds WebGPU's
1093
+ * 65535 per-dimension cap. Used by the audio codec-decoder kernels (Conv1dFull /
1094
+ * ConvTranspose1d / Snake1d / RVQDequant) whose outputs can run to hundreds of
1095
+ * thousands of workgroups for multi-second clips. The kernels recover the flat index
1096
+ * as `gid.y * (num_workgroups.x * 64) + gid.x`, so the x dimension must stay a
1097
+ * multiple of the natural grid width — we keep x = min(count, 65535) and tile y.
1098
+ */
1099
+ const MAX_WORKGROUPS_PER_DIM = 65535;
1100
+ function dispatch2D(workgroups) {
1101
+ if (workgroups <= MAX_WORKGROUPS_PER_DIM) return [
1102
+ workgroups,
1103
+ 1,
1104
+ 1
1105
+ ];
1106
+ const x = MAX_WORKGROUPS_PER_DIM;
1107
+ return [
1108
+ x,
1109
+ cdiv(workgroups, x),
1110
+ 1
1111
+ ];
1112
+ }
1091
1113
  /** Reinterpret an f32 value as its u32 bit pattern. */
1092
1114
  function f32BitsToU32(value) {
1093
1115
  const f = new Float32Array(1);
@@ -3298,9 +3320,12 @@ struct Params {
3298
3320
  @group(0) @binding(2) var<storage, read_write> output: array<f32>;
3299
3321
  @group(0) @binding(3) var<storage, read> params: Params;
3300
3322
 
3323
+ // 2D-dispatch safe: for very large tensors (e.g. DAC vocoder residual adds on
3324
+ // multi-second clips) the workgroup count exceeds the 65535 per-dim cap, so the
3325
+ // dispatch spreads over y. Flat index = gid.y * (num_workgroups.x * 256) + gid.x.
3301
3326
  @compute @workgroup_size(256)
3302
- fn main(@builtin(global_invocation_id) gid: vec3u) {
3303
- let idx = gid.x;
3327
+ fn main(@builtin(global_invocation_id) gid: vec3u, @builtin(num_workgroups) ng: vec3u) {
3328
+ let idx = gid.y * (ng.x * 256u) + gid.x;
3304
3329
  if (idx >= params.count) { return; }
3305
3330
  output[idx] = a[idx] + b[idx];
3306
3331
  }
@@ -5471,11 +5496,7 @@ const addSpec = {
5471
5496
  { type: "uniform" }
5472
5497
  ],
5473
5498
  getDispatchSize(op, resolvedShapes) {
5474
- return [
5475
- cdiv(outputElementCount(op, resolvedShapes), 256),
5476
- 1,
5477
- 1
5478
- ];
5499
+ return dispatch2D(cdiv(outputElementCount(op, resolvedShapes), 256));
5479
5500
  },
5480
5501
  buildParams(op, resolvedShapes) {
5481
5502
  return buildUniformBuffer([outputElementCount(op, resolvedShapes)]);
@@ -7046,9 +7067,12 @@ struct Params {
7046
7067
  @group(0) @binding(3) var<storage, read_write> y: array<f32>;
7047
7068
  @group(0) @binding(4) var<storage, read> params: Params;
7048
7069
 
7070
+ // 2D dispatch: outputs can exceed 65535 workgroups in x for long audio, so the
7071
+ // dispatch spreads across y. Flat index = gid.y * (num_workgroups.x * 64) + gid.x
7072
+ // (num_workgroups is the builtin grid size; no extra param needed).
7049
7073
  @compute @workgroup_size(64)
7050
- fn main(@builtin(global_invocation_id) gid: vec3u) {
7051
- let idx = gid.x;
7074
+ fn main(@builtin(global_invocation_id) gid: vec3u, @builtin(num_workgroups) ng: vec3u) {
7075
+ let idx = gid.y * (ng.x * 64u) + gid.x;
7052
7076
  let total = params.Cout * params.Lout;
7053
7077
  if (idx >= total) { return; }
7054
7078
  let oc = idx / params.Lout;
@@ -7085,8 +7109,8 @@ struct Params {
7085
7109
  @group(0) @binding(4) var<storage, read> params: Params;
7086
7110
 
7087
7111
  @compute @workgroup_size(64)
7088
- fn main(@builtin(global_invocation_id) gid: vec3u) {
7089
- let idx = gid.x;
7112
+ fn main(@builtin(global_invocation_id) gid: vec3u, @builtin(num_workgroups) ng: vec3u) {
7113
+ let idx = gid.y * (ng.x * 64u) + gid.x;
7090
7114
  let total = params.Cout * params.Lout;
7091
7115
  if (idx >= total) { return; }
7092
7116
  let oc = idx / params.Lout;
@@ -7118,8 +7142,8 @@ struct Params { C: u32, L: u32 }
7118
7142
  @group(0) @binding(3) var<storage, read> params: Params;
7119
7143
 
7120
7144
  @compute @workgroup_size(64)
7121
- fn main(@builtin(global_invocation_id) gid: vec3u) {
7122
- let idx = gid.x;
7145
+ fn main(@builtin(global_invocation_id) gid: vec3u, @builtin(num_workgroups) ng: vec3u) {
7146
+ let idx = gid.y * (ng.x * 64u) + gid.x;
7123
7147
  let total = params.C * params.L;
7124
7148
  if (idx >= total) { return; }
7125
7149
  let c = idx / params.L;
@@ -7128,6 +7152,145 @@ fn main(@builtin(global_invocation_id) gid: vec3u) {
7128
7152
  y[idx] = x[idx] + (1.0 / (a + 1e-9)) * s * s;
7129
7153
  }
7130
7154
  `;
7155
+ const WGSL_RVQ_DEQUANT = `\
7156
+ // Residual-Vector-Quantizer dequant for DAC.speech (descript-audio-codec lineage).
7157
+ // Reconstruct the continuous latent z[Cout, T] from codes[NCB, T] (u32 indices):
7158
+ // z[oc, t] = sum_c ( out_proj_bias[c][oc]
7159
+ // + sum_d codebook[c][ codes[c,t], d ] * out_proj_w[c][oc, d] )
7160
+ // where each quantizer c (0..NCB-1) has:
7161
+ // codebook : [codebook_size, codebook_dim] (nn.Embedding)
7162
+ // out_proj : Conv1d(codebook_dim -> Cout, kernel=1) -> weight [Cout, codebook_dim], bias [Cout]
7163
+ // All NCB quantizers share the same codebook_dim (D) and Cout. Tensors are packed
7164
+ // codebook-major: codebook[c] starts at c*codebook_size*D, out_proj_w[c] at c*Cout*D,
7165
+ // out_proj_bias[c] at c*Cout, codes[c] row at c*T. One thread per (oc, t) output.
7166
+ // Mobile-safe: flat workgroup, no select(), no shared memory, no exp().
7167
+ struct Params { NCB: u32, Cout: u32, T: u32, D: u32, codebook_size: u32, _p0: u32, _p1: u32, _p2: u32 }
7168
+ @group(0) @binding(0) var<storage, read> codes: array<u32>; // [NCB, T]
7169
+ @group(0) @binding(1) var<storage, read> codebook: array<f32>; // [NCB, codebook_size, D]
7170
+ @group(0) @binding(2) var<storage, read> proj_w: array<f32>; // [NCB, Cout, D]
7171
+ @group(0) @binding(3) var<storage, read> proj_b: array<f32>; // [NCB, Cout]
7172
+ @group(0) @binding(4) var<storage, read_write> z: array<f32>; // [Cout, T]
7173
+ @group(0) @binding(5) var<storage, read> params: Params;
7174
+
7175
+ @compute @workgroup_size(64)
7176
+ fn main(@builtin(global_invocation_id) gid: vec3u, @builtin(num_workgroups) ng: vec3u) {
7177
+ let flat = gid.y * (ng.x * 64u) + gid.x;
7178
+ let total = params.Cout * params.T;
7179
+ if (flat >= total) { return; }
7180
+ let oc = flat / params.T;
7181
+ let t = flat % params.T;
7182
+ let D = params.D;
7183
+ var acc: f32 = 0.0;
7184
+ for (var c: u32 = 0u; c < params.NCB; c = c + 1u) {
7185
+ let idx = codes[c * params.T + t];
7186
+ let cb_row = (c * params.codebook_size + idx) * D; // codebook[c][idx, :]
7187
+ let w_row = (c * params.Cout + oc) * D; // out_proj_w[c][oc, :]
7188
+ var dot: f32 = 0.0;
7189
+ for (var d: u32 = 0u; d < D; d = d + 1u) {
7190
+ dot = dot + codebook[cb_row + d] * proj_w[w_row + d];
7191
+ }
7192
+ acc = acc + dot + proj_b[c * params.Cout + oc];
7193
+ }
7194
+ z[oc * params.T + t] = acc;
7195
+ }
7196
+ `;
7197
+ const WGSL_RVQ_ENCODE = `\
7198
+ // Residual-Vector-Quantizer ENCODE for DAC.speech (descript-audio-codec lineage),
7199
+ // the voice-cloning mirror of RVQDequant. Maps the encoder latent z[Cout, T] to
7200
+ // discrete codes[NCB, T] exactly like torch quantizer.encode:
7201
+ // residual = z
7202
+ // for c in 0..NCB:
7203
+ // z_e = in_proj_c(residual) # Conv1d(Cout->D, k1): [D, T]
7204
+ // idx = argmin_n || normalize(z_e) - normalize(codebook_c[n]) ||^2 (ViT-VQGAN)
7205
+ // codes[c, t] = idx
7206
+ // z_q = out_proj_c(codebook_c[idx]) # Conv1d(D->Cout, k1): [Cout]
7207
+ // residual = residual - z_q
7208
+ // The L2-normalized euclidean argmin equals the max cosine-similarity entry. One
7209
+ // thread per frame t; the codebook loop and the (small, recomputed) residual run
7210
+ // inside the thread so no Cout-wide scratch is needed. NCB is tiny (2) and the
7211
+ // residual removal is recomputed per step from the already-chosen codes, which is
7212
+ // O(NCB^2 * Cout * D) per frame — negligible for DAC.speech (NCB=2, Cout=1024, D=8).
7213
+ // Mobile-safe: flat workgroup_size(64), no shared memory, no select(), no exp().
7214
+ //
7215
+ // Layout (codebook-major): z[Cout,T]; in_proj_w[NCB,D,Cout], in_proj_b[NCB,D];
7216
+ // codebook[NCB,codebook_size,D]; out_proj_w[NCB,Cout,D], out_proj_b[NCB,Cout].
7217
+ const MAX_NCB: u32 = 8u; // DAC.speech uses 2; cap registers conservatively.
7218
+ const MAX_D: u32 = 16u; // codebook_dim 8.
7219
+ struct Params { NCB: u32, Cout: u32, T: u32, D: u32, codebook_size: u32, _p0: u32, _p1: u32, _p2: u32 }
7220
+ @group(0) @binding(0) var<storage, read> z: array<f32>; // [Cout, T]
7221
+ @group(0) @binding(1) var<storage, read> in_w: array<f32>; // [NCB, D, Cout]
7222
+ @group(0) @binding(2) var<storage, read> in_b: array<f32>; // [NCB, D]
7223
+ @group(0) @binding(3) var<storage, read> codebook: array<f32>; // [NCB, codebook_size, D]
7224
+ @group(0) @binding(4) var<storage, read> out_w: array<f32>; // [NCB, Cout, D]
7225
+ @group(0) @binding(5) var<storage, read> out_b: array<f32>; // [NCB, Cout]
7226
+ @group(0) @binding(6) var<storage, read_write> codes: array<u32>; // [NCB, T]
7227
+ @group(0) @binding(7) var<storage, read> params: Params;
7228
+
7229
+ @compute @workgroup_size(64)
7230
+ fn main(@builtin(global_invocation_id) gid: vec3u, @builtin(num_workgroups) ng: vec3u) {
7231
+ let t = gid.y * (ng.x * 64u) + gid.x;
7232
+ if (t >= params.T) { return; }
7233
+ let Cout = params.Cout;
7234
+ let D = params.D;
7235
+ let cbsize = params.codebook_size;
7236
+
7237
+ var chosen: array<u32, 8>; // chosen[c] = code idx for codebook c so far (<= MAX_NCB)
7238
+
7239
+ for (var c: u32 = 0u; c < params.NCB; c = c + 1u) {
7240
+ // ── z_e[d] = in_proj_c(residual)[d], residual = z - sum_{c'<c} out_proj_{c'}(cb_{c'}[chosen[c']]) ──
7241
+ // Project the residual without materializing it: in_proj is linear, so
7242
+ // z_e[d] = in_b[c][d] + sum_oc in_w[c][d][oc] * residual[oc]
7243
+ // and residual[oc] = z[oc] - sum_{c'<c} ( out_b[c'][oc] + sum_k out_w[c'][oc][k]*cb_sel_{c'}[k] ).
7244
+ var ze: array<f32, 16>;
7245
+ for (var d: u32 = 0u; d < D; d = d + 1u) {
7246
+ ze[d] = in_b[c * D + d];
7247
+ }
7248
+ for (var oc: u32 = 0u; oc < Cout; oc = oc + 1u) {
7249
+ // residual at this output channel
7250
+ var res_oc: f32 = z[oc * params.T + t];
7251
+ for (var cp: u32 = 0u; cp < c; cp = cp + 1u) {
7252
+ let sel = chosen[cp];
7253
+ let cb_row = (cp * cbsize + sel) * D;
7254
+ let ow_row = (cp * Cout + oc) * D;
7255
+ var zq: f32 = out_b[cp * Cout + oc];
7256
+ for (var k: u32 = 0u; k < D; k = k + 1u) {
7257
+ zq = zq + out_w[ow_row + k] * codebook[cb_row + k];
7258
+ }
7259
+ res_oc = res_oc - zq;
7260
+ }
7261
+ for (var d: u32 = 0u; d < D; d = d + 1u) {
7262
+ ze[d] = ze[d] + in_w[(c * D + d) * Cout + oc] * res_oc;
7263
+ }
7264
+ }
7265
+
7266
+ // ── L2-normalize z_e over its D dims (ViT-VQGAN); torch F.normalize uses eps=1e-12. ──
7267
+ var ze_norm2: f32 = 0.0;
7268
+ for (var d: u32 = 0u; d < D; d = d + 1u) { ze_norm2 = ze_norm2 + ze[d] * ze[d]; }
7269
+ let ze_inv = 1.0 / max(sqrt(ze_norm2), 1e-12);
7270
+ var zen: array<f32, 16>;
7271
+ for (var d: u32 = 0u; d < D; d = d + 1u) { zen[d] = ze[d] * ze_inv; }
7272
+
7273
+ // ── argmax cosine sim == argmin L2 over the (also L2-normalized) codebook. ──
7274
+ var best: u32 = 0u;
7275
+ var best_sim: f32 = -3.4e38;
7276
+ let cb_base = c * cbsize * D;
7277
+ for (var n: u32 = 0u; n < cbsize; n = n + 1u) {
7278
+ let row = cb_base + n * D;
7279
+ var nn2: f32 = 0.0;
7280
+ var dot: f32 = 0.0;
7281
+ for (var d: u32 = 0u; d < D; d = d + 1u) {
7282
+ let cv = codebook[row + d];
7283
+ nn2 = nn2 + cv * cv;
7284
+ dot = dot + zen[d] * cv;
7285
+ }
7286
+ let sim = dot / max(sqrt(nn2), 1e-12);
7287
+ if (sim > best_sim) { best_sim = sim; best = n; }
7288
+ }
7289
+ chosen[c] = best;
7290
+ codes[c * params.T + t] = best;
7291
+ }
7292
+ }
7293
+ `;
7131
7294
  const WGSL_TANH = `\
7132
7295
  // Elementwise tanh (Moonshine conv1 activation). Clamp the argument: on Metal/Dawn
7133
7296
  // tanh() of a large magnitude returns NaN (internal exp overflows). |arg|>=10
@@ -7417,11 +7580,7 @@ const conv1dFullSpec = {
7417
7580
  getDispatchSize(op) {
7418
7581
  const Cout = op.attributes.Cout;
7419
7582
  const Lout = op.attributes.Lout;
7420
- return [
7421
- cdiv(Cout * Lout, 64),
7422
- 1,
7423
- 1
7424
- ];
7583
+ return dispatch2D(cdiv(Cout * Lout, 64));
7425
7584
  },
7426
7585
  buildParams(op) {
7427
7586
  return buildUniformBuffer([
@@ -7449,11 +7608,7 @@ const convTranspose1dSpec = {
7449
7608
  getDispatchSize(op) {
7450
7609
  const Cout = op.attributes.Cout;
7451
7610
  const Lout = op.attributes.Lout;
7452
- return [
7453
- cdiv(Cout * Lout, 64),
7454
- 1,
7455
- 1
7456
- ];
7611
+ return dispatch2D(cdiv(Cout * Lout, 64));
7457
7612
  },
7458
7613
  buildParams(op) {
7459
7614
  return buildUniformBuffer([
@@ -7480,16 +7635,71 @@ const snake1dSpec = {
7480
7635
  getDispatchSize(op) {
7481
7636
  const C = op.attributes.C;
7482
7637
  const L = op.attributes.L;
7483
- return [
7484
- cdiv(C * L, 64),
7485
- 1,
7486
- 1
7487
- ];
7638
+ return dispatch2D(cdiv(C * L, 64));
7488
7639
  },
7489
7640
  buildParams(op) {
7490
7641
  return buildUniformBuffer([op.attributes.C, op.attributes.L]);
7491
7642
  }
7492
7643
  };
7644
+ const rvqDequantSpec = {
7645
+ shaderCode: WGSL_RVQ_DEQUANT,
7646
+ entryPoint: "main",
7647
+ bindings: [
7648
+ { type: "storage-read" },
7649
+ { type: "storage-read" },
7650
+ { type: "storage-read" },
7651
+ { type: "storage-read" },
7652
+ { type: "storage-read-write" },
7653
+ { type: "uniform" }
7654
+ ],
7655
+ getDispatchSize(op) {
7656
+ const Cout = op.attributes.Cout;
7657
+ const T = op.attributes.T;
7658
+ return dispatch2D(cdiv(Cout * T, 64));
7659
+ },
7660
+ buildParams(op) {
7661
+ return buildUniformBuffer([
7662
+ op.attributes.NCB,
7663
+ op.attributes.Cout,
7664
+ op.attributes.T,
7665
+ op.attributes.D,
7666
+ op.attributes.codebook_size,
7667
+ 0,
7668
+ 0,
7669
+ 0
7670
+ ]);
7671
+ }
7672
+ };
7673
+ const rvqEncodeSpec = {
7674
+ shaderCode: WGSL_RVQ_ENCODE,
7675
+ entryPoint: "main",
7676
+ bindings: [
7677
+ { type: "storage-read" },
7678
+ { type: "storage-read" },
7679
+ { type: "storage-read" },
7680
+ { type: "storage-read" },
7681
+ { type: "storage-read" },
7682
+ { type: "storage-read" },
7683
+ { type: "storage-read-write" },
7684
+ { type: "uniform" }
7685
+ ],
7686
+ getDispatchSize(op) {
7687
+ const T = op.attributes.T;
7688
+ return dispatch2D(cdiv(T, 64));
7689
+ },
7690
+ buildParams(op) {
7691
+ return buildUniformBuffer([
7692
+ op.attributes.NCB,
7693
+ op.attributes.Cout,
7694
+ op.attributes.T,
7695
+ op.attributes.D,
7696
+ op.attributes.codebook_size,
7697
+ 0,
7698
+ 0,
7699
+ 0
7700
+ ]);
7701
+ }
7702
+ };
7493
7703
  const WGSL_FSQ_DEQUANT = `\
7494
7704
  // Finite-scalar-quantization decode. codes[groups,T] (u32) -> latent[groups*dims,T]
7495
7705
  // (f32). Channel ch = g*dims + d; per-dim level/base passed as small constants.
@@ -7724,6 +7934,8 @@ const KERNEL_REGISTRY = {
7724
7934
  Conv1dFull: conv1dFullSpec,
7725
7935
  ConvTranspose1d: convTranspose1dSpec,
7726
7936
  Snake1d: snake1dSpec,
7937
+ RVQDequant: rvqDequantSpec,
7938
+ RVQEncode: rvqEncodeSpec,
7727
7939
  FSQDequant: fsqDequantSpec,
7728
7940
  HalfSnake1d: halfSnake1dSpec,
7729
7941
  ConvTranspose1dDepthwise: convTranspose1dDepthwiseSpec,
@@ -12036,6 +12248,64 @@ function quantizeKaniBackbone(graph, weights) {
12036
12248
  weights.delete(sourceName);
12037
12249
  }
12038
12250
  }
12251
+ /**
12252
+ * Generic INT4 backbone quantizer (architecture-neutral alias of quantizeKaniBackbone).
12253
+ * Walks a built graph's MatMulInt4 nodes and quantizes each linear's f32 source weight
12254
+ * into `.q`/`.scales`/`.zeros`, freeing the f32. Used by the OuteTTS (Qwen3) backbone;
12255
+ * the embedding/LM-head are left untouched (the graph keeps them f32). Idempotent.
12256
+ */
12257
+ const quantizeBackboneInt4 = quantizeKaniBackbone;
12258
+ const OUTETTS_DEFAULT_REPO = "OuteAI/OuteTTS-1.0-0.6B";
12259
+ /** Parse a folded DAC safetensors buffer into a canonical-name weight map (F32 only). */
12260
+ function parseFoldedDacSafetensors(buf) {
12261
+ const file = parseSafetensorsHeader(buf);
12262
+ const out = /* @__PURE__ */ new Map();
12263
+ for (const entry of file.entries) out.set(entry.name, {
12264
+ data: toF32(entry, buf, file),
12265
+ shape: entry.shape
12266
+ });
12267
+ return out;
12268
+ }
12269
+ async function loadOuteTTS(options) {
12270
+ const revision = options.revision ?? "main";
12271
+ const baseURL = await resolveModelBaseURL(options.repo ?? OUTETTS_DEFAULT_REPO, revision);
12272
+ await initFs();
12273
+ options.onProgress?.(0, 100, "Fetching config + tokenizer…");
12274
+ const [rawConfig, tokenizerJSON] = await Promise.all([fetchJSON(baseURL, "config.json", options.hfToken, options.cacheDir), fetchJSON(baseURL, "tokenizer.json", options.hfToken, options.cacheDir)]);
12275
+ const tokenizerConfig = await fetchJSON(baseURL, "tokenizer_config.json", options.hfToken, options.cacheDir).catch(() => null);
12276
+ const tokenizer = Tokenizer.fromJSON(tokenizerJSON, tokenizerConfig);
12277
+ options.onProgress?.(8, 100, "Downloading OuteTTS backbone…");
12278
+ const backboneBuf = await fetchBinary(baseURL, "model.safetensors", options.hfToken, (loaded, total) => options.onProgress?.(8 + loaded / (total || 1) * 75, 100, "backbone weights"), options.cacheDir);
12279
+ const backboneFile = parseSafetensorsHeader(backboneBuf);
12280
+ const backboneWeights = /* @__PURE__ */ new Map();
12281
+ for (const entry of backboneFile.entries) {
12282
+ const key = entry.name.startsWith("model.") ? entry.name.slice(6) : entry.name;
12283
+ backboneWeights.set(key, {
12284
+ data: toF32(entry, backboneBuf, backboneFile),
12285
+ shape: entry.shape
12286
+ });
12287
+ }
12288
+ options.onProgress?.(85, 100, "Loading DAC.speech decoder…");
12289
+ const codecPath = options.codecWeightsPath;
12290
+ let codecBuf;
12291
+ if (/^https?:\/\//.test(codecPath)) {
12292
+ const resp = await fetch(codecPath);
12293
+ if (!resp.ok) throw new Error(`Failed to fetch DAC codec weights from ${codecPath}: ${resp.status}`);
12294
+ codecBuf = await resp.arrayBuffer();
12295
+ } else {
12296
+ if (!_fs) throw new Error("loadOuteTTS: codecWeightsPath is a local path but Node fs is unavailable. Pass a mirror URL in the browser.");
12297
+ const fileBuf = _fs.readFileSync(codecPath);
12298
+ codecBuf = fileBuf.buffer.slice(fileBuf.byteOffset, fileBuf.byteOffset + fileBuf.byteLength);
12299
+ }
12300
+ const codecWeights = parseFoldedDacSafetensors(codecBuf);
12301
+ options.onProgress?.(100, 100, "OuteTTS loaded.");
12302
+ return {
12303
+ backboneWeights,
12304
+ codecWeights,
12305
+ tokenizer,
12306
+ rawConfig
12307
+ };
12308
+ }
12039
12309
 
12040
12310
  //#endregion
12041
12311
  //#region src/gpu/moonshine-executor.ts
@@ -12401,5 +12671,5 @@ function selectGraphWeights(graph, weights) {
12401
12671
  }
12402
12672
 
12403
12673
  //#endregion
12404
- export { initGPU as _, loadMoonshine as a, Executor as c, clearPipelineCache as d, createBindGroup as f, getOrCreatePipeline as g, destroyBuffers as h, loadModel as i, KERNEL_REGISTRY as l, createUniformBuffer as m, MoonshineEncoderExecutor as n, quantizeKaniBackbone as o, createStorageBuffer as p, loadKaniTTS as r, remapPrunedToken as s, MoonshineSTT as t, MATMUL_BIAS_F16C_SPEC as u, verifyGPU as v };
12405
- //# sourceMappingURL=moonshine-stt-Bj1zJfZg.mjs.map
12674
+ export { destroyBuffers as _, loadMoonshine as a, verifyGPU as b, quantizeKaniBackbone as c, KERNEL_REGISTRY as d, MATMUL_BIAS_F16C_SPEC as f, createUniformBuffer as g, createStorageBuffer as h, loadModel as i, remapPrunedToken as l, createBindGroup as m, MoonshineEncoderExecutor as n, loadOuteTTS as o, clearPipelineCache as p, loadKaniTTS as r, quantizeBackboneInt4 as s, MoonshineSTT as t, Executor as u, getOrCreatePipeline as v, initGPU as y };
12675
+ //# sourceMappingURL=moonshine-stt-BO5gZ_D6.mjs.map