@genai-fi/nanogpt 0.8.0 → 0.8.2
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.d.ts +2 -1
- package/dist/Generator.js +44 -37
- package/dist/{RealDiv-N8TpOMYv.js → RealDiv-D_q39E3A.js} +14 -14
- package/dist/{Reshape-B-lWQRnF.js → Reshape-41YpQqEo.js} +1 -1
- package/dist/{Reshape-Bo8HzP8V.js → Reshape-Bh_jzKzV.js} +2 -2
- package/dist/TeachableLLM.js +7 -5
- package/dist/{axis_util-DubwyOhW.js → axis_util-Did9235A.js} +1 -1
- package/dist/backend.js +2 -2
- package/dist/{backend_util-BJ-_jSeK.js → backend_util-yC3YH1jo.js} +17 -17
- package/dist/{broadcast_to-BYfCp5iL.js → broadcast_to-CUvOdOT5.js} +2 -2
- package/dist/checks/appendCache.d.ts +1 -0
- package/dist/checks/appendCache.js +22 -0
- package/dist/checks/attentionMask.d.ts +1 -0
- package/dist/checks/attentionMask.js +37 -0
- package/dist/checks/check.d.ts +9 -0
- package/dist/checks/check.js +20 -0
- package/dist/checks/gelu.d.ts +1 -0
- package/dist/checks/gelu.js +18 -0
- package/dist/checks/index.d.ts +22 -0
- package/dist/checks/index.js +24 -0
- package/dist/checks/normRMS.d.ts +1 -0
- package/dist/checks/normRMS.js +16 -0
- package/dist/checks/normRMSGrad.d.ts +1 -0
- package/dist/checks/normRMSGrad.js +12 -0
- package/dist/checks/qkv.d.ts +1 -0
- package/dist/checks/qkv.js +50 -0
- package/dist/checks/rope.d.ts +1 -0
- package/dist/checks/rope.js +38 -0
- package/dist/checks/weights.d.ts +16 -0
- package/dist/checks/weights.js +29 -0
- package/dist/{concat-BmDqqFsa.js → concat-pHiVqR3L.js} +1 -1
- package/dist/{dataset-CJmEGu6D.js → dataset-DPPl-iLT.js} +7 -7
- package/dist/{dropout-sx0sjVAT.js → dropout-CcKSfOYE.js} +11 -11
- package/dist/{exports_initializers-DAKM8UO9.js → exports_initializers-DKk7-bsx.js} +1 -1
- package/dist/{gather-C1siEkdp.js → gather-CPg6ZlQA.js} +1 -1
- package/dist/{gelu-Bd3UBBxg.js → gelu-BkcmEEyD.js} +1 -1
- package/dist/{gpgpu_math-TFLxaLkw.js → gpgpu_math-D_ODOLix.js} +2 -2
- package/dist/{index-CUQrfsw_.js → index-DdmHGZjq.js} +655 -647
- package/dist/{index-BaPo_0H8.js → index-evZ57wr4.js} +10 -10
- package/dist/{kernel_funcs_utils-P9aFa232.js → kernel_funcs_utils-CDfFpUab.js} +15 -15
- package/dist/layers/BaseLayer.js +2 -2
- package/dist/layers/CausalSelfAttention.js +29 -29
- package/dist/layers/MLP.js +18 -18
- 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 +11 -11
- package/dist/layers/TransformerBlock.js +1 -1
- package/dist/loader/loadTransformers.js +1 -1
- package/dist/loader/oldZipLoad.js +9 -7
- package/dist/{log_sum_exp-C142qZqY.js → log_sum_exp-C8yFJfZz.js} +45 -24
- package/dist/main.d.ts +2 -0
- package/dist/main.js +9 -7
- package/dist/{mat_mul-DMkduNJu.js → mat_mul-Dpy2mMRu.js} +1 -1
- package/dist/{mod-uUuj4gSb.js → mod-CbibJi3D.js} +1 -1
- package/dist/models/NanoGPTV1.js +1 -1
- package/dist/models/model.js +9 -7
- package/dist/{mulmat_packed_gpu-Cm2gw-c8.js → mulmat_packed_gpu-q_Gmwyld.js} +1 -1
- package/dist/{ones-ZdgQGBCP.js → ones-BAqVh-eA.js} +2 -2
- package/dist/ops/adamAdjust.js +1 -1
- package/dist/ops/adamMoments.js +1 -1
- package/dist/ops/appendCache.js +3 -3
- package/dist/ops/attentionMask.js +1 -1
- package/dist/ops/cpu/adamAdjust.js +1 -1
- package/dist/ops/cpu/adamMoments.js +2 -2
- package/dist/ops/cpu/appendCache.js +2 -2
- package/dist/ops/cpu/attentionMask.js +5 -5
- package/dist/ops/cpu/fusedSoftmax.js +2 -2
- package/dist/ops/cpu/gatherSub.js +5 -5
- package/dist/ops/cpu/gelu.js +1 -1
- package/dist/ops/cpu/matMulGelu.js +2 -2
- package/dist/ops/cpu/matMulMul.js +1 -1
- package/dist/ops/cpu/mulDropout.js +1 -1
- 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 +13 -13
- 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 +2 -2
- package/dist/ops/grads/matMulGelu.js +1 -1
- package/dist/ops/grads/normRMS.js +1 -1
- package/dist/ops/grads/qkv.js +1 -1
- package/dist/ops/grads/rope.js +1 -1
- 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.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/fusedSoftmax.js +4 -4
- package/dist/ops/webgl/gatherSub.js +1 -1
- package/dist/ops/webgl/gelu.js +2 -2
- package/dist/ops/webgl/log.js +3 -3
- package/dist/ops/webgl/matMulGelu.js +4 -4
- package/dist/ops/webgl/matMulMul.js +1 -1
- 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 +1 -1
- package/dist/ops/webgpu/adamAdjust.js +3 -3
- package/dist/ops/webgpu/adamMoments.js +3 -3
- package/dist/ops/webgpu/appendCache.js +3 -3
- package/dist/ops/webgpu/attentionMask.js +3 -3
- package/dist/ops/webgpu/gatherSub.js +3 -3
- package/dist/ops/webgpu/gelu.js +3 -3
- package/dist/ops/webgpu/normRMS.js +2 -2
- package/dist/ops/webgpu/normRMSGrad.js +5 -5
- package/dist/ops/webgpu/qkv.js +3 -3
- package/dist/ops/webgpu/rope.js +3 -3
- package/dist/ops/webgpu/scatterSub.js +3 -3
- package/dist/ops/webgpu/utils/reductions.js +4 -4
- package/dist/ops-542ai2vG.js +1525 -0
- package/dist/{random_width-D8Pwy_na.js → random_width-DKGeiFuR.js} +1514 -1581
- package/dist/{range-LVHrSLdi.js → range-BcUvLuf5.js} +1 -1
- package/dist/{reciprocal-CaR9e67G.js → reciprocal-DhDWSKiD.js} +1 -1
- package/dist/{register_all_kernels-DUshvVWP.js → register_all_kernels-Do9VvZmo.js} +2312 -2335
- package/dist/{max-B3JOcNGb.js → relu-B1AXs7p5.js} +6 -6
- package/dist/{reshape-DEfQGSin.js → reshape-WeJkT3ja.js} +1 -1
- package/dist/{scatter_nd_util-CUPPNLaA.js → scatter_nd_util-B7yDhiQr.js} +1 -1
- package/dist/{selu_util-8vv5JxQV.js → selu_util-BgUO9gHY.js} +125 -146
- package/dist/{shared-D1elLckx.js → shared-CZiWmQCI.js} +1 -1
- package/dist/{shared-CkNorDcU.js → shared-V6D_md-c.js} +120 -120
- package/dist/{sin-D2CKKmyR.js → sin-CPxad7Am.js} +1 -1
- package/dist/{slice-BnyE-M_7.js → slice-B7jXtPnp.js} +1 -1
- package/dist/{softmax-DLoZWYBx.js → softmax-BfsyI4As.js} +1 -1
- package/dist/{split-By_n4TKP.js → split-BPxr8_8m.js} +1 -1
- package/dist/{stack-DkdFLq37.js → stack-BNwLzE43.js} +1 -1
- package/dist/{sum-l_0SqM4h.js → sum-ByFINZgi.js} +1 -1
- package/dist/{tensor-BAQdLqoU.js → tensor-DbqgIV9B.js} +1 -1
- package/dist/tensor1d-CtJq5BOv.js +27 -0
- package/dist/{tensor2d-BHy261cI.js → tensor2d-CObBWBkW.js} +1 -1
- package/dist/tensor4d-DLtk7Nxh.js +30 -0
- package/dist/training/Adam.js +2 -2
- package/dist/training/AdamExt.js +1 -1
- package/dist/training/DatasetBuilder.js +2 -2
- package/dist/training/FullTrainer.js +1 -1
- package/dist/training/Trainer.js +2 -2
- package/dist/training/sparseCrossEntropy.js +8 -9
- package/dist/utilities/arrayClose.d.ts +1 -1
- package/dist/utilities/arrayClose.js +16 -7
- package/dist/utilities/dummy.js +2 -2
- package/dist/utilities/multinomialCPU.js +2 -2
- package/dist/utilities/performance.js +1 -1
- package/dist/utilities/profile.js +1 -1
- package/dist/utilities/safetensors.js +2 -2
- package/dist/utilities/weights.js +2 -2
- package/dist/{variable-C9hihzDB.js → variable-DPFOJyRG.js} +1 -1
- package/dist/{webgpu_program-dFEVbDPL.js → webgpu_program-Dhk9R5aG.js} +1 -1
- package/dist/{webgpu_util-DLImlSc6.js → webgpu_util-BqGnZg8t.js} +1 -1
- package/dist/{zeros-VZ72lWXM.js → zeros-Dnwix0p4.js} +1 -1
- package/package.json +1 -1
- package/dist/ops-C_1K_-35.js +0 -1202
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z as o, A as s, B as t } from "./index-DdmHGZjq.js";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
* =============================================================================
|
|
17
|
+
*/
|
|
18
|
+
function h(r, e) {
|
|
19
|
+
o(r);
|
|
20
|
+
const n = s(r, e);
|
|
21
|
+
if (n.length !== 1)
|
|
22
|
+
throw new Error("tensor1d() requires values to be a flat/TypedArray");
|
|
23
|
+
return t(r, null, n, e);
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
h as t
|
|
27
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z as t, A as a, B as s } from "./index-DdmHGZjq.js";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
* =============================================================================
|
|
17
|
+
*/
|
|
18
|
+
function i(n, r, o) {
|
|
19
|
+
if (t(n), r != null && r.length !== 4)
|
|
20
|
+
throw new Error("tensor4d() requires shape to have four numbers");
|
|
21
|
+
const e = a(n, o);
|
|
22
|
+
if (e.length !== 4 && e.length !== 1)
|
|
23
|
+
throw new Error("tensor4d() requires values to be number[][][][] or flat/TypedArray");
|
|
24
|
+
if (e.length === 1 && r == null)
|
|
25
|
+
throw new Error("tensor4d() requires shape to be provided when `values` are a flat array");
|
|
26
|
+
return s(n, r, e, o);
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
i as t
|
|
30
|
+
};
|
package/dist/training/Adam.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { adamAdjust as b } from "../ops/adamAdjust.js";
|
|
2
2
|
import { adamMoments as d } from "../ops/adamMoments.js";
|
|
3
|
-
import { O as g, e as h, t as o, d as B } from "../index-
|
|
4
|
-
import { z as M } from "../zeros-
|
|
3
|
+
import { O as g, e as h, t as o, d as B } from "../index-DdmHGZjq.js";
|
|
4
|
+
import { z as M } from "../zeros-Dnwix0p4.js";
|
|
5
5
|
/**
|
|
6
6
|
* @license
|
|
7
7
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
package/dist/training/AdamExt.js
CHANGED
package/dist/training/Trainer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DatasetBuilder as m, flattenTokens as c, PAGE_FACTOR as g } from "./DatasetBuilder.js";
|
|
2
2
|
import u from "./AdamExt.js";
|
|
3
|
-
import { t as f, v as y, d as p } from "../index-
|
|
4
|
-
import { z as h } from "../zeros-
|
|
3
|
+
import { t as f, v as y, d as p } from "../index-DdmHGZjq.js";
|
|
4
|
+
import { z as h } from "../zeros-Dnwix0p4.js";
|
|
5
5
|
class x {
|
|
6
6
|
constructor(t, e, i = 1e-3) {
|
|
7
7
|
this.tokenizer = e, this.model = t, this.learningRate = i, this.resetOptimizer(), this.datasetBuilder = new m(e, t.config.blockSize);
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { gatherSub as x } from "../ops/gatherSub.js";
|
|
2
2
|
import { scatterSub as L } from "../ops/scatterSub.js";
|
|
3
|
-
import {
|
|
4
|
-
import { s as y } from "../softmax-
|
|
5
|
-
import { m as z } from "../
|
|
6
|
-
import { l as v } from "../log_sum_exp-C142qZqY.js";
|
|
3
|
+
import { J as C, t as u, L as E, c as G } from "../index-DdmHGZjq.js";
|
|
4
|
+
import { s as y } from "../softmax-BfsyI4As.js";
|
|
5
|
+
import { m as z, l as v } from "../log_sum_exp-C8yFJfZz.js";
|
|
7
6
|
function k(t, s) {
|
|
8
7
|
return u(() => {
|
|
9
|
-
const n = t.shape[t.shape.length - 1], c = t.shape.slice(0, -1).reduce((o, e) => o * e, 1), h = t.shape.length > 2 ? t.reshape([c, n]) : t, p = s.shape.length > 1 ? s.reshape([c]).cast("int32") : s.cast("int32"), r = z(h, -1, !0), a = G(h, r),
|
|
10
|
-
return x(
|
|
8
|
+
const n = t.shape[t.shape.length - 1], c = t.shape.slice(0, -1).reduce((o, e) => o * e, 1), h = t.shape.length > 2 ? t.reshape([c, n]) : t, p = s.shape.length > 1 ? s.reshape([c]).cast("int32") : s.cast("int32"), r = z(h, -1, !0), a = G(h, r), d = v(a, -1);
|
|
9
|
+
return x(d, p, a);
|
|
11
10
|
});
|
|
12
11
|
}
|
|
13
12
|
function q() {
|
|
14
13
|
return C(
|
|
15
14
|
// @ts-expect-error Invalid params
|
|
16
|
-
(s, n,
|
|
17
|
-
const c = s.shape[s.shape.length - 1], p = s.shape.slice(0, -1).reduce((o, e) => o * e, 1), r = s.reshape([p, c]), a = n.reshape([p]).cast("int32"),
|
|
18
|
-
return
|
|
15
|
+
(s, n, m) => {
|
|
16
|
+
const c = s.shape[s.shape.length - 1], p = s.shape.slice(0, -1).reduce((o, e) => o * e, 1), r = s.reshape([p, c]), a = n.reshape([p]).cast("int32"), d = k(r, a);
|
|
17
|
+
return m([r, a]), r.dispose(), a.dispose(), { value: d, gradFunc: (o, e) => u(() => {
|
|
19
18
|
const S = e[0], f = e[1], b = y(S), l = L(b, f, o), g = E(n);
|
|
20
19
|
return [l.reshape(s.shape), g];
|
|
21
20
|
}) };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function arraysClose(a: unknown, b: unknown
|
|
1
|
+
export declare function arraysClose(a: unknown, b: unknown): number;
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
function
|
|
1
|
+
function n(r, e) {
|
|
2
|
+
let t = 0;
|
|
2
3
|
if (Array.isArray(r) && Array.isArray(e)) {
|
|
3
|
-
if (r.length !== e.length) return
|
|
4
|
-
for (let
|
|
5
|
-
|
|
6
|
-
return
|
|
7
|
-
} else
|
|
4
|
+
if (r.length !== e.length) return Number.POSITIVE_INFINITY;
|
|
5
|
+
for (let i = 0; i < r.length; ++i)
|
|
6
|
+
t = Math.max(t, n(r[i], e[i]));
|
|
7
|
+
return t;
|
|
8
|
+
} else if (typeof r == "number" && typeof e == "number") {
|
|
9
|
+
if (isNaN(r) && isNaN(e))
|
|
10
|
+
return 0;
|
|
11
|
+
if (!isFinite(r) || !isFinite(e))
|
|
12
|
+
return r === e ? 0 : Number.POSITIVE_INFINITY;
|
|
13
|
+
const i = Math.abs(r - e);
|
|
14
|
+
return t = Math.max(t, i), t;
|
|
15
|
+
} else
|
|
16
|
+
return Number.POSITIVE_INFINITY;
|
|
8
17
|
}
|
|
9
18
|
export {
|
|
10
|
-
|
|
19
|
+
n as arraysClose
|
|
11
20
|
};
|
package/dist/utilities/dummy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { m as y, v as P, e as S } from "../index-
|
|
2
|
-
import { z as i } from "../zeros-
|
|
1
|
+
import { m as y, v as P, e as S } from "../index-DdmHGZjq.js";
|
|
2
|
+
import { z as i } from "../zeros-Dnwix0p4.js";
|
|
3
3
|
async function w(s) {
|
|
4
4
|
const t = i([1, s.config.blockSize], "int32"), [e, n] = s.forward({ training: !1 }, t);
|
|
5
5
|
await e.data(), e.dispose(), n && n.dispose(), t.dispose();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "../index-
|
|
2
|
-
import { t as p } from "../tensor-
|
|
1
|
+
import "../index-DdmHGZjq.js";
|
|
2
|
+
import { t as p } from "../tensor-DbqgIV9B.js";
|
|
3
3
|
function h(n) {
|
|
4
4
|
const e = n.reduce((s, o) => s + o.length, 0), a = new Float32Array(e);
|
|
5
5
|
let t = 0;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as m, D as r, a4 as l, E as c, aa as i, M as p, ab as u, j as f } from "./index-DdmHGZjq.js";
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2020 Google LLC. All Rights Reserved.
|