@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
package/dist/tokenise.js
CHANGED
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import t from "./tokeniser/
|
|
3
|
-
import n from "./
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
var o = /* @__PURE__ */ e({
|
|
8
|
-
BPETokeniser: () => n,
|
|
9
|
-
CharTokeniser: () => t,
|
|
10
|
-
TokenStore: () => r,
|
|
11
|
-
createTokenStore: () => i,
|
|
12
|
-
tokensFromStreams: () => a
|
|
13
|
-
});
|
|
14
|
-
//#endregion
|
|
15
|
-
export { n as BPETokeniser, t as CharTokeniser, r as TokenStore, i as createTokenStore, o as t, a as tokensFromStreams };
|
|
1
|
+
import e from "./tokeniser/CharTokeniser.js";
|
|
2
|
+
import t from "./tokeniser/bpe.js";
|
|
3
|
+
import { TokenStore as n, createTokenStore as r } from "./training/tasks/TokenStore.js";
|
|
4
|
+
import { tokensFromStreams as i } from "./training/tasks/tokenStream.js";
|
|
5
|
+
import "./tokenise-DbS2Ea-T.js";
|
|
6
|
+
export { t as BPETokeniser, e as CharTokeniser, n as TokenStore, r as createTokenStore, i as tokensFromStreams };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as e } from "../eventemitter3-
|
|
2
|
-
|
|
1
|
+
import { t as e } from "../eventemitter3-wmfmOP_f.js";
|
|
2
|
+
// lib/tokeniser/BaseTokeniser.ts
|
|
3
3
|
var t = [
|
|
4
4
|
"<eos>",
|
|
5
5
|
"<bos>",
|
|
@@ -53,6 +53,7 @@ var t = [
|
|
|
53
53
|
];
|
|
54
54
|
}
|
|
55
55
|
encodeAsSequence(e, t) {
|
|
56
|
+
if (!e || e.length === 0) return t ? [this.bosToken] : [];
|
|
56
57
|
let n = e.flatMap((e) => this.encode(e.content));
|
|
57
58
|
return t ? [
|
|
58
59
|
this.bosToken,
|
|
@@ -89,9 +90,7 @@ var t = [
|
|
|
89
90
|
case "system":
|
|
90
91
|
r.push([a[2]]), e = !0;
|
|
91
92
|
break;
|
|
92
|
-
case "text":
|
|
93
|
-
r[r.length - 1][0] !== this.bosToken && r.push([this.bosToken]);
|
|
94
|
-
break;
|
|
93
|
+
case "text": r[r.length - 1][0] !== this.bosToken && r.push([this.bosToken]);
|
|
95
94
|
}
|
|
96
95
|
switch (r.push(s), t.role) {
|
|
97
96
|
case "user":
|
|
@@ -103,9 +102,7 @@ var t = [
|
|
|
103
102
|
case "system":
|
|
104
103
|
r.push([o[2]]);
|
|
105
104
|
break;
|
|
106
|
-
case "text":
|
|
107
|
-
r.push([this.eosToken]);
|
|
108
|
-
break;
|
|
105
|
+
case "text": r.push([this.eosToken]);
|
|
109
106
|
}
|
|
110
107
|
n && i && e ? (i.push([!1]), i.push(s.map(() => !1)), i.push([!1])) : n && i && (i.push([!1]), i.push(s.map(() => !0)), i.push([!0]));
|
|
111
108
|
}
|
|
@@ -137,5 +134,4 @@ var t = [
|
|
|
137
134
|
return this.specialTokens.get(e);
|
|
138
135
|
}
|
|
139
136
|
};
|
|
140
|
-
//#endregion
|
|
141
137
|
export { t as SPECIALS, n as default };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import e, { SPECIALS as t } from "./BaseTokeniser.js";
|
|
2
|
-
|
|
2
|
+
// lib/tokeniser/CharTokeniser.ts
|
|
3
3
|
var n = ["<eos>", "<unk>"], r = class extends e {
|
|
4
4
|
vocabSize = 0;
|
|
5
5
|
eosToken = 0;
|
|
@@ -82,5 +82,4 @@ var n = ["<eos>", "<unk>"], r = class extends e {
|
|
|
82
82
|
return [r, i];
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
|
-
//#endregion
|
|
86
85
|
export { r as default };
|
package/dist/tokeniser/bpe.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import r from "
|
|
4
|
-
|
|
1
|
+
import { yieldIfNeeded as e } from "../utilities/yielder.js";
|
|
2
|
+
import t from "../utilities/tokenParse.js";
|
|
3
|
+
import n, { SPECIALS as r } from "./BaseTokeniser.js";
|
|
4
|
+
// lib/tokeniser/bpe.ts
|
|
5
5
|
function i(e, t) {
|
|
6
6
|
return `${e}-::-${t}`;
|
|
7
7
|
}
|
|
@@ -33,7 +33,7 @@ function o(e, t, n, r, a) {
|
|
|
33
33
|
a: t,
|
|
34
34
|
b: n,
|
|
35
35
|
count: a,
|
|
36
|
-
instances: new Set([r])
|
|
36
|
+
instances: /* @__PURE__ */ new Set([r])
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
function s(e) {
|
|
@@ -58,16 +58,16 @@ function l(e, t) {
|
|
|
58
58
|
e.tokens[n] = i;
|
|
59
59
|
}), e.pairs.delete(i(t.a, t.b));
|
|
60
60
|
}
|
|
61
|
-
var u = class extends
|
|
61
|
+
var u = class extends n {
|
|
62
62
|
targetSize;
|
|
63
63
|
vocab = /* @__PURE__ */ new Set();
|
|
64
64
|
vocabIndex = /* @__PURE__ */ new Map();
|
|
65
65
|
merges = [];
|
|
66
66
|
pretokenMap = /* @__PURE__ */ new Map();
|
|
67
|
-
constructor(e,
|
|
67
|
+
constructor(e, t) {
|
|
68
68
|
super(), Array.isArray(e) ? (e.forEach((e, t) => {
|
|
69
69
|
this.vocab.add(e), this.vocabIndex.set(e, t);
|
|
70
|
-
}),
|
|
70
|
+
}), t && (this.merges = t), this.targetSize = e.length, r.forEach((t) => {
|
|
71
71
|
let n = e.indexOf(t);
|
|
72
72
|
n !== -1 && this.addSpecialToken(t, n);
|
|
73
73
|
})) : (this.addSpecialTokens(), this.targetSize = e);
|
|
@@ -84,7 +84,7 @@ var u = class extends e {
|
|
|
84
84
|
this.vocab.clear(), this.vocabIndex.clear(), this.merges = [], this.pretokenMap.clear();
|
|
85
85
|
}
|
|
86
86
|
get trained() {
|
|
87
|
-
return this.vocab.size >
|
|
87
|
+
return this.vocab.size > r.length && this.vocab.size <= this.targetSize;
|
|
88
88
|
}
|
|
89
89
|
get vocabSize() {
|
|
90
90
|
return this.vocab.size;
|
|
@@ -98,22 +98,22 @@ var u = class extends e {
|
|
|
98
98
|
get unkToken() {
|
|
99
99
|
return this.vocabIndex.get("") ?? 1;
|
|
100
100
|
}
|
|
101
|
-
async train(
|
|
101
|
+
async train(n = [], r, i) {
|
|
102
102
|
this.datasetID = i;
|
|
103
103
|
let o = /* @__PURE__ */ new Set();
|
|
104
104
|
this.vocab = /* @__PURE__ */ new Set(), this.pretokenMap.clear(), this.merges = [], this.addSpecialTokens();
|
|
105
|
-
for (let
|
|
106
|
-
for (let
|
|
107
|
-
let e =
|
|
105
|
+
for (let e of n) await e.begin((e) => {
|
|
106
|
+
for (let n of e) {
|
|
107
|
+
let e = t(n.content);
|
|
108
108
|
for (let t of e) o.has(t) || (o.add(t), Array.from(t).forEach((e) => this.vocab.add(e)));
|
|
109
109
|
}
|
|
110
|
-
},
|
|
110
|
+
}, r ? () => r(this.vocab.size) : void 0);
|
|
111
111
|
let c = performance.now(), u = Array.from(o), d = u.map((e) => Array.from(e)), f = a(d);
|
|
112
|
-
if (c = await
|
|
112
|
+
if (c = await e(c, r, this.vocab.size), this.vocab.size >= this.targetSize) throw console.warn("Initial vocab size is greater than or equal to target size. No merges will be performed.", this.vocab.size, this.targetSize), Error("too_small_vocab");
|
|
113
113
|
for (; this.vocab.size < this.targetSize && this.merges.length < this.targetSize;) {
|
|
114
|
-
let
|
|
115
|
-
if (!
|
|
116
|
-
this.merges.push([
|
|
114
|
+
let t = s(f);
|
|
115
|
+
if (!t) break;
|
|
116
|
+
this.merges.push([t.a, t.b]), this.vocab.add(t.a + t.b), l(f, t), c = await e(c, r, this.vocab.size);
|
|
117
117
|
}
|
|
118
118
|
u.forEach((e, t) => {
|
|
119
119
|
let n = d[t];
|
|
@@ -136,7 +136,7 @@ var u = class extends e {
|
|
|
136
136
|
}), this.pretokenMap.set(e, t), t;
|
|
137
137
|
}
|
|
138
138
|
tokeniseStrings(e) {
|
|
139
|
-
return e.map((e) =>
|
|
139
|
+
return e.map((e) => t(e).map((e) => this.pretokenMap.has(e) ? this.pretokenMap.get(e) : this.tokeniseWord(e)).flat(1));
|
|
140
140
|
}
|
|
141
141
|
tokenise(e, t) {
|
|
142
142
|
let n = this.tokeniseStrings(e);
|
|
@@ -153,5 +153,4 @@ var u = class extends e {
|
|
|
153
153
|
return this.detokenise([e])[0];
|
|
154
154
|
}
|
|
155
155
|
};
|
|
156
|
-
//#endregion
|
|
157
156
|
export { u as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Q as e, Z as t, li as n, rt as r } from "./dist-CMMLi-qO.js";
|
|
2
|
+
// node_modules/@tensorflow/tfjs-core/dist/ops/topk.js
|
|
3
|
+
function i(t, i = 1, a = !0) {
|
|
4
|
+
let o = e(t, "x", "topk");
|
|
5
|
+
if (o.rank === 0) throw Error("topk() expects the input to be of rank 1 or higher");
|
|
6
|
+
let s = o.shape[o.shape.length - 1];
|
|
7
|
+
if (i < 0) throw Error(`'k' passed to topk() must be >= 0 but got ${i}`);
|
|
8
|
+
if (i > s) throw Error(`'k' passed to topk() must be <= the last dimension (${s}) but got ${i}`);
|
|
9
|
+
let c = { x: o }, l = {
|
|
10
|
+
k: i,
|
|
11
|
+
sorted: a
|
|
12
|
+
}, [u, d] = r.runKernel(n, c, l);
|
|
13
|
+
return {
|
|
14
|
+
values: u,
|
|
15
|
+
indices: d
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
var a = /* @__PURE__ */ t({ topk_: i });
|
|
19
|
+
export { a as t };
|
package/dist/training/AdamW.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import { clipScale as
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { adamAdjust as e } from "../ops/adamAdjust.js";
|
|
2
|
+
import { t } from "../zeros-hxKGkRfl.js";
|
|
3
|
+
import { adamMoments as n } from "../ops/adamMoments.js";
|
|
4
|
+
import { B as r, H as i, Y as a, b as o, c as s } from "../dist-CMMLi-qO.js";
|
|
5
|
+
import c from "./LRScheduler.js";
|
|
6
|
+
import { clipScale as l } from "../ops/globalNorm.js";
|
|
7
|
+
import { load_safetensors as u, save_safetensors as d } from "../utilities/safetensors.js";
|
|
8
|
+
// lib/training/AdamW.ts
|
|
9
|
+
var f = class extends s {
|
|
9
10
|
config;
|
|
10
11
|
className = "AdamW";
|
|
11
12
|
accBeta1 = 0;
|
|
@@ -22,7 +23,7 @@ var f = class extends t {
|
|
|
22
23
|
orthGradEpsilon = 1e-30;
|
|
23
24
|
orthGrad;
|
|
24
25
|
constructor(e) {
|
|
25
|
-
super(), this.config = e, this.accBeta1 = e.accBeta1 ?? e.beta1, this.accBeta2 = e.accBeta2 ?? e.beta2, this.learningRate = e.learningRate, this.beta1 = e.beta1, this.beta2 = e.beta2, this.weightDecay = e.weightDecay, this.lossScaling = e.lossScaling, this.clipNorm = e.clipNorm, this.orthGrad = e.orthoGrad ?? !1, e.epsilon === null || e.epsilon === void 0 ?
|
|
26
|
+
super(), this.config = e, this.accBeta1 = e.accBeta1 ?? e.beta1, this.accBeta2 = e.accBeta2 ?? e.beta2, this.learningRate = e.learningRate, this.beta1 = e.beta1, this.beta2 = e.beta2, this.weightDecay = e.weightDecay, this.lossScaling = e.lossScaling, this.clipNorm = e.clipNorm, this.orthGrad = e.orthoGrad ?? !1, this.epsilon = e.epsilon === null || e.epsilon === void 0 ? i().backend.epsilon() : e.epsilon, this.lrScheduler = new c(e.learningRate, e);
|
|
26
27
|
}
|
|
27
28
|
get lr() {
|
|
28
29
|
return this.learningRate;
|
|
@@ -31,10 +32,10 @@ var f = class extends t {
|
|
|
31
32
|
let e = {};
|
|
32
33
|
return this.accumulatedMoments.forEach((t) => {
|
|
33
34
|
e[t.originalName] = t.variable;
|
|
34
|
-
}),
|
|
35
|
+
}), d(e);
|
|
35
36
|
}
|
|
36
37
|
async loadMoments(e) {
|
|
37
|
-
let t = await
|
|
38
|
+
let t = await u(e);
|
|
38
39
|
Object.entries(t).forEach(([e, t]) => {
|
|
39
40
|
let n = t.variable(!1);
|
|
40
41
|
this.accumulatedMoments.push({
|
|
@@ -59,7 +60,7 @@ var f = class extends t {
|
|
|
59
60
|
};
|
|
60
61
|
}
|
|
61
62
|
orthogonalizeGradient(e, t) {
|
|
62
|
-
return
|
|
63
|
+
return a(() => {
|
|
63
64
|
let n = e.reshape([-1]), r = t.reshape([-1]), i = n.mul(n).sum().add(this.orthGradEpsilon), a = n.mul(r).sum().div(i), o = r.sub(n.mul(a)), s = r.norm(), c = o.norm().add(this.orthGradEpsilon);
|
|
64
65
|
return o.mul(s.div(c)).reshape(t.shape);
|
|
65
66
|
});
|
|
@@ -71,29 +72,33 @@ var f = class extends t {
|
|
|
71
72
|
};
|
|
72
73
|
this.learningRate = t.learningRate, this.beta1 = t.beta1, this.beta2 = t.beta2, this.weightDecay = t.weightDecay, this.lossScaling = t.lossScaling, this.epsilon = t.epsilon ?? this.epsilon, this.clipNorm = t.clipNorm, this.lrScheduler.updateConfig(t, t.learningRate);
|
|
73
74
|
}
|
|
74
|
-
applyGradients(
|
|
75
|
-
let
|
|
76
|
-
this.learningRate =
|
|
77
|
-
let
|
|
78
|
-
let
|
|
79
|
-
|
|
80
|
-
let
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
75
|
+
applyGradients(r) {
|
|
76
|
+
let s = this.lrScheduler.getNextLR();
|
|
77
|
+
this.learningRate = s;
|
|
78
|
+
let c = Array.isArray(r) ? r.map((e) => e.name) : Object.keys(r), u = a(() => {
|
|
79
|
+
let s = 1 - this.accBeta1, u = 1 - this.accBeta2, d;
|
|
80
|
+
if (this.clipNorm !== void 0) {
|
|
81
|
+
let e = c.map((e, t) => Array.isArray(r) ? r[t].tensor : r[e]);
|
|
82
|
+
d = l(e, 1 / this.lossScaling, this.clipNorm);
|
|
83
|
+
} else d = o(1 / this.lossScaling);
|
|
84
|
+
return c.forEach((o, c) => {
|
|
85
|
+
let l = i().registeredVariables[o];
|
|
86
|
+
this.accumulatedMoments[c] ?? (this.accumulatedMoments[c] = {
|
|
87
|
+
originalName: `${o}/m`,
|
|
88
|
+
variable: a(() => t([...l.shape, 2]).variable(!1))
|
|
84
89
|
});
|
|
85
|
-
let f = Array.isArray(
|
|
90
|
+
let f = Array.isArray(r) ? r[c].tensor : r[o];
|
|
86
91
|
if (f == null) return;
|
|
87
|
-
let p = this.orthGrad ? this.orthogonalizeGradient(
|
|
92
|
+
let p = this.orthGrad ? this.orthogonalizeGradient(l, f) : f, m = this.accumulatedMoments[c].variable, h = n(m, p, this.beta1, this.beta2, d);
|
|
88
93
|
m.assign(h), this.orthGrad && p.dispose();
|
|
89
|
-
let g =
|
|
90
|
-
|
|
91
|
-
}), this.accBeta1 *= this.beta1, this.accBeta2 *= this.beta2,
|
|
94
|
+
let g = e(h, l, s, u, this.epsilon ?? 1e-8, this.learningRate, l.shape.length > 1 ? this.weightDecay : 0);
|
|
95
|
+
l.assign(g);
|
|
96
|
+
}), this.accBeta1 *= this.beta1, this.accBeta2 *= this.beta2, d;
|
|
92
97
|
});
|
|
93
|
-
return this.incrementIterations(),
|
|
98
|
+
return this.incrementIterations(), u;
|
|
94
99
|
}
|
|
95
100
|
dispose() {
|
|
96
|
-
this.accumulatedMoments != null &&
|
|
101
|
+
this.accumulatedMoments != null && r(this.accumulatedMoments.map((e) => e.variable));
|
|
97
102
|
}
|
|
98
103
|
async getWeights() {
|
|
99
104
|
let e = [...this.accumulatedMoments];
|
|
@@ -103,7 +108,7 @@ var f = class extends t {
|
|
|
103
108
|
})));
|
|
104
109
|
}
|
|
105
110
|
async setWeights(e) {
|
|
106
|
-
e = await this.extractIterations(e),
|
|
111
|
+
e = await this.extractIterations(e), a(() => {
|
|
107
112
|
this.accBeta1 = this.beta1 ** +(this.iterations_ + 1), this.accBeta2 = this.beta2 ** +(this.iterations_ + 1);
|
|
108
113
|
});
|
|
109
114
|
let t = e.length / 2;
|
|
@@ -124,5 +129,4 @@ var f = class extends t {
|
|
|
124
129
|
return new e(t.learningRate, t.beta1, t.beta2, t.epsilon);
|
|
125
130
|
}
|
|
126
131
|
};
|
|
127
|
-
//#endregion
|
|
128
132
|
export { f as AdamWOptimizer };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import e from "./Evaluator.js";
|
|
2
|
+
import { t } from "../zeros-hxKGkRfl.js";
|
|
3
|
+
import { B as n, W as r, Y as i, _ as a, b as o } from "../dist-CMMLi-qO.js";
|
|
3
4
|
import s from "../utilities/profile.js";
|
|
4
|
-
import {
|
|
5
|
-
import u from "./
|
|
6
|
-
import {
|
|
5
|
+
import { createTensorStatistics as c } from "../checks/weights.js";
|
|
6
|
+
import { calculateAccuracy as l, calculateLoss as u } from "./loss.js";
|
|
7
|
+
import { AdamWOptimizer as d } from "./AdamW.js";
|
|
7
8
|
import f from "./configure.js";
|
|
8
|
-
|
|
9
|
+
// lib/training/BasicTrainer.ts
|
|
9
10
|
var p = {
|
|
10
11
|
logInterval: 200,
|
|
11
12
|
maxEpochs: 100,
|
|
@@ -44,7 +45,7 @@ var p = {
|
|
|
44
45
|
...n,
|
|
45
46
|
lossScaling: n?.lossScaling ?? e.lossScaling
|
|
46
47
|
};
|
|
47
|
-
let i = r || new
|
|
48
|
+
let i = r || new d(this.optimizerConfig);
|
|
48
49
|
r && r.updateConfig(this.optimizerConfig), this.optimizer = i;
|
|
49
50
|
}
|
|
50
51
|
setLossMasking() {
|
|
@@ -96,7 +97,7 @@ var p = {
|
|
|
96
97
|
}), this.optimizer.updateConfig(this.optimizerConfig);
|
|
97
98
|
}
|
|
98
99
|
resumeFromLog(e) {
|
|
99
|
-
|
|
100
|
+
this.lastState && this.lastState.step !== 0 || (this.lastState = {
|
|
100
101
|
losses: [],
|
|
101
102
|
validationLosses: [],
|
|
102
103
|
logStartTime: 0,
|
|
@@ -106,44 +107,44 @@ var p = {
|
|
|
106
107
|
trainingDuration: e.duration
|
|
107
108
|
});
|
|
108
109
|
}
|
|
109
|
-
trainStep(
|
|
110
|
-
return
|
|
110
|
+
trainStep(e, t, s = !1, c = !1) {
|
|
111
|
+
return i(() => {
|
|
111
112
|
this.model.getProfiler()?.startMemory();
|
|
112
|
-
let { xs:
|
|
113
|
-
let
|
|
113
|
+
let { xs: i, ys: d } = t, { value: f, grads: p } = a(() => {
|
|
114
|
+
let t = this.model.forward({
|
|
114
115
|
training: !0,
|
|
115
116
|
checkpointing: this._gradientCheckpointing,
|
|
116
117
|
mixedPrecision: this._mixedPrecision,
|
|
117
118
|
dropout: this._dropout,
|
|
118
119
|
layerDrop: this._layerDrop,
|
|
119
120
|
ropePositionOffset: 0
|
|
120
|
-
},
|
|
121
|
-
this.metrics.has("accuracy") && (
|
|
122
|
-
let
|
|
123
|
-
return
|
|
121
|
+
}, i), n = u(t, d, this.maskedLoss, !1, this._labelSmoothing);
|
|
122
|
+
this.metrics.has("accuracy") && (e.accuracy = l(t, d), r(e.accuracy)), t.dispose();
|
|
123
|
+
let a = n.mul(o(this.optimizerConfig.lossScaling));
|
|
124
|
+
return n.dispose(), a;
|
|
124
125
|
});
|
|
125
126
|
if (s) this.model.getProfiler()?.endMemory("Training");
|
|
126
127
|
else {
|
|
127
|
-
let
|
|
128
|
-
this.metrics.has("gradientNorm") ? (
|
|
129
|
-
let
|
|
130
|
-
this.model.weightStore.touchVariables(
|
|
128
|
+
let t = this.optimizer.applyGradients(p);
|
|
129
|
+
this.metrics.has("gradientNorm") ? (e.gradientNorm = t, r(t)) : (e.gradientNorm = void 0, t.dispose());
|
|
130
|
+
let i = Object.keys(p);
|
|
131
|
+
this.model.weightStore.touchVariables(i), this.model.getProfiler()?.endMemory("Training"), c ? (e.gradients = p, Object.values(p).forEach((e) => r(e))) : n(p);
|
|
131
132
|
}
|
|
132
|
-
return f.mul(
|
|
133
|
+
return f.mul(o(1 / this.optimizerConfig.lossScaling));
|
|
133
134
|
});
|
|
134
135
|
}
|
|
135
136
|
async dummyPass() {
|
|
136
|
-
let e =
|
|
137
|
+
let e = t([1, this.model.config.blockSize], "int32"), n = t([1, this.model.config.blockSize], "int32");
|
|
137
138
|
try {
|
|
138
|
-
let
|
|
139
|
+
let t = this.trainStep({}, {
|
|
139
140
|
xs: e,
|
|
140
|
-
ys:
|
|
141
|
+
ys: n
|
|
141
142
|
}, !0);
|
|
142
|
-
await
|
|
143
|
+
await t.data(), t.dispose();
|
|
143
144
|
} catch (e) {
|
|
144
145
|
console.error("Error during dummy pass:", e);
|
|
145
146
|
} finally {
|
|
146
|
-
e.dispose(),
|
|
147
|
+
e.dispose(), n.dispose();
|
|
147
148
|
}
|
|
148
149
|
}
|
|
149
150
|
dispose() {
|
|
@@ -164,19 +165,19 @@ var p = {
|
|
|
164
165
|
async performLogging(e, t, n, r) {
|
|
165
166
|
let i = this.metrics.has("gradientStatistics"), a = this.lastState, o = [];
|
|
166
167
|
o.push(e.data()), o.push(a.accuracy ? a.accuracy.data() : null), o.push(a.gradientNorm ? a.gradientNorm.data() : null);
|
|
167
|
-
let s = await Promise.all(o),
|
|
168
|
-
a.lastLoss =
|
|
168
|
+
let s = await Promise.all(o), l = s[0]?.[0] ?? 0, u = s[1] ? s[1][0] : void 0, d = s[2] ? s[2][1] : void 0;
|
|
169
|
+
a.lastLoss = l, a.trainingDuration += Date.now() - a.logStartTime;
|
|
169
170
|
let f = a.totalSteps * t * this.model.config.blockSize;
|
|
170
171
|
this._tokensProcessed = f;
|
|
171
172
|
let p = {
|
|
172
173
|
trainingMetrics: {
|
|
173
174
|
loss: a.lastLoss,
|
|
174
175
|
perplexity: this.metrics.has("perplexity") ? Math.exp(a.lastLoss) : void 0,
|
|
175
|
-
accuracy:
|
|
176
|
+
accuracy: u
|
|
176
177
|
},
|
|
177
178
|
step: a.step,
|
|
178
179
|
time: Date.now() - a.logStartTime,
|
|
179
|
-
gradientNorm:
|
|
180
|
+
gradientNorm: d,
|
|
180
181
|
batchSize: t,
|
|
181
182
|
learningRate: this.metrics.has("learningRate") ? this.optimizer.lr : void 0,
|
|
182
183
|
duration: a.trainingDuration,
|
|
@@ -193,7 +194,7 @@ var p = {
|
|
|
193
194
|
duration: a.trainingDuration
|
|
194
195
|
}, i && a.gradients) {
|
|
195
196
|
let e = /* @__PURE__ */ new Map();
|
|
196
|
-
for (let [t, n] of Object.entries(a.gradients)) e.set(t, await
|
|
197
|
+
for (let [t, n] of Object.entries(a.gradients)) e.set(t, await c(n)), n.dispose();
|
|
197
198
|
p.gradientMetrics = e;
|
|
198
199
|
}
|
|
199
200
|
if (n) try {
|
|
@@ -226,49 +227,48 @@ var p = {
|
|
|
226
227
|
};
|
|
227
228
|
this.running = !0;
|
|
228
229
|
}
|
|
229
|
-
async trainOnDataset(
|
|
230
|
-
let { logInterval:
|
|
230
|
+
async trainOnDataset(t, r, i, a) {
|
|
231
|
+
let { logInterval: o = 40, maxEpochs: c = Infinity } = {
|
|
231
232
|
...p,
|
|
232
|
-
...
|
|
233
|
-
},
|
|
234
|
-
await this.dummyPass(),
|
|
235
|
-
let
|
|
236
|
-
if (!
|
|
233
|
+
...r
|
|
234
|
+
}, l = c * (r?.epochSteps || 1e3);
|
|
235
|
+
await this.dummyPass(), r?.metrics?.includes("memoryUsage") && (this.model.getProfiler() || this.model.setProfiler(new s()));
|
|
236
|
+
let u = this.lastState;
|
|
237
|
+
if (!u) throw Error("Trainer state has not been initialized. Call prepareToTrain() first.");
|
|
237
238
|
let d = Date.now();
|
|
238
|
-
|
|
239
|
-
let f = d, m =
|
|
239
|
+
u.logStartTime = d;
|
|
240
|
+
let f = d, m = i ? new e(this.model, i, this.maskedLoss) : void 0, h = await t.iterator(), g = h.next();
|
|
240
241
|
try {
|
|
241
242
|
for (; this.running;) {
|
|
242
243
|
let e = await g;
|
|
243
244
|
if (g = h.next(), e.done) break;
|
|
244
|
-
let
|
|
245
|
-
|
|
246
|
-
let s = (
|
|
247
|
-
if (
|
|
248
|
-
let e = (await
|
|
249
|
-
if (isNaN(e) || !isFinite(e)) throw console.error("Invalid loss value:", e), console.error("Batch xs:", await
|
|
250
|
-
console.log(`Step ${
|
|
245
|
+
let t = e.value, n = Date.now(), i = n - f >= o;
|
|
246
|
+
i && (f = n);
|
|
247
|
+
let s = (r?.metrics?.includes("gradientStatistics") || !1) && i, c = this.trainStep(u, t, !1, s);
|
|
248
|
+
if (r.debug) {
|
|
249
|
+
let e = (await c.data())[0];
|
|
250
|
+
if (isNaN(e) || !isFinite(e)) throw console.error("Invalid loss value:", e), console.error("Batch xs:", await t.xs.array()), console.error("Batch ys:", await t.ys.array()), console.error("State:", u), Error("Loss is NaN or Infinity");
|
|
251
|
+
console.log(`Step ${u.step}: Loss = ${e}`);
|
|
251
252
|
}
|
|
252
|
-
|
|
253
|
-
let d =
|
|
254
|
-
|
|
253
|
+
t.xs.dispose(), t.ys.dispose(), u.step++, u.totalSteps++;
|
|
254
|
+
let d = u.step >= l;
|
|
255
|
+
i || d ? await this.performLogging(c, t.xs.shape[0], m, a) : (u.gradientNorm &&= (u.gradientNorm.dispose(), void 0), u.accuracy &&= (u.accuracy.dispose(), void 0)), c.dispose(), d && this.stop();
|
|
255
256
|
}
|
|
256
257
|
} catch (e) {
|
|
257
|
-
throw console.error("Training error:", e),
|
|
258
|
+
throw console.error("Training error:", e), n(), e;
|
|
258
259
|
}
|
|
259
|
-
|
|
260
|
+
n(), this.running = !1, this.model.metaData.actionLog = this.model.metaData.actionLog || [];
|
|
260
261
|
let _ = Date.now();
|
|
261
262
|
return this.model.metaData.actionLog.push({
|
|
262
263
|
action: "pretrain",
|
|
263
264
|
timestamp: _,
|
|
264
265
|
duration: _ - d,
|
|
265
266
|
tokensProcessed: this.tokensProcessed,
|
|
266
|
-
options:
|
|
267
|
+
options: r
|
|
267
268
|
}), {
|
|
268
|
-
losses:
|
|
269
|
-
validationLosses:
|
|
269
|
+
losses: u.losses,
|
|
270
|
+
validationLosses: u.validationLosses
|
|
270
271
|
};
|
|
271
272
|
}
|
|
272
273
|
};
|
|
273
|
-
//#endregion
|
|
274
274
|
export { h as default };
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { i as DatasetBuilder, n as flattenTokens, r as flattenTokensWithMask, t as moveToNext, e as shuffle };
|
|
1
|
+
export { t as DatasetBuilder, n as flattenTokens, r as flattenTokensWithMask, i as moveToNext, a as shuffle } from "../DatasetBuilder-DRDW8tcM.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Y as e } from "../dist-CMMLi-qO.js";
|
|
2
2
|
import { calculateAccuracy as t, calculateLoss as n } from "./loss.js";
|
|
3
|
-
|
|
3
|
+
// lib/training/Evaluator.ts
|
|
4
4
|
var r = class {
|
|
5
5
|
model;
|
|
6
6
|
iterator;
|
|
@@ -43,9 +43,9 @@ var r = class {
|
|
|
43
43
|
loss: t / r,
|
|
44
44
|
accuracy: n / r
|
|
45
45
|
};
|
|
46
|
-
}
|
|
46
|
+
}
|
|
47
|
+
if (this.xs && this.ys) return this.calculateBatchLoss(this.xs, this.ys, !0, !0);
|
|
47
48
|
throw Error("No data available for evaluation");
|
|
48
49
|
}
|
|
49
50
|
};
|
|
50
|
-
//#endregion
|
|
51
51
|
export { r as default };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import t from "
|
|
3
|
-
|
|
1
|
+
import e from "./BasicTrainer.js";
|
|
2
|
+
import { t } from "../DatasetBuilder-DRDW8tcM.js";
|
|
3
|
+
// lib/training/PreTrainer.ts
|
|
4
4
|
var n = {
|
|
5
5
|
decayEpochs: 100,
|
|
6
6
|
epochSteps: 1e4,
|
|
@@ -8,15 +8,14 @@ var n = {
|
|
|
8
8
|
minLearningRate: 3e-5,
|
|
9
9
|
weightDecay: .1,
|
|
10
10
|
learningRate: 3e-4
|
|
11
|
-
}, r = class extends
|
|
11
|
+
}, r = class extends e {
|
|
12
12
|
tokenizer;
|
|
13
13
|
datasetBuilder;
|
|
14
|
-
constructor(
|
|
15
|
-
super(
|
|
14
|
+
constructor(e, r, i, a) {
|
|
15
|
+
super(e, r, {
|
|
16
16
|
...n,
|
|
17
17
|
...i
|
|
18
|
-
}, a), this.tokenizer = r, this.optimizerConfig.minLearningRate = i?.minLearningRate ?? this.optimizerConfig.learningRate / 20, this.updateOptimizer(), this.datasetBuilder = new
|
|
18
|
+
}, a), this.tokenizer = r, this.optimizerConfig.minLearningRate = i?.minLearningRate ?? this.optimizerConfig.learningRate / 20, this.updateOptimizer(), this.datasetBuilder = new t(r, e.config.blockSize);
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
|
-
//#endregion
|
|
22
21
|
export { r as default };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import t from "
|
|
3
|
-
|
|
1
|
+
import e from "./BasicTrainer.js";
|
|
2
|
+
import { t } from "../DatasetBuilder-DRDW8tcM.js";
|
|
3
|
+
// lib/training/SFTTrainer.ts
|
|
4
4
|
var n = {
|
|
5
5
|
decayEpochs: 100,
|
|
6
6
|
epochSteps: 1e4,
|
|
@@ -9,16 +9,15 @@ var n = {
|
|
|
9
9
|
weightDecay: .1,
|
|
10
10
|
beta2: .95,
|
|
11
11
|
learningRate: 3e-4
|
|
12
|
-
}, r = class extends
|
|
12
|
+
}, r = class extends e {
|
|
13
13
|
tokenizer;
|
|
14
14
|
datasetBuilder;
|
|
15
15
|
loraName;
|
|
16
|
-
constructor(
|
|
17
|
-
super(
|
|
16
|
+
constructor(e, r, i, a) {
|
|
17
|
+
super(e, r, {
|
|
18
18
|
...n,
|
|
19
19
|
...i
|
|
20
|
-
}, a), this.tokenizer = r, this.optimizerConfig.minLearningRate = i?.minLearningRate ?? this.optimizerConfig.learningRate / 20, this.updateOptimizer(), this.datasetBuilder = new
|
|
20
|
+
}, a), this.tokenizer = r, this.optimizerConfig.minLearningRate = i?.minLearningRate ?? this.optimizerConfig.learningRate / 20, this.updateOptimizer(), this.datasetBuilder = new t(r, e.config.blockSize), this.maskedLoss = !0;
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
|
-
//#endregion
|
|
24
23
|
export { r as default };
|