@genai-fi/nanogpt 0.18.0 → 0.19.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/Generator.js +30 -30
- package/dist/{RealDiv-ioj6Z-ox.js → RealDiv-CGwv0liw.js} +9 -9
- package/dist/{Reshape-BZC-ebeR.js → Reshape-BW__R4mZ.js} +7 -7
- package/dist/{Reshape-pwprEaej.js → Reshape-CPBkTIH2.js} +1 -1
- package/dist/TeachableLLM.js +17 -17
- package/dist/Trainer.js +97 -95
- package/dist/{axis_util-QWWgLjut.js → axis_util-GTVlo58H.js} +1 -1
- package/dist/backend.js +2 -2
- package/dist/{backend_util-qwSFfxYx.js → backend_util-GaFarB78.js} +21 -21
- package/dist/{backend_webgpu-DI2wXEC2.js → backend_webgpu-BqASlsbV.js} +8 -8
- package/dist/{broadcast_to-C_EJTVTZ.js → broadcast_to-eS93CCN_.js} +2 -2
- package/dist/checks/appendCache.js +2 -2
- package/dist/checks/attentionMask.js +5 -5
- package/dist/checks/gelu.js +2 -2
- package/dist/checks/matMulGelu.js +2 -2
- package/dist/checks/normRMS.js +6 -6
- package/dist/checks/normRMSGrad.js +3 -3
- package/dist/checks/packUnpack.js +6 -6
- package/dist/checks/qkv.js +2 -2
- package/dist/checks/rope.js +2 -2
- package/dist/{clip_by_value-CLAD4h_I.js → clip_by_value-DDA7rrcT.js} +1 -1
- package/dist/complex-DI35Q-gW.js +11 -0
- package/dist/{concat-Dqk7Xk7h.js → concat-CAQpCret.js} +5 -5
- package/dist/{concat_util-C1Mxe27t.js → concat_util-D18dJ4fD.js} +1 -1
- package/dist/{dataset-DlqAN81i.js → dataset-CGGp1z9P.js} +3 -3
- package/dist/{dropout_util-N0z8Os-K.js → dropout_util--NxWuYg2.js} +1 -1
- package/dist/{expand_dims-D0rBtgT1.js → expand_dims-Bkd1YD5x.js} +4 -4
- package/dist/{exports_initializers-DIOZQt_L.js → exports_initializers-CYzKLjN7.js} +1 -1
- package/dist/{floor-CymuCmTO.js → floor-BQtb-Azg.js} +1 -1
- package/dist/{gather-DEyjXNb1.js → gather-qIqEqaGn.js} +1 -1
- package/dist/{gelu-DpTCC3eB.js → gelu-B220X1Go.js} +1 -1
- package/dist/{gpgpu_math-3bCb5ooU.js → gpgpu_math-BwvV12df.js} +25 -25
- package/dist/{index-DSGwv2Yx.js → index-CUXkjxiT.js} +33 -33
- package/dist/{index-BQvB7LCC.js → index-CjOWnMXP.js} +15 -15
- package/dist/{kernel_funcs_utils-DGqzNlHT.js → kernel_funcs_utils-pq0CK9co.js} +6 -6
- package/dist/layers/BaseLayer.js +4 -4
- package/dist/layers/CausalSelfAttention.d.ts +1 -0
- package/dist/layers/CausalSelfAttention.js +14 -14
- package/dist/layers/LoRA.js +4 -4
- package/dist/layers/MLP.js +4 -4
- package/dist/layers/PositionEmbedding.js +5 -5
- package/dist/layers/RMSNorm.js +3 -3
- package/dist/layers/RoPECache.js +4 -4
- package/dist/layers/TiedEmbedding.js +6 -6
- package/dist/layers/TransformerBlock.d.ts +1 -0
- package/dist/layers/TransformerBlock.js +1 -1
- package/dist/layers/WeightStore.js +2 -2
- package/dist/loader/loadTransformers.js +9 -9
- package/dist/loader/oldZipLoad.js +9 -9
- package/dist/loader/save.js +38 -30
- package/dist/loader/types.d.ts +1 -0
- package/dist/main.js +9 -9
- package/dist/{matMul16-BIT70Vya.js → matMul16-BcVC_E62.js} +3 -3
- package/dist/{matMulGelu-CsZnh18H.js → matMulGelu-JNLZqKQp.js} +18 -18
- package/dist/mat_mul-DhG0Newp.js +11 -0
- package/dist/mod-CSdCpRjf.js +11 -0
- package/dist/models/NanoGPTV1.js +2 -2
- package/dist/models/NanoGPTV2.js +2 -2
- package/dist/models/model.d.ts +1 -0
- package/dist/models/model.js +9 -9
- package/dist/{not_equal-CkQKkKZy.js → not_equal-hurPF26l.js} +15 -15
- package/dist/{ones-DbVB5N58.js → ones-BytntneX.js} +3 -3
- package/dist/ops/adamAdjust.js +3 -3
- package/dist/ops/adamMoments.js +3 -3
- package/dist/ops/add16.js +1 -1
- package/dist/ops/appendCache.js +6 -6
- package/dist/ops/attentionMask.js +3 -3
- package/dist/ops/concat16.js +3 -3
- package/dist/ops/cpu/adamAdjust.js +9 -9
- package/dist/ops/cpu/adamMoments.js +5 -5
- package/dist/ops/cpu/appendCache.js +2 -2
- package/dist/ops/cpu/attentionMask.js +6 -6
- package/dist/ops/cpu/fusedSoftmax.js +4 -4
- package/dist/ops/cpu/gatherSub.js +5 -5
- package/dist/ops/cpu/gelu.js +4 -4
- package/dist/ops/cpu/matMul16.js +2 -2
- package/dist/ops/cpu/matMulGelu.js +7 -7
- package/dist/ops/cpu/matMulMul.js +2 -2
- package/dist/ops/cpu/mulDropout.js +5 -5
- package/dist/ops/cpu/normRMS.js +1 -1
- package/dist/ops/cpu/qkv.js +3 -3
- package/dist/ops/cpu/rope.js +5 -5
- package/dist/ops/cpu/scatterSub.js +5 -5
- package/dist/ops/dot16.js +2 -2
- package/dist/ops/dropout.js +6 -6
- package/dist/ops/dropout16.js +1 -1
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/gelu.js +2 -2
- package/dist/ops/globalNorm.js +7 -7
- package/dist/ops/grads/add16.js +1 -1
- package/dist/ops/grads/attentionMask.js +2 -2
- package/dist/ops/grads/dropout16.js +1 -1
- package/dist/ops/grads/gelu.js +2 -2
- package/dist/ops/grads/matMul16.js +3 -3
- package/dist/ops/grads/matMulGelu.js +1 -1
- package/dist/ops/grads/mul16.js +1 -1
- package/dist/ops/grads/normRMS.js +7 -7
- package/dist/ops/grads/pack16.js +3 -3
- package/dist/ops/grads/qkv.js +11 -11
- package/dist/ops/grads/rope.js +2 -2
- package/dist/ops/grads/softmax16.js +1 -1
- package/dist/ops/grads/unpack16.js +2 -2
- package/dist/ops/matMul16.js +3 -3
- package/dist/ops/matMulGelu.js +6 -6
- package/dist/ops/matMulMul.js +3 -3
- package/dist/ops/mul16.js +1 -1
- package/dist/ops/mulDrop.js +3 -3
- package/dist/ops/normRMS.js +4 -4
- package/dist/ops/pack16.js +2 -2
- package/dist/ops/qkv.js +3 -3
- package/dist/ops/reshape16.js +6 -6
- package/dist/ops/rope.js +2 -2
- package/dist/ops/scatterSub.js +1 -1
- package/dist/ops/slice16.js +2 -2
- package/dist/ops/softmax16.js +1 -1
- package/dist/ops/sub16.js +1 -1
- package/dist/ops/sum16.js +6 -6
- package/dist/ops/transpose16.js +3 -3
- package/dist/ops/unpack16.js +2 -2
- package/dist/ops/webgl/adamAdjust.js +2 -2
- package/dist/ops/webgl/adamMoments.js +1 -1
- package/dist/ops/webgl/appendCache.js +1 -1
- package/dist/ops/webgl/attentionMask.js +1 -1
- package/dist/ops/webgl/dropout16.js +1 -1
- package/dist/ops/webgl/fusedSoftmax.js +7 -7
- package/dist/ops/webgl/gatherSub.js +3 -3
- package/dist/ops/webgl/gelu.js +2 -2
- package/dist/ops/webgl/log.js +3 -3
- package/dist/ops/webgl/matMul16.js +13 -13
- package/dist/ops/webgl/matMulGelu.js +4 -4
- package/dist/ops/webgl/matMulMul.js +2 -2
- package/dist/ops/webgl/mulDropout.js +1 -1
- 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 +2 -2
- package/dist/ops/webgpu/adamAdjust.js +3 -3
- package/dist/ops/webgpu/adamMoments.js +3 -3
- package/dist/ops/webgpu/add16.js +6 -6
- package/dist/ops/webgpu/appendCache.js +3 -3
- package/dist/ops/webgpu/attentionMask.js +2 -2
- package/dist/ops/webgpu/attentionMask32_program.js +2 -2
- package/dist/ops/webgpu/clipScale.js +7 -7
- package/dist/ops/webgpu/concat16.js +5 -5
- package/dist/ops/webgpu/dropout16.js +6 -6
- package/dist/ops/webgpu/gatherSub.js +3 -3
- package/dist/ops/webgpu/gelu.js +8 -8
- package/dist/ops/webgpu/matMul16.js +16 -16
- package/dist/ops/webgpu/matMul16_program.js +2 -2
- package/dist/ops/webgpu/mul16.js +5 -5
- package/dist/ops/webgpu/norm2.js +1 -1
- package/dist/ops/webgpu/normRMS.js +2 -2
- package/dist/ops/webgpu/normRMSGrad.js +4 -4
- package/dist/ops/webgpu/pack16.js +4 -4
- package/dist/ops/webgpu/pack16_program.js +2 -2
- package/dist/ops/webgpu/qkv.js +2 -2
- package/dist/ops/webgpu/rope.js +3 -3
- package/dist/ops/webgpu/scatterSub.js +3 -3
- package/dist/ops/webgpu/slice16.js +4 -4
- package/dist/ops/webgpu/softmax16.js +4 -4
- package/dist/ops/webgpu/softmax16_program.js +2 -2
- package/dist/ops/webgpu/softmax16_subgroup_program.js +2 -2
- package/dist/ops/webgpu/softmax16grad.js +4 -4
- package/dist/ops/webgpu/sub16.js +6 -6
- package/dist/ops/webgpu/sum16.js +3 -3
- package/dist/ops/webgpu/transpose16.js +8 -8
- package/dist/ops/webgpu/transpose16_program.js +2 -2
- package/dist/ops/webgpu/transpose16_shared_program.js +3 -3
- package/dist/ops/webgpu/unpack16.js +3 -3
- package/dist/ops/webgpu/utils/binary_op.js +3 -3
- package/dist/ops/webgpu/utils/reductions.js +5 -5
- package/dist/{ops-CURIZSVt.js → ops-CsXeTq1P.js} +100 -100
- package/dist/{pack16-WlOSOuZA.js → pack16-bqltoUlR.js} +2 -2
- package/dist/patches/webgpu_backend.js +6 -6
- package/dist/patches/webgpu_base.js +1 -1
- package/dist/patches/webgpu_program.js +2 -2
- package/dist/{random_normal-CIm8lk2-.js → random_normal-IBRrha8a.js} +1 -1
- package/dist/{random_width-B_fVXhGx.js → random_width-DN5ZtQkM.js} +131 -131
- package/dist/{range-BDxO73mk.js → range-C-CjF-LI.js} +1 -1
- package/dist/relu-J_X6MUzx.js +9 -0
- package/dist/{reshape-BIN71H3p.js → reshape-BDOuCSNW.js} +1 -1
- package/dist/{resize_nearest_neighbor-C6_0dAnK.js → resize_nearest_neighbor-BojqlfRe.js} +41 -41
- package/dist/{rope-CC5RjmKU.js → rope-DcrZM_e6.js} +5 -5
- package/dist/{scatter_nd_util-C-x73Cj6.js → scatter_nd_util-ByNJaL6I.js} +1 -1
- package/dist/{segment_util-4zuHV5IG.js → segment_util-Dasb2Zaf.js} +2 -2
- package/dist/{selu_util-BXdhy_W6.js → selu_util-BLhIqRkw.js} +5 -5
- package/dist/{shared-zTaJ5siv.js → shared-3agzAqQ_.js} +1 -1
- package/dist/{shared-DRWDyk9w.js → shared-CagdqkLh.js} +6 -6
- package/dist/slice-BzS11Qh0.js +12 -0
- package/dist/{slice_util-DPY56GzQ.js → slice_util-CC35pLmT.js} +5 -5
- package/dist/{softmax-BLGJqdwx.js → softmax-D4q1LJN7.js} +1 -1
- package/dist/split-C2Sj255c.js +9 -0
- package/dist/{squeeze-O_YWJpw_.js → squeeze-ho4wLUek.js} +2 -2
- package/dist/{stack-z6QE7kmP.js → stack-DudVrtmG.js} +1 -1
- package/dist/{step-DQY6_ABw.js → step-BTxPtq1r.js} +4 -4
- package/dist/{sum-D39FeU5h.js → sum-BpiwSWvg.js} +3 -3
- package/dist/{tensor-D8e0Gd7c.js → tensor-BWFldCso.js} +1 -1
- package/dist/{tensor1d-BMl0eZYV.js → tensor1d-LMGMIUlr.js} +1 -1
- package/dist/{tensor2d-DTtQ1QcT.js → tensor2d-BnXMKScO.js} +1 -1
- package/dist/{tensor4d-Dj4rDssL.js → tensor4d-C6UCG_u8.js} +1 -1
- package/dist/{tfjs_backend-Bk3PmK91.js → tfjs_backend-BGnG-ppu.js} +65 -65
- package/dist/{tile-CsWlVKKz.js → tile-CFy-xTO6.js} +1 -1
- package/dist/tokeniser/BaseTokeniser.d.ts +5 -1
- package/dist/tokeniser/BaseTokeniser.js +62 -53
- package/dist/tokeniser/type.d.ts +8 -0
- package/dist/training/AdamW.js +2 -2
- package/dist/training/BasicTrainer.d.ts +1 -0
- package/dist/training/BasicTrainer.js +95 -79
- package/dist/training/DatasetBuilder.d.ts +6 -2
- package/dist/training/DatasetBuilder.js +60 -41
- package/dist/training/Evaluator.d.ts +1 -2
- package/dist/training/Evaluator.js +21 -31
- package/dist/training/SFTTrainer.d.ts +3 -2
- package/dist/training/SFTTrainer.js +4 -3
- package/dist/training/orthoGrad.js +1 -1
- package/dist/training/sparseCrossEntropy.js +38 -38
- package/dist/training/tasks/ConversationTask.d.ts +4 -0
- package/dist/training/tasks/ConversationTask.js +7 -7
- package/dist/training/tasks/PretrainingTask.d.ts +4 -0
- package/dist/training/tasks/PretrainingTask.js +11 -7
- package/dist/training/tasks/StartSentenceTask.d.ts +4 -0
- package/dist/training/tasks/StartSentenceTask.js +5 -5
- package/dist/training/tasks/Task.d.ts +12 -0
- package/dist/training/tasks/Task.js +55 -31
- package/dist/training/types.d.ts +1 -0
- package/dist/training/validation.d.ts +1 -1
- package/dist/training/validation.js +33 -32
- package/dist/{transpose-Qxz-4os3.js → transpose-9kRxIXWR.js} +7 -7
- package/dist/{unsorted_segment_sum-BfFVV9Zm.js → unsorted_segment_sum-DJvk5xnh.js} +20 -20
- package/dist/utilities/dummy.js +6 -6
- package/dist/utilities/multinomialCPU.js +2 -2
- package/dist/utilities/packed.js +1 -1
- package/dist/utilities/performance.js +1 -1
- package/dist/utilities/profile.js +1 -1
- package/dist/utilities/safetensors.js +2 -2
- package/dist/utilities/sentences.js +5 -5
- package/dist/utilities/weights.js +2 -2
- package/dist/{variable-SSATClyt.js → variable-Ck482e3n.js} +1 -1
- package/dist/{webgpu_program-CbjdYLYk.js → webgpu_program-B4HmApL1.js} +1 -1
- package/dist/{webgpu_util-DuofJBMo.js → webgpu_util-DYlGSwOJ.js} +7 -7
- package/dist/{zeros-Bw0puq_w.js → zeros-DvZpK8s6.js} +2 -2
- package/dist/{zeros_like-rOHr54NY.js → zeros_like-CWjDdwr-.js} +69 -69
- package/package.json +1 -1
- package/dist/complex-3DpPEG9B.js +0 -11
- package/dist/mat_mul-DP86qZtZ.js +0 -11
- package/dist/mod-BXjLYwvM.js +0 -11
- package/dist/readers-17HLdxVM.js +0 -12
- package/dist/relu-DTvZKBsZ.js +0 -9
- package/dist/slice-BvItlgXu.js +0 -12
- package/dist/split-BN9LkEgS.js +0 -9
- package/dist/training/SFTDatasetBuilder.d.ts +0 -23
- package/dist/training/SFTDatasetBuilder.js +0 -85
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
import { gatherSub as
|
|
1
|
+
import { gatherSub as $ } from "../ops/gatherSub.js";
|
|
2
2
|
import { scatterSub as T } from "../ops/scatterSub.js";
|
|
3
|
-
import { t as
|
|
4
|
-
import { m as J, l as K, a as E, n as N, w as O } from "../not_equal-
|
|
5
|
-
import { s as m } from "../sum-
|
|
6
|
-
import { s as Q } from "../softmax-
|
|
7
|
-
function R(e,
|
|
8
|
-
return
|
|
9
|
-
const S = e.shape[e.shape.length - 1], i = v || e.shape.slice(0, -1),
|
|
3
|
+
import { t as F, a1 as G, j as A, m as x, i as U, a2 as D, a as j, a3 as q } from "../index-CUXkjxiT.js";
|
|
4
|
+
import { m as J, l as K, a as E, n as N, w as O } from "../not_equal-hurPF26l.js";
|
|
5
|
+
import { s as m } from "../sum-BpiwSWvg.js";
|
|
6
|
+
import { s as Q } from "../softmax-D4q1LJN7.js";
|
|
7
|
+
function R(e, l, a, g, v, t = 0) {
|
|
8
|
+
return F(() => {
|
|
9
|
+
const S = e.shape[e.shape.length - 1], i = v || e.shape.slice(0, -1), f = i.reduce((c, d) => c * d, 1), h = e.shape.length > 2 ? e.reshape([f, S]) : e, y = l.shape.length > 1 ? l.reshape([f]).cast("int32") : l.cast("int32"), u = J(h, -1, !0), o = G(h, u), n = K(o, -1), p = $(n, y, o);
|
|
10
10
|
let s;
|
|
11
|
-
if (
|
|
12
|
-
const
|
|
13
|
-
s = A(x(
|
|
11
|
+
if (t > 0) {
|
|
12
|
+
const c = G(n, E(o, -1));
|
|
13
|
+
s = A(x(p, 1 - t), x(c, t));
|
|
14
14
|
} else
|
|
15
|
-
s =
|
|
16
|
-
if (
|
|
17
|
-
if (s = x(s,
|
|
18
|
-
const
|
|
19
|
-
s = U(m(s.reshape(i), -1),
|
|
15
|
+
s = p;
|
|
16
|
+
if (a)
|
|
17
|
+
if (s = x(s, a), g) {
|
|
18
|
+
const c = m(a.reshape(i), -1);
|
|
19
|
+
s = U(m(s.reshape(i), -1), c);
|
|
20
20
|
} else {
|
|
21
|
-
const
|
|
22
|
-
s = U(m(s),
|
|
21
|
+
const c = m(a);
|
|
22
|
+
s = U(m(s), c);
|
|
23
23
|
}
|
|
24
24
|
else
|
|
25
25
|
g ? s = E(s.reshape(i), -1) : s = E(s);
|
|
26
26
|
return s;
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
function as(e, l, a = 0) {
|
|
30
30
|
return D(
|
|
31
31
|
// @ts-expect-error Invalid params
|
|
32
|
-
(
|
|
33
|
-
const
|
|
34
|
-
let
|
|
32
|
+
(t, S, i) => {
|
|
33
|
+
const f = t.shape[t.shape.length - 1], h = t.shape.slice(0, -1), y = h.reduce((d, r) => d * r, 1), u = t.reshape([y, f]), o = S.reshape([y]).cast("int32");
|
|
34
|
+
let n, p = null;
|
|
35
35
|
if (e) {
|
|
36
|
-
const
|
|
37
|
-
|
|
36
|
+
const d = j(65535, "int32"), r = N(o, d);
|
|
37
|
+
p = r.cast("float32"), n = O(r, o, q(o)), d.dispose(), r.dispose();
|
|
38
38
|
} else
|
|
39
|
-
|
|
39
|
+
n = o;
|
|
40
40
|
const s = R(
|
|
41
41
|
u,
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
n,
|
|
43
|
+
p || void 0,
|
|
44
|
+
l,
|
|
44
45
|
h,
|
|
45
|
-
|
|
46
|
-
t
|
|
46
|
+
a
|
|
47
47
|
);
|
|
48
|
-
return i(
|
|
49
|
-
const C =
|
|
48
|
+
return i(p ? [u, n, p] : [u, n]), u.dispose(), o.dispose(), { value: s, gradFunc: (d, r) => F(() => {
|
|
49
|
+
const C = r[0], z = r[1], b = e ? r[2] : void 0, w = Q(C), H = b ? m(b) : j(C.shape[0], "float32"), I = d.div(H).broadcastTo([C.shape[0]]), M = b && e ? x(I, b) : I;
|
|
50
50
|
let L;
|
|
51
|
-
if (
|
|
52
|
-
const
|
|
51
|
+
if (a > 0) {
|
|
52
|
+
const V = a / f, W = G(w, V);
|
|
53
53
|
L = T(
|
|
54
|
-
|
|
54
|
+
W,
|
|
55
55
|
z,
|
|
56
|
-
x(M, 1 -
|
|
56
|
+
x(M, 1 - a)
|
|
57
57
|
);
|
|
58
58
|
} else
|
|
59
59
|
L = T(w, z, M);
|
|
60
|
-
const
|
|
61
|
-
return [L.reshape(
|
|
60
|
+
const P = q(S);
|
|
61
|
+
return [L.reshape(t.shape), P];
|
|
62
62
|
}) };
|
|
63
63
|
}
|
|
64
64
|
);
|
|
65
65
|
}
|
|
66
66
|
export {
|
|
67
|
-
|
|
67
|
+
as as createSoftmaxCrossEntropyWithGrad,
|
|
68
68
|
R as sparseSoftmaxCrossEntropy
|
|
69
69
|
};
|
|
@@ -9,6 +9,10 @@ export default class ConversationTask extends Task {
|
|
|
9
9
|
hasMoreConversations(): boolean;
|
|
10
10
|
nextConversation(): Conversation[] | null;
|
|
11
11
|
nextTokens(tokeniser: ITokeniser): number[] | null;
|
|
12
|
+
nextTokens(tokeniser: ITokeniser, masking: boolean): {
|
|
13
|
+
tokens: number[];
|
|
14
|
+
mask: boolean[];
|
|
15
|
+
} | null;
|
|
12
16
|
shuffle(): void;
|
|
13
17
|
estimateTokens(tokeniser: ITokeniser): Promise<number>;
|
|
14
18
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Task as t } from "./Task.js";
|
|
2
|
-
import { shuffle as
|
|
3
|
-
class
|
|
2
|
+
import { shuffle as i } from "../DatasetBuilder.js";
|
|
3
|
+
class f extends t {
|
|
4
4
|
rawConvo;
|
|
5
5
|
shuffledIndices = null;
|
|
6
6
|
index = 0;
|
|
@@ -19,9 +19,9 @@ class a extends t {
|
|
|
19
19
|
const n = this.rawConvo[this.shuffledIndices ? this.shuffledIndices[this.index] : this.index];
|
|
20
20
|
return this.index++, n;
|
|
21
21
|
}
|
|
22
|
-
nextTokens(n) {
|
|
22
|
+
nextTokens(n, s) {
|
|
23
23
|
const e = this.nextConversation();
|
|
24
|
-
return e ? n.encodeConversation(e) : null;
|
|
24
|
+
return e ? n.encodeConversation(e, !1, s) : null;
|
|
25
25
|
}
|
|
26
26
|
shuffle() {
|
|
27
27
|
if (!this.shuffledIndices) {
|
|
@@ -29,12 +29,12 @@ class a extends t {
|
|
|
29
29
|
for (let n = 0; n < this.rawConvo.length; n++)
|
|
30
30
|
this.shuffledIndices[n] = n;
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
i(this.shuffledIndices), this.index = 0;
|
|
33
33
|
}
|
|
34
34
|
async estimateTokens(n) {
|
|
35
|
-
return
|
|
35
|
+
return n.encodeConversation(this.rawConvo[0]).length * this.length;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
export {
|
|
39
|
-
|
|
39
|
+
f as default
|
|
40
40
|
};
|
|
@@ -8,6 +8,10 @@ export default class PretrainingTask extends Task {
|
|
|
8
8
|
hasMoreConversations(): boolean;
|
|
9
9
|
nextConversation(): Conversation[] | null;
|
|
10
10
|
nextTokens(tokeniser: ITokeniser): number[] | null;
|
|
11
|
+
nextTokens(tokeniser: ITokeniser, masking: boolean): {
|
|
12
|
+
tokens: number[];
|
|
13
|
+
mask: boolean[];
|
|
14
|
+
} | null;
|
|
11
15
|
shuffle(): void;
|
|
12
16
|
estimateTokens(tokeniser: ITokeniser): Promise<number>;
|
|
13
17
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Task as
|
|
2
|
-
class
|
|
1
|
+
import { Task as r } from "./Task.js";
|
|
2
|
+
class h extends r {
|
|
3
3
|
rawText;
|
|
4
4
|
index = 0;
|
|
5
5
|
get length() {
|
|
@@ -20,24 +20,28 @@ class r extends n {
|
|
|
20
20
|
};
|
|
21
21
|
return this.index++, [t];
|
|
22
22
|
}
|
|
23
|
-
nextTokens(t) {
|
|
23
|
+
nextTokens(t, n) {
|
|
24
24
|
if (this.index >= this.rawText.length)
|
|
25
25
|
return null;
|
|
26
26
|
const e = t.encodeSequence(this.rawText[this.index]);
|
|
27
|
-
|
|
27
|
+
if (this.index++, n) {
|
|
28
|
+
const s = new Array(e.length).fill(!0);
|
|
29
|
+
return { tokens: e, mask: s };
|
|
30
|
+
}
|
|
31
|
+
return e;
|
|
28
32
|
}
|
|
29
33
|
shuffle() {
|
|
30
34
|
this.index = 0;
|
|
31
35
|
}
|
|
32
36
|
async estimateTokens(t) {
|
|
33
|
-
return
|
|
37
|
+
return t.encodeConversation([
|
|
34
38
|
{
|
|
35
39
|
role: "assistant",
|
|
36
40
|
content: this.rawText[0]
|
|
37
41
|
}
|
|
38
|
-
])
|
|
42
|
+
]).length * this.length;
|
|
39
43
|
}
|
|
40
44
|
}
|
|
41
45
|
export {
|
|
42
|
-
|
|
46
|
+
h as default
|
|
43
47
|
};
|
|
@@ -8,6 +8,10 @@ export default class StartSentenceTask extends Task {
|
|
|
8
8
|
hasMoreConversations(): boolean;
|
|
9
9
|
nextConversation(): Conversation[] | null;
|
|
10
10
|
nextTokens(tokeniser: ITokeniser): number[] | null;
|
|
11
|
+
nextTokens(tokeniser: ITokeniser, masking: boolean): {
|
|
12
|
+
tokens: number[];
|
|
13
|
+
mask: boolean[];
|
|
14
|
+
} | null;
|
|
11
15
|
shuffle(): void;
|
|
12
16
|
private conversationFromString;
|
|
13
17
|
estimateTokens(tokeniser: ITokeniser): Promise<number>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Task as
|
|
2
|
-
class a extends
|
|
1
|
+
import { Task as r } from "./Task.js";
|
|
2
|
+
class a extends r {
|
|
3
3
|
rawText;
|
|
4
4
|
index = 0;
|
|
5
5
|
get length() {
|
|
@@ -17,9 +17,9 @@ class a extends e {
|
|
|
17
17
|
const t = this.rawText[this.index];
|
|
18
18
|
return this.index++, this.conversationFromString(t);
|
|
19
19
|
}
|
|
20
|
-
nextTokens(t) {
|
|
21
|
-
const
|
|
22
|
-
return
|
|
20
|
+
nextTokens(t, n) {
|
|
21
|
+
const e = this.nextConversation();
|
|
22
|
+
return e ? t.encodeConversation(e, !1, n) : null;
|
|
23
23
|
}
|
|
24
24
|
shuffle() {
|
|
25
25
|
this.index = 0;
|
|
@@ -4,7 +4,19 @@ export declare abstract class Task {
|
|
|
4
4
|
abstract hasMoreConversations(): boolean;
|
|
5
5
|
abstract nextConversation(): Conversation[] | null;
|
|
6
6
|
abstract nextTokens(tokeniser: ITokeniser): number[] | null;
|
|
7
|
+
abstract nextTokens(tokeniser: ITokeniser, masking: boolean): {
|
|
8
|
+
tokens: number[];
|
|
9
|
+
mask: boolean[];
|
|
10
|
+
} | null;
|
|
11
|
+
abstract nextTokens(tokeniser: ITokeniser, masking?: boolean): number[] | {
|
|
12
|
+
tokens: number[];
|
|
13
|
+
mask: boolean[];
|
|
14
|
+
} | null;
|
|
7
15
|
abstract estimateTokens(tokeniser: ITokeniser): Promise<number>;
|
|
8
16
|
abstract shuffle(): void;
|
|
9
17
|
}
|
|
10
18
|
export declare function tokensFromTasks(tasks: Task[], tokenizer: ITokeniser, cb?: (tokens: number) => void): Promise<Uint16Array>;
|
|
19
|
+
export declare function tokensFromTasks(tasks: Task[], tokenizer: ITokeniser, cb?: (tokens: number) => void, masking?: boolean): Promise<{
|
|
20
|
+
tokens: Uint16Array;
|
|
21
|
+
mask: Uint8Array;
|
|
22
|
+
}>;
|
|
@@ -1,44 +1,68 @@
|
|
|
1
|
-
import { yieldIfNeeded as
|
|
2
|
-
class
|
|
1
|
+
import { yieldIfNeeded as k } from "../../utilities/yielder.js";
|
|
2
|
+
class w {
|
|
3
3
|
}
|
|
4
|
-
function
|
|
5
|
-
for (const
|
|
6
|
-
const
|
|
7
|
-
if (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
c.
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
function m(y, i, u, o, g, n) {
|
|
5
|
+
for (const a of y) {
|
|
6
|
+
const e = a.nextTokens(u, n ? !0 : void 0);
|
|
7
|
+
if (e) {
|
|
8
|
+
const f = Array.isArray(e) ? e : e.tokens;
|
|
9
|
+
o.total += f.length;
|
|
10
|
+
const c = i[i.length - 1], l = n ? n[n.length - 1] : null;
|
|
11
|
+
if (o.offset + f.length > c.length) {
|
|
12
|
+
const s = c.length - o.offset;
|
|
13
|
+
c.set(f.slice(0, s), o.offset);
|
|
14
|
+
const t = new Uint16Array(Math.floor(g * 0.1) + 100);
|
|
15
|
+
if (t.set(f.slice(s), 0), i.push(t), n && l && !Array.isArray(e)) {
|
|
16
|
+
l.set(
|
|
17
|
+
e.mask.slice(0, s).map((h) => h ? 1 : 0),
|
|
18
|
+
o.offset
|
|
19
|
+
);
|
|
20
|
+
const r = new Uint8Array(t.length);
|
|
21
|
+
r.set(
|
|
22
|
+
e.mask.slice(s).map((h) => h ? 1 : 0),
|
|
23
|
+
0
|
|
24
|
+
), n.push(r);
|
|
25
|
+
}
|
|
26
|
+
o.offset = f.length - s;
|
|
15
27
|
} else
|
|
16
|
-
c.set(
|
|
28
|
+
c.set(f, o.offset), l && !Array.isArray(e) && l.set(
|
|
29
|
+
e.mask.map((s) => s ? 1 : 0),
|
|
30
|
+
o.offset
|
|
31
|
+
), o.offset += f.length;
|
|
17
32
|
}
|
|
18
33
|
}
|
|
19
34
|
}
|
|
20
|
-
async function
|
|
21
|
-
const
|
|
22
|
-
(await Promise.all(
|
|
23
|
-
|
|
24
|
-
), n = [new Uint16Array(
|
|
35
|
+
async function p(y, i, u, o) {
|
|
36
|
+
const g = Math.min(
|
|
37
|
+
(await Promise.all(y.map((t) => t.estimateTokens(i)))).reduce((t, r) => t + r, 0),
|
|
38
|
+
i.vocabSize * 1e4
|
|
39
|
+
), n = [new Uint16Array(g)], a = o ? [new Uint8Array(g)] : null, e = {
|
|
25
40
|
offset: 0,
|
|
26
41
|
total: 0
|
|
27
42
|
};
|
|
28
|
-
let
|
|
29
|
-
for (;
|
|
30
|
-
|
|
43
|
+
let f = performance.now();
|
|
44
|
+
for (; e.offset < g && (m(y, n, i, e, g, a || void 0), !y.every((t) => !t.hasMoreConversations())); )
|
|
45
|
+
f = await k(f, u, e.total);
|
|
31
46
|
if (n.length === 1)
|
|
32
|
-
return n[0].subarray(0,
|
|
33
|
-
const c = n.reduce((
|
|
34
|
-
let
|
|
35
|
-
for (let
|
|
36
|
-
const
|
|
37
|
-
|
|
47
|
+
return a ? { tokens: n[0].subarray(0, e.offset), mask: a[0].subarray(0, e.offset) } : n[0].subarray(0, e.offset);
|
|
48
|
+
const c = n.reduce((t, r) => t + r.length, 0) - (n[n.length - 1].length - e.offset), l = new Uint16Array(c);
|
|
49
|
+
let s = 0;
|
|
50
|
+
for (let t = 0; t < n.length; t++) {
|
|
51
|
+
const r = n[t];
|
|
52
|
+
t === n.length - 1 ? (l.set(r.subarray(0, e.offset), s), s += e.offset) : (l.set(r, s), s += r.length);
|
|
38
53
|
}
|
|
39
|
-
|
|
54
|
+
if (a) {
|
|
55
|
+
const t = new Uint8Array(c);
|
|
56
|
+
s = 0;
|
|
57
|
+
for (let r = 0; r < a.length; r++) {
|
|
58
|
+
const h = a[r];
|
|
59
|
+
r === a.length - 1 ? (t.set(h.subarray(0, e.offset), s), s += e.offset) : (t.set(h, s), s += h.length);
|
|
60
|
+
}
|
|
61
|
+
return { tokens: l, mask: t };
|
|
62
|
+
}
|
|
63
|
+
return l;
|
|
40
64
|
}
|
|
41
65
|
export {
|
|
42
|
-
|
|
43
|
-
|
|
66
|
+
w as Task,
|
|
67
|
+
p as tokensFromTasks
|
|
44
68
|
};
|
package/dist/training/types.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ITokeniser, Task } from '../main';
|
|
|
2
2
|
import { Tensor } from '@tensorflow/tfjs-core';
|
|
3
3
|
import { Dataset } from '@tensorflow/tfjs-data';
|
|
4
4
|
import { DatasetBuilder, DatasetState } from './DatasetBuilder';
|
|
5
|
-
export declare function createTrainValidationSplit(tasks: Task[] | Uint16Array, tokeniser: ITokeniser, datasetBuilder: DatasetBuilder, batchSize: number, validationSplit?: number): Promise<{
|
|
5
|
+
export declare function createTrainValidationSplit(tasks: Task[] | Uint16Array, tokeniser: ITokeniser, datasetBuilder: DatasetBuilder, batchSize: number, validationSplit?: number, masking?: boolean): Promise<{
|
|
6
6
|
trainDataset: Dataset<{
|
|
7
7
|
xs: Tensor;
|
|
8
8
|
ys: Tensor;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import "../index-
|
|
2
|
-
import "../random_width-
|
|
3
|
-
import "../zeros_like-
|
|
1
|
+
import "../index-CUXkjxiT.js";
|
|
2
|
+
import "../random_width-DN5ZtQkM.js";
|
|
3
|
+
import "../zeros_like-CWjDdwr-.js";
|
|
4
4
|
import "../Generator.js";
|
|
5
5
|
import "../index-Cp39cXWe.js";
|
|
6
|
-
import "../dataset-
|
|
6
|
+
import "../dataset-CGGp1z9P.js";
|
|
7
7
|
import "../ops/cpu/attentionMask.js";
|
|
8
8
|
import "../ops/webgl/attentionMask.js";
|
|
9
9
|
import "../ops/grads/attentionMask.js";
|
|
10
10
|
import "../ops/cpu/rope.js";
|
|
11
11
|
import "../ops/webgl/rope.js";
|
|
12
|
-
import "../rope-
|
|
12
|
+
import "../rope-DcrZM_e6.js";
|
|
13
13
|
import "../ops/cpu/appendCache.js";
|
|
14
14
|
import "../ops/webgl/appendCache.js";
|
|
15
15
|
import "../ops/grads/softmax16.js";
|
|
16
|
-
import "../matMul16-
|
|
16
|
+
import "../matMul16-BcVC_E62.js";
|
|
17
17
|
import "../ops/webgl/matMul16.js";
|
|
18
18
|
import "../ops/cpu/matMul16.js";
|
|
19
|
-
import "../pack16-
|
|
19
|
+
import "../pack16-bqltoUlR.js";
|
|
20
20
|
import "../ops/transpose16.js";
|
|
21
21
|
import "../ops/reshape16.js";
|
|
22
22
|
import "../ops/cpu/qkv.js";
|
|
@@ -38,46 +38,47 @@ import "../ops/cpu/gatherSub.js";
|
|
|
38
38
|
import "../ops/webgl/gatherSub.js";
|
|
39
39
|
import "../ops/cpu/scatterSub.js";
|
|
40
40
|
import "../ops/webgl/scatterSub.js";
|
|
41
|
-
import { PAGE_FACTOR as
|
|
42
|
-
import { tokensFromTasks as k } from "./tasks/Task.js";
|
|
41
|
+
import { PAGE_FACTOR as a, shuffle as k } from "./DatasetBuilder.js";
|
|
43
42
|
import "../papaparse.min-C0cScC2i.js";
|
|
43
|
+
import { tokensFromTasks as y } from "./tasks/Task.js";
|
|
44
44
|
import "../ops/cpu/matMulGelu.js";
|
|
45
|
-
import "../matMulGelu-
|
|
45
|
+
import "../matMulGelu-JNLZqKQp.js";
|
|
46
46
|
import "../ops/grads/matMulGelu.js";
|
|
47
47
|
import "../ops/cpu/gelu.js";
|
|
48
48
|
import "../ops/webgl/gelu.js";
|
|
49
|
-
import "../gelu-
|
|
49
|
+
import "../gelu-B220X1Go.js";
|
|
50
50
|
import "../ops/webgl/log.js";
|
|
51
51
|
import "../checks/normRMS.js";
|
|
52
52
|
import "../checks/normRMSGrad.js";
|
|
53
|
-
async function
|
|
54
|
-
const
|
|
55
|
-
if (
|
|
56
|
-
const t = Math.floor(i.length / (o.blockSize *
|
|
57
|
-
for (;
|
|
58
|
-
const
|
|
59
|
-
|
|
53
|
+
async function Mt(n, x, o, l, c = 0.1, d) {
|
|
54
|
+
const r = n instanceof Uint16Array ? n : await y(n, x, void 0, d), i = r instanceof Uint16Array ? r : r.tokens, f = r instanceof Uint16Array ? void 0 : r.mask, m = /* @__PURE__ */ new Set();
|
|
55
|
+
if (c > 0) {
|
|
56
|
+
const t = Math.floor(i.length / (o.blockSize * a)), s = Math.max(1, Math.floor(t * c));
|
|
57
|
+
for (; m.size < s; ) {
|
|
58
|
+
const M = Math.floor(Math.random() * t);
|
|
59
|
+
m.add(M);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
const
|
|
63
|
-
i.length -
|
|
64
|
-
), e = new Uint32Array(
|
|
65
|
-
let
|
|
62
|
+
const p = new Uint32Array(
|
|
63
|
+
i.length - m.size * o.blockSize * a
|
|
64
|
+
), e = new Uint32Array(m.size * o.blockSize * a);
|
|
65
|
+
let h = 0, g = 0;
|
|
66
66
|
for (let t = 0; t < i.length; t++) {
|
|
67
|
-
const
|
|
68
|
-
|
|
67
|
+
const s = Math.floor(t / (o.blockSize * a));
|
|
68
|
+
m.has(s) ? g < e.length && (e[g++] = t) : h < p.length && (p[h++] = t);
|
|
69
69
|
}
|
|
70
|
-
const { dataset:
|
|
70
|
+
const { dataset: v, state: w } = await o.createTextDataset(
|
|
71
71
|
i,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
l,
|
|
73
|
+
k(p),
|
|
74
|
+
f || void 0
|
|
75
|
+
), { dataset: z, state: A } = await o.createTextDataset(
|
|
75
76
|
i,
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
l,
|
|
78
|
+
k(e)
|
|
78
79
|
);
|
|
79
|
-
return { trainDataset:
|
|
80
|
+
return { trainDataset: v, validationDataset: z, size: i.length, validationState: A, trainState: w };
|
|
80
81
|
}
|
|
81
82
|
export {
|
|
82
|
-
|
|
83
|
+
Mt as createTrainValidationSplit
|
|
83
84
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { o as u,
|
|
2
|
-
import { c as k } from "./complex-
|
|
1
|
+
import { o as u, q as i, E as o, ao as $, ap as g, aq as x, x as l, t as m, ar as p } from "./index-CUXkjxiT.js";
|
|
2
|
+
import { c as k } from "./complex-DI35Q-gW.js";
|
|
3
3
|
function K(r) {
|
|
4
4
|
const e = { input: i(r, "input", "imag") };
|
|
5
5
|
return o.runKernel($, e);
|
|
@@ -12,25 +12,25 @@ function E(r) {
|
|
|
12
12
|
const _ = /* @__PURE__ */ u({ neg_: E });
|
|
13
13
|
function b(r) {
|
|
14
14
|
const e = { input: i(r, "input", "real") };
|
|
15
|
-
return o.runKernel(
|
|
15
|
+
return o.runKernel(x, e);
|
|
16
16
|
}
|
|
17
17
|
const d = /* @__PURE__ */ u({ real_: b });
|
|
18
|
-
function
|
|
18
|
+
function N(r, t, e) {
|
|
19
19
|
const n = i(r, "x", "transpose");
|
|
20
20
|
if (t == null && (t = n.shape.map((s, a) => a).reverse()), l(n.rank === t.length, () => `Error in transpose: rank of input ${n.rank} must match length of perm ${t}.`), t.forEach((s) => {
|
|
21
21
|
l(s >= 0 && s < n.rank, () => `All entries in 'perm' must be between 0 and ${n.rank - 1} but got ${t}`);
|
|
22
22
|
}), n.rank <= 1)
|
|
23
23
|
return n.clone();
|
|
24
24
|
const f = { x: n }, c = { perm: t };
|
|
25
|
-
return n.dtype === "complex64" ?
|
|
25
|
+
return n.dtype === "complex64" ? m(() => {
|
|
26
26
|
let s = d(n), a = h(n);
|
|
27
27
|
return s = o.runKernel(p, { x: s }, c), a = o.runKernel(p, { x: a }, c), e && (a = _(a)), k(s, a);
|
|
28
28
|
}) : o.runKernel(p, f, c);
|
|
29
29
|
}
|
|
30
|
-
const
|
|
30
|
+
const v = /* @__PURE__ */ u({ transpose_: N });
|
|
31
31
|
export {
|
|
32
32
|
h as i,
|
|
33
33
|
_ as n,
|
|
34
34
|
d as r,
|
|
35
|
-
|
|
35
|
+
v as t
|
|
36
36
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { o as h,
|
|
2
|
-
import { k as C, c as g, m as D } from "./step-
|
|
3
|
-
import { r as b } from "./reshape-
|
|
4
|
-
import { m as pn, b as hn, e as w } from "./not_equal-
|
|
5
|
-
import { s as K } from "./sum-
|
|
1
|
+
import { o as h, q as c, E as d, bm as T, bn as q, bo as H, x as l, bp as P, L as _, bq as y, br as B, bs as I, bt as W, bu as A, bv as L, bw as G, bx as O, by as z, bz as F, B as M, _ as j, bA as J, bB as U, bC as V, a2 as Q, a1 as N, m as X, bD as Y, bE as Z, bF as R, bG as nn, bH as tn, bI as sn, bJ as en, bK as rn, bL as on, bM as an, bN as un, aE as cn, bO as ln } from "./index-CUXkjxiT.js";
|
|
2
|
+
import { k as C, c as g, m as D } from "./step-BTxPtq1r.js";
|
|
3
|
+
import { r as b } from "./reshape-BDOuCSNW.js";
|
|
4
|
+
import { m as pn, b as hn, e as w } from "./not_equal-hurPF26l.js";
|
|
5
|
+
import { s as K } from "./sum-BpiwSWvg.js";
|
|
6
6
|
function fn(s, n = null, t = !1) {
|
|
7
7
|
const i = { x: c(s, "x", "all", "bool") }, o = { axis: n, keepDims: t };
|
|
8
8
|
return d.runKernel(T, i, o);
|
|
@@ -37,7 +37,7 @@ function xn(s, n, t) {
|
|
|
37
37
|
const e = c(s, "x", "batchToSpaceND"), i = n.reduce((r, a) => r * a);
|
|
38
38
|
l(e.rank >= 1 + n.length, () => `input rank is ${e.rank} but should be > than blockShape.length ${n.length}`), l(t.length === n.length, () => `crops.length is ${t.length} but should be equal to blockShape.length ${n.length}`), l(e.shape[0] % i === 0, () => `input tensor batch is ${e.shape[0]} but is not divisible by the product of the elements of blockShape ${n.join(" * ")} === ${i}`);
|
|
39
39
|
const o = { x: e }, p = { blockShape: n, crops: t };
|
|
40
|
-
return d.runKernel(
|
|
40
|
+
return d.runKernel(B, o, p);
|
|
41
41
|
}
|
|
42
42
|
const ot = /* @__PURE__ */ h({ batchToSpaceND_: xn });
|
|
43
43
|
function kn(s) {
|
|
@@ -57,7 +57,7 @@ function vn(s, n, t, e, i, o) {
|
|
|
57
57
|
offset: m,
|
|
58
58
|
mean: r,
|
|
59
59
|
variance: a
|
|
60
|
-
}, k = { varianceEpsilon: o }, $ = d.runKernel(
|
|
60
|
+
}, k = { varianceEpsilon: o }, $ = d.runKernel(I, x, k);
|
|
61
61
|
return b($, p.shape);
|
|
62
62
|
}
|
|
63
63
|
const at = /* @__PURE__ */ h({ batchNorm_: vn });
|
|
@@ -67,7 +67,7 @@ function gn(s, n, t, e, i = "NHWC", o = [1, 1], p) {
|
|
|
67
67
|
r.rank === 3 && (m = !0, u = b(r, [1, r.shape[0], r.shape[1], r.shape[2]])), l(u.rank === 4, () => `Error in conv2d: input must be rank 4, but got rank ${u.rank}.`), l(a.rank === 4, () => `Error in conv2d: filter must be rank 4, but got rank ${a.rank}.`), g("conv2d", e, p);
|
|
68
68
|
const f = i === "NHWC" ? u.shape[3] : u.shape[1];
|
|
69
69
|
l(f === a.shape[2], () => `Error in conv2d: depth of input (${f}) must match input depth for filter ${a.shape[2]}.`), l(C(t, o), () => `Error in conv2D: Either strides or dilations must be 1. Got strides ${t} and dilations '${o}'`), l(D(o), () => "Error in conv2D: Dilated rates should be larger than 0."), l(D(t), () => "Error in conv2D: Strides should be larger than 0.");
|
|
70
|
-
const x = { x: u, filter: a }, k = { strides: t, pad: e, dataFormat: i, dilations: o, dimRoundingMode: p }, $ = d.runKernel(
|
|
70
|
+
const x = { x: u, filter: a }, k = { strides: t, pad: e, dataFormat: i, dilations: o, dimRoundingMode: p }, $ = d.runKernel(W, x, k);
|
|
71
71
|
return m ? b($, [$.shape[1], $.shape[2], $.shape[3]]) : $;
|
|
72
72
|
}
|
|
73
73
|
const S = /* @__PURE__ */ h({ conv2d_: gn });
|
|
@@ -96,12 +96,12 @@ function Nn(s, n, t, e, i, o) {
|
|
|
96
96
|
const ut = /* @__PURE__ */ h({ conv2dTranspose_: Nn });
|
|
97
97
|
function _n(s) {
|
|
98
98
|
const t = { x: c(s, "x", "cos", "float32") };
|
|
99
|
-
return d.runKernel(
|
|
99
|
+
return d.runKernel(L, t);
|
|
100
100
|
}
|
|
101
101
|
const ct = /* @__PURE__ */ h({ cos_: _n });
|
|
102
102
|
function wn(s) {
|
|
103
103
|
const t = { x: c(s, "x", "cosh", "float32") };
|
|
104
|
-
return d.runKernel(
|
|
104
|
+
return d.runKernel(G, t);
|
|
105
105
|
}
|
|
106
106
|
const lt = /* @__PURE__ */ h({ cosh_: wn });
|
|
107
107
|
function Kn(s, n = 0, t = !1, e = !1) {
|
|
@@ -143,7 +143,7 @@ function yn(s) {
|
|
|
143
143
|
return d.runKernel(V, t);
|
|
144
144
|
}
|
|
145
145
|
const mt = /* @__PURE__ */ h({ softplus_: yn });
|
|
146
|
-
function
|
|
146
|
+
function Bn(s, n = -1) {
|
|
147
147
|
const t = c(s, "logits", "logSoftmax");
|
|
148
148
|
if (n === -1 && (n = t.rank - 1), n !== t.rank - 1)
|
|
149
149
|
throw Error(`Log Softmax along a non-last dimension is not yet supported. Logits was rank ${t.rank} and axis was ${n}`);
|
|
@@ -155,20 +155,20 @@ function In(s, n = -1) {
|
|
|
155
155
|
} };
|
|
156
156
|
})(t);
|
|
157
157
|
}
|
|
158
|
-
const $t = /* @__PURE__ */ h({ logSoftmax_:
|
|
159
|
-
function
|
|
158
|
+
const $t = /* @__PURE__ */ h({ logSoftmax_: Bn });
|
|
159
|
+
function In(s) {
|
|
160
160
|
const t = { x: c(s, "x", "logicalNot", "bool") };
|
|
161
161
|
return d.runKernel(Y, t);
|
|
162
162
|
}
|
|
163
|
-
const bt = /* @__PURE__ */ h({ logicalNot_:
|
|
164
|
-
function
|
|
163
|
+
const bt = /* @__PURE__ */ h({ logicalNot_: In });
|
|
164
|
+
function Wn(s, n, t, e, i) {
|
|
165
165
|
const o = c(s, "x", "maxPool"), p = 1;
|
|
166
166
|
let r = o, a = !1;
|
|
167
167
|
o.rank === 3 && (a = !0, r = b(o, [1, o.shape[0], o.shape[1], o.shape[2]])), l(r.rank === 4, () => `Error in maxPool: input must be rank 4 but got rank ${r.rank}.`), l(C(t, p), () => `Error in maxPool: Either strides or dilations must be 1. Got strides ${t} and dilations '${p}'`), g("maxPool", e, i);
|
|
168
168
|
const u = { x: r }, m = { filterSize: n, strides: t, pad: e, dimRoundingMode: i }, f = d.runKernel(Z, u, m);
|
|
169
169
|
return a ? b(f, [f.shape[1], f.shape[2], f.shape[3]]) : f;
|
|
170
170
|
}
|
|
171
|
-
const xt = /* @__PURE__ */ h({ maxPool_:
|
|
171
|
+
const xt = /* @__PURE__ */ h({ maxPool_: Wn });
|
|
172
172
|
function An(s, n, t = 1, e = 0, i = "int32") {
|
|
173
173
|
if (n < 2)
|
|
174
174
|
throw new Error(`Error in oneHot: depth must be >=2, but it is ${n}`);
|
|
@@ -176,19 +176,19 @@ function An(s, n, t = 1, e = 0, i = "int32") {
|
|
|
176
176
|
return d.runKernel(R, p, r);
|
|
177
177
|
}
|
|
178
178
|
const kt = /* @__PURE__ */ h({ oneHot_: An });
|
|
179
|
-
function
|
|
179
|
+
function Ln(s) {
|
|
180
180
|
const t = { x: c(s, "x", "onesLike") };
|
|
181
181
|
return d.runKernel(nn, t);
|
|
182
182
|
}
|
|
183
|
-
const vt = /* @__PURE__ */ h({ onesLike_:
|
|
184
|
-
function
|
|
183
|
+
const vt = /* @__PURE__ */ h({ onesLike_: Ln });
|
|
184
|
+
function Gn(s, n, t = 0) {
|
|
185
185
|
const e = c(s, "x", "pad");
|
|
186
186
|
if (e.rank === 0)
|
|
187
187
|
throw new Error("pad(scalar) is not defined. Pass non-scalar to pad");
|
|
188
188
|
const i = { paddings: n, constantValue: t }, o = { x: e };
|
|
189
189
|
return d.runKernel(tn, o, i);
|
|
190
190
|
}
|
|
191
|
-
const gt = /* @__PURE__ */ h({ pad_:
|
|
191
|
+
const gt = /* @__PURE__ */ h({ pad_: Gn });
|
|
192
192
|
function On(s, n, t) {
|
|
193
193
|
const e = c(s, "x", "spaceToBatchND");
|
|
194
194
|
l(e.rank >= 1 + n.length, () => `input rank ${e.rank} should be > than [blockShape] ${n.length}`), l(t.length === n.length, () => `paddings.shape[0] ${t.length} must be equal to [blockShape] ${n.length}`), l(e.shape.reduce((p, r, a) => a > 0 && a <= n.length ? p && (r + t[a - 1][0] + t[a - 1][1]) % n[a - 1] === 0 : p, !0), () => `input spatial dimensions ${e.shape.slice(1)} with paddings ${t.toString()} must be divisible by blockShapes ${n.toString()}`);
|