@genai-fi/nanogpt 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{DatasetBuilder-DU1G1OKX.js → DatasetBuilder-DRDW8tcM.js} +85 -86
- package/dist/Generator-BcR_14Cj.js +316 -0
- package/dist/{RealDiv-CSnvtN2E.js → RealDiv-Cl8k3YTx.js} +54 -62
- package/dist/{Reshape-BlylqwWy.js → Reshape-CKxKPKqi.js} +9 -12
- package/dist/Reshape-H5zZRgr9.js +16 -0
- package/dist/RoPECache-dYscFINl.js +722 -0
- package/dist/TeachableLLM.js +29 -34
- package/dist/api/beamer.js +5 -6
- package/dist/api/responses.js +11 -12
- package/dist/api/training.js +12 -14
- package/dist/axis_util-rF9RnwKE.js +37 -0
- package/dist/backend.js +5 -6
- package/dist/{backend_util-DAV0I34P.js → backend_util-Cpp0Gwlp.js} +180 -185
- package/dist/{binary_op_util-CrYk9LXL.js → binary_op_util-WY9YIl0q.js} +3 -7
- package/dist/broadcast_to-CGvLNiQ0.js +20 -0
- package/dist/checks/appendCache.js +7 -7
- package/dist/checks/attentionMask.js +9 -8
- package/dist/checks/check.js +1 -2
- package/dist/checks/gelu.js +6 -6
- package/dist/checks/index.js +24 -25
- package/dist/checks/matMulGelu.js +7 -7
- package/dist/checks/normRMS.js +14 -12
- package/dist/checks/normRMSGrad.js +9 -8
- package/dist/checks/packUnpack.js +7 -7
- package/dist/checks/qkv.js +1 -34
- package/dist/checks/rope.js +6 -6
- package/dist/checks/weights.js +1 -2
- package/dist/clip_by_value-D-UX9am5.js +13 -0
- package/dist/complex-Cl904TqN.js +13 -0
- package/dist/{complex_util-CkazZsaH.js → complex_util-BBlPAm-s.js} +1 -2
- package/dist/concat-Oip5acVY.js +14 -0
- package/dist/{concat_util-CWzvQQlK.js → concat_util-CY45Hf4F.js} +2 -3
- package/dist/data/docx.js +3 -4
- package/dist/data/pdf.js +11 -14
- package/dist/data/stream.js +1 -2
- package/dist/data/textLoader.js +16 -15
- package/dist/data-CV_i_H6B.js +11 -0
- package/dist/data.js +5 -12
- package/dist/dist-CMMLi-qO.js +2675 -0
- package/dist/{dist-BGVm64AY.js → dist-DeVH1nGn.js} +1465 -1573
- package/dist/{dist-CwK5S7Ls.js → dist-DyL7qSLJ.js} +2664 -2400
- package/dist/dropout16-CA31Ud5a.js +20 -0
- package/dist/dropout_util-SiFMbFXz.js +22 -0
- package/dist/{eventemitter3-D_qV3Lof.js → eventemitter3-wmfmOP_f.js} +2 -3
- package/dist/expand_dims-Dh3Fulyn.js +10 -0
- package/dist/floor-BwjmUb7X.js +8 -0
- package/dist/gather-B5Z1RFt5.js +14 -0
- package/dist/gatherSub-CRUfUzBa.js +22 -0
- package/dist/gelu-Xx9-ohH9.js +25 -0
- package/dist/{gpgpu_math-20tPK8LM.js → gpgpu_math-48m8q3jI.js} +265 -286
- package/dist/inference/Beamer.js +34 -27
- package/dist/inference/Generator.js +1 -273
- package/dist/inference/tokenisePrompt.js +5 -4
- package/dist/inference/types.d.ts +6 -0
- package/dist/inference/utilities.js +1 -2
- package/dist/{jszip.min-DKa1Rjyn.js → jszip.min-Btv48m44.js} +68 -64
- package/dist/{kernel_funcs_utils-ql8Y8qPn.js → kernel_funcs_utils-BYRpSfV_.js} +39 -42
- package/dist/layers/BaseLayer.js +9 -10
- package/dist/layers/GQA.js +45 -44
- package/dist/layers/HeadLayer.js +13 -13
- package/dist/layers/LoRA.js +17 -20
- package/dist/layers/MHA.d.ts +2 -2
- package/dist/layers/MHA.js +46 -45
- package/dist/layers/MLP.js +22 -21
- package/dist/layers/PositionEmbedding.js +14 -13
- package/dist/layers/RMSNorm.js +14 -13
- package/dist/layers/RoPECache.js +1 -338
- package/dist/layers/TiedEmbedding.js +15 -14
- package/dist/layers/TransformerBlock.d.ts +3 -9
- package/dist/layers/TransformerBlock.js +29 -30
- package/dist/layers/WeightStore.js +4 -5
- package/dist/layers-CFqEip3s.js +13 -0
- package/dist/layers.js +3 -11
- package/dist/loader/load.js +27 -24
- package/dist/loader/loadHF.js +3 -3
- package/dist/loader/loadTransformers.js +5 -6
- package/dist/loader/loadZipMeta.js +1 -2
- package/dist/loader/newZipLoad.js +1 -2
- package/dist/loader/oldZipLoad.js +8 -9
- package/dist/loader/save.js +15 -16
- package/dist/main.js +3281 -3463
- package/dist/{matMul16-CO1QhsRt.js → matMul16-tE26fnhf.js} +29 -27
- package/dist/{matMulGelu-CBoqTZM7.js → matMulGelu-ASUWlKqu.js} +33 -33
- package/dist/mat_mul-R9_DWmIT.js +16 -0
- package/dist/models/Llama.js +48 -49
- package/dist/models/NanoGPTV1.js +53 -54
- package/dist/models/NanoGPTV2.js +48 -49
- package/dist/models/Qwen3.js +48 -49
- package/dist/models/config.js +3 -8
- package/dist/models/factory.js +7 -8
- package/dist/models/model.d.ts +5 -7
- package/dist/models/model.js +1 -2
- package/dist/models-DyBpJJwM.js +13 -0
- package/dist/models.js +6 -14
- package/dist/mul16-C7sqgqik.js +41 -0
- package/dist/non_max_suppression_impl-B0H318rb.js +72 -0
- package/dist/not_equal-Bu3O8rh_.js +67 -0
- package/dist/one_hot-TEMPumJj.js +14 -0
- package/dist/ones-DpPXWa6A.js +13 -0
- package/dist/ops/adamAdjust.js +2 -3
- package/dist/ops/adamMoments.js +2 -3
- package/dist/ops/add16.js +2 -3
- package/dist/ops/appendCache.js +9 -8
- package/dist/ops/attentionMask.d.ts +1 -1
- package/dist/ops/attentionMask.js +8 -5
- package/dist/ops/concat16.js +5 -5
- package/dist/ops/cpu/adamAdjust.js +7 -8
- package/dist/ops/cpu/adamMoments.js +5 -5
- package/dist/ops/cpu/appendCache.js +3 -3
- package/dist/ops/cpu/attentionMask.js +12 -8
- package/dist/ops/cpu/fusedSoftmax.js +3 -3
- package/dist/ops/cpu/gatherSub.js +1 -12
- package/dist/ops/cpu/gelu.js +12 -13
- package/dist/ops/cpu/matMul16.js +7 -7
- package/dist/ops/cpu/matMulGelu.js +21 -18
- package/dist/ops/cpu/matMulMul.js +8 -9
- package/dist/ops/cpu/mulDropout.js +8 -9
- package/dist/ops/cpu/normRMS.js +12 -13
- package/dist/ops/cpu/qkv.js +14 -13
- package/dist/ops/cpu/rope.js +11 -8
- package/dist/ops/cpu/scatterSub.js +1 -12
- package/dist/ops/dot16.js +16 -17
- package/dist/ops/dropout.js +9 -8
- package/dist/ops/dropout16.js +1 -22
- package/dist/ops/gatherSub.js +3 -4
- package/dist/ops/gelu.js +1 -2
- package/dist/ops/globalNorm.js +10 -10
- package/dist/ops/grads/add16.js +16 -17
- package/dist/ops/grads/attentionMask.js +6 -7
- package/dist/ops/grads/dropout16.js +1 -1
- package/dist/ops/grads/gelu.js +1 -2
- package/dist/ops/grads/matMul16.js +1 -2
- package/dist/ops/grads/matMulGelu.js +6 -7
- package/dist/ops/grads/mul16.js +1 -1
- package/dist/ops/grads/normRMS.js +8 -9
- package/dist/ops/grads/pack16.js +1 -2
- package/dist/ops/grads/qkv.js +10 -10
- package/dist/ops/grads/rope.js +1 -2
- package/dist/ops/grads/silu.js +1 -2
- package/dist/ops/grads/softmax16.js +6 -7
- package/dist/ops/grads/unpack16.js +1 -2
- package/dist/ops/grads/utils.js +1 -2
- package/dist/ops/matMul16.d.ts +1 -1
- package/dist/ops/matMul16.js +1 -2
- package/dist/ops/matMulGelu.js +3 -4
- package/dist/ops/matMulMul.js +2 -3
- package/dist/ops/mul16.js +1 -43
- package/dist/ops/mulDrop.js +2 -3
- package/dist/ops/normRMS.js +2 -3
- package/dist/ops/pack16.js +1 -2
- package/dist/ops/qkv.js +2 -3
- package/dist/ops/reshape16.js +11 -11
- package/dist/ops/rope.js +1 -2
- package/dist/ops/scatterSub.js +3 -4
- package/dist/ops/silu.js +1 -2
- package/dist/ops/slice16.js +5 -5
- package/dist/ops/softmax16.js +3 -4
- package/dist/ops/sub16.js +3 -4
- package/dist/ops/sum16.js +3 -3
- package/dist/ops/transpose16.js +16 -15
- package/dist/ops/unpack16.js +1 -2
- package/dist/ops/webgl/adamAdjust.js +8 -9
- package/dist/ops/webgl/adamMoments.js +2 -3
- package/dist/ops/webgl/appendCache.js +2 -3
- package/dist/ops/webgl/attentionMask.js +2 -3
- package/dist/ops/webgl/dropout16.js +2 -3
- package/dist/ops/webgl/fusedSoftmax.js +13 -13
- package/dist/ops/webgl/gatherSub.js +2 -3
- package/dist/ops/webgl/gelu.js +11 -12
- package/dist/ops/webgl/log.js +10 -10
- package/dist/ops/webgl/matMul16.js +31 -24
- package/dist/ops/webgl/matMulGelu.js +1 -2
- package/dist/ops/webgl/matMulMul.js +3 -4
- package/dist/ops/webgl/mulDropout.js +2 -3
- package/dist/ops/webgl/normRMS.js +11 -10
- package/dist/ops/webgl/qkv.js +2 -3
- package/dist/ops/webgl/rope.js +4 -5
- package/dist/ops/webgl/scatterSub.js +2 -3
- package/dist/ops/webgpu/adamAdjust.js +13 -14
- package/dist/ops/webgpu/adamMoments.js +13 -14
- package/dist/ops/webgpu/add16.js +3 -4
- package/dist/ops/webgpu/appendCache.js +20 -21
- package/dist/ops/webgpu/attentionMask.js +18 -19
- package/dist/ops/webgpu/attentionMask32_program.js +7 -8
- package/dist/ops/webgpu/clipScale.js +11 -12
- package/dist/ops/webgpu/concat16.js +17 -18
- package/dist/ops/webgpu/dropout16.js +6 -7
- package/dist/ops/webgpu/gatherSub.js +11 -12
- package/dist/ops/webgpu/gelu.js +10 -11
- package/dist/ops/webgpu/index.js +17 -17
- package/dist/ops/webgpu/matMul16.js +74 -63
- package/dist/ops/webgpu/matMul16_program.d.ts +2 -1
- package/dist/ops/webgpu/matMul16_program.js +29 -21
- package/dist/ops/webgpu/mul16.js +3 -4
- package/dist/ops/webgpu/norm2.js +9 -10
- package/dist/ops/webgpu/normRMS.js +9 -10
- package/dist/ops/webgpu/normRMS16_program.js +1 -2
- package/dist/ops/webgpu/normRMS32_program.js +1 -2
- package/dist/ops/webgpu/normRMSGrad.js +30 -30
- package/dist/ops/webgpu/pack16.js +2 -3
- package/dist/ops/webgpu/pack16_program.js +3 -4
- package/dist/ops/webgpu/qkv.js +10 -11
- package/dist/ops/webgpu/rope.js +26 -27
- package/dist/ops/webgpu/scatterSub.js +12 -13
- package/dist/ops/webgpu/silu.js +10 -11
- package/dist/ops/webgpu/slice16.js +17 -18
- package/dist/ops/webgpu/softmax16.js +9 -9
- package/dist/ops/webgpu/softmax16_program.js +9 -10
- package/dist/ops/webgpu/softmax16_subgroup_program.js +11 -12
- package/dist/ops/webgpu/softmax16grad.js +8 -9
- package/dist/ops/webgpu/sub16.js +3 -4
- package/dist/ops/webgpu/sum16.js +16 -15
- package/dist/ops/webgpu/transpose16.js +13 -12
- package/dist/ops/webgpu/transpose16_program.js +3 -4
- package/dist/ops/webgpu/transpose16_shared_program.js +17 -18
- package/dist/ops/webgpu/unpack16.js +8 -9
- package/dist/ops/webgpu/utils/binary_op.js +20 -21
- package/dist/ops/webgpu/utils/deviceInfo.js +1 -2
- package/dist/ops/webgpu/utils/reductions.js +21 -20
- package/dist/ops-Be5ACU5R.js +13 -0
- package/dist/ops-C1UpdEYM.js +509 -0
- package/dist/{pack16-BhuXNUS7.js → pack16-BHO4t1-M.js} +14 -17
- package/dist/pad-Dy-1IP3A.js +13 -0
- package/dist/patches/webgpu_backend.js +18 -19
- package/dist/patches/webgpu_base.js +2 -3
- package/dist/patches/webgpu_program.js +21 -22
- package/dist/{pdf-Bzuk68Vy.js → pdf-CbnQ75VG.js} +380 -701
- package/dist/{picomatch-BO4HbNfo.js → picomatch--TW6gyBJ.js} +229 -291
- package/dist/qkv-BQfNPucX.js +42 -0
- package/dist/rand_util-_vCY93Uw.js +44 -0
- package/dist/random_normal-DUIT8kyC.js +11 -0
- package/dist/range-CYvQC3fW.js +13 -0
- package/dist/relu-C4XULT8A.js +8 -0
- package/dist/reshape-DJb1jgMt.js +8 -0
- package/dist/resize_nearest_neighbor-DAqcTYUe.js +188 -0
- package/dist/{chunk-CWhphoD1.js → rolldown-runtime-CwxnZyOB.js} +4 -5
- package/dist/{rope-BPu_uooz.js → rope-JjBVufF_.js} +6 -8
- package/dist/scatterSub-BOnqk-uY.js +27 -0
- package/dist/scatter_nd_util-BepMCpLY.js +34 -0
- package/dist/seedrandom-SHEGFK6H.js +282 -0
- package/dist/selu_util-DeOTf-sc.js +27 -0
- package/dist/shared-BIDMUBCs.js +1864 -0
- package/dist/{shared-CfTzpULd.js → shared-CX_iPI5K.js} +2 -3
- package/dist/silu-DsAE2cJ5.js +23 -0
- package/dist/slice-Dlb1FlzG.js +13 -0
- package/dist/{slice_util-Dve4TkDn.js → slice_util-BVgPRoij.js} +3 -4
- package/dist/softmax-Dpav_dWw.js +10 -0
- package/dist/split-DYnT8chz.js +11 -0
- package/dist/squeeze-B3XYGAlg.js +9 -0
- package/dist/stack-Dbbt9mIk.js +10 -0
- package/dist/step-DA-5DNu9.js +348 -0
- package/dist/{stream-BpAwcvHz.js → stream-BBe2apn4.js} +68 -88
- package/dist/sum-C8qNbFNp.js +13 -0
- package/dist/tensor-ALxWZfmz.js +7 -0
- package/dist/tensor1d-BHgkkhTE.js +9 -0
- package/dist/tensor2d-ARItvqVn.js +10 -0
- package/dist/tensor4d-D1zRBipJ.js +10 -0
- package/dist/tfjs_backend-CsXOum0h.js +685 -0
- package/dist/tile-DfyQ0KX-.js +10 -0
- package/dist/tokenise-DbS2Ea-T.js +14 -0
- package/dist/tokenise.js +6 -15
- package/dist/tokeniser/BaseTokeniser.js +5 -9
- package/dist/tokeniser/CharTokeniser.js +1 -2
- package/dist/tokeniser/bpe.js +19 -20
- package/dist/topk-BrU2pkrR.js +19 -0
- package/dist/training/AdamW.js +35 -31
- package/dist/training/BasicTrainer.js +56 -56
- package/dist/training/DatasetBuilder.js +1 -2
- package/dist/training/Evaluator.js +4 -4
- package/dist/training/LRScheduler.js +1 -2
- package/dist/training/PreTrainer.js +7 -8
- package/dist/training/SFTTrainer.js +7 -8
- package/dist/training/configure.js +16 -15
- package/dist/training/factory.js +1 -2
- package/dist/training/loss.js +1 -2
- package/dist/training/orthoGrad.js +2 -3
- package/dist/training/prepareData.js +18 -17
- package/dist/training/sparseCrossEntropy.js +38 -32
- package/dist/training/tasks/TokenStore.js +21 -22
- package/dist/training/tasks/tokenStream.js +1 -2
- package/dist/training/validateOptions.js +1 -2
- package/dist/training/validation.js +1 -2
- package/dist/transpose-BC-M_OoT.js +34 -0
- package/dist/unsorted_segment_sum-BelC7R-q.js +408 -0
- package/dist/utilities/arrayClose.js +5 -4
- package/dist/utilities/arrayShape.js +1 -2
- package/dist/utilities/datasetID.js +1 -2
- package/dist/utilities/dummy.js +15 -15
- package/dist/utilities/float16.js +10 -10
- package/dist/utilities/maxHeap.js +1 -2
- package/dist/utilities/multinomialCPU.d.ts +1 -2
- package/dist/utilities/multinomialCPU.js +6 -8
- package/dist/utilities/packed.js +2 -3
- package/dist/utilities/parameters.js +3 -4
- package/dist/utilities/performance.js +2 -3
- package/dist/utilities/profile.js +3 -4
- package/dist/utilities/random.js +1 -2
- package/dist/utilities/safetensors.js +14 -14
- package/dist/utilities/sentences.js +16 -13
- package/dist/utilities/tokenParse.js +1 -2
- package/dist/utilities/tokens.js +5 -6
- package/dist/utilities/topP.d.ts +1 -0
- package/dist/utilities/topP.js +20 -13
- package/dist/utilities/waitForModel.js +1 -2
- package/dist/utilities/weights.js +4 -4
- package/dist/utilities/yielder.js +1 -2
- package/dist/{v4-BK7K-jy_.js → v4-YCkfo8OR.js} +4 -7
- package/dist/{webgpu-IAn9VotJ.js → webgpu-BHX-uBym.js} +156 -163
- package/dist/{webgpu_program-B0PokuRJ.js → webgpu_program-DvkFqRlR.js} +28 -29
- package/dist/{webgpu_util-DfODg6XI.js → webgpu_util-5QTyovaf.js} +2 -3
- package/dist/zeros-hxKGkRfl.js +12 -0
- package/package.json +3 -3
- package/dist/Reshape-CwxdaU8n.js +0 -17
- package/dist/dist-Da20xy8E.js +0 -6375
- package/dist/gelu-B6637MKa.js +0 -27
- package/dist/selu_util-B_AFEfoz.js +0 -24
- package/dist/shared-24EoeHJl.js +0 -1314
- package/dist/silu-B6bvCgJ7.js +0 -25
- package/dist/tfjs_backend-h5weiy1O.js +0 -614
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { t as e } from "./eventemitter3-wmfmOP_f.js";
|
|
2
|
+
import t from "./tokeniser/CharTokeniser.js";
|
|
3
|
+
import { Q as n, W as r, Y as i, Z as a, b as o, ir as s, rt as c } from "./dist-CMMLi-qO.js";
|
|
4
|
+
import { t as l } from "./reshape-DJb1jgMt.js";
|
|
5
|
+
import { t as u } from "./concat-Oip5acVY.js";
|
|
6
|
+
import { t as d } from "./gather-B5Z1RFt5.js";
|
|
7
|
+
import { t as f } from "./pad-Dy-1IP3A.js";
|
|
8
|
+
import { t as p } from "./softmax-Dpav_dWw.js";
|
|
9
|
+
import { t as m } from "./tensor2d-ARItvqVn.js";
|
|
10
|
+
import { t as h } from "./topk-BrU2pkrR.js";
|
|
11
|
+
import g from "./utilities/multinomialCPU.js";
|
|
12
|
+
import _ from "./utilities/topP.js";
|
|
13
|
+
import { sparseSoftmaxCrossEntropy as v } from "./training/sparseCrossEntropy.js";
|
|
14
|
+
import y, { tensorFromTokens as b } from "./inference/tokenisePrompt.js";
|
|
15
|
+
import { CHARS as x, getTokenConfidence as S, padArray as C } from "./inference/utilities.js";
|
|
16
|
+
// node_modules/@tensorflow/tfjs-core/dist/ops/multinomial.js
|
|
17
|
+
function w(e, t, r, i = !1) {
|
|
18
|
+
let a = n(e, "logits", "multinomial"), o = a.size, u = a.rank;
|
|
19
|
+
if (o < 2) throw Error(`Error in multinomial: you need at least 2 outcomes, but got ${o}.`);
|
|
20
|
+
if (u > 2) throw Error(`Rank of probabilities must be 1 or 2, but is ${u}`);
|
|
21
|
+
r ||= Math.random();
|
|
22
|
+
let d = { logits: u === 1 ? l(a, [1, -1]) : a }, f = {
|
|
23
|
+
numSamples: t,
|
|
24
|
+
seed: r,
|
|
25
|
+
normalized: i
|
|
26
|
+
}, p = c.runKernel(s, d, f);
|
|
27
|
+
return u === 1 ? l(p, [p.size]) : p;
|
|
28
|
+
}
|
|
29
|
+
var T = /* @__PURE__ */ a({ multinomial_: w });
|
|
30
|
+
// lib/inference/Generator.ts
|
|
31
|
+
function E(e) {
|
|
32
|
+
return Array.isArray(e);
|
|
33
|
+
}
|
|
34
|
+
var D = class extends e {
|
|
35
|
+
model;
|
|
36
|
+
tokeniser;
|
|
37
|
+
active = !1;
|
|
38
|
+
cache = null;
|
|
39
|
+
initialPrompt = null;
|
|
40
|
+
outputConversation = [];
|
|
41
|
+
actualTokeniser;
|
|
42
|
+
lastToken = -1;
|
|
43
|
+
lastLoss = null;
|
|
44
|
+
rawOutput = [];
|
|
45
|
+
jobQueue = [];
|
|
46
|
+
processingJob = !1;
|
|
47
|
+
startTime = null;
|
|
48
|
+
tokenCount = 0;
|
|
49
|
+
constructor(e, t) {
|
|
50
|
+
super(), this.model = e, this.tokeniser = t, this.actualTokeniser = t;
|
|
51
|
+
}
|
|
52
|
+
shouldTerminate(e, t) {
|
|
53
|
+
if (e) return !1;
|
|
54
|
+
let n = this.tokeniser.getSpecialTokenIndex("<|assistant_end|>");
|
|
55
|
+
return t === this.actualTokeniser.eosToken || t === n;
|
|
56
|
+
}
|
|
57
|
+
async _generateToken(e, t, n) {
|
|
58
|
+
let a = n?.temperature ?? 1, s = n?.topK, c = n?.topP, l = n?.usePadding ?? !1, u = {
|
|
59
|
+
training: !1,
|
|
60
|
+
attentionScores: n?.outputAttention ? { attentionOut: [] } : void 0,
|
|
61
|
+
cache: t,
|
|
62
|
+
outputEmbeddings: !!n?.outputHiddenStates,
|
|
63
|
+
mixedPrecision: !1
|
|
64
|
+
}, [y, b] = i(() => {
|
|
65
|
+
let t = e, i = t.shape[1], o = i <= this.model.config.blockSize ? t : t.slice([0, i - this.model.config.blockSize], [t.shape[0], this.model.config.blockSize]), s = l ? this.model.config.blockSize - o.shape[1] : 0, c = s > 0 ? f(o, [[0, 0], [0, s]]) : o, d = this.model.forward(u, c), p = d.shape[1] - 1 - s, h = d.slice([
|
|
66
|
+
0,
|
|
67
|
+
p,
|
|
68
|
+
0
|
|
69
|
+
], [
|
|
70
|
+
d.shape[0],
|
|
71
|
+
1,
|
|
72
|
+
d.shape[2]
|
|
73
|
+
]), g;
|
|
74
|
+
if (n?.targets) {
|
|
75
|
+
let e = n.targets.shift();
|
|
76
|
+
if (e !== void 0) {
|
|
77
|
+
let t = m([[e]], [1, 1], "int32"), n = v(h, t);
|
|
78
|
+
g = n.mean(), t.dispose(), n.dispose();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return u.attentionScores?.attentionOut && u.attentionScores.attentionOut.forEach((e, t) => {
|
|
82
|
+
e.shape[1] !== 1 && (u.attentionScores.attentionOut[t] = r(e.slice([
|
|
83
|
+
0,
|
|
84
|
+
p,
|
|
85
|
+
0
|
|
86
|
+
], [
|
|
87
|
+
e.shape[0],
|
|
88
|
+
1,
|
|
89
|
+
e.shape[2]
|
|
90
|
+
])), e.dispose());
|
|
91
|
+
}), d.dispose(), [h.div(a).squeeze([1]), g];
|
|
92
|
+
}), x, C, w, E, D = Math.random(), O = n?.rescore ?? !1;
|
|
93
|
+
if (O) {
|
|
94
|
+
let e = p(y), t = await e.array();
|
|
95
|
+
e.dispose();
|
|
96
|
+
let n = this.rawOutput[this.tokenCount];
|
|
97
|
+
if (!n) return null;
|
|
98
|
+
w = t, C = n.token, x = o(n.token, "int32");
|
|
99
|
+
} else if (c) {
|
|
100
|
+
let e = p(y), t = await e.array();
|
|
101
|
+
e.dispose();
|
|
102
|
+
let r = _(t, c);
|
|
103
|
+
(n?.outputScores || n?.outputConfidence || n?.outputScore) && (w = t), C = g(r, D), x = o(C, "int32");
|
|
104
|
+
} else if (s) {
|
|
105
|
+
let { values: e, indices: t } = h(y, s), r = s === 1 ? o(0, "int32") : T(e, 1);
|
|
106
|
+
if (x = d(t, r, 1), n?.outputScores || n?.outputConfidence || n?.outputScore) {
|
|
107
|
+
let e = p(y), t = await e.array();
|
|
108
|
+
e.dispose(), w = t;
|
|
109
|
+
}
|
|
110
|
+
e.dispose(), t.dispose(), r.dispose();
|
|
111
|
+
} else if (x = T(y, 1), n?.outputScores || n?.outputConfidence) {
|
|
112
|
+
let e = p(y);
|
|
113
|
+
w = await e.array(), e.dispose();
|
|
114
|
+
}
|
|
115
|
+
if (u.embeddings) {
|
|
116
|
+
let e = (n?.outputHiddenStates === "all" ? u.embeddings : u.embeddings.filter((e) => e.name.startsWith("block_output_"))).map(async (e) => {
|
|
117
|
+
let t = e.tensor.shape[1], r = e.tensor.slice([
|
|
118
|
+
0,
|
|
119
|
+
t - 1,
|
|
120
|
+
0
|
|
121
|
+
], [
|
|
122
|
+
e.tensor.shape[0],
|
|
123
|
+
1,
|
|
124
|
+
e.tensor.shape[2]
|
|
125
|
+
]);
|
|
126
|
+
e.tensor.dispose();
|
|
127
|
+
let i = r.squeeze([1]);
|
|
128
|
+
if (r.dispose(), n?.outputHiddenStates === "softmax") {
|
|
129
|
+
let t = this.model.project(i);
|
|
130
|
+
i.dispose();
|
|
131
|
+
let n = p(t, -1);
|
|
132
|
+
t.dispose();
|
|
133
|
+
let r = {
|
|
134
|
+
name: e.name,
|
|
135
|
+
tensor: await n.array()
|
|
136
|
+
};
|
|
137
|
+
return n.dispose(), r;
|
|
138
|
+
}
|
|
139
|
+
if (n?.outputHiddenStates === "logits") {
|
|
140
|
+
let t = this.model.project(i);
|
|
141
|
+
i.dispose();
|
|
142
|
+
let n = {
|
|
143
|
+
name: e.name,
|
|
144
|
+
tensor: await t.array()
|
|
145
|
+
};
|
|
146
|
+
return t.dispose(), n;
|
|
147
|
+
}
|
|
148
|
+
{
|
|
149
|
+
let t = await i.array();
|
|
150
|
+
return i.dispose(), {
|
|
151
|
+
name: e.name,
|
|
152
|
+
tensor: t
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
E = await Promise.all(e);
|
|
157
|
+
}
|
|
158
|
+
let k = x.reshape([1, 1]);
|
|
159
|
+
x.dispose(), x = k;
|
|
160
|
+
let A = C === void 0 ? (await x.array())[0][0] : C, j = this.actualTokeniser.decode([A]);
|
|
161
|
+
this.lastToken = A;
|
|
162
|
+
let M = this.shouldTerminate(n?.allowSpecial ?? !1, A), N;
|
|
163
|
+
if (!O) N = {
|
|
164
|
+
outputTensor: x,
|
|
165
|
+
token: A,
|
|
166
|
+
text: j,
|
|
167
|
+
confidence: n?.outputConfidence && w ? S(w[0]) : null,
|
|
168
|
+
score: n?.outputScore && w ? w[0][A] : null,
|
|
169
|
+
logits: n?.outputLogits ? (await y.array())[0] : null,
|
|
170
|
+
scores: n?.outputScores && w ? w[0] : null,
|
|
171
|
+
hiddenStates: E ? E.map((e) => e.tensor[0]) : null,
|
|
172
|
+
attention: n?.outputAttention ? await Promise.all(u.attentionScores?.attentionOut?.map((e) => e.array()) ?? []) : null,
|
|
173
|
+
loss: this.lastLoss,
|
|
174
|
+
multinomialRand: D,
|
|
175
|
+
terminated: M
|
|
176
|
+
}, this.rawOutput.push(N);
|
|
177
|
+
else if (N = this.rawOutput[this.tokenCount], N.outputTensor = x, N.rescore = w ? w[0][A] : void 0, !N) throw Error(`No raw output found for token index ${this.tokenCount}`);
|
|
178
|
+
if (y.dispose(), b) {
|
|
179
|
+
let e = await b.array();
|
|
180
|
+
b.dispose(), N.loss = e;
|
|
181
|
+
}
|
|
182
|
+
return n?.chunkSize && this.tokenCount % n.chunkSize !== 0 || (this.emit("tokens", N), n?._onChunk && await n._onChunk(N)), this.tokenCount++, N;
|
|
183
|
+
}
|
|
184
|
+
async _generate(e, t) {
|
|
185
|
+
let n = !1;
|
|
186
|
+
if (e?.rescore && this.outputConversation.length > 0) {
|
|
187
|
+
let e = this.outputConversation.pop();
|
|
188
|
+
if (!e || !e._output) throw Error("No raw output found for the last conversation entry");
|
|
189
|
+
this.rawOutput = e?._output;
|
|
190
|
+
}
|
|
191
|
+
this.outputConversation.length === 0 || this.outputConversation[this.outputConversation.length - 1]._completed || this.outputConversation[this.outputConversation.length - 1].role !== "assistant" && e?.nonConversational !== !0 || this.outputConversation[this.outputConversation.length - 1].role !== "text" && e?.nonConversational === !0 ? (this.outputConversation.push({
|
|
192
|
+
role: e?.nonConversational === !0 ? "text" : "assistant",
|
|
193
|
+
content: "",
|
|
194
|
+
_timestamp: Date.now()
|
|
195
|
+
}), n = !0, this.resetCache(!e?.noCache)) : (this.lastToken < 0 || t) && this.resetCache(!e?.noCache);
|
|
196
|
+
let r = this.outputConversation[this.outputConversation.length - 1];
|
|
197
|
+
r.content.length > 0 && (!r._output || r._output.length === 0) && (r._output = this.actualTokeniser.encode(r.content).map((e) => ({
|
|
198
|
+
token: e,
|
|
199
|
+
text: this.actualTokeniser.decode([e]),
|
|
200
|
+
confidence: 1,
|
|
201
|
+
score: 1,
|
|
202
|
+
logits: null,
|
|
203
|
+
hiddenStates: null,
|
|
204
|
+
scores: null,
|
|
205
|
+
attention: null,
|
|
206
|
+
loss: null,
|
|
207
|
+
multinomialRand: null,
|
|
208
|
+
terminated: !1
|
|
209
|
+
})));
|
|
210
|
+
let i = this.lastToken >= 0 && this.cache ? m([this.lastToken], [1, 1], "int32") : b(await y(this.actualTokeniser, this.model.config.blockSize, t ? n ? this.outputConversation.slice(0, -1) : this.outputConversation : void 0, n ? e : {
|
|
211
|
+
...e,
|
|
212
|
+
continuation: !0
|
|
213
|
+
})), a = e?.maxLength ?? 1e3;
|
|
214
|
+
for (let t = 0; t < a && this.active; t++) {
|
|
215
|
+
let n = await this._generateToken(i, this.cache ? this.cache : void 0, {
|
|
216
|
+
...e,
|
|
217
|
+
usePadding: !this.cache
|
|
218
|
+
}), r = this.outputConversation[this.outputConversation.length - 1];
|
|
219
|
+
if (!n) {
|
|
220
|
+
r._completed = !0;
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
if (this.cache) i.dispose(), i = n.outputTensor;
|
|
224
|
+
else {
|
|
225
|
+
let e = i;
|
|
226
|
+
i = u([i, n.outputTensor], 1), e.dispose();
|
|
227
|
+
}
|
|
228
|
+
if (this.cache || n.outputTensor.dispose(), n.terminated) {
|
|
229
|
+
r._completed = !0;
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
t === a - 1 && a > 1 && (r._completed = !0, n.terminated = !0), r.content += n.text, r._output ||= [], r._output.push(n);
|
|
233
|
+
}
|
|
234
|
+
return i.dispose(), this.outputConversation;
|
|
235
|
+
}
|
|
236
|
+
resetCache(e) {
|
|
237
|
+
this.cache && (this.cache.forEach((e) => {
|
|
238
|
+
e && (e.k && e.k.dispose(), e.v && e.v.dispose(), e.k = void 0, e.v = void 0, e.cumulativeLength = 0, e.length = 0);
|
|
239
|
+
}), e || (this.cache = null)), this.lastToken = -1;
|
|
240
|
+
}
|
|
241
|
+
reset() {
|
|
242
|
+
this.resetCache(), this.outputConversation = [], this.initialPrompt = null, this.rawOutput = [], this.lastLoss = null, this.emit("reset");
|
|
243
|
+
}
|
|
244
|
+
dispose() {
|
|
245
|
+
this.reset();
|
|
246
|
+
}
|
|
247
|
+
initialise(e, n) {
|
|
248
|
+
if (this.cache && n?.noCache && this.reset(), this.initialPrompt = e || null, this.lastToken === -1 && this.outputConversation.length === 0 ? this.outputConversation = this.initialPrompt || [] : e && e.length > 0 && (e.forEach((e) => {
|
|
249
|
+
this.outputConversation.push(e);
|
|
250
|
+
}), this.resetCache()), !this.cache && !n?.noCache && (this.model.config.modelType !== "GenAI_NanoGPT_v1" || this.model.config.useRope)) {
|
|
251
|
+
let e = Array(this.model.config.nLayer);
|
|
252
|
+
for (let t = 0; t < this.model.config.nLayer; t++) e[t] = {
|
|
253
|
+
k: void 0,
|
|
254
|
+
v: void 0,
|
|
255
|
+
length: 0,
|
|
256
|
+
cumulativeLength: 0
|
|
257
|
+
};
|
|
258
|
+
this.cache = e, this.lastToken = -1;
|
|
259
|
+
}
|
|
260
|
+
let r = this.tokeniser.trained ? this.tokeniser : new t(C(x, this.tokeniser.vocabSize));
|
|
261
|
+
this.actualTokeniser = r, n?.loraName ? this.model.attachLoRA(n.loraName) : this.model.hasLoRA() && this.model.detachLoRA();
|
|
262
|
+
}
|
|
263
|
+
async step(e, t) {
|
|
264
|
+
let n = {
|
|
265
|
+
...t,
|
|
266
|
+
maxLength: 1
|
|
267
|
+
};
|
|
268
|
+
return E(e) ? this.generate(e, n) : this.generate({
|
|
269
|
+
...e,
|
|
270
|
+
...n
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
async generate(e, t) {
|
|
274
|
+
let n;
|
|
275
|
+
if (Array.isArray(e) ? n = e : typeof e == "object" && (t = e), this.processingJob) {
|
|
276
|
+
if (this.jobQueue.length > 10) throw Error("Job queue is too long, rejecting new job");
|
|
277
|
+
return new Promise((e, r) => {
|
|
278
|
+
this.jobQueue.push({
|
|
279
|
+
prompt: n,
|
|
280
|
+
options: t,
|
|
281
|
+
resolve: e,
|
|
282
|
+
reject: r
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
this.processingJob = !0, this.startTime = Date.now();
|
|
287
|
+
try {
|
|
288
|
+
let e = await this.startJob(n, t);
|
|
289
|
+
if (this.processingJob = !1, this.jobQueue.length > 0) {
|
|
290
|
+
let e = this.jobQueue.shift();
|
|
291
|
+
this.generate(e.prompt || [], e.options).then(e.resolve).catch(e.reject);
|
|
292
|
+
}
|
|
293
|
+
return e;
|
|
294
|
+
} catch (e) {
|
|
295
|
+
throw this.processingJob = !1, e;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
async startJob(e, t) {
|
|
299
|
+
this.initialise(e, t), this.active = !0, this.model.metaData.generationSettings = t, t?.maxLength !== 1 && this.emit("start");
|
|
300
|
+
let n = await this._generate(t, !!e);
|
|
301
|
+
return this.active = !1, this.startTime !== null && (this.startTime = null), this.emit("stop"), n;
|
|
302
|
+
}
|
|
303
|
+
getQueueLength() {
|
|
304
|
+
return this.jobQueue.length;
|
|
305
|
+
}
|
|
306
|
+
stop() {
|
|
307
|
+
this.active = !1;
|
|
308
|
+
}
|
|
309
|
+
getConversation() {
|
|
310
|
+
return this.outputConversation;
|
|
311
|
+
}
|
|
312
|
+
getRawOutput() {
|
|
313
|
+
return this.rawOutput;
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
export { E as n, D as t };
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
1
|
+
import { Ni as e, Ui as t, _i as n, ct as r, qi as i, xr as a } from "./dist-CMMLi-qO.js";
|
|
2
|
+
import { a as o, i as s, o as c, s as l, t as u } from "./axis_util-rF9RnwKE.js";
|
|
3
|
+
import { L as d } from "./backend_util-Cpp0Gwlp.js";
|
|
4
|
+
import { Z as f } from "./gpgpu_math-48m8q3jI.js";
|
|
5
|
+
import { b as p, n as m } from "./kernel_funcs_utils-BYRpSfV_.js";
|
|
6
|
+
import { t as h } from "./Reshape-CKxKPKqi.js";
|
|
7
|
+
import { J as g, b as _ } from "./shared-CX_iPI5K.js";
|
|
8
|
+
// node_modules/@tensorflow/tfjs-backend-webgl/dist/mean_gpu.js
|
|
8
9
|
var v = class {
|
|
9
|
-
constructor(
|
|
10
|
+
constructor(t, n) {
|
|
10
11
|
this.variableNames = ["x"];
|
|
11
|
-
let { windowSize:
|
|
12
|
+
let { windowSize: r, batchSize: i, inSize: a, outSize: o } = t;
|
|
12
13
|
this.outputShape = [i, o];
|
|
13
|
-
let s = Math.floor(
|
|
14
|
-
if (
|
|
15
|
-
let
|
|
16
|
-
l = `sumValue += dot(values * ${
|
|
14
|
+
let s = Math.floor(r / 4) * 4, c = r % 4, l = "sumValue += dot(values, ones);";
|
|
15
|
+
if (n != null) {
|
|
16
|
+
let t = 1 / n;
|
|
17
|
+
l = `sumValue += dot(values * ${e(t) ? t.toPrecision(2) : t}, ones);`;
|
|
17
18
|
}
|
|
18
19
|
let u = "";
|
|
19
|
-
a %
|
|
20
|
+
a % r > 0 && (u = `
|
|
20
21
|
if (inIdx < 0 || inIdx >= ${a}) {
|
|
21
22
|
return 0.0;
|
|
22
23
|
}
|
|
@@ -32,7 +33,7 @@ var v = class {
|
|
|
32
33
|
ivec2 coords = getOutputCoords();
|
|
33
34
|
int batch = coords[0];
|
|
34
35
|
int outIdx = coords[1];
|
|
35
|
-
int inOffset = outIdx * ${
|
|
36
|
+
int inOffset = outIdx * ${r};
|
|
36
37
|
|
|
37
38
|
float sumValue = 0.0;
|
|
38
39
|
|
|
@@ -170,8 +171,7 @@ var v = class {
|
|
|
170
171
|
`;
|
|
171
172
|
}
|
|
172
173
|
};
|
|
173
|
-
|
|
174
|
-
//#region node_modules/@tensorflow/tfjs-backend-webgl/dist/kernel_utils/reduce.js
|
|
174
|
+
// node_modules/@tensorflow/tfjs-backend-webgl/dist/kernel_utils/reduce.js
|
|
175
175
|
function b(e) {
|
|
176
176
|
let t = [];
|
|
177
177
|
for (; t.length === 0 || t[t.length - 1].outSize !== 1;) {
|
|
@@ -207,8 +207,7 @@ function x(e, t, n, r) {
|
|
|
207
207
|
}
|
|
208
208
|
return a;
|
|
209
209
|
}
|
|
210
|
-
|
|
211
|
-
//#region node_modules/@tensorflow/tfjs-backend-webgl/dist/transpose_gpu.js
|
|
210
|
+
// node_modules/@tensorflow/tfjs-backend-webgl/dist/transpose_gpu.js
|
|
212
211
|
var S = class {
|
|
213
212
|
constructor(e, t) {
|
|
214
213
|
this.variableNames = ["A"];
|
|
@@ -238,8 +237,7 @@ function C(e) {
|
|
|
238
237
|
for (let t = 0; t < e.length; t++) r[e[t]] = n[t];
|
|
239
238
|
return r.join();
|
|
240
239
|
}
|
|
241
|
-
|
|
242
|
-
//#region node_modules/@tensorflow/tfjs-backend-webgl/dist/transpose_packed_gpu.js
|
|
240
|
+
// node_modules/@tensorflow/tfjs-backend-webgl/dist/transpose_packed_gpu.js
|
|
243
241
|
var w = class {
|
|
244
242
|
constructor(e, t) {
|
|
245
243
|
this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0;
|
|
@@ -269,32 +267,29 @@ var w = class {
|
|
|
269
267
|
`;
|
|
270
268
|
}
|
|
271
269
|
};
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
return n.runWebGLProgram(r, [e], e.dtype);
|
|
270
|
+
// node_modules/@tensorflow/tfjs-backend-webgl/dist/kernels/Transpose_impl.js
|
|
271
|
+
function T(e, t, r) {
|
|
272
|
+
let i = n().getBool("WEBGL_PACK_ARRAY_OPERATIONS") ? new w(e.shape, t) : new S(e.shape, t);
|
|
273
|
+
return r.runWebGLProgram(i, [e], e.dtype);
|
|
277
274
|
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
let w = c(S), E = c(n.shape) / w, D = h({
|
|
275
|
+
// node_modules/@tensorflow/tfjs-backend-webgl/dist/kernels/Sum_impl.js
|
|
276
|
+
function E(e, n, a, d) {
|
|
277
|
+
let f = n, p = e.shape.length, m = t(f, e.shape), g = m, _ = c(g, p), v = _ != null, y = e;
|
|
278
|
+
v && (y = T(e, _, d), g = l(g.length, p)), u("sum", g, p);
|
|
279
|
+
let [b, S] = s(y.shape, g), C = b;
|
|
280
|
+
a && (C = o(b, m));
|
|
281
|
+
let w = i(S), E = i(e.shape) / w, D = h({
|
|
286
282
|
inputs: { x: y },
|
|
287
283
|
attrs: { shape: [E, w] },
|
|
288
284
|
backend: d
|
|
289
|
-
}), O = x(D,
|
|
285
|
+
}), O = x(D, r(e.dtype), "sum", d), k = h({
|
|
290
286
|
inputs: { x: O },
|
|
291
287
|
attrs: { shape: C },
|
|
292
288
|
backend: d
|
|
293
289
|
});
|
|
294
290
|
return d.disposeIntermediateTensorInfo(D), d.disposeIntermediateTensorInfo(O), v && d.disposeIntermediateTensorInfo(y), k;
|
|
295
291
|
}
|
|
296
|
-
|
|
297
|
-
//#region node_modules/@tensorflow/tfjs-backend-webgl/dist/kernels/Sum.js
|
|
292
|
+
// node_modules/@tensorflow/tfjs-backend-webgl/dist/kernels/Sum.js
|
|
298
293
|
function D(e) {
|
|
299
294
|
let { inputs: t, backend: n, attrs: r } = e, { x: i } = t, { axis: a, keepDims: o } = r;
|
|
300
295
|
return E(i, a, o, n);
|
|
@@ -304,46 +299,44 @@ var O = {
|
|
|
304
299
|
backendName: "webgl",
|
|
305
300
|
kernelFunc: D
|
|
306
301
|
};
|
|
307
|
-
|
|
308
|
-
//#region node_modules/@tensorflow/tfjs-backend-webgl/dist/kernels/Max_impl.js
|
|
302
|
+
// node_modules/@tensorflow/tfjs-backend-webgl/dist/kernels/Max_impl.js
|
|
309
303
|
function k(e, t, n, r) {
|
|
310
|
-
let
|
|
304
|
+
let a = i(t), o = i(e.shape) / a, s = h({
|
|
311
305
|
inputs: { x: e },
|
|
312
|
-
attrs: { shape: [
|
|
306
|
+
attrs: { shape: [o, a] },
|
|
313
307
|
backend: r
|
|
314
|
-
}),
|
|
315
|
-
inputs: { x:
|
|
308
|
+
}), c = x(s, e.dtype, "max", r), l = h({
|
|
309
|
+
inputs: { x: c },
|
|
316
310
|
attrs: { shape: n },
|
|
317
311
|
backend: r
|
|
318
312
|
});
|
|
319
|
-
return r.disposeIntermediateTensorInfo(
|
|
313
|
+
return r.disposeIntermediateTensorInfo(s), r.disposeIntermediateTensorInfo(c), l;
|
|
320
314
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
let { inputs: r, backend: i, attrs: a } = n, { x: d } = r, { reductionIndices: f, keepDims: p } = a, m = d.shape.length, h = s(f, d.shape), v = h, y = t(v, m), b = y != null, x = i.shouldExecuteOnCPU([d]), S = d;
|
|
315
|
+
// node_modules/@tensorflow/tfjs-backend-webgl/dist/kernels/Max.js
|
|
316
|
+
function A(e) {
|
|
317
|
+
let { inputs: n, backend: r, attrs: a } = e, { x: d } = n, { reductionIndices: f, keepDims: p } = a, m = d.shape.length, h = t(f, d.shape), v = h, y = c(v, m), b = y != null, x = r.shouldExecuteOnCPU([d]), S = d;
|
|
325
318
|
if (b) {
|
|
326
319
|
if (x) {
|
|
327
|
-
let e =
|
|
320
|
+
let e = r.texData.get(S.dataId).values, t = Array(m);
|
|
328
321
|
for (let e = 0; e < t.length; e++) t[e] = d.shape[y[e]];
|
|
329
322
|
let n = g(e, d.shape, d.dtype, y, t);
|
|
330
|
-
S =
|
|
331
|
-
let
|
|
332
|
-
|
|
333
|
-
} else S = T(d, y,
|
|
334
|
-
v =
|
|
323
|
+
S = r.makeTensorInfo(t, d.dtype);
|
|
324
|
+
let i = r.texData.get(S.dataId);
|
|
325
|
+
i.values = n;
|
|
326
|
+
} else S = T(d, y, r);
|
|
327
|
+
v = l(v.length, m);
|
|
335
328
|
}
|
|
336
329
|
u("max", v, m);
|
|
337
|
-
let [C, w] =
|
|
330
|
+
let [C, w] = s(S.shape, v), E = C;
|
|
338
331
|
p && (E = o(C, h));
|
|
339
332
|
let D;
|
|
340
333
|
if (x) {
|
|
341
|
-
let e =
|
|
342
|
-
D =
|
|
343
|
-
let n =
|
|
334
|
+
let e = r.texData.get(S.dataId).values, t = _(e, i(w), E, d.dtype);
|
|
335
|
+
D = r.makeTensorInfo(E, d.dtype);
|
|
336
|
+
let n = r.texData.get(D.dataId);
|
|
344
337
|
n.values = t;
|
|
345
|
-
} else D = k(S, w, E,
|
|
346
|
-
return b &&
|
|
338
|
+
} else D = k(S, w, E, r);
|
|
339
|
+
return b && r.disposeIntermediateTensorInfo(S), D;
|
|
347
340
|
}
|
|
348
341
|
var j = {
|
|
349
342
|
kernelName: "Max",
|
|
@@ -354,9 +347,8 @@ var j = {
|
|
|
354
347
|
packedOpSnippet: "\n // vec4 one = vec4(equal(a, b));\n // return one + (vec4(1.0) - one) * a / b;\n vec4 result = a / b;\n if(a.x == b.x) {\n result.x = 1.;\n }\n if(a.y == b.y) {\n result.y = 1.;\n }\n if(a.z == b.z) {\n result.z = 1.;\n }\n if(a.w == b.w) {\n result.w = 1.;\n }\n\n return result;\n",
|
|
355
348
|
checkOutOfBounds: !0
|
|
356
349
|
}), N = {
|
|
357
|
-
kernelName:
|
|
350
|
+
kernelName: a,
|
|
358
351
|
backendName: "webgl",
|
|
359
352
|
kernelFunc: M
|
|
360
353
|
};
|
|
361
|
-
//#endregion
|
|
362
354
|
export { D as a, x as c, j as i, N as n, O as o, A as r, T as s, M as t };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $ as i, C as a, a as o, et as s, j as c, nt as l, tt as u, v as d } from "./gpgpu_math-
|
|
3
|
-
|
|
1
|
+
import { Mi as e, Tr as t, qi as n, yi as r } from "./dist-CMMLi-qO.js";
|
|
2
|
+
import { $ as i, C as a, a as o, et as s, j as c, nt as l, tt as u, v as d } from "./gpgpu_math-48m8q3jI.js";
|
|
3
|
+
// node_modules/@tensorflow/tfjs-backend-webgl/dist/reshape_packed_gpu.js
|
|
4
4
|
var f = class {
|
|
5
5
|
constructor(e, t) {
|
|
6
6
|
this.variableNames = ["A"], this.packedInputs = !0, this.packedOutput = !0, this.customUniforms = [{
|
|
@@ -59,8 +59,7 @@ function p(e, t) {
|
|
|
59
59
|
}
|
|
60
60
|
`;
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
//#region node_modules/@tensorflow/tfjs-backend-webgl/dist/kernel_utils/reshape.js
|
|
62
|
+
// node_modules/@tensorflow/tfjs-backend-webgl/dist/kernel_utils/reshape.js
|
|
64
63
|
function m(e, t, n) {
|
|
65
64
|
let r = [d(e.shape), ...a(e.shape)], i = {
|
|
66
65
|
dtype: e.dtype,
|
|
@@ -73,11 +72,10 @@ function m(e, t, n) {
|
|
|
73
72
|
dtype: c.dtype
|
|
74
73
|
};
|
|
75
74
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
n(d === p, () => `The new shape (${f}) has ${p} elements and the old shape (${s.shape}) has ${d} elements. The new shape and old shape must have the same number of elements.`);
|
|
75
|
+
// node_modules/@tensorflow/tfjs-backend-webgl/dist/kernels/Reshape.js
|
|
76
|
+
function h(t) {
|
|
77
|
+
let { inputs: i, backend: a, attrs: o } = t, { x: s } = i, { shape: l } = o, u = a, d = n(s.shape), f = e(l, d), p = n(f);
|
|
78
|
+
r(d === p, () => `The new shape (${f}) has ${p} elements and the old shape (${s.shape}) has ${d} elements. The new shape and old shape must have the same number of elements.`);
|
|
81
79
|
let h = u.texData.get(s.dataId);
|
|
82
80
|
return h.isPacked && !c(s.shape, f) && !(h.texture !== null && c(h.shape, f)) ? m(s, f, u) : (u.incRef(s.dataId), {
|
|
83
81
|
dataId: s.dataId,
|
|
@@ -86,9 +84,8 @@ function h(e) {
|
|
|
86
84
|
});
|
|
87
85
|
}
|
|
88
86
|
var g = {
|
|
89
|
-
kernelName:
|
|
87
|
+
kernelName: t,
|
|
90
88
|
backendName: "webgl",
|
|
91
89
|
kernelFunc: h
|
|
92
90
|
};
|
|
93
|
-
//#endregion
|
|
94
91
|
export { g as n, f as r, h as t };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Mi as e, Tr as t, qi as n, yi as r } from "./dist-CMMLi-qO.js";
|
|
2
|
+
// node_modules/@tensorflow/tfjs-backend-webgpu/dist/kernels/Reshape.js
|
|
3
|
+
function i(t) {
|
|
4
|
+
let { inputs: i, attrs: a } = t, { x: o } = i, { shape: s } = a, c = n(o.shape), l = e(s, c), u = n(l);
|
|
5
|
+
return r(c === u, () => `The new shape (${l}) has ${u} elements and the old shape (${o.shape}) has ${c} elements. The new shape and old shape must have the same number of elements.`), t.backend.incRef(o.dataId), {
|
|
6
|
+
dataId: o.dataId,
|
|
7
|
+
shape: l,
|
|
8
|
+
dtype: o.dtype
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
var a = {
|
|
12
|
+
kernelName: t,
|
|
13
|
+
backendName: "webgpu",
|
|
14
|
+
kernelFunc: i
|
|
15
|
+
};
|
|
16
|
+
export { a as n, i as t };
|