@genai-fi/nanogpt 0.6.3 → 0.7.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/Generator.js +17 -13
- package/dist/NanoGPTModel.d.ts +2 -2
- package/dist/NanoGPTModel.js +104 -136
- package/dist/{RealDiv-BYViZwhN.js → RealDiv-CVYNbZxu.js} +30 -29
- package/dist/{Reshape-t7Kcikjk.js → Reshape-CEsEp0AI.js} +5 -5
- package/dist/Reshape-Do18N3gO.js +30 -0
- package/dist/TeachableLLM.js +9 -5
- package/dist/{TiedEmbedding-9WeDwvjO.js → TiedEmbedding-ccLBFiZi.js} +4 -4
- package/dist/{axis_util-Bu4h7XWV.js → axis_util-5DTW2tFV.js} +3 -3
- package/dist/backend.d.ts +1 -0
- package/dist/backend.js +7 -0
- package/dist/backend_util-C9Ut8n0Q.js +749 -0
- package/dist/{broadcast_to-DARN-DBD.js → broadcast_to-Ba9h_8DO.js} +2 -2
- package/dist/{concat-5aPGqw3Z.js → concat-CbXTetof.js} +8 -8
- package/dist/{dataset-pgqp-YfL.js → dataset-U3PrjwgU.js} +7 -7
- package/dist/{dropout-Bciw46HT.js → dropout-DPfPgWWe.js} +8 -8
- package/dist/{gather-DjyCjmOD.js → gather-Bbh8DHhM.js} +1 -1
- package/dist/gelu-BFwVnd1r.js +26 -0
- package/dist/gpgpu_math-DffelNS-.js +2371 -0
- package/dist/index-DYD_yPa-.js +12076 -0
- package/dist/{index-BAzbokzv.js → index-UdZhlibC.js} +414 -398
- package/dist/{kernel_funcs_utils-CUxJCg0g.js → kernel_funcs_utils-CXDy3EN7.js} +31 -30
- package/dist/layers/BaseLayer.js +2 -2
- package/dist/layers/CausalSelfAttention.js +8 -8
- package/dist/layers/MLP.js +5 -5
- package/dist/layers/RMSNorm.js +3 -3
- package/dist/layers/RoPECache.js +4 -4
- package/dist/layers/TiedEmbedding.js +5 -5
- package/dist/layers/TransformerBlock.js +1 -1
- package/dist/loader/loadTransformers.js +1 -1
- package/dist/loader/oldZipLoad.js +11 -7
- package/dist/{log_sum_exp-YEo2h3gb.js → log_sum_exp-BnmCkHWl.js} +16 -16
- package/dist/main.d.ts +13 -0
- package/dist/main.js +44 -23
- package/dist/{mat_mul-7121rsJk.js → mat_mul-dwmZz69e.js} +4 -4
- package/dist/{max-DtlIuVeW.js → max-ByjEGoFx.js} +3 -3
- package/dist/{mulmat_packed_gpu-D4nKF7Je.js → mulmat_packed_gpu-IGPBp6h9.js} +1 -1
- package/dist/non_max_suppression_impl-CsEgBuMA.js +134 -0
- package/dist/{ones-BBlSRqn1.js → ones-C8Mfln6-.js} +2 -2
- package/dist/ops/adamAdjust.d.ts +2 -0
- package/dist/ops/adamAdjust.js +9 -0
- package/dist/ops/adamMoments.d.ts +2 -0
- package/dist/ops/adamMoments.js +9 -0
- package/dist/ops/appendCache.js +3 -3
- package/dist/ops/attentionMask.js +1 -1
- package/dist/ops/cpu/adamAdjust.d.ts +1 -0
- package/dist/ops/cpu/adamAdjust.js +18 -0
- package/dist/ops/cpu/adamMoments.d.ts +1 -0
- package/dist/ops/cpu/adamMoments.js +16 -0
- package/dist/ops/cpu/appendCache.js +8 -8
- package/dist/ops/cpu/attentionMask.js +9 -9
- package/dist/ops/cpu/fusedSoftmax.js +17 -11
- package/dist/ops/cpu/gatherSub.js +7 -7
- package/dist/ops/cpu/gelu.js +13 -13
- package/dist/ops/cpu/matMulGelu.js +36 -24
- package/dist/ops/cpu/matMulMul.js +14 -8
- package/dist/ops/cpu/mulDropout.js +9 -3
- package/dist/ops/cpu/normRMS.js +5 -5
- package/dist/ops/cpu/qkv.js +3 -3
- package/dist/ops/cpu/rope.js +5 -5
- package/dist/ops/cpu/scatterSub.js +11 -11
- package/dist/ops/fusedSoftmax.js +1 -1
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/gelu.js +2 -2
- package/dist/ops/grads/attentionMask.js +1 -1
- package/dist/ops/grads/fusedSoftmax.js +2 -2
- package/dist/ops/grads/gelu.js +3 -24
- package/dist/ops/grads/matMulGelu.js +5 -5
- package/dist/ops/grads/normRMS.js +6 -6
- package/dist/ops/grads/qkv.js +1 -1
- package/dist/ops/grads/rope.js +3 -3
- package/dist/ops/matMulGelu.js +1 -1
- package/dist/ops/matMulMul.js +1 -1
- package/dist/ops/mulDrop.js +1 -1
- package/dist/ops/normRMS.js +1 -1
- package/dist/ops/qkv.js +1 -1
- package/dist/ops/rope.js +4 -4
- package/dist/ops/scatterSub.js +1 -1
- package/dist/ops/webgl/adamAdjust.d.ts +1 -0
- package/dist/ops/webgl/adamAdjust.js +50 -0
- package/dist/ops/webgl/adamMoments.d.ts +1 -0
- package/dist/ops/webgl/adamMoments.js +38 -0
- package/dist/ops/webgl/appendCache.js +1 -1
- package/dist/ops/webgl/attentionMask.js +1 -1
- package/dist/ops/webgl/fusedSoftmax.js +4 -4
- package/dist/ops/webgl/gatherSub.js +8 -8
- package/dist/ops/webgl/gelu.js +2 -2
- package/dist/ops/webgl/log.js +5 -5
- package/dist/ops/webgl/matMulGelu.js +17 -17
- package/dist/ops/webgl/matMulMul.js +1 -1
- package/dist/ops/webgl/mulDropout.js +4 -4
- package/dist/ops/webgl/normRMS.js +2 -2
- package/dist/ops/webgl/qkv.js +1 -1
- package/dist/ops/webgl/rope.js +1 -1
- package/dist/ops/webgl/scatterSub.js +1 -1
- package/dist/ops/webgpu/adamAdjust.d.ts +1 -0
- package/dist/ops/webgpu/adamAdjust.js +52 -0
- package/dist/ops/webgpu/adamMoments.d.ts +1 -0
- package/dist/ops/webgpu/adamMoments.js +51 -0
- package/dist/ops/webgpu/appendCache.d.ts +1 -0
- package/dist/ops/webgpu/appendCache.js +57 -0
- package/dist/ops/webgpu/attentionMask.d.ts +1 -0
- package/dist/ops/webgpu/attentionMask.js +65 -0
- package/dist/ops/webgpu/gatherSub.d.ts +1 -0
- package/dist/ops/webgpu/gatherSub.js +52 -0
- package/dist/ops/webgpu/gelu.d.ts +14 -0
- package/dist/ops/webgpu/gelu.js +87 -0
- package/dist/ops/webgpu/index.d.ts +0 -0
- package/dist/ops/webgpu/index.js +11 -0
- package/dist/ops/webgpu/normRMS.d.ts +1 -0
- package/dist/ops/webgpu/normRMS.js +41 -0
- package/dist/ops/webgpu/normRMSGrad.d.ts +1 -0
- package/dist/ops/webgpu/normRMSGrad.js +128 -0
- package/dist/ops/webgpu/qkv.d.ts +1 -0
- package/dist/ops/webgpu/qkv.js +57 -0
- package/dist/ops/webgpu/rope.d.ts +1 -0
- package/dist/ops/webgpu/rope.js +69 -0
- package/dist/ops/webgpu/scatterSub.d.ts +1 -0
- package/dist/ops/webgpu/scatterSub.js +38 -0
- package/dist/ops/webgpu/utils/reductions.d.ts +9 -0
- package/dist/ops/webgpu/utils/reductions.js +68 -0
- package/dist/{ops-C0sQEcPw.js → ops-aRTXR2Sr.js} +433 -508
- package/dist/{random_width-DWzaOgrn.js → random_width-DbSpgl4o.js} +144 -144
- package/dist/{range-DYsrnfiy.js → range-D9CZhVlR.js} +1 -1
- package/dist/{reciprocal-CJQeasVa.js → reciprocal-CGB48wZB.js} +1 -1
- package/dist/{register_all_kernels-BfFCQAqs.js → register_all_kernels-DnbAyBXt.js} +203 -200
- package/dist/{reshape-krWGKraP.js → reshape-BR0eoLYN.js} +1 -1
- package/dist/{scatter_nd_util-93ln7Hut.js → scatter_nd_util-OjyAxku2.js} +3 -3
- package/dist/{selu_util-sntGesxr.js → selu_util-Ce6pu9IM.js} +44 -44
- package/dist/{shared-Ca6iDobD.js → shared-Czipaeb6.js} +541 -606
- package/dist/shared-DS5waSIY.js +69 -0
- package/dist/{sin-D_h-qCSx.js → sin-CiBxrDqX.js} +1 -1
- package/dist/slice-BHbDHObE.js +28 -0
- package/dist/{softmax-fsdtf6JC.js → softmax-JMEIUo2J.js} +1 -1
- package/dist/{split-eiktj-6L.js → split-CRU0PjVV.js} +4 -4
- package/dist/{stack-dfEEz2OY.js → stack-ikk2Y8_P.js} +2 -2
- package/dist/{sum-BE_Irnim.js → sum-NLYbiDag.js} +3 -3
- package/dist/{tensor-Xyi595sG.js → tensor-Do9PKbIE.js} +1 -1
- package/dist/{tensor2d-CPEkynbH.js → tensor2d-CWHxHpLh.js} +1 -1
- package/dist/training/Adam.d.ts +22 -0
- package/dist/training/Adam.js +93 -0
- package/dist/training/AdamExt.d.ts +1 -1
- package/dist/training/AdamExt.js +13 -12
- package/dist/training/DatasetBuilder.js +2 -2
- package/dist/training/Evaluator.js +1 -1
- package/dist/training/FullTrainer.js +27 -27
- package/dist/training/Trainer.d.ts +5 -6
- package/dist/training/Trainer.js +54 -55
- package/dist/training/sparseCrossEntropy.d.ts +0 -4
- package/dist/training/sparseCrossEntropy.js +7 -7
- package/dist/utilities/arrayClose.d.ts +1 -0
- package/dist/utilities/arrayClose.js +11 -0
- package/dist/utilities/dummy.js +19 -19
- package/dist/utilities/generate.js +15 -16
- package/dist/utilities/multinomialCPU.d.ts +2 -0
- package/dist/utilities/multinomialCPU.js +13 -0
- package/dist/utilities/performance.d.ts +2 -0
- package/dist/utilities/performance.js +16 -0
- package/dist/utilities/profile.d.ts +1 -0
- package/dist/utilities/profile.js +9 -6
- package/dist/utilities/safetensors.js +2 -2
- package/dist/utilities/weights.js +2 -2
- package/dist/{variable-wSS22xj5.js → variable-BTBkayv_.js} +1 -1
- package/dist/webgpu_program-WaoMq-WD.js +548 -0
- package/dist/webgpu_util-DhSeP4b6.js +80 -0
- package/dist/{zeros-YJDE7oRb.js → zeros-DnPT2nD4.js} +10 -10
- package/package.json +2 -1
- package/dist/gpgpu_math-CNslybmD.js +0 -3115
- package/dist/norm-CzltS9Fz.js +0 -86
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
* =============================================================================
|
|
16
|
+
*/
|
|
17
|
+
function J(e, t, o) {
|
|
18
|
+
const n = k(e, t, o), s = n < 0 ? -(n + 1) : n;
|
|
19
|
+
e.splice(s, 0, t);
|
|
20
|
+
}
|
|
21
|
+
function k(e, t, o) {
|
|
22
|
+
return A(e, t, o || v);
|
|
23
|
+
}
|
|
24
|
+
function v(e, t) {
|
|
25
|
+
return e > t ? 1 : e < t ? -1 : 0;
|
|
26
|
+
}
|
|
27
|
+
function A(e, t, o) {
|
|
28
|
+
let n = 0, s = e.length, r = 0, u = !1;
|
|
29
|
+
for (; n < s; ) {
|
|
30
|
+
r = n + (s - n >>> 1);
|
|
31
|
+
const l = o(t, e[r]);
|
|
32
|
+
l > 0 ? n = r + 1 : (s = r, u = !l);
|
|
33
|
+
}
|
|
34
|
+
return u ? n : -n - 1;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @license
|
|
38
|
+
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
39
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
40
|
+
* you may not use this file except in compliance with the License.
|
|
41
|
+
* You may obtain a copy of the License at
|
|
42
|
+
*
|
|
43
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
44
|
+
*
|
|
45
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
46
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
47
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
48
|
+
* See the License for the specific language governing permissions and
|
|
49
|
+
* limitations under the License.
|
|
50
|
+
* =============================================================================
|
|
51
|
+
*/
|
|
52
|
+
function O(e, t, o, n, s) {
|
|
53
|
+
return y(
|
|
54
|
+
e,
|
|
55
|
+
t,
|
|
56
|
+
o,
|
|
57
|
+
n,
|
|
58
|
+
s,
|
|
59
|
+
0
|
|
60
|
+
/* softNmsSigma */
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
function P(e, t, o, n, s, r) {
|
|
64
|
+
return y(
|
|
65
|
+
e,
|
|
66
|
+
t,
|
|
67
|
+
o,
|
|
68
|
+
n,
|
|
69
|
+
s,
|
|
70
|
+
0,
|
|
71
|
+
!1,
|
|
72
|
+
r,
|
|
73
|
+
!0
|
|
74
|
+
/* returnValidOutputs */
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
function X(e, t, o, n, s, r) {
|
|
78
|
+
return y(
|
|
79
|
+
e,
|
|
80
|
+
t,
|
|
81
|
+
o,
|
|
82
|
+
n,
|
|
83
|
+
s,
|
|
84
|
+
r,
|
|
85
|
+
!0
|
|
86
|
+
/* returnScoresTensor */
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
function y(e, t, o, n, s, r, u = !1, l = !1, h = !1) {
|
|
90
|
+
const c = [];
|
|
91
|
+
for (let i = 0; i < t.length; i++)
|
|
92
|
+
t[i] > s && c.push({ score: t[i], boxIndex: i, suppressBeginIndex: 0 });
|
|
93
|
+
c.sort(C);
|
|
94
|
+
const d = r > 0 ? -0.5 / r : 0, a = [], f = [];
|
|
95
|
+
for (; a.length < o && c.length > 0; ) {
|
|
96
|
+
const i = c.pop(), { score: M, boxIndex: I, suppressBeginIndex: g } = i;
|
|
97
|
+
if (M < s)
|
|
98
|
+
break;
|
|
99
|
+
let S = !1;
|
|
100
|
+
for (let b = a.length - 1; b >= g; --b) {
|
|
101
|
+
const w = B(e, I, a[b]);
|
|
102
|
+
if (w >= n) {
|
|
103
|
+
S = !0;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
if (i.score = i.score * V(n, d, w), i.score <= s)
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
i.suppressBeginIndex = a.length, S || (i.score === M ? (a.push(I), f.push(i.score)) : i.score > s && J(c, i, C));
|
|
110
|
+
}
|
|
111
|
+
const x = a.length, p = o - x;
|
|
112
|
+
l && p > 0 && (a.push(...new Array(p).fill(0)), f.push(...new Array(p).fill(0)));
|
|
113
|
+
const m = { selectedIndices: a };
|
|
114
|
+
return u && (m.selectedScores = f), h && (m.validOutputs = x), m;
|
|
115
|
+
}
|
|
116
|
+
function B(e, t, o) {
|
|
117
|
+
const n = e.subarray(t * 4, t * 4 + 4), s = e.subarray(o * 4, o * 4 + 4), r = Math.min(n[0], n[2]), u = Math.min(n[1], n[3]), l = Math.max(n[0], n[2]), h = Math.max(n[1], n[3]), c = Math.min(s[0], s[2]), d = Math.min(s[1], s[3]), a = Math.max(s[0], s[2]), f = Math.max(s[1], s[3]), x = (l - r) * (h - u), p = (a - c) * (f - d);
|
|
118
|
+
if (x <= 0 || p <= 0)
|
|
119
|
+
return 0;
|
|
120
|
+
const m = Math.max(r, c), i = Math.max(u, d), M = Math.min(l, a), I = Math.min(h, f), g = Math.max(M - m, 0) * Math.max(I - i, 0);
|
|
121
|
+
return g / (x + p - g);
|
|
122
|
+
}
|
|
123
|
+
function V(e, t, o) {
|
|
124
|
+
const n = Math.exp(t * o * o);
|
|
125
|
+
return o <= e ? n : 0;
|
|
126
|
+
}
|
|
127
|
+
function C(e, t) {
|
|
128
|
+
return e.score - t.score || e.score === t.score && t.boxIndex - e.boxIndex;
|
|
129
|
+
}
|
|
130
|
+
export {
|
|
131
|
+
X as a,
|
|
132
|
+
P as b,
|
|
133
|
+
O as n
|
|
134
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { z as c, c as f } from "./zeros-
|
|
1
|
+
import { F as n, H as t, j as m, E as i } from "./index-UdZhlibC.js";
|
|
2
|
+
import { z as c, c as f } from "./zeros-DnPT2nD4.js";
|
|
3
3
|
/**
|
|
4
4
|
* @license
|
|
5
5
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { e as i } from "../index-UdZhlibC.js";
|
|
2
|
+
import "./cpu/adamAdjust.js";
|
|
3
|
+
import "./webgl/adamAdjust.js";
|
|
4
|
+
function p(r, t, e, n, m, o) {
|
|
5
|
+
return i().runKernel("AdamAdjust", { moments: r, value: t }, { beta1: e, beta2: n, epsilon: m, learningRate: o });
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
p as adamAdjust
|
|
9
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { e as o } from "../index-UdZhlibC.js";
|
|
2
|
+
import "./cpu/adamMoments.js";
|
|
3
|
+
import "./webgl/adamMoments.js";
|
|
4
|
+
function p(e, n, r, m) {
|
|
5
|
+
return o().runKernel("AdamMoments", { moments: e, gradient: n }, { beta1: r, beta2: m });
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
p as adamMoments
|
|
9
|
+
};
|
package/dist/ops/appendCache.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { e as a } from "../index-
|
|
1
|
+
import { e as a } from "../index-UdZhlibC.js";
|
|
2
2
|
import "./cpu/appendCache.js";
|
|
3
3
|
import "./webgl/appendCache.js";
|
|
4
|
-
import { c as s } from "../concat-
|
|
5
|
-
import { z as c } from "../zeros-
|
|
4
|
+
import { c as s } from "../concat-CbXTetof.js";
|
|
5
|
+
import { z as c } from "../zeros-DnPT2nD4.js";
|
|
6
6
|
function i(r, p, n, o) {
|
|
7
7
|
if (!o) {
|
|
8
8
|
const e = r.shape[2];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { f as k, n as t, o as i, a as q, q as z } from "../../index-UdZhlibC.js";
|
|
2
|
+
function A(a) {
|
|
3
|
+
const { moments: n, value: r } = a.inputs, { beta1: l, beta2: u, epsilon: m, learningRate: d } = a.attrs, e = n.shape.length, c = new Array(e).fill(0), s = n.shape.slice();
|
|
4
|
+
s[e - 1] = 1;
|
|
5
|
+
const o = c.slice();
|
|
6
|
+
o[e - 1] = 1;
|
|
7
|
+
const b = s.slice(), p = n.slice(c, s).squeeze([e - 1]), M = n.slice(o, b).squeeze([e - 1]), f = t(p, l), g = t(M, u);
|
|
8
|
+
return i(
|
|
9
|
+
q(t(f, i(z(g), m ?? 1e-8)), -d),
|
|
10
|
+
r
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
const C = {
|
|
14
|
+
kernelName: "AdamAdjust",
|
|
15
|
+
backendName: "cpu",
|
|
16
|
+
kernelFunc: A
|
|
17
|
+
};
|
|
18
|
+
k(C);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { f as p } from "../../index-UdZhlibC.js";
|
|
2
|
+
import { s as f } from "../../stack-ikk2Y8_P.js";
|
|
3
|
+
function b(t) {
|
|
4
|
+
const { moments: n, gradient: c } = t.inputs, { beta1: o, beta2: m } = t.attrs, e = n.shape.length, a = new Array(e).fill(0), s = n.shape.slice();
|
|
5
|
+
s[e - 1] = 1;
|
|
6
|
+
const i = a.slice();
|
|
7
|
+
i[e - 1] = 1;
|
|
8
|
+
const r = s.slice(), l = n.slice(a, s).squeeze([e - 1]), u = n.slice(i, r).squeeze([e - 1]), M = l.mul(o).add(c.mul(1 - o)), d = u.mul(m).add(c.square().mul(1 - m));
|
|
9
|
+
return f([M, d], -1);
|
|
10
|
+
}
|
|
11
|
+
const g = {
|
|
12
|
+
kernelName: "AdamMoments",
|
|
13
|
+
backendName: "cpu",
|
|
14
|
+
kernelFunc: b
|
|
15
|
+
};
|
|
16
|
+
p(g);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as h } from "../../concat-
|
|
1
|
+
import { f as d } from "../../index-UdZhlibC.js";
|
|
2
|
+
import { c as h } from "../../concat-CbXTetof.js";
|
|
3
3
|
function u(p) {
|
|
4
|
-
const { cache: n, item: s } = p.inputs, { maxSize:
|
|
5
|
-
if (c + e <=
|
|
6
|
-
const
|
|
7
|
-
return
|
|
4
|
+
const { cache: n, item: s } = p.inputs, { maxSize: i, pastLen: c } = p.attrs, t = n.shape[0], o = n.shape[1], a = n.shape[3], e = s.shape[2];
|
|
5
|
+
if (c + e <= i) {
|
|
6
|
+
const l = n.slice([0, 0, 0, 0], [t, o, c, a]), m = n.slice([0, 0, c + e, 0], [t, o, i - c - e, a]), r = e < e ? s.slice([0, 0, 0, 0], [t, o, e, a]) : s, k = h([l, r, m], 2);
|
|
7
|
+
return l.dispose(), m.dispose(), r !== s && r.dispose(), k;
|
|
8
8
|
}
|
|
9
|
-
const
|
|
10
|
-
return
|
|
9
|
+
const f = n.slice([0, 0, e, 0], [t, o, i - e, a]), C = h([f, s], 2);
|
|
10
|
+
return f.dispose(), C;
|
|
11
11
|
}
|
|
12
12
|
const w = {
|
|
13
13
|
kernelName: "AppendCache",
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { l as N, w as b } from "../../ops-
|
|
3
|
-
import { o as A } from "../../ones-
|
|
4
|
-
import { z as I } from "../../zeros-
|
|
5
|
-
import { m as g } from "../../mat_mul-
|
|
1
|
+
import { f as a, h as p, b as u } from "../../index-UdZhlibC.js";
|
|
2
|
+
import { l as N, w as b } from "../../ops-aRTXR2Sr.js";
|
|
3
|
+
import { o as A } from "../../ones-C8Mfln6-.js";
|
|
4
|
+
import { z as I } from "../../zeros-DnPT2nD4.js";
|
|
5
|
+
import { m as g } from "../../mat_mul-dwmZz69e.js";
|
|
6
6
|
function o(n) {
|
|
7
7
|
const { q: s, k: e } = n.inputs, { divisor: r } = n.attrs, c = s.shape[2], t = e.shape[2], m = N.bandPart(A([t, t]), -1, 0).cast("bool"), l = I([t, t]), i = p([t, t], Number.NEGATIVE_INFINITY), f = b(m, l, i), k = g(s, e, !1, !0).mul(u(r)), d = f.slice([0, 0], [c, t]).expandDims(0).expandDims(0);
|
|
8
8
|
return k.add(d);
|
|
9
9
|
}
|
|
10
|
-
const
|
|
10
|
+
const h = {
|
|
11
11
|
kernelName: "AttentionMask",
|
|
12
12
|
backendName: "cpu",
|
|
13
13
|
kernelFunc: o
|
|
14
14
|
};
|
|
15
|
-
a(
|
|
16
|
-
const
|
|
15
|
+
a(h);
|
|
16
|
+
const w = {
|
|
17
17
|
kernelName: "AttentionMask",
|
|
18
18
|
backendName: "tensorflow",
|
|
19
19
|
kernelFunc: o
|
|
20
20
|
};
|
|
21
|
-
a(
|
|
21
|
+
a(w);
|
|
@@ -1,23 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { s as f } from "../../softmax-
|
|
3
|
-
function
|
|
4
|
-
const { inputs: s, attrs:
|
|
1
|
+
import { f as e } from "../../index-UdZhlibC.js";
|
|
2
|
+
import { s as f } from "../../softmax-JMEIUo2J.js";
|
|
3
|
+
function n(t) {
|
|
4
|
+
const { inputs: s, attrs: a } = t, { logits: o } = s, { dim: i, dropoutRate: r } = a;
|
|
5
5
|
if (!o)
|
|
6
6
|
throw new Error("Error in softmax: input logits is null");
|
|
7
|
-
return
|
|
7
|
+
return r !== void 0 && r > 0 && console.warn("Dropout in fusedSoftmax not implemented for CPU backend, skipping dropout."), f(o, i);
|
|
8
8
|
}
|
|
9
9
|
const m = {
|
|
10
10
|
kernelName: "FusedSoftmax",
|
|
11
11
|
backendName: "cpu",
|
|
12
|
-
kernelFunc:
|
|
12
|
+
kernelFunc: n
|
|
13
13
|
};
|
|
14
|
-
|
|
15
|
-
const
|
|
14
|
+
e(m);
|
|
15
|
+
const u = {
|
|
16
16
|
kernelName: "FusedSoftmax",
|
|
17
17
|
backendName: "tensorflow",
|
|
18
|
-
kernelFunc:
|
|
18
|
+
kernelFunc: n
|
|
19
|
+
};
|
|
20
|
+
e(u);
|
|
21
|
+
const l = {
|
|
22
|
+
kernelName: "FusedSoftmax",
|
|
23
|
+
backendName: "webgpu",
|
|
24
|
+
kernelFunc: n
|
|
19
25
|
};
|
|
20
|
-
|
|
26
|
+
e(l);
|
|
21
27
|
export {
|
|
22
|
-
|
|
28
|
+
n as softmaxCPU
|
|
23
29
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as
|
|
3
|
-
import { s as
|
|
1
|
+
import { B as u, C as c, E as g, a4 as h, f as m, c as p } from "../../index-UdZhlibC.js";
|
|
2
|
+
import { r as f } from "../../range-D9CZhVlR.js";
|
|
3
|
+
import { s as l } from "../../stack-ikk2Y8_P.js";
|
|
4
4
|
/**
|
|
5
5
|
* @license
|
|
6
6
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -17,14 +17,14 @@ import { s as N } from "../../stack-dfEEz2OY.js";
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
* =============================================================================
|
|
19
19
|
*/
|
|
20
|
-
function
|
|
20
|
+
function N(e, t) {
|
|
21
21
|
const n = c(t, "indices", "gatherND", "int32"), s = { params: c(e, "x", "gatherND", "string_or_numeric"), indices: n };
|
|
22
22
|
return g.runKernel(h, s);
|
|
23
23
|
}
|
|
24
|
-
const
|
|
24
|
+
const b = /* @__PURE__ */ u({ gatherND_: N });
|
|
25
25
|
function d(e) {
|
|
26
|
-
const { values: t, labels: n, logits: r } = e.inputs, s = n.shape[0],
|
|
27
|
-
return p(t,
|
|
26
|
+
const { values: t, labels: n, logits: r } = e.inputs, s = n.shape[0], a = f(0, s, 1, "int32"), i = l([a, n], 1), o = b(r, i);
|
|
27
|
+
return p(t, o);
|
|
28
28
|
}
|
|
29
29
|
const k = {
|
|
30
30
|
kernelName: "EfficientGatherSub",
|
package/dist/ops/cpu/gelu.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as t, t as d } from "../../index-UdZhlibC.js";
|
|
2
2
|
const o = 0.7978845608028654, c = 0.044715;
|
|
3
|
-
function m(
|
|
4
|
-
const { inputs:
|
|
3
|
+
function m(r) {
|
|
4
|
+
const { inputs: u } = r, { x: n } = u, e = n;
|
|
5
5
|
return d(() => {
|
|
6
|
-
const
|
|
7
|
-
return
|
|
6
|
+
const l = e.pow(3), s = e.add(l.mul(c)).mul(o).tanh().add(1).mul(0.5);
|
|
7
|
+
return e.mul(s);
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
|
-
const
|
|
10
|
+
const p = {
|
|
11
11
|
kernelName: "Gelu",
|
|
12
12
|
backendName: "cpu",
|
|
13
13
|
kernelFunc: m
|
|
14
14
|
};
|
|
15
|
-
t(
|
|
16
|
-
const
|
|
15
|
+
t(p);
|
|
16
|
+
const K = {
|
|
17
17
|
kernelName: "Gelu",
|
|
18
18
|
backendName: "tensorflow",
|
|
19
19
|
kernelFunc: m
|
|
20
20
|
};
|
|
21
|
-
t(
|
|
22
|
-
function i(
|
|
23
|
-
const { dy:
|
|
21
|
+
t(K);
|
|
22
|
+
function i(r) {
|
|
23
|
+
const { dy: u, x: n } = r.inputs;
|
|
24
24
|
return d(() => {
|
|
25
|
-
const
|
|
26
|
-
return
|
|
25
|
+
const e = n.square(), l = e.mul(n), a = n.add(l.mul(c)).mul(o).tanh(), f = a.square().neg().add(1), k = e.mul(3 * c).add(1), g = a.add(1).mul(0.5), G = n.mul(f).mul(o).mul(k).mul(0.5), N = g.add(G);
|
|
26
|
+
return u.mul(N);
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
const x = {
|
|
@@ -1,40 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
const { inputs:
|
|
5
|
-
return
|
|
6
|
-
const
|
|
7
|
-
return
|
|
1
|
+
import { f as e, t as m } from "../../index-UdZhlibC.js";
|
|
2
|
+
import { g as d, d as M } from "../../gelu-BFwVnd1r.js";
|
|
3
|
+
function c(t) {
|
|
4
|
+
const { inputs: u } = t, { x: n, kernel: l } = u, a = n, r = l;
|
|
5
|
+
return m(() => {
|
|
6
|
+
const o = a.matMul(r);
|
|
7
|
+
return d(o);
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
|
-
const
|
|
10
|
+
const G = {
|
|
11
11
|
kernelName: "MatMulGelu",
|
|
12
12
|
backendName: "cpu",
|
|
13
|
-
kernelFunc:
|
|
13
|
+
kernelFunc: c
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
const
|
|
15
|
+
e(G);
|
|
16
|
+
const i = {
|
|
17
17
|
kernelName: "MatMulGelu",
|
|
18
18
|
backendName: "tensorflow",
|
|
19
|
-
kernelFunc:
|
|
19
|
+
kernelFunc: c
|
|
20
20
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
e(i);
|
|
22
|
+
const f = {
|
|
23
|
+
kernelName: "MatMulGelu",
|
|
24
|
+
backendName: "webgpu",
|
|
25
|
+
kernelFunc: c
|
|
26
|
+
};
|
|
27
|
+
e(f);
|
|
28
|
+
function s(t) {
|
|
29
|
+
const { dy: u, x: n, kernel: l } = t.inputs;
|
|
30
|
+
return m(() => {
|
|
31
|
+
const a = n.matMul(l), r = M(u, a), o = r.matMul(l.transpose()), k = n.transpose().matMul(r);
|
|
32
|
+
return [o, k];
|
|
27
33
|
});
|
|
28
34
|
}
|
|
29
|
-
const
|
|
35
|
+
const g = {
|
|
30
36
|
kernelName: "MatMulGeluGrad",
|
|
31
37
|
backendName: "cpu",
|
|
32
|
-
kernelFunc:
|
|
38
|
+
kernelFunc: s
|
|
33
39
|
};
|
|
34
|
-
|
|
35
|
-
const
|
|
40
|
+
e(g);
|
|
41
|
+
const p = {
|
|
36
42
|
kernelName: "MatMulGeluGrad",
|
|
37
43
|
backendName: "tensorflow",
|
|
38
|
-
kernelFunc:
|
|
44
|
+
kernelFunc: s
|
|
45
|
+
};
|
|
46
|
+
e(p);
|
|
47
|
+
const N = {
|
|
48
|
+
kernelName: "MatMulGeluGrad",
|
|
49
|
+
backendName: "webgpu",
|
|
50
|
+
kernelFunc: s
|
|
39
51
|
};
|
|
40
|
-
|
|
52
|
+
e(N);
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
function
|
|
3
|
-
const { inputs: r, attrs:
|
|
4
|
-
return
|
|
1
|
+
import { f as e, t as i } from "../../index-UdZhlibC.js";
|
|
2
|
+
function n(t) {
|
|
3
|
+
const { inputs: r, attrs: l } = t, { transposeA: o, transposeB: s } = l, { x: u, kernel: a, y: c } = r, m = u, k = a, M = c;
|
|
4
|
+
return i(() => m.matMul(k, o, s).mul(M));
|
|
5
5
|
}
|
|
6
6
|
const f = {
|
|
7
7
|
kernelName: "MatMulMul",
|
|
8
8
|
backendName: "cpu",
|
|
9
|
-
kernelFunc:
|
|
9
|
+
kernelFunc: n
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
e(f);
|
|
12
12
|
const p = {
|
|
13
13
|
kernelName: "MatMulMul",
|
|
14
14
|
backendName: "tensorflow",
|
|
15
|
-
kernelFunc:
|
|
15
|
+
kernelFunc: n
|
|
16
16
|
};
|
|
17
|
-
|
|
17
|
+
e(p);
|
|
18
|
+
const g = {
|
|
19
|
+
kernelName: "MatMulMul",
|
|
20
|
+
backendName: "webgpu",
|
|
21
|
+
kernelFunc: n
|
|
22
|
+
};
|
|
23
|
+
e(g);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as e, a as t } from "../../index-UdZhlibC.js";
|
|
2
2
|
function n(o) {
|
|
3
|
-
const { inputs: r } = o, { a: l, b:
|
|
4
|
-
return console.warn("Using fallback mulDrop implementation without dropout."),
|
|
3
|
+
const { inputs: r } = o, { a: l, b: u } = r;
|
|
4
|
+
return console.warn("Using fallback mulDrop implementation without dropout."), t(l, u);
|
|
5
5
|
}
|
|
6
6
|
const a = {
|
|
7
7
|
kernelName: "MulDropout",
|
|
@@ -15,3 +15,9 @@ const c = {
|
|
|
15
15
|
kernelFunc: n
|
|
16
16
|
};
|
|
17
17
|
e(c);
|
|
18
|
+
const m = {
|
|
19
|
+
kernelName: "MulDropout",
|
|
20
|
+
backendName: "webgpu",
|
|
21
|
+
kernelFunc: n
|
|
22
|
+
};
|
|
23
|
+
e(m);
|
package/dist/ops/cpu/normRMS.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as o, t as d } from "../../index-UdZhlibC.js";
|
|
2
2
|
function i(t) {
|
|
3
3
|
const { inputs: e } = t, { x: n, gamma: s } = e, r = n, a = s;
|
|
4
4
|
return d(() => {
|
|
@@ -6,12 +6,12 @@ function i(t) {
|
|
|
6
6
|
return r.mul(u).mul(a);
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
|
-
const
|
|
9
|
+
const k = {
|
|
10
10
|
kernelName: "RMSNorm",
|
|
11
11
|
backendName: "cpu",
|
|
12
12
|
kernelFunc: i
|
|
13
13
|
};
|
|
14
|
-
o(
|
|
14
|
+
o(k);
|
|
15
15
|
const g = {
|
|
16
16
|
kernelName: "RMSNorm",
|
|
17
17
|
backendName: "tensorflow",
|
|
@@ -21,8 +21,8 @@ o(g);
|
|
|
21
21
|
function N(t) {
|
|
22
22
|
const { dy: e, x: n, gamma: s } = t.inputs;
|
|
23
23
|
return d(() => {
|
|
24
|
-
const r = n.shape[n.shape.length - 1], a = n.square().mean(-1, !0), m = a.add(1e-8).rsqrt(), u = n.mul(m), l = e.mul(u).sum([0, 1]), c = e.mul(s),
|
|
25
|
-
return [c.mul(m).sub(n.mul(
|
|
24
|
+
const r = n.shape[n.shape.length - 1], a = n.square().mean(-1, !0), m = a.add(1e-8).rsqrt(), u = n.mul(m), l = e.mul(u).sum([0, 1]), c = e.mul(s), f = c.mul(n).sum(-1, !0).div(r);
|
|
25
|
+
return [c.mul(m).sub(n.mul(f).mul(m).div(a.add(1e-8))), l];
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
const S = {
|
package/dist/ops/cpu/qkv.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as o } from "../../reshape-
|
|
3
|
-
import { s as x } from "../../split-
|
|
1
|
+
import { f as q } from "../../index-UdZhlibC.js";
|
|
2
|
+
import { r as o } from "../../reshape-BR0eoLYN.js";
|
|
3
|
+
import { s as x } from "../../split-CRU0PjVV.js";
|
|
4
4
|
function v(p) {
|
|
5
5
|
const { x: c, kernel: K } = p.inputs, { heads: n } = p.attrs, [s, e, t] = c.shape, a = o(c, [s * e, t]), i = a.dot(K);
|
|
6
6
|
a.dispose();
|
package/dist/ops/cpu/rope.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as F } from "../../range-
|
|
3
|
-
import { g as I } from "../../gather-
|
|
4
|
-
import { s as E } from "../../stack-
|
|
5
|
-
import { c as T } from "../../concat-
|
|
1
|
+
import { f as S } from "../../index-UdZhlibC.js";
|
|
2
|
+
import { r as F } from "../../range-D9CZhVlR.js";
|
|
3
|
+
import { g as I } from "../../gather-Bbh8DHhM.js";
|
|
4
|
+
import { s as E } from "../../stack-ikk2Y8_P.js";
|
|
5
|
+
import { c as T } from "../../concat-CbXTetof.js";
|
|
6
6
|
function U(t, c, p, o, r) {
|
|
7
7
|
const n = o.shape[3], s = p;
|
|
8
8
|
if (s > n) return o;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { v as D } from "../../scatter_nd_util-
|
|
3
|
-
import { r as k } from "../../range-
|
|
4
|
-
import { s as v } from "../../stack-
|
|
5
|
-
import { o as E } from "../../ones-
|
|
1
|
+
import { B as f, F as g, C as r, E as l, a3 as N, f as b, c as S, a as h } from "../../index-UdZhlibC.js";
|
|
2
|
+
import { v as D } from "../../scatter_nd_util-OjyAxku2.js";
|
|
3
|
+
import { r as k } from "../../range-D9CZhVlR.js";
|
|
4
|
+
import { s as v } from "../../stack-ikk2Y8_P.js";
|
|
5
|
+
import { o as E } from "../../ones-C8Mfln6-.js";
|
|
6
6
|
/**
|
|
7
7
|
* @license
|
|
8
8
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -26,14 +26,14 @@ function I(a, e, s) {
|
|
|
26
26
|
const c = { indices: n, updates: t }, o = { shape: s };
|
|
27
27
|
return l.runKernel(N, c, o);
|
|
28
28
|
}
|
|
29
|
-
const
|
|
30
|
-
function
|
|
31
|
-
const { logits: e, labels: s, dy: n } = a.inputs, t = s.shape[0], c = e.shape[1], o = k(0, t, 1, "int32"), i = v([o, s], 1), d = E([t]), u =
|
|
29
|
+
const C = /* @__PURE__ */ f({ scatterND_: I });
|
|
30
|
+
function K(a) {
|
|
31
|
+
const { logits: e, labels: s, dy: n } = a.inputs, t = s.shape[0], c = e.shape[1], o = k(0, t, 1, "int32"), i = v([o, s], 1), d = E([t]), u = C(i, d, [t, c]), p = S(e, u), m = n.reshape([t, 1]);
|
|
32
32
|
return h(p, m);
|
|
33
33
|
}
|
|
34
|
-
const
|
|
34
|
+
const L = {
|
|
35
35
|
kernelName: "EfficientScatterSub",
|
|
36
36
|
backendName: "cpu",
|
|
37
|
-
kernelFunc:
|
|
37
|
+
kernelFunc: K
|
|
38
38
|
};
|
|
39
|
-
b(
|
|
39
|
+
b(L);
|
package/dist/ops/fusedSoftmax.js
CHANGED
package/dist/ops/gatherSub.js
CHANGED