@tryhamster/gerbil 1.10.2 → 1.11.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/dist/{architectures-BHkqQ9xp.mjs → architectures-DmZMEFsA.mjs} +652 -9
- package/dist/architectures-DmZMEFsA.mjs.map +1 -0
- package/dist/cli.mjs +8 -8
- package/dist/cli.mjs.map +1 -1
- package/dist/{defaults-C_bJK9zs.mjs → defaults-DfGx4d1m.mjs} +22 -2
- package/dist/{defaults-C_bJK9zs.mjs.map → defaults-DfGx4d1m.mjs.map} +1 -1
- package/dist/frameworks/express.mjs +1 -1
- package/dist/frameworks/fastify.mjs +1 -1
- package/dist/frameworks/hono.mjs +1 -1
- package/dist/frameworks/next.d.mts +2 -2
- package/dist/frameworks/next.mjs +1 -1
- package/dist/frameworks/trpc.mjs +1 -1
- package/dist/gerbil-BY5EW-Jk.mjs +4 -0
- package/dist/{gerbil-sQ7eqzn3.mjs → gerbil-BpYemKEH.mjs} +5 -4
- package/dist/{gerbil-sQ7eqzn3.mjs.map → gerbil-BpYemKEH.mjs.map} +1 -1
- package/dist/{gerbil-PEAdJdsH.d.mts → gerbil-CaAGG2VP.d.mts} +2 -2
- package/dist/{gerbil-PEAdJdsH.d.mts.map → gerbil-CaAGG2VP.d.mts.map} +1 -1
- package/dist/gpu/hooks.d.mts +1 -1
- package/dist/gpu/hooks.mjs +1 -1
- package/dist/gpu/index.d.mts +2 -2
- package/dist/gpu/index.mjs +5 -5
- package/dist/{gpu-Ps1eQaXG.mjs → gpu-BCfd_K38.mjs} +71 -652
- package/dist/gpu-BCfd_K38.mjs.map +1 -0
- package/dist/index-B3tjyDJI.d.mts.map +1 -1
- package/dist/{index-CJux7zbV.d.mts → index-DqJMofyU.d.mts} +49 -13
- package/dist/index-DqJMofyU.d.mts.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +6 -6
- package/dist/integrations/ai-sdk.mjs +1 -1
- package/dist/integrations/langchain.mjs +1 -1
- package/dist/integrations/llamaindex.mjs +1 -1
- package/dist/integrations/mcp.d.mts +2 -2
- package/dist/integrations/mcp.mjs +4 -4
- package/dist/{mcp-BX-ryGGJ.mjs → mcp-DSpjqWZC.mjs} +3 -3
- package/dist/{mcp-BX-ryGGJ.mjs.map → mcp-DSpjqWZC.mjs.map} +1 -1
- package/dist/moonshine-stt-CcVt4Vdd.mjs +4 -0
- package/dist/{moonshine-stt-BKeD6OYF.mjs → moonshine-stt-CgDXoLFd.mjs} +2 -2
- package/dist/{moonshine-stt-BKeD6OYF.mjs.map → moonshine-stt-CgDXoLFd.mjs.map} +1 -1
- package/dist/{one-liner-m6NjYWMg.mjs → one-liner-BgNDxJSJ.mjs} +2 -2
- package/dist/{one-liner-m6NjYWMg.mjs.map → one-liner-BgNDxJSJ.mjs.map} +1 -1
- package/dist/repl-DSK2hDzu.mjs +9 -0
- package/dist/skills/index.d.mts +13 -13
- package/dist/skills/index.d.mts.map +1 -1
- package/dist/skills/index.mjs +3 -3
- package/dist/{skills-DZ5OITy0.mjs → skills-Cd75ZGew.mjs} +2 -2
- package/dist/{skills-DZ5OITy0.mjs.map → skills-Cd75ZGew.mjs.map} +1 -1
- package/dist/tune/index.d.mts.map +1 -1
- package/dist/tune/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/architectures-BHkqQ9xp.mjs.map +0 -1
- package/dist/gerbil-IqsK32DM.mjs +0 -4
- package/dist/gpu-Ps1eQaXG.mjs.map +0 -1
- package/dist/index-CJux7zbV.d.mts.map +0 -1
- package/dist/moonshine-stt-DKC0PHF_.mjs +0 -4
- package/dist/repl-hN4jSHrb.mjs +0 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { E as GEMMA4_VIS_KEYS,
|
|
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-
|
|
1
|
+
import { a as resolveDefaultRepo, i as isTTSRepo, n as OUTETTS_ASSETS, r as OUTETTS_PRESET_VOICES, t as DEFAULT_MODELS } from "./defaults-DfGx4d1m.mjs";
|
|
2
|
+
import { A as kaniSinTensor, C as computeKaniPositions, D as kaniAttentionLayerIndices, E as generateNanoCodecDecoderGraph, F as CANONICAL_KEYS, I as DTYPE_BYTES, L as GEMMA4_VIS_KEYS, M as parseKaniConfig, N as DEFAULT_GROUP_SIZE, O as kaniCosTensor, S as buildKaniLayerCosSin, T as generateKaniTtsGraph, a as PARLER_DAC_LATENT_DIM, b as KANI_START_OF_HUMAN, c as PARLER_SAMPLE_RATE, d as generateParlerEncoderGraph, f as parseParlerConfig, i as PARLER_DAC_DECODER_DIM, k as kaniLayerAlpha, l as buildT5RelativeBias, o as PARLER_DECODER_RATES, p as revertDelayPattern, r as PARLER_BOS_TOKEN_ID, s as PARLER_EOS_TOKEN_ID, u as generateParlerDecoderGraph, x as audioTokensToCodes, y as KANI_END_OF_HUMAN } from "./architectures-DmZMEFsA.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-CgDXoLFd.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/gpu/architectures/gemma4_vision.ts
|
|
6
6
|
/**
|
|
@@ -3266,633 +3266,6 @@ var OuteTTS = class OuteTTS {
|
|
|
3266
3266
|
}
|
|
3267
3267
|
};
|
|
3268
3268
|
|
|
3269
|
-
//#endregion
|
|
3270
|
-
//#region src/gpu/architectures/parler.ts
|
|
3271
|
-
const PARLER_SAMPLE_RATE = 44100;
|
|
3272
|
-
const PARLER_NUM_CODEBOOKS = 9;
|
|
3273
|
-
const PARLER_DECODER_RATES = [
|
|
3274
|
-
8,
|
|
3275
|
-
8,
|
|
3276
|
-
4,
|
|
3277
|
-
2
|
|
3278
|
-
];
|
|
3279
|
-
const PARLER_DAC_LATENT_DIM = 1024;
|
|
3280
|
-
const PARLER_DAC_DECODER_DIM = 1536;
|
|
3281
|
-
/** Decoder audio-vocab: 1024 codes + eos(1024)+bos(1025)+pad(1024); lm_head vocab. */
|
|
3282
|
-
const PARLER_AUDIO_VOCAB = 1088;
|
|
3283
|
-
const PARLER_BOS_TOKEN_ID = 1025;
|
|
3284
|
-
const PARLER_EOS_TOKEN_ID = 1024;
|
|
3285
|
-
const PARLER_PAD_TOKEN_ID = 1024;
|
|
3286
|
-
const CAPS = {
|
|
3287
|
-
text: true,
|
|
3288
|
-
vision: false,
|
|
3289
|
-
moe: false
|
|
3290
|
-
};
|
|
3291
|
-
/** Pull Parler dims from the (nested) HF config. */
|
|
3292
|
-
function parseParlerConfig(raw) {
|
|
3293
|
-
const te = raw.text_encoder ?? {};
|
|
3294
|
-
const dec = raw.decoder ?? {};
|
|
3295
|
-
const enc_heads = te.num_heads ?? 16;
|
|
3296
|
-
const enc_d_model = te.d_model ?? 1024;
|
|
3297
|
-
const dec_heads = dec.num_attention_heads ?? 16;
|
|
3298
|
-
return {
|
|
3299
|
-
enc_d_model,
|
|
3300
|
-
enc_layers: te.num_layers ?? 24,
|
|
3301
|
-
enc_heads,
|
|
3302
|
-
enc_d_kv: te.d_kv ?? Math.floor(enc_d_model / enc_heads),
|
|
3303
|
-
enc_d_ff: te.d_ff ?? 2816,
|
|
3304
|
-
enc_vocab: te.vocab_size ?? 32128,
|
|
3305
|
-
rel_num_buckets: te.relative_attention_num_buckets ?? 32,
|
|
3306
|
-
rel_max_distance: te.relative_attention_max_distance ?? 128,
|
|
3307
|
-
ln_eps: te.layer_norm_epsilon ?? 1e-6,
|
|
3308
|
-
dec_hidden: dec.hidden_size ?? 1024,
|
|
3309
|
-
dec_layers: dec.num_hidden_layers ?? 24,
|
|
3310
|
-
dec_heads,
|
|
3311
|
-
dec_kv_heads: dec.num_key_value_heads ?? dec_heads,
|
|
3312
|
-
dec_ffn: dec.ffn_dim ?? 4096,
|
|
3313
|
-
num_codebooks: dec.num_codebooks ?? PARLER_NUM_CODEBOOKS,
|
|
3314
|
-
audio_vocab: dec.vocab_size ?? PARLER_AUDIO_VOCAB,
|
|
3315
|
-
embed_vocab: (dec.vocab_size ?? PARLER_AUDIO_VOCAB) + 1,
|
|
3316
|
-
max_position: dec.max_position_embeddings ?? 4096,
|
|
3317
|
-
bos_token_id: dec.bos_token_id ?? PARLER_BOS_TOKEN_ID,
|
|
3318
|
-
eos_token_id: dec.eos_token_id ?? PARLER_EOS_TOKEN_ID,
|
|
3319
|
-
pad_token_id: dec.pad_token_id ?? PARLER_PAD_TOKEN_ID
|
|
3320
|
-
};
|
|
3321
|
-
}
|
|
3322
|
-
function baseConfig(c, hidden, heads, layers) {
|
|
3323
|
-
return {
|
|
3324
|
-
hidden_size: hidden,
|
|
3325
|
-
num_layers: layers,
|
|
3326
|
-
num_heads: heads,
|
|
3327
|
-
num_kv_heads: heads,
|
|
3328
|
-
head_dim: Math.floor(hidden / heads),
|
|
3329
|
-
intermediate_size: c.dec_ffn,
|
|
3330
|
-
vocab_size: c.audio_vocab,
|
|
3331
|
-
context_length: c.max_position,
|
|
3332
|
-
rms_norm_eps: c.ln_eps,
|
|
3333
|
-
norm_type: "layernorm",
|
|
3334
|
-
rope_base: 0,
|
|
3335
|
-
rope_dim: 0,
|
|
3336
|
-
kv_layout: "LHSd",
|
|
3337
|
-
is_moe: false,
|
|
3338
|
-
has_vision_tower: false
|
|
3339
|
-
};
|
|
3340
|
-
}
|
|
3341
|
-
/**
|
|
3342
|
-
* T5's bidirectional relative-position bucket (verbatim port of
|
|
3343
|
-
* transformers' T5Attention._relative_position_bucket, bidirectional=True).
|
|
3344
|
-
* Maps a signed relative position (key − query) to a bucket id in [0, num_buckets).
|
|
3345
|
-
*/
|
|
3346
|
-
function relativePositionBucket(relativePosition, numBuckets, maxDistance) {
|
|
3347
|
-
let bucket = 0;
|
|
3348
|
-
let n = relativePosition;
|
|
3349
|
-
const halfBuckets = Math.floor(numBuckets / 2);
|
|
3350
|
-
if (n > 0) bucket += halfBuckets;
|
|
3351
|
-
else n = -n;
|
|
3352
|
-
const maxExact = Math.floor(halfBuckets / 2);
|
|
3353
|
-
const isSmall = n < maxExact;
|
|
3354
|
-
let largeVal = maxExact + Math.floor(Math.log(n / maxExact) / Math.log(maxDistance / maxExact) * (halfBuckets - maxExact));
|
|
3355
|
-
largeVal = Math.min(largeVal, halfBuckets - 1);
|
|
3356
|
-
bucket += isSmall ? n : largeVal;
|
|
3357
|
-
return bucket;
|
|
3358
|
-
}
|
|
3359
|
-
/**
|
|
3360
|
-
* Build the dense per-head relative-position bias B[head, q, k] = bias_table[bucket(k-q), head]
|
|
3361
|
-
* for a length-S encoder sequence. `biasTable` is the learned
|
|
3362
|
-
* relative_attention_bias.weight, row-major [num_buckets, num_heads].
|
|
3363
|
-
* Returns a flat Float32Array of length num_heads*S*S (head-major, then q, then k).
|
|
3364
|
-
*/
|
|
3365
|
-
function buildT5RelativeBias(biasTable, numBuckets, maxDistance, numHeads, S) {
|
|
3366
|
-
const out = new Float32Array(numHeads * S * S);
|
|
3367
|
-
const buckets = new Int32Array(S * S);
|
|
3368
|
-
for (let q = 0; q < S; q++) for (let k = 0; k < S; k++) buckets[q * S + k] = relativePositionBucket(k - q, numBuckets, maxDistance);
|
|
3369
|
-
for (let h = 0; h < numHeads; h++) {
|
|
3370
|
-
const headBase = h * S * S;
|
|
3371
|
-
for (let q = 0; q < S; q++) for (let k = 0; k < S; k++) {
|
|
3372
|
-
const bucket = buckets[q * S + k];
|
|
3373
|
-
out[headBase + q * S + k] = biasTable[bucket * numHeads + h];
|
|
3374
|
-
}
|
|
3375
|
-
}
|
|
3376
|
-
return out;
|
|
3377
|
-
}
|
|
3378
|
-
/**
|
|
3379
|
-
* Build the T5 encoder graph for a concrete description length S. The relative
|
|
3380
|
-
* bias `t5_rel_bias` enters as a host-written activation [num_heads, S, S]. Like
|
|
3381
|
-
* Moonshine, the graph also pre-projects encoder_out through every decoder layer's
|
|
3382
|
-
* encoder_attn.k/v_proj → enc_k_layer{i}/enc_v_layer{i} (frozen cross-attn K/V).
|
|
3383
|
-
*/
|
|
3384
|
-
function generateParlerEncoderGraph(raw, sDesc) {
|
|
3385
|
-
const c = parseParlerConfig(raw);
|
|
3386
|
-
const H = c.enc_d_model;
|
|
3387
|
-
const innerDim = c.enc_heads * c.enc_d_kv;
|
|
3388
|
-
const tensors = {};
|
|
3389
|
-
const nodes = [];
|
|
3390
|
-
const executionOrder = [];
|
|
3391
|
-
const addTensor = (t) => {
|
|
3392
|
-
tensors[t.name] = t;
|
|
3393
|
-
};
|
|
3394
|
-
const addNode = (n) => {
|
|
3395
|
-
nodes.push(n);
|
|
3396
|
-
executionOrder.push(n.id);
|
|
3397
|
-
};
|
|
3398
|
-
const w = (name, shape) => addTensor({
|
|
3399
|
-
name,
|
|
3400
|
-
shape,
|
|
3401
|
-
dtype: "f32",
|
|
3402
|
-
storage: "constant",
|
|
3403
|
-
safetensorsKey: name
|
|
3404
|
-
});
|
|
3405
|
-
const act = (name, shape) => addTensor({
|
|
3406
|
-
name,
|
|
3407
|
-
shape,
|
|
3408
|
-
dtype: "f32",
|
|
3409
|
-
storage: "activation"
|
|
3410
|
-
});
|
|
3411
|
-
const linear = (id, inp, weight, out, K, N) => {
|
|
3412
|
-
w(weight, [N, K]);
|
|
3413
|
-
addNode({
|
|
3414
|
-
id,
|
|
3415
|
-
opType: "MatMul",
|
|
3416
|
-
inputs: [inp, weight],
|
|
3417
|
-
outputs: [out],
|
|
3418
|
-
attributes: {
|
|
3419
|
-
M_tensor: inp,
|
|
3420
|
-
K,
|
|
3421
|
-
N
|
|
3422
|
-
}
|
|
3423
|
-
});
|
|
3424
|
-
};
|
|
3425
|
-
const t5norm = (id, inp, weight, out) => {
|
|
3426
|
-
w(weight, [H]);
|
|
3427
|
-
act(out, [sDesc, H]);
|
|
3428
|
-
addNode({
|
|
3429
|
-
id,
|
|
3430
|
-
opType: "RMSNorm",
|
|
3431
|
-
inputs: [inp, weight],
|
|
3432
|
-
outputs: [out],
|
|
3433
|
-
attributes: {
|
|
3434
|
-
hidden_size: H,
|
|
3435
|
-
eps: c.ln_eps,
|
|
3436
|
-
seq_len_tensor: inp
|
|
3437
|
-
}
|
|
3438
|
-
});
|
|
3439
|
-
};
|
|
3440
|
-
addTensor({
|
|
3441
|
-
name: "input_ids",
|
|
3442
|
-
shape: ["T"],
|
|
3443
|
-
dtype: "u32",
|
|
3444
|
-
storage: "activation"
|
|
3445
|
-
});
|
|
3446
|
-
addTensor({
|
|
3447
|
-
name: "text_encoder.shared.weight",
|
|
3448
|
-
shape: [c.enc_vocab, H],
|
|
3449
|
-
dtype: "f32",
|
|
3450
|
-
storage: "constant",
|
|
3451
|
-
safetensorsKey: "text_encoder.shared.weight"
|
|
3452
|
-
});
|
|
3453
|
-
act("enc_embed", [sDesc, H]);
|
|
3454
|
-
addNode({
|
|
3455
|
-
id: "enc_embed",
|
|
3456
|
-
opType: "Embedding",
|
|
3457
|
-
inputs: ["input_ids", "text_encoder.shared.weight"],
|
|
3458
|
-
outputs: ["enc_embed"],
|
|
3459
|
-
attributes: {
|
|
3460
|
-
vocab_size: c.enc_vocab,
|
|
3461
|
-
hidden_size: H
|
|
3462
|
-
}
|
|
3463
|
-
});
|
|
3464
|
-
addTensor({
|
|
3465
|
-
name: "t5_rel_bias",
|
|
3466
|
-
shape: [
|
|
3467
|
-
c.enc_heads,
|
|
3468
|
-
sDesc,
|
|
3469
|
-
sDesc
|
|
3470
|
-
],
|
|
3471
|
-
dtype: "f32",
|
|
3472
|
-
storage: "activation"
|
|
3473
|
-
});
|
|
3474
|
-
let prev = "enc_embed";
|
|
3475
|
-
for (let i = 0; i < c.enc_layers; i++) {
|
|
3476
|
-
const p = `enc${i}`;
|
|
3477
|
-
const k = (s) => `text_encoder.encoder.block.${i}.${s}`;
|
|
3478
|
-
t5norm(`${p}_norm0`, prev, k("layer.0.layer_norm.weight"), `${p}_n0`);
|
|
3479
|
-
act(`${p}_q`, [sDesc, innerDim]);
|
|
3480
|
-
act(`${p}_k`, [sDesc, innerDim]);
|
|
3481
|
-
act(`${p}_v`, [sDesc, innerDim]);
|
|
3482
|
-
linear(`${p}_qp`, `${p}_n0`, k("layer.0.SelfAttention.q.weight"), `${p}_q`, H, innerDim);
|
|
3483
|
-
linear(`${p}_kp`, `${p}_n0`, k("layer.0.SelfAttention.k.weight"), `${p}_k`, H, innerDim);
|
|
3484
|
-
linear(`${p}_vp`, `${p}_n0`, k("layer.0.SelfAttention.v.weight"), `${p}_v`, H, innerDim);
|
|
3485
|
-
act(`${p}_attn`, [sDesc, innerDim]);
|
|
3486
|
-
addNode({
|
|
3487
|
-
id: `${p}_sa`,
|
|
3488
|
-
opType: "T5Attention",
|
|
3489
|
-
inputs: [
|
|
3490
|
-
`${p}_q`,
|
|
3491
|
-
`${p}_k`,
|
|
3492
|
-
`${p}_v`,
|
|
3493
|
-
"t5_rel_bias"
|
|
3494
|
-
],
|
|
3495
|
-
outputs: [`${p}_attn`],
|
|
3496
|
-
attributes: {
|
|
3497
|
-
num_heads: c.enc_heads,
|
|
3498
|
-
head_dim: c.enc_d_kv,
|
|
3499
|
-
S: sDesc
|
|
3500
|
-
}
|
|
3501
|
-
});
|
|
3502
|
-
act(`${p}_o`, [sDesc, H]);
|
|
3503
|
-
linear(`${p}_op`, `${p}_attn`, k("layer.0.SelfAttention.o.weight"), `${p}_o`, innerDim, H);
|
|
3504
|
-
act(`${p}_res0`, [sDesc, H]);
|
|
3505
|
-
addNode({
|
|
3506
|
-
id: `${p}_add0`,
|
|
3507
|
-
opType: "Add",
|
|
3508
|
-
inputs: [prev, `${p}_o`],
|
|
3509
|
-
outputs: [`${p}_res0`],
|
|
3510
|
-
attributes: {
|
|
3511
|
-
count_tensor: prev,
|
|
3512
|
-
hidden_size: H
|
|
3513
|
-
}
|
|
3514
|
-
});
|
|
3515
|
-
t5norm(`${p}_norm1`, `${p}_res0`, k("layer.1.layer_norm.weight"), `${p}_n1`);
|
|
3516
|
-
act(`${p}_wi0`, [sDesc, c.enc_d_ff]);
|
|
3517
|
-
act(`${p}_wi1`, [sDesc, c.enc_d_ff]);
|
|
3518
|
-
linear(`${p}_wi0p`, `${p}_n1`, k("layer.1.DenseReluDense.wi_0.weight"), `${p}_wi0`, H, c.enc_d_ff);
|
|
3519
|
-
linear(`${p}_wi1p`, `${p}_n1`, k("layer.1.DenseReluDense.wi_1.weight"), `${p}_wi1`, H, c.enc_d_ff);
|
|
3520
|
-
act(`${p}_gelu`, [sDesc, c.enc_d_ff]);
|
|
3521
|
-
addNode({
|
|
3522
|
-
id: `${p}_act`,
|
|
3523
|
-
opType: "GELU",
|
|
3524
|
-
inputs: [`${p}_wi0`],
|
|
3525
|
-
outputs: [`${p}_gelu`],
|
|
3526
|
-
attributes: { count_tensor: `${p}_wi0` }
|
|
3527
|
-
});
|
|
3528
|
-
act(`${p}_gated`, [sDesc, c.enc_d_ff]);
|
|
3529
|
-
addNode({
|
|
3530
|
-
id: `${p}_gate`,
|
|
3531
|
-
opType: "Mul",
|
|
3532
|
-
inputs: [`${p}_gelu`, `${p}_wi1`],
|
|
3533
|
-
outputs: [`${p}_gated`],
|
|
3534
|
-
attributes: {
|
|
3535
|
-
count_tensor: `${p}_gelu`,
|
|
3536
|
-
hidden_size: c.enc_d_ff
|
|
3537
|
-
}
|
|
3538
|
-
});
|
|
3539
|
-
act(`${p}_wo`, [sDesc, H]);
|
|
3540
|
-
linear(`${p}_wop`, `${p}_gated`, k("layer.1.DenseReluDense.wo.weight"), `${p}_wo`, c.enc_d_ff, H);
|
|
3541
|
-
act(`${p}_res1`, [sDesc, H]);
|
|
3542
|
-
addNode({
|
|
3543
|
-
id: `${p}_add1`,
|
|
3544
|
-
opType: "Add",
|
|
3545
|
-
inputs: [`${p}_res0`, `${p}_wo`],
|
|
3546
|
-
outputs: [`${p}_res1`],
|
|
3547
|
-
attributes: {
|
|
3548
|
-
count_tensor: `${p}_res0`,
|
|
3549
|
-
hidden_size: H
|
|
3550
|
-
}
|
|
3551
|
-
});
|
|
3552
|
-
prev = `${p}_res1`;
|
|
3553
|
-
}
|
|
3554
|
-
w("text_encoder.encoder.final_layer_norm.weight", [H]);
|
|
3555
|
-
act("encoder_out", [sDesc, H]);
|
|
3556
|
-
addNode({
|
|
3557
|
-
id: "enc_final_norm",
|
|
3558
|
-
opType: "RMSNorm",
|
|
3559
|
-
inputs: [prev, "text_encoder.encoder.final_layer_norm.weight"],
|
|
3560
|
-
outputs: ["encoder_out"],
|
|
3561
|
-
attributes: {
|
|
3562
|
-
hidden_size: H,
|
|
3563
|
-
eps: c.ln_eps,
|
|
3564
|
-
seq_len_tensor: prev
|
|
3565
|
-
}
|
|
3566
|
-
});
|
|
3567
|
-
const outputs = ["encoder_out"];
|
|
3568
|
-
for (let i = 0; i < c.dec_layers; i++) {
|
|
3569
|
-
const kw = `decoder.model.decoder.layers.${i}.encoder_attn.k_proj.weight`;
|
|
3570
|
-
const vw = `decoder.model.decoder.layers.${i}.encoder_attn.v_proj.weight`;
|
|
3571
|
-
w(kw, [H, H]);
|
|
3572
|
-
w(vw, [H, H]);
|
|
3573
|
-
const encK = `enc_k_layer${i}`;
|
|
3574
|
-
const encV = `enc_v_layer${i}`;
|
|
3575
|
-
act(encK, [sDesc, H]);
|
|
3576
|
-
act(encV, [sDesc, H]);
|
|
3577
|
-
addNode({
|
|
3578
|
-
id: `enc_kproj${i}`,
|
|
3579
|
-
opType: "MatMul",
|
|
3580
|
-
inputs: ["encoder_out", kw],
|
|
3581
|
-
outputs: [encK],
|
|
3582
|
-
attributes: {
|
|
3583
|
-
M_tensor: "encoder_out",
|
|
3584
|
-
K: H,
|
|
3585
|
-
N: H
|
|
3586
|
-
}
|
|
3587
|
-
});
|
|
3588
|
-
addNode({
|
|
3589
|
-
id: `enc_vproj${i}`,
|
|
3590
|
-
opType: "MatMul",
|
|
3591
|
-
inputs: ["encoder_out", vw],
|
|
3592
|
-
outputs: [encV],
|
|
3593
|
-
attributes: {
|
|
3594
|
-
M_tensor: "encoder_out",
|
|
3595
|
-
K: H,
|
|
3596
|
-
N: H
|
|
3597
|
-
}
|
|
3598
|
-
});
|
|
3599
|
-
outputs.push(encK, encV);
|
|
3600
|
-
}
|
|
3601
|
-
return {
|
|
3602
|
-
architecture: "ParlerTextEncoder",
|
|
3603
|
-
config: baseConfig(c, H, c.enc_heads, c.enc_layers),
|
|
3604
|
-
capabilities: CAPS,
|
|
3605
|
-
tensors,
|
|
3606
|
-
nodes,
|
|
3607
|
-
executionOrder,
|
|
3608
|
-
inputs: ["input_ids", "t5_rel_bias"],
|
|
3609
|
-
outputs
|
|
3610
|
-
};
|
|
3611
|
-
}
|
|
3612
|
-
/**
|
|
3613
|
-
* Build the Parler decoder graph for a single decode step (T=1). The host supplies:
|
|
3614
|
-
* - `dec_input_embed` [1, H]: the SUMMED 9-codebook embedding of the current step's
|
|
3615
|
-
* codes PLUS the sinusoidal position (computed host-side from embed_tokens +
|
|
3616
|
-
* embed_positions, since the 9-way embedding sum is cheap on the host and avoids
|
|
3617
|
-
* 9 Embedding ops + an Add tree per step).
|
|
3618
|
-
* - `enc_k_layer{i}` / `enc_v_layer{i}`: frozen cross-attn K/V from the encoder.
|
|
3619
|
-
* Output: 9 logit rows `logits_cb{c}` [1, audio_vocab] (one per codebook head).
|
|
3620
|
-
*
|
|
3621
|
-
* The prompt prefix (transcript) is handled by prefilling its embeddings through the
|
|
3622
|
-
* SAME graph before audio decode begins (the driver feeds the prompt rows first, with
|
|
3623
|
-
* their sinusoidal positions, so the self-attn KV-cache holds [prompt ++ audio]).
|
|
3624
|
-
*/
|
|
3625
|
-
function generateParlerDecoderGraph(raw, sEnc) {
|
|
3626
|
-
const c = parseParlerConfig(raw);
|
|
3627
|
-
const H = c.dec_hidden;
|
|
3628
|
-
const heads = c.dec_heads;
|
|
3629
|
-
const headDim = Math.floor(H / heads);
|
|
3630
|
-
const tensors = {};
|
|
3631
|
-
const nodes = [];
|
|
3632
|
-
const executionOrder = [];
|
|
3633
|
-
const addTensor = (t) => {
|
|
3634
|
-
tensors[t.name] = t;
|
|
3635
|
-
};
|
|
3636
|
-
const addNode = (n) => {
|
|
3637
|
-
nodes.push(n);
|
|
3638
|
-
executionOrder.push(n.id);
|
|
3639
|
-
};
|
|
3640
|
-
const w = (name, shape) => addTensor({
|
|
3641
|
-
name,
|
|
3642
|
-
shape,
|
|
3643
|
-
dtype: "f32",
|
|
3644
|
-
storage: "constant",
|
|
3645
|
-
safetensorsKey: name
|
|
3646
|
-
});
|
|
3647
|
-
const act = (name, shape) => addTensor({
|
|
3648
|
-
name,
|
|
3649
|
-
shape,
|
|
3650
|
-
dtype: "f32",
|
|
3651
|
-
storage: "activation"
|
|
3652
|
-
});
|
|
3653
|
-
const linear = (id, inp, weight, out, K, N) => {
|
|
3654
|
-
w(weight, [N, K]);
|
|
3655
|
-
addNode({
|
|
3656
|
-
id,
|
|
3657
|
-
opType: "MatMul",
|
|
3658
|
-
inputs: [inp, weight],
|
|
3659
|
-
outputs: [out],
|
|
3660
|
-
attributes: {
|
|
3661
|
-
M_tensor: inp,
|
|
3662
|
-
K,
|
|
3663
|
-
N
|
|
3664
|
-
}
|
|
3665
|
-
});
|
|
3666
|
-
};
|
|
3667
|
-
const layernorm = (id, inp, prefix, out) => {
|
|
3668
|
-
w(`${prefix}.weight`, [H]);
|
|
3669
|
-
w(`${prefix}.bias`, [H]);
|
|
3670
|
-
act(out, ["T", H]);
|
|
3671
|
-
addNode({
|
|
3672
|
-
id,
|
|
3673
|
-
opType: "LayerNorm",
|
|
3674
|
-
inputs: [
|
|
3675
|
-
inp,
|
|
3676
|
-
`${prefix}.weight`,
|
|
3677
|
-
`${prefix}.bias`
|
|
3678
|
-
],
|
|
3679
|
-
outputs: [out],
|
|
3680
|
-
attributes: {
|
|
3681
|
-
hidden_size: H,
|
|
3682
|
-
eps: c.ln_eps,
|
|
3683
|
-
seq_len_tensor: inp,
|
|
3684
|
-
has_bias: true
|
|
3685
|
-
}
|
|
3686
|
-
});
|
|
3687
|
-
};
|
|
3688
|
-
const inputs = ["dec_input_embed"];
|
|
3689
|
-
addTensor({
|
|
3690
|
-
name: "dec_input_embed",
|
|
3691
|
-
shape: ["T", H],
|
|
3692
|
-
dtype: "f32",
|
|
3693
|
-
storage: "activation"
|
|
3694
|
-
});
|
|
3695
|
-
let prev = "dec_input_embed";
|
|
3696
|
-
for (let i = 0; i < c.dec_layers; i++) {
|
|
3697
|
-
const p = `dec${i}`;
|
|
3698
|
-
const lk = `decoder.model.decoder.layers.${i}`;
|
|
3699
|
-
layernorm(`${p}_n1`, prev, `${lk}.self_attn_layer_norm`, `${p}_ln1`);
|
|
3700
|
-
act(`${p}_q`, ["T", H]);
|
|
3701
|
-
act(`${p}_k`, ["T", H]);
|
|
3702
|
-
act(`${p}_v`, ["T", H]);
|
|
3703
|
-
linear(`${p}_qp`, `${p}_ln1`, `${lk}.self_attn.q_proj.weight`, `${p}_q`, H, H);
|
|
3704
|
-
linear(`${p}_kp`, `${p}_ln1`, `${lk}.self_attn.k_proj.weight`, `${p}_k`, H, H);
|
|
3705
|
-
linear(`${p}_vp`, `${p}_ln1`, `${lk}.self_attn.v_proj.weight`, `${p}_v`, H, H);
|
|
3706
|
-
addTensor({
|
|
3707
|
-
name: `${p}_kcache`,
|
|
3708
|
-
shape: ["L_max", H],
|
|
3709
|
-
dtype: "f32",
|
|
3710
|
-
storage: "kv_cache"
|
|
3711
|
-
});
|
|
3712
|
-
addTensor({
|
|
3713
|
-
name: `${p}_vcache`,
|
|
3714
|
-
shape: ["L_max", H],
|
|
3715
|
-
dtype: "f32",
|
|
3716
|
-
storage: "kv_cache"
|
|
3717
|
-
});
|
|
3718
|
-
addNode({
|
|
3719
|
-
id: `${p}_kappend`,
|
|
3720
|
-
opType: "KVCacheAppend",
|
|
3721
|
-
inputs: [`${p}_k`],
|
|
3722
|
-
outputs: [`${p}_kcache`],
|
|
3723
|
-
attributes: {
|
|
3724
|
-
width: H,
|
|
3725
|
-
T_tensor: `${p}_k`
|
|
3726
|
-
}
|
|
3727
|
-
});
|
|
3728
|
-
addNode({
|
|
3729
|
-
id: `${p}_vappend`,
|
|
3730
|
-
opType: "KVCacheAppend",
|
|
3731
|
-
inputs: [`${p}_v`],
|
|
3732
|
-
outputs: [`${p}_vcache`],
|
|
3733
|
-
attributes: {
|
|
3734
|
-
width: H,
|
|
3735
|
-
T_tensor: `${p}_v`
|
|
3736
|
-
}
|
|
3737
|
-
});
|
|
3738
|
-
act(`${p}_sa`, ["T", H]);
|
|
3739
|
-
addNode({
|
|
3740
|
-
id: `${p}_self_attn`,
|
|
3741
|
-
opType: "Attention",
|
|
3742
|
-
inputs: [
|
|
3743
|
-
`${p}_q`,
|
|
3744
|
-
`${p}_kcache`,
|
|
3745
|
-
`${p}_vcache`
|
|
3746
|
-
],
|
|
3747
|
-
outputs: [`${p}_sa`],
|
|
3748
|
-
attributes: {
|
|
3749
|
-
hidden_size: H,
|
|
3750
|
-
num_q_heads: heads,
|
|
3751
|
-
num_kv_heads: c.dec_kv_heads,
|
|
3752
|
-
head_dim: headDim,
|
|
3753
|
-
causal: true,
|
|
3754
|
-
layer_index: i
|
|
3755
|
-
}
|
|
3756
|
-
});
|
|
3757
|
-
act(`${p}_sao`, ["T", H]);
|
|
3758
|
-
linear(`${p}_sap`, `${p}_sa`, `${lk}.self_attn.out_proj.weight`, `${p}_sao`, H, H);
|
|
3759
|
-
act(`${p}_res1`, ["T", H]);
|
|
3760
|
-
addNode({
|
|
3761
|
-
id: `${p}_add1`,
|
|
3762
|
-
opType: "Add",
|
|
3763
|
-
inputs: [prev, `${p}_sao`],
|
|
3764
|
-
outputs: [`${p}_res1`],
|
|
3765
|
-
attributes: {
|
|
3766
|
-
count_tensor: prev,
|
|
3767
|
-
hidden_size: H
|
|
3768
|
-
}
|
|
3769
|
-
});
|
|
3770
|
-
layernorm(`${p}_n2`, `${p}_res1`, `${lk}.encoder_attn_layer_norm`, `${p}_ln2`);
|
|
3771
|
-
act(`${p}_cq`, ["T", H]);
|
|
3772
|
-
linear(`${p}_cqp`, `${p}_ln2`, `${lk}.encoder_attn.q_proj.weight`, `${p}_cq`, H, H);
|
|
3773
|
-
const encK = `enc_k_layer${i}`;
|
|
3774
|
-
const encV = `enc_v_layer${i}`;
|
|
3775
|
-
act(encK, [sEnc, H]);
|
|
3776
|
-
act(encV, [sEnc, H]);
|
|
3777
|
-
inputs.push(encK, encV);
|
|
3778
|
-
act(`${p}_ca`, ["T", H]);
|
|
3779
|
-
addNode({
|
|
3780
|
-
id: `${p}_cross_attn`,
|
|
3781
|
-
opType: "CrossAttention",
|
|
3782
|
-
inputs: [
|
|
3783
|
-
`${p}_cq`,
|
|
3784
|
-
encK,
|
|
3785
|
-
encV
|
|
3786
|
-
],
|
|
3787
|
-
outputs: [`${p}_ca`],
|
|
3788
|
-
attributes: {
|
|
3789
|
-
num_q_heads: heads,
|
|
3790
|
-
num_kv_heads: c.dec_kv_heads,
|
|
3791
|
-
head_dim: headDim
|
|
3792
|
-
}
|
|
3793
|
-
});
|
|
3794
|
-
act(`${p}_cao`, ["T", H]);
|
|
3795
|
-
linear(`${p}_cap`, `${p}_ca`, `${lk}.encoder_attn.out_proj.weight`, `${p}_cao`, H, H);
|
|
3796
|
-
act(`${p}_res2`, ["T", H]);
|
|
3797
|
-
addNode({
|
|
3798
|
-
id: `${p}_add2`,
|
|
3799
|
-
opType: "Add",
|
|
3800
|
-
inputs: [`${p}_res1`, `${p}_cao`],
|
|
3801
|
-
outputs: [`${p}_res2`],
|
|
3802
|
-
attributes: {
|
|
3803
|
-
count_tensor: `${p}_res1`,
|
|
3804
|
-
hidden_size: H
|
|
3805
|
-
}
|
|
3806
|
-
});
|
|
3807
|
-
layernorm(`${p}_n3`, `${p}_res2`, `${lk}.final_layer_norm`, `${p}_ln3`);
|
|
3808
|
-
act(`${p}_fc1`, ["T", c.dec_ffn]);
|
|
3809
|
-
linear(`${p}_fc1p`, `${p}_ln3`, `${lk}.fc1.weight`, `${p}_fc1`, H, c.dec_ffn);
|
|
3810
|
-
act(`${p}_gelu`, ["T", c.dec_ffn]);
|
|
3811
|
-
addNode({
|
|
3812
|
-
id: `${p}_act`,
|
|
3813
|
-
opType: "GeluErf",
|
|
3814
|
-
inputs: [`${p}_fc1`],
|
|
3815
|
-
outputs: [`${p}_gelu`],
|
|
3816
|
-
attributes: { count_tensor: `${p}_fc1` }
|
|
3817
|
-
});
|
|
3818
|
-
act(`${p}_fc2`, ["T", H]);
|
|
3819
|
-
linear(`${p}_fc2p`, `${p}_gelu`, `${lk}.fc2.weight`, `${p}_fc2`, c.dec_ffn, H);
|
|
3820
|
-
act(`${p}_res3`, ["T", H]);
|
|
3821
|
-
addNode({
|
|
3822
|
-
id: `${p}_add3`,
|
|
3823
|
-
opType: "Add",
|
|
3824
|
-
inputs: [`${p}_res2`, `${p}_fc2`],
|
|
3825
|
-
outputs: [`${p}_res3`],
|
|
3826
|
-
attributes: {
|
|
3827
|
-
count_tensor: `${p}_res2`,
|
|
3828
|
-
hidden_size: H
|
|
3829
|
-
}
|
|
3830
|
-
});
|
|
3831
|
-
prev = `${p}_res3`;
|
|
3832
|
-
}
|
|
3833
|
-
layernorm("dec_final_norm", prev, "decoder.model.decoder.layer_norm", "dec_normed");
|
|
3834
|
-
act("dec_last", [1, H]);
|
|
3835
|
-
addNode({
|
|
3836
|
-
id: "slice_last",
|
|
3837
|
-
opType: "SliceLastRow",
|
|
3838
|
-
inputs: ["dec_normed"],
|
|
3839
|
-
outputs: ["dec_last"],
|
|
3840
|
-
attributes: { width: H }
|
|
3841
|
-
});
|
|
3842
|
-
const outputs = [];
|
|
3843
|
-
for (let cb = 0; cb < c.num_codebooks; cb++) {
|
|
3844
|
-
const headW = `decoder.lm_heads.${cb}.weight`;
|
|
3845
|
-
w(headW, [c.audio_vocab, H]);
|
|
3846
|
-
const logit = `logits_cb${cb}`;
|
|
3847
|
-
act(logit, [1, c.audio_vocab]);
|
|
3848
|
-
addNode({
|
|
3849
|
-
id: `lm_head${cb}`,
|
|
3850
|
-
opType: "MatMul",
|
|
3851
|
-
inputs: ["dec_last", headW],
|
|
3852
|
-
outputs: [logit],
|
|
3853
|
-
attributes: {
|
|
3854
|
-
M_tensor: "dec_last",
|
|
3855
|
-
K: H,
|
|
3856
|
-
N: c.audio_vocab
|
|
3857
|
-
}
|
|
3858
|
-
});
|
|
3859
|
-
outputs.push(logit);
|
|
3860
|
-
}
|
|
3861
|
-
return {
|
|
3862
|
-
architecture: "ParlerTTSDecoder",
|
|
3863
|
-
config: baseConfig(c, H, heads, c.dec_layers),
|
|
3864
|
-
capabilities: CAPS,
|
|
3865
|
-
tensors,
|
|
3866
|
-
nodes,
|
|
3867
|
-
executionOrder,
|
|
3868
|
-
inputs,
|
|
3869
|
-
outputs
|
|
3870
|
-
};
|
|
3871
|
-
}
|
|
3872
|
-
/**
|
|
3873
|
-
* Apply the Parler/MusicGen delay pattern to a [numCodebooks, T] code grid produced
|
|
3874
|
-
* by AR decode. During generation, codebook `i` is delayed by `i` steps: at decode
|
|
3875
|
-
* step t the model emits, for each codebook i, the code for ACOUSTIC frame (t − i).
|
|
3876
|
-
* To recover the aligned acoustic grid we simply read codebook i's stream starting
|
|
3877
|
-
* at offset i. This returns the de-delayed [numCodebooks, frames] grid (codebook-major)
|
|
3878
|
-
* ready for the DAC decoder, where frames = T − (numCodebooks − 1).
|
|
3879
|
-
*
|
|
3880
|
-
* `delayed` is codebook-major [numCodebooks, T] (delayed[i*T + t]).
|
|
3881
|
-
*/
|
|
3882
|
-
function revertDelayPattern(delayed, numCodebooks, T) {
|
|
3883
|
-
const frames = T - (numCodebooks - 1);
|
|
3884
|
-
if (frames <= 0) return {
|
|
3885
|
-
codes: new Uint32Array(0),
|
|
3886
|
-
frames: 0
|
|
3887
|
-
};
|
|
3888
|
-
const codes = new Uint32Array(numCodebooks * frames);
|
|
3889
|
-
for (let i = 0; i < numCodebooks; i++) for (let f = 0; f < frames; f++) codes[i * frames + f] = delayed[i * T + (f + i)];
|
|
3890
|
-
return {
|
|
3891
|
-
codes,
|
|
3892
|
-
frames
|
|
3893
|
-
};
|
|
3894
|
-
}
|
|
3895
|
-
|
|
3896
3269
|
//#endregion
|
|
3897
3270
|
//#region src/gpu/parler-tts.ts
|
|
3898
3271
|
/**
|
|
@@ -3918,12 +3291,18 @@ function revertDelayPattern(delayed, numCodebooks, T) {
|
|
|
3918
3291
|
* 4. Revert the delay pattern → [9, frames] code grid → shared DAC decode → 44.1 kHz
|
|
3919
3292
|
* PCM (tanh applied host-side).
|
|
3920
3293
|
*
|
|
3921
|
-
* STATUS —
|
|
3922
|
-
*
|
|
3923
|
-
*
|
|
3924
|
-
*
|
|
3925
|
-
*
|
|
3926
|
-
*
|
|
3294
|
+
* STATUS — WIRED + RUNS END-TO-END. Typechecks + builds, and the full pipeline runs
|
|
3295
|
+
* on Dawn (node): parler-tts/parler-tts-mini-v1 loads, the T5 encoder runs, the prompt
|
|
3296
|
+
* prefills, the 9-codebook delay-pattern AR loop decodes, and the shared DAC decoder
|
|
3297
|
+
* produces finite, non-silent, in-range 44.1 kHz PCM (verified via
|
|
3298
|
+
* scripts/engine/test-parler-speak.mjs). Reached from the high-level engine through
|
|
3299
|
+
* `g.speak(text, { model: DEFAULT_MODELS.ttsParler, describeVoice })`, which routes
|
|
3300
|
+
* Parler repos here directly (bypassing the single-graph text loader, the same way
|
|
3301
|
+
* MoonshineSTT is reached for STT). A bit-exact reference diff vs transformers
|
|
3302
|
+
* ParlerTTSForConditionalGeneration (T5 encoder cosine + a decoder forward; see
|
|
3303
|
+
* scripts/engine/parler-*-ref.py stubs) remains as a follow-up for numerical parity.
|
|
3304
|
+
* The architecture, weight layout, tokenization, delay pattern, and DAC config are all
|
|
3305
|
+
* verified against the live config.json + safetensors header.
|
|
3927
3306
|
*/
|
|
3928
3307
|
const MAP_MODE_READ$1 = 1;
|
|
3929
3308
|
/** Default voice description when the caller doesn't supply one. */
|
|
@@ -5722,9 +5101,22 @@ function parseAgentToolCall(text) {
|
|
|
5722
5101
|
return null;
|
|
5723
5102
|
}
|
|
5724
5103
|
var WebGPUEngine = class WebGPUEngine {
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
5104
|
+
_ctx;
|
|
5105
|
+
_executor;
|
|
5106
|
+
_tokenizer;
|
|
5107
|
+
get ctx() {
|
|
5108
|
+
if (!this._ctx) throw new Error(WebGPUEngine.TTS_LITE_ERROR);
|
|
5109
|
+
return this._ctx;
|
|
5110
|
+
}
|
|
5111
|
+
get executor() {
|
|
5112
|
+
if (!this._executor) throw new Error(WebGPUEngine.TTS_LITE_ERROR);
|
|
5113
|
+
return this._executor;
|
|
5114
|
+
}
|
|
5115
|
+
get tokenizer() {
|
|
5116
|
+
if (!this._tokenizer) throw new Error(WebGPUEngine.TTS_LITE_ERROR);
|
|
5117
|
+
return this._tokenizer;
|
|
5118
|
+
}
|
|
5119
|
+
static TTS_LITE_ERROR = "This engine was created for a TTS checkpoint; base-model ops (generate/embed/describeImage) are unavailable. Use speak() / encodeSpeaker().";
|
|
5728
5120
|
_destroyed = false;
|
|
5729
5121
|
_isEmbedding;
|
|
5730
5122
|
/** HF architecture string (e.g. "Gemma3TextModel", "Qwen3ForCausalLM"). */
|
|
@@ -5776,16 +5168,25 @@ var WebGPUEngine = class WebGPUEngine {
|
|
|
5776
5168
|
_genQueueTail = Promise.resolve();
|
|
5777
5169
|
/** Model capabilities (text, vision, moe). */
|
|
5778
5170
|
capabilities;
|
|
5779
|
-
/** Model architecture config. */
|
|
5780
|
-
|
|
5171
|
+
/** Model architecture config (null on a TTS-only lite engine). */
|
|
5172
|
+
_config;
|
|
5173
|
+
/** Model architecture config. Throws on a TTS-only lite engine. */
|
|
5174
|
+
get config() {
|
|
5175
|
+
if (!this._config) throw new Error(WebGPUEngine.TTS_LITE_ERROR);
|
|
5176
|
+
return this._config;
|
|
5177
|
+
}
|
|
5781
5178
|
constructor(ctx, executor, tokenizer, graph, opts, vision) {
|
|
5782
|
-
this.
|
|
5783
|
-
this.
|
|
5784
|
-
this.
|
|
5785
|
-
this.capabilities = graph
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
|
|
5179
|
+
this._ctx = ctx;
|
|
5180
|
+
this._executor = executor;
|
|
5181
|
+
this._tokenizer = tokenizer;
|
|
5182
|
+
this.capabilities = graph?.capabilities ?? {
|
|
5183
|
+
text: true,
|
|
5184
|
+
vision: false,
|
|
5185
|
+
moe: false
|
|
5186
|
+
};
|
|
5187
|
+
this._config = graph?.config ?? null;
|
|
5188
|
+
this._isEmbedding = graph?.outputs.includes("embedding") ?? false;
|
|
5189
|
+
this._architecture = graph?.architecture ?? "";
|
|
5789
5190
|
this.visionExecutor = vision?.executor ?? null;
|
|
5790
5191
|
this.visionConfig = vision?.config ?? null;
|
|
5791
5192
|
this.visionPosEmbedTable = vision?.posEmbedTable ?? null;
|
|
@@ -5902,6 +5303,7 @@ var WebGPUEngine = class WebGPUEngine {
|
|
|
5902
5303
|
...options,
|
|
5903
5304
|
repo: resolveDefaultRepo(options)
|
|
5904
5305
|
};
|
|
5306
|
+
if (isTTSRepo(options.repo)) return WebGPUEngine._buildTTSLite(options);
|
|
5905
5307
|
const ctx = await initGPU();
|
|
5906
5308
|
try {
|
|
5907
5309
|
return await WebGPUEngine._buildFromContext(ctx, options);
|
|
@@ -5912,6 +5314,21 @@ var WebGPUEngine = class WebGPUEngine {
|
|
|
5912
5314
|
throw err;
|
|
5913
5315
|
}
|
|
5914
5316
|
}
|
|
5317
|
+
/**
|
|
5318
|
+
* Build a lightweight TTS-only engine: no GPU device is initialized and no base
|
|
5319
|
+
* text graph is loaded. It stores the create() options; the first `speak()`
|
|
5320
|
+
* (or `encodeSpeaker()`) lazily builds the dedicated native TTS engine —
|
|
5321
|
+
* {@link KaniTTS}, {@link OuteTTS}, or {@link ParlerTTS} — which brings its own
|
|
5322
|
+
* GPU device and weights. Base-model ops throw {@link WebGPUEngine.TTS_LITE_ERROR}.
|
|
5323
|
+
*/
|
|
5324
|
+
static _buildTTSLite(options) {
|
|
5325
|
+
return new WebGPUEngine(null, null, null, null, {
|
|
5326
|
+
multimodalGraph: false,
|
|
5327
|
+
rawConfig: {},
|
|
5328
|
+
maxSeqLen: options.maxSeqLen ?? 2048,
|
|
5329
|
+
createOptions: options
|
|
5330
|
+
}, null);
|
|
5331
|
+
}
|
|
5915
5332
|
static async _buildFromContext(ctx, options) {
|
|
5916
5333
|
const isBrowser = typeof navigator !== "undefined" && typeof location !== "undefined";
|
|
5917
5334
|
const isSafari = isBrowser && /Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent);
|
|
@@ -7306,13 +6723,15 @@ var WebGPUEngine = class WebGPUEngine {
|
|
|
7306
6723
|
destroy() {
|
|
7307
6724
|
if (this._destroyed) return;
|
|
7308
6725
|
this._destroyed = true;
|
|
7309
|
-
this.
|
|
6726
|
+
this._executor?.destroy();
|
|
7310
6727
|
this._kaniTTS?.destroy();
|
|
7311
6728
|
this._outeTTS?.destroy();
|
|
7312
6729
|
this._parlerTTS?.destroy();
|
|
7313
6730
|
this.visionExecutor?.destroy();
|
|
7314
|
-
|
|
7315
|
-
|
|
6731
|
+
if (this._ctx) {
|
|
6732
|
+
clearPipelineCache(this._ctx.device);
|
|
6733
|
+
this._ctx.device.destroy();
|
|
6734
|
+
}
|
|
7316
6735
|
}
|
|
7317
6736
|
checkDestroyed() {
|
|
7318
6737
|
if (this._destroyed) throw new Error("WebGPUEngine has been destroyed");
|
|
@@ -7343,4 +6762,4 @@ var WebGPUEngine = class WebGPUEngine {
|
|
|
7343
6762
|
|
|
7344
6763
|
//#endregion
|
|
7345
6764
|
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 };
|
|
7346
|
-
//# sourceMappingURL=gpu-
|
|
6765
|
+
//# sourceMappingURL=gpu-BCfd_K38.mjs.map
|