@genai-fi/nanogpt 0.19.1 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BaseTokeniser-DSg9zcYq.js +221 -0
- package/dist/DatasetBuilder-DgURD85T.js +712 -0
- package/dist/Generator.js +2 -11941
- package/dist/RealDiv-DBu0FQqT.js +362 -0
- package/dist/Reshape-CABOPB9d.js +94 -0
- package/dist/Reshape-DqO3r8BC.js +17 -0
- package/dist/TeachableLLM.d.ts +5 -5
- package/dist/TeachableLLM.js +2 -273
- package/dist/Trainer.js +2 -244
- package/dist/backend.js +12 -12
- package/dist/backend_util-Cg-roD1p.js +399 -0
- package/dist/binary_op_util-CrYk9LXL.js +103 -0
- package/dist/checks/appendCache.js +54 -21
- package/dist/checks/attentionMask.js +55 -36
- package/dist/checks/check.js +31 -19
- package/dist/checks/gelu.js +45 -17
- package/dist/checks/index.js +25 -25
- package/dist/checks/matMulGelu.js +83 -27
- package/dist/checks/normRMS.js +27 -15
- package/dist/checks/normRMSGrad.js +21 -11
- package/dist/checks/packUnpack.js +45 -17
- package/dist/checks/qkv.js +33 -33
- package/dist/checks/rope.js +29 -35
- package/dist/checks/weights.d.ts +1 -1
- package/dist/checks/weights.js +25 -29
- package/dist/chunk-BPntVaq0.js +23 -0
- package/dist/complex_util-CkazZsaH.js +60 -0
- package/dist/concat_util-CWDZCBlA.js +19 -0
- package/dist/data/docx.js +3044 -13
- package/dist/data/pdf.js +16 -13
- package/dist/data/textLoader.js +607 -112
- package/dist/dist-BewPQWjc.js +7572 -0
- package/dist/dist-DVmq73nz.js +8775 -0
- package/dist/dist-DXwIvKxl.js +896 -0
- package/dist/dist-VEU5mfO0.js +7545 -0
- package/dist/gelu-Bf1HW1RY.js +27 -0
- package/dist/gpgpu_math-DvLcCH6u.js +1612 -0
- package/dist/inference/types.js +0 -1
- package/dist/kernel_funcs_utils-HiXOOx3f.js +229 -0
- package/dist/layers/BaseLayer.d.ts +2 -2
- package/dist/layers/BaseLayer.js +75 -73
- package/dist/layers/CausalSelfAttention.d.ts +1 -1
- package/dist/layers/CausalSelfAttention.js +98 -85
- package/dist/layers/LoRA.js +47 -57
- package/dist/layers/MLP.d.ts +1 -1
- package/dist/layers/MLP.js +33 -43
- package/dist/layers/PositionEmbedding.d.ts +1 -1
- package/dist/layers/PositionEmbedding.js +26 -30
- package/dist/layers/RMSNorm.d.ts +1 -1
- package/dist/layers/RMSNorm.js +19 -21
- package/dist/layers/RoPECache.js +336 -49
- package/dist/layers/TiedEmbedding.d.ts +1 -1
- package/dist/layers/TiedEmbedding.js +30 -34
- package/dist/layers/TransformerBlock.d.ts +1 -1
- package/dist/layers/TransformerBlock.js +50 -39
- package/dist/layers/WeightStore.js +68 -75
- package/dist/loader/load.js +2 -68
- package/dist/loader/loadHF.d.ts +2 -2
- package/dist/loader/loadHF.js +2 -22
- package/dist/loader/loadTransformers.d.ts +1 -1
- package/dist/loader/loadTransformers.js +2 -44
- package/dist/loader/loadZipMeta.js +15 -15
- package/dist/loader/newZipLoad.js +2 -31
- package/dist/loader/oldZipLoad.d.ts +2 -2
- package/dist/loader/oldZipLoad.js +2 -80
- package/dist/loader/save.d.ts +5 -5
- package/dist/loader/save.js +2 -90
- package/dist/loader/types.d.ts +9 -8
- package/dist/loader/types.js +0 -1
- package/dist/main-CPjeMv0G.js +13500 -0
- package/dist/main.d.ts +1 -1
- package/dist/main.js +16 -109
- package/dist/matMul16-BNfZSnNM.js +81 -0
- package/dist/matMulGelu-CPTntosE.js +162 -0
- package/dist/models/NanoGPTV1.js +2 -99
- package/dist/models/NanoGPTV2.js +2 -90
- package/dist/models/config.js +34 -47
- package/dist/models/factory.d.ts +1 -1
- package/dist/models/factory.js +2 -16
- package/dist/models/model.d.ts +2 -2
- package/dist/models/model.js +2 -134
- package/dist/ops/adamAdjust.js +15 -6
- package/dist/ops/adamMoments.js +13 -6
- package/dist/ops/add16.js +9 -6
- package/dist/ops/appendCache.js +22 -19
- package/dist/ops/attentionMask.js +12 -6
- package/dist/ops/concat16.js +7 -8
- package/dist/ops/cpu/adamAdjust.js +15 -17
- package/dist/ops/cpu/adamMoments.js +15 -15
- package/dist/ops/cpu/appendCache.js +64 -22
- package/dist/ops/cpu/attentionMask.js +15 -21
- package/dist/ops/cpu/fusedSoftmax.js +21 -28
- package/dist/ops/cpu/gatherSub.js +11 -17
- package/dist/ops/cpu/gelu.js +34 -38
- package/dist/ops/cpu/matMul16.js +13 -14
- package/dist/ops/cpu/matMulGelu.js +39 -51
- package/dist/ops/cpu/matMulMul.js +19 -22
- package/dist/ops/cpu/mulDropout.js +19 -22
- package/dist/ops/cpu/normRMS.js +33 -37
- package/dist/ops/cpu/qkv.js +72 -40
- package/dist/ops/cpu/rope.js +79 -36
- package/dist/ops/cpu/scatterSub.js +11 -22
- package/dist/ops/dot16.js +28 -41
- package/dist/ops/dropout.js +10 -13
- package/dist/ops/dropout16.js +20 -23
- package/dist/ops/gatherSub.js +10 -6
- package/dist/ops/gelu.js +2 -8
- package/dist/ops/globalNorm.js +18 -12
- package/dist/ops/grads/add16.js +27 -26
- package/dist/ops/grads/attentionMask.js +26 -21
- package/dist/ops/grads/dropout16.js +0 -1
- package/dist/ops/grads/gelu.js +2 -5
- package/dist/ops/grads/matMul16.js +2 -9
- package/dist/ops/grads/matMulGelu.js +21 -16
- package/dist/ops/grads/mul16.js +0 -3
- package/dist/ops/grads/normRMS.js +34 -30
- package/dist/ops/grads/pack16.js +2 -6
- package/dist/ops/grads/qkv.js +44 -32
- package/dist/ops/grads/rope.js +2 -5
- package/dist/ops/grads/softmax16.js +21 -23
- package/dist/ops/grads/unpack16.js +2 -5
- package/dist/ops/grads/utils.js +9 -11
- package/dist/ops/matMul16.js +2 -13
- package/dist/ops/matMulGelu.js +16 -10
- package/dist/ops/matMulMul.js +13 -6
- package/dist/ops/mul16.js +42 -38
- package/dist/ops/mulDrop.js +12 -6
- package/dist/ops/normRMS.js +18 -15
- package/dist/ops/pack16.js +2 -5
- package/dist/ops/qkv.js +12 -6
- package/dist/ops/reshape16.js +31 -39
- package/dist/ops/rope.d.ts +1 -1
- package/dist/ops/rope.js +2 -7
- package/dist/ops/scatterSub.js +10 -6
- package/dist/ops/slice16.js +9 -7
- package/dist/ops/softmax16.js +7 -7
- package/dist/ops/sub16.js +9 -6
- package/dist/ops/sum16.js +12 -12
- package/dist/ops/transpose16.js +29 -37
- package/dist/ops/unpack16.js +2 -6
- package/dist/ops/webgl/adamAdjust.js +62 -29
- package/dist/ops/webgl/adamMoments.js +30 -26
- package/dist/ops/webgl/appendCache.js +30 -21
- package/dist/ops/webgl/attentionMask.js +43 -24
- package/dist/ops/webgl/dropout16.js +11 -10
- package/dist/ops/webgl/fusedSoftmax.js +69 -79
- package/dist/ops/webgl/gatherSub.js +27 -26
- package/dist/ops/webgl/gelu.js +32 -34
- package/dist/ops/webgl/log.js +14 -23
- package/dist/ops/webgl/matMul16.js +36 -44
- package/dist/ops/webgl/matMulGelu.js +2 -9
- package/dist/ops/webgl/matMulMul.js +23 -27
- package/dist/ops/webgl/mulDropout.js +31 -40
- package/dist/ops/webgl/normRMS.js +92 -71
- package/dist/ops/webgl/qkv.js +35 -27
- package/dist/ops/webgl/rope.js +37 -21
- package/dist/ops/webgl/scatterSub.js +27 -26
- package/dist/ops/webgpu/adamAdjust.js +59 -39
- package/dist/ops/webgpu/adamMoments.js +62 -46
- package/dist/ops/webgpu/add16.js +13 -12
- package/dist/ops/webgpu/appendCache.js +79 -54
- package/dist/ops/webgpu/attentionMask.js +41 -25
- package/dist/ops/webgpu/attentionMask32_program.js +34 -26
- package/dist/ops/webgpu/clipScale.js +44 -57
- package/dist/ops/webgpu/concat16.js +96 -111
- package/dist/ops/webgpu/dropout16.js +40 -32
- package/dist/ops/webgpu/gatherSub.js +43 -30
- package/dist/ops/webgpu/gelu.js +88 -82
- package/dist/ops/webgpu/index.js +16 -16
- package/dist/ops/webgpu/matMul16.js +69 -64
- package/dist/ops/webgpu/matMul16_program.js +152 -192
- package/dist/ops/webgpu/mul16.js +13 -12
- package/dist/ops/webgpu/norm2.js +45 -75
- package/dist/ops/webgpu/normRMS.js +25 -33
- package/dist/ops/webgpu/normRMS16_program.js +21 -18
- package/dist/ops/webgpu/normRMS32_program.js +21 -18
- package/dist/ops/webgpu/normRMSGrad.js +125 -184
- package/dist/ops/webgpu/pack16.js +20 -17
- package/dist/ops/webgpu/pack16_program.js +48 -47
- package/dist/ops/webgpu/qkv.js +63 -23
- package/dist/ops/webgpu/rope.js +85 -57
- package/dist/ops/webgpu/scatterSub.js +43 -30
- package/dist/ops/webgpu/slice16.js +66 -61
- package/dist/ops/webgpu/softmax16.js +17 -20
- package/dist/ops/webgpu/softmax16_program.js +34 -18
- package/dist/ops/webgpu/softmax16_subgroup_program.js +40 -45
- package/dist/ops/webgpu/softmax16grad.js +30 -36
- package/dist/ops/webgpu/sub16.js +13 -12
- package/dist/ops/webgpu/sum16.js +28 -37
- package/dist/ops/webgpu/transpose16.js +36 -33
- package/dist/ops/webgpu/transpose16_program.js +40 -39
- package/dist/ops/webgpu/transpose16_shared_program.js +53 -44
- package/dist/ops/webgpu/unpack16.js +49 -37
- package/dist/ops/webgpu/utils/binary_op.js +70 -68
- package/dist/ops/webgpu/utils/deviceInfo.d.ts +1 -1
- package/dist/ops/webgpu/utils/deviceInfo.js +10 -10
- package/dist/ops/webgpu/utils/reductions.js +136 -148
- package/dist/pack16-Ck-spx_F.js +39 -0
- package/dist/patches/webgpu_backend.d.ts +2 -2
- package/dist/patches/webgpu_backend.js +42 -55
- package/dist/patches/webgpu_base.js +21 -33
- package/dist/patches/webgpu_program.js +213 -320
- package/dist/pdf-UoDqCYzz.js +16726 -0
- package/dist/picomatch-3tUnMMbd.js +1063 -0
- package/dist/rope-CbeGlsV8.js +25 -0
- package/dist/selu_util-zkAx5doH.js +24 -0
- package/dist/shared-D1coEFea.js +1314 -0
- package/dist/shared-DOgWaqvL.js +5 -0
- package/dist/slice_util-Dgb3ANWI.js +208 -0
- package/dist/tfjs_backend-BjuQ5FqB.js +614 -0
- package/dist/tokeniser/BaseTokeniser.js +2 -124
- package/dist/tokeniser/CharTokeniser.js +91 -106
- package/dist/tokeniser/bpe.js +163 -166
- package/dist/tokeniser/messages.js +0 -1
- package/dist/tokeniser/type.js +0 -1
- package/dist/training/AdamW.js +127 -137
- package/dist/training/BasicTrainer.d.ts +1 -1
- package/dist/training/BasicTrainer.js +264 -264
- package/dist/training/DatasetBuilder.js +2 -86
- package/dist/training/Evaluator.d.ts +1 -1
- package/dist/training/Evaluator.js +47 -38
- package/dist/training/LRScheduler.js +37 -33
- package/dist/training/PreTrainer.d.ts +2 -2
- package/dist/training/PreTrainer.js +21 -19
- package/dist/training/SFTTrainer.d.ts +2 -2
- package/dist/training/SFTTrainer.js +23 -21
- package/dist/training/loss.js +17 -22
- package/dist/training/orthoGrad.js +9 -9
- package/dist/training/sparseCrossEntropy.js +45 -67
- package/dist/training/tasks/ConversationTask.d.ts +1 -1
- package/dist/training/tasks/ConversationTask.js +36 -38
- package/dist/training/tasks/PretrainingTask.d.ts +1 -1
- package/dist/training/tasks/PretrainingTask.js +41 -46
- package/dist/training/tasks/StartSentenceTask.d.ts +1 -1
- package/dist/training/tasks/StartSentenceTask.js +44 -48
- package/dist/training/tasks/Task.d.ts +1 -1
- package/dist/training/tasks/Task.js +53 -66
- package/dist/training/tasks/splitter.js +17 -20
- package/dist/training/types.d.ts +2 -2
- package/dist/training/types.js +0 -1
- package/dist/training/validation.d.ts +1 -1
- package/dist/training/validation.js +2 -84
- package/dist/utilities/arrayClose.js +15 -19
- package/dist/utilities/datasetID.js +17 -20
- package/dist/utilities/dummy.d.ts +1 -1
- package/dist/utilities/dummy.js +33 -40
- package/dist/utilities/multinomialCPU.js +8 -12
- package/dist/utilities/naming.js +0 -1
- package/dist/utilities/packed.js +10 -12
- package/dist/utilities/parameters.d.ts +1 -1
- package/dist/utilities/parameters.js +32 -51
- package/dist/utilities/performance.js +15 -15
- package/dist/utilities/profile.js +32 -37
- package/dist/utilities/safetensors.js +49 -79
- package/dist/utilities/sentences.d.ts +1 -1
- package/dist/utilities/sentences.js +29 -38
- package/dist/utilities/tokenParse.js +16 -20
- package/dist/utilities/topP.js +11 -12
- package/dist/utilities/waitForModel.d.ts +1 -1
- package/dist/utilities/waitForModel.js +11 -11
- package/dist/utilities/weights.js +37 -42
- package/dist/utilities/yielder.js +6 -6
- package/dist/webgpu-Dt7BMzWz.js +525 -0
- package/dist/webgpu_program-WOyIVMlZ.js +392 -0
- package/dist/webgpu_util-B_F3SShA.js +106 -0
- package/package.json +9 -10
- package/dist/RealDiv-CGwv0liw.js +0 -365
- package/dist/Reshape-BW__R4mZ.js +0 -79
- package/dist/Reshape-CPBkTIH2.js +0 -14
- package/dist/_commonjsHelpers-ByX85dGu.js +0 -33
- package/dist/axis_util-GTVlo58H.js +0 -55
- package/dist/backend_util-GaFarB78.js +0 -425
- package/dist/backend_webgpu-BqASlsbV.js +0 -545
- package/dist/binary_op_util-pKXltfxI.js +0 -192
- package/dist/broadcast_to-eS93CCN_.js +0 -28
- package/dist/clip_by_value-DDA7rrcT.js +0 -12
- package/dist/complex-DI35Q-gW.js +0 -11
- package/dist/complex_util-Yc1A_gV1.js +0 -55
- package/dist/concat-CAQpCret.js +0 -17
- package/dist/concat_util-D18dJ4fD.js +0 -22
- package/dist/data/parquet.d.ts +0 -2
- package/dist/data/parquet.js +0 -17
- package/dist/dataset-CGGp1z9P.js +0 -1124
- package/dist/dropout_util--NxWuYg2.js +0 -27
- package/dist/expand_dims-Bkd1YD5x.js +0 -11
- package/dist/exports_initializers-CYzKLjN7.js +0 -7
- package/dist/floor-BQtb-Azg.js +0 -9
- package/dist/gather-qIqEqaGn.js +0 -9
- package/dist/gelu-B220X1Go.js +0 -26
- package/dist/gpgpu_math-BwvV12df.js +0 -2022
- package/dist/index-CUXkjxiT.js +0 -3516
- package/dist/index-CieiGp4Y.js +0 -349
- package/dist/index-CjOWnMXP.js +0 -7308
- package/dist/index-Cp39cXWe.js +0 -1016
- package/dist/index-D5v913EJ.js +0 -4
- package/dist/index-DmeWGGmS.js +0 -1074
- package/dist/index-DvYrXKkX.js +0 -113
- package/dist/index-Ksja3su6.js +0 -151
- package/dist/index-xuotMAFm.js +0 -118
- package/dist/jszip.min-BZhlzntC.js +0 -2313
- package/dist/kernel_funcs_utils-pq0CK9co.js +0 -306
- package/dist/matMul16-BcVC_E62.js +0 -80
- package/dist/matMulGelu-JNLZqKQp.js +0 -163
- package/dist/mat_mul-DhG0Newp.js +0 -11
- package/dist/mod-CSdCpRjf.js +0 -11
- package/dist/non_max_suppression_impl-B2W7YjZB.js +0 -102
- package/dist/not_equal-hurPF26l.js +0 -64
- package/dist/ones-BytntneX.js +0 -14
- package/dist/ops-CsXeTq1P.js +0 -476
- package/dist/pack16-bqltoUlR.js +0 -39
- package/dist/papaparse.min-C0cScC2i.js +0 -418
- package/dist/parquet-Bqjmp2vo.js +0 -44231
- package/dist/pdf-NIhmP3sq.js +0 -19477
- package/dist/rand_util-CZ7yLoUm.js +0 -50
- package/dist/random_normal-IBRrha8a.js +0 -14
- package/dist/random_width-DN5ZtQkM.js +0 -9796
- package/dist/range-C-CjF-LI.js +0 -10
- package/dist/relu-J_X6MUzx.js +0 -9
- package/dist/reshape-BDOuCSNW.js +0 -9
- package/dist/resize_nearest_neighbor-BojqlfRe.js +0 -150
- package/dist/rope-DcrZM_e6.js +0 -24
- package/dist/scatter_nd_util-ByNJaL6I.js +0 -46
- package/dist/segment_util-Dasb2Zaf.js +0 -43
- package/dist/selu_util-BLhIqRkw.js +0 -44
- package/dist/shared-3agzAqQ_.js +0 -53
- package/dist/shared-CagdqkLh.js +0 -2143
- package/dist/slice-BzS11Qh0.js +0 -12
- package/dist/slice_util-CC35pLmT.js +0 -153
- package/dist/softmax-D4q1LJN7.js +0 -12
- package/dist/split-C2Sj255c.js +0 -9
- package/dist/squeeze-ho4wLUek.js +0 -10
- package/dist/stack-DudVrtmG.js +0 -11
- package/dist/step-BTxPtq1r.js +0 -261
- package/dist/sum-BpiwSWvg.js +0 -11
- package/dist/tensor-BWFldCso.js +0 -8
- package/dist/tensor1d-LMGMIUlr.js +0 -11
- package/dist/tensor2d-BnXMKScO.js +0 -14
- package/dist/tensor4d-C6UCG_u8.js +0 -14
- package/dist/tfjs_backend-BGnG-ppu.js +0 -654
- package/dist/tile-CFy-xTO6.js +0 -11
- package/dist/transpose-9kRxIXWR.js +0 -36
- package/dist/unsorted_segment_sum-DJvk5xnh.js +0 -277
- package/dist/variable-Ck482e3n.js +0 -7
- package/dist/webgpu_program-B4HmApL1.js +0 -525
- package/dist/webgpu_util-DYlGSwOJ.js +0 -64
- package/dist/zeros-DvZpK8s6.js +0 -13
- package/dist/zeros_like-CWjDdwr-.js +0 -721
package/dist/TeachableLLM.js
CHANGED
|
@@ -1,273 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { loadModel as u } from "./loader/load.js";
|
|
4
|
-
import f from "./Generator.js";
|
|
5
|
-
import h from "./Trainer.js";
|
|
6
|
-
import { E as c } from "./index-DvYrXKkX.js";
|
|
7
|
-
import { dummyPassTrainAsync as d } from "./utilities/dummy.js";
|
|
8
|
-
import "./index-CUXkjxiT.js";
|
|
9
|
-
import "./random_width-DN5ZtQkM.js";
|
|
10
|
-
import "./zeros_like-CWjDdwr-.js";
|
|
11
|
-
import "./index-Cp39cXWe.js";
|
|
12
|
-
import "./dataset-CGGp1z9P.js";
|
|
13
|
-
import "./ops/cpu/attentionMask.js";
|
|
14
|
-
import "./ops/webgl/attentionMask.js";
|
|
15
|
-
import "./ops/grads/attentionMask.js";
|
|
16
|
-
import "./ops/cpu/rope.js";
|
|
17
|
-
import "./ops/webgl/rope.js";
|
|
18
|
-
import "./rope-DcrZM_e6.js";
|
|
19
|
-
import "./ops/cpu/appendCache.js";
|
|
20
|
-
import "./ops/webgl/appendCache.js";
|
|
21
|
-
import "./ops/grads/softmax16.js";
|
|
22
|
-
import "./matMul16-BcVC_E62.js";
|
|
23
|
-
import "./ops/webgl/matMul16.js";
|
|
24
|
-
import "./ops/cpu/matMul16.js";
|
|
25
|
-
import "./pack16-bqltoUlR.js";
|
|
26
|
-
import "./ops/transpose16.js";
|
|
27
|
-
import "./ops/reshape16.js";
|
|
28
|
-
import "./ops/cpu/qkv.js";
|
|
29
|
-
import "./ops/webgl/qkv.js";
|
|
30
|
-
import "./ops/grads/qkv.js";
|
|
31
|
-
import "./ops/cpu/normRMS.js";
|
|
32
|
-
import "./ops/webgl/normRMS.js";
|
|
33
|
-
import "./ops/grads/normRMS.js";
|
|
34
|
-
import "./ops/dropout16.js";
|
|
35
|
-
import "./ops/webgl/dropout16.js";
|
|
36
|
-
import "./ops/grads/add16.js";
|
|
37
|
-
import g from "./tokeniser/CharTokeniser.js";
|
|
38
|
-
import w from "./tokeniser/bpe.js";
|
|
39
|
-
import "./papaparse.min-C0cScC2i.js";
|
|
40
|
-
import "./jszip.min-BZhlzntC.js";
|
|
41
|
-
import "./ops/cpu/gatherSub.js";
|
|
42
|
-
import "./ops/webgl/gatherSub.js";
|
|
43
|
-
import "./ops/cpu/scatterSub.js";
|
|
44
|
-
import "./ops/webgl/scatterSub.js";
|
|
45
|
-
import "./ops/cpu/matMulGelu.js";
|
|
46
|
-
import "./matMulGelu-JNLZqKQp.js";
|
|
47
|
-
import "./ops/grads/matMulGelu.js";
|
|
48
|
-
import "./ops/cpu/gelu.js";
|
|
49
|
-
import "./ops/webgl/gelu.js";
|
|
50
|
-
import "./gelu-B220X1Go.js";
|
|
51
|
-
import "./ops/webgl/log.js";
|
|
52
|
-
import "./ops/cpu/adamMoments.js";
|
|
53
|
-
import "./ops/webgl/adamMoments.js";
|
|
54
|
-
import "./ops/cpu/adamAdjust.js";
|
|
55
|
-
import "./ops/webgl/adamAdjust.js";
|
|
56
|
-
import "./checks/normRMS.js";
|
|
57
|
-
import "./checks/normRMSGrad.js";
|
|
58
|
-
import k from "./utilities/profile.js";
|
|
59
|
-
import y from "./models/factory.js";
|
|
60
|
-
class l {
|
|
61
|
-
ee = new c();
|
|
62
|
-
_config;
|
|
63
|
-
_model;
|
|
64
|
-
_tokeniser;
|
|
65
|
-
_status = "loading";
|
|
66
|
-
_memoryRequirements;
|
|
67
|
-
meta = {
|
|
68
|
-
version: 2,
|
|
69
|
-
application: "@genai-fi/nanogpt"
|
|
70
|
-
};
|
|
71
|
-
_trainer = null;
|
|
72
|
-
constructor(t, i) {
|
|
73
|
-
this._config = i?.config, this._tokeniser = t, this._model = i, i?.metaData && (this.meta = i.metaData);
|
|
74
|
-
}
|
|
75
|
-
get currentTrainer() {
|
|
76
|
-
return this._trainer;
|
|
77
|
-
}
|
|
78
|
-
get vocab() {
|
|
79
|
-
return this._tokeniser?.getVocab() || [];
|
|
80
|
-
}
|
|
81
|
-
get phase() {
|
|
82
|
-
return this._model?.metaData?.phase ?? "untrained";
|
|
83
|
-
}
|
|
84
|
-
set phase(t) {
|
|
85
|
-
if (!this._model)
|
|
86
|
-
throw new Error("model_not_initialized.");
|
|
87
|
-
this._model.metaData.phase = t, this.ee.emit("phase", t);
|
|
88
|
-
}
|
|
89
|
-
/** Model is fully loaded */
|
|
90
|
-
get loaded() {
|
|
91
|
-
return !!this._model && !!this._tokeniser && !!this._config;
|
|
92
|
-
}
|
|
93
|
-
get config() {
|
|
94
|
-
if (!this._config)
|
|
95
|
-
throw new Error("configuration_not_initialized.");
|
|
96
|
-
return this._config;
|
|
97
|
-
}
|
|
98
|
-
get model() {
|
|
99
|
-
if (!this._model)
|
|
100
|
-
throw new Error("model_not_initialized.");
|
|
101
|
-
return this._model;
|
|
102
|
-
}
|
|
103
|
-
get tokeniser() {
|
|
104
|
-
if (!this._tokeniser)
|
|
105
|
-
throw new Error("tokeniser_not_initialized.");
|
|
106
|
-
return this._tokeniser;
|
|
107
|
-
}
|
|
108
|
-
get status() {
|
|
109
|
-
return this._status;
|
|
110
|
-
}
|
|
111
|
-
/** Model is both ready and not busy */
|
|
112
|
-
get ready() {
|
|
113
|
-
return this._status === "ready" && !!this._model && !!this._tokeniser;
|
|
114
|
-
}
|
|
115
|
-
get busy() {
|
|
116
|
-
return this._status === "busy" || this._status === "training";
|
|
117
|
-
}
|
|
118
|
-
createLoRA(t, i) {
|
|
119
|
-
if (!this._model)
|
|
120
|
-
throw new Error("model_not_initialized.");
|
|
121
|
-
this._model.createLoRA(t, i), this.ee.emit("changeLoRA");
|
|
122
|
-
}
|
|
123
|
-
deleteLoRA(t) {
|
|
124
|
-
if (!this._model)
|
|
125
|
-
throw new Error("model_not_initialized.");
|
|
126
|
-
this._model.deleteLoRA(t), this.ee.emit("changeLoRA");
|
|
127
|
-
}
|
|
128
|
-
renameLoRA(t, i) {
|
|
129
|
-
if (!this._model)
|
|
130
|
-
throw new Error("model_not_initialized.");
|
|
131
|
-
this._model.renameLoRA(t, i), this.ee.emit("changeLoRA");
|
|
132
|
-
}
|
|
133
|
-
attachLoRA(t) {
|
|
134
|
-
if (!this._model)
|
|
135
|
-
throw new Error("model_not_initialized.");
|
|
136
|
-
this.model.lora?.name !== t && (this._trainer && (this._trainer.dispose(), this._trainer = null), this._model.attachLoRA(t), this.ee.emit("changeLoRA"));
|
|
137
|
-
}
|
|
138
|
-
detachLoRA() {
|
|
139
|
-
if (!this._model)
|
|
140
|
-
throw new Error("model_not_initialized.");
|
|
141
|
-
this._model.detachLoRA(), this.ee.emit("changeLoRA");
|
|
142
|
-
}
|
|
143
|
-
hasLoRA(t) {
|
|
144
|
-
if (!this._model)
|
|
145
|
-
throw new Error("model_not_initialized.");
|
|
146
|
-
return this._model.hasLoRA(t);
|
|
147
|
-
}
|
|
148
|
-
listLoRAs() {
|
|
149
|
-
if (!this._model)
|
|
150
|
-
throw new Error("model_not_initialized.");
|
|
151
|
-
return this._model.listLoRAs();
|
|
152
|
-
}
|
|
153
|
-
estimateTrainingMemoryUsage(t) {
|
|
154
|
-
const i = this._memoryRequirements ?? { perBatch: 0, gradients: 0 }, e = i.perBatch * t, o = i.gradients;
|
|
155
|
-
return e * 0.66 + o * 4;
|
|
156
|
-
}
|
|
157
|
-
setStatus(t) {
|
|
158
|
-
this._status !== t && (this._status = t, this.ee.emit("status", t));
|
|
159
|
-
}
|
|
160
|
-
saveModel(t) {
|
|
161
|
-
if (!this._model || !this._tokeniser)
|
|
162
|
-
throw new Error("model_or_tokeniser_not_initialized.");
|
|
163
|
-
return p(
|
|
164
|
-
this._model,
|
|
165
|
-
this._tokeniser,
|
|
166
|
-
{
|
|
167
|
-
...t,
|
|
168
|
-
name: t?.name || this.meta.name
|
|
169
|
-
},
|
|
170
|
-
t?.includeOptimizer && this._trainer?.trainingType === "pretraining" ? { optimizer: this._trainer.optimizer, trainingLog: this._trainer.log } : void 0
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
static loadModel(t, i) {
|
|
174
|
-
const e = new l();
|
|
175
|
-
return u(t, i).then(({ model: o, tokeniser: s, metaData: r, optimizer: n, log: a }) => {
|
|
176
|
-
_(o.config), e._model = o, e._tokeniser = s, e._config = o.config, r && (e.meta = r), e.setStatus("warmup"), d(o).then((m) => {
|
|
177
|
-
e._memoryRequirements = m, n && (e._trainer = new h(
|
|
178
|
-
o,
|
|
179
|
-
s,
|
|
180
|
-
"pretraining",
|
|
181
|
-
o.metaData.pretrainingSettings,
|
|
182
|
-
n
|
|
183
|
-
), a && (e._trainer.log = a)), e.setStatus("ready"), e.ee.emit("loaded"), e.ee.emit("phase", e.phase);
|
|
184
|
-
}).catch((m) => {
|
|
185
|
-
e.setStatus("error"), e.ee.emit("error", m), console.error("Error during warmup:", m);
|
|
186
|
-
});
|
|
187
|
-
}).catch((o) => {
|
|
188
|
-
e.setStatus("error"), e.ee.emit("error", o), console.error("Error loading model:", o);
|
|
189
|
-
}), e;
|
|
190
|
-
}
|
|
191
|
-
static create(t, i) {
|
|
192
|
-
_(i);
|
|
193
|
-
const e = i, o = t === "char" ? new g(e.vocabSize) : new w(e.vocabSize), s = y(e), r = new l(o, s);
|
|
194
|
-
return r.setStatus("warmup"), d(s).then((n) => {
|
|
195
|
-
r._memoryRequirements = n, r.tokeniser.trained ? (r.setStatus("ready"), r.ee.emit("loaded"), r.ee.emit("phase", r.phase)) : (r.setStatus("awaitingTokens"), r.ee.emit("loaded"), r.ee.emit("phase", r.phase), r.tokeniser.once("trainStatus", (a) => {
|
|
196
|
-
a === "trained" && r.setStatus("ready");
|
|
197
|
-
}));
|
|
198
|
-
}).catch((n) => {
|
|
199
|
-
r.setStatus("error"), r.ee.emit("error", n), console.error("Error during warmup:", n);
|
|
200
|
-
}), r;
|
|
201
|
-
}
|
|
202
|
-
getProfiler() {
|
|
203
|
-
return this._model?.getProfiler();
|
|
204
|
-
}
|
|
205
|
-
get enableProfiler() {
|
|
206
|
-
return !!this._model?.getProfiler();
|
|
207
|
-
}
|
|
208
|
-
set enableProfiler(t) {
|
|
209
|
-
if (t) {
|
|
210
|
-
if (!this._config)
|
|
211
|
-
return;
|
|
212
|
-
this.model.getProfiler() || this.model.setProfiler(new k());
|
|
213
|
-
} else
|
|
214
|
-
this.model.getProfiler() && this.model.setProfiler(null);
|
|
215
|
-
}
|
|
216
|
-
getNumParams() {
|
|
217
|
-
return this._model ? this._model.getNumParams() : 0;
|
|
218
|
-
}
|
|
219
|
-
trainer(t, i) {
|
|
220
|
-
if (!this._model || !this._tokeniser)
|
|
221
|
-
throw new Error("model_or_tokeniser_not_initialized.");
|
|
222
|
-
this._trainer && t && this._trainer.trainingType !== t && (this._trainer.dispose(), this._trainer = null);
|
|
223
|
-
const e = this._trainer === null ? new h(this._model, this._tokeniser, t, i) : new h(this._trainer, i);
|
|
224
|
-
return e.on("start", () => {
|
|
225
|
-
this.setStatus("training"), this.phase = t === "sft" ? "finetuned" : "pretrained";
|
|
226
|
-
}), e.on("stop", () => this.setStatus("ready")), e.on("log", async (o) => {
|
|
227
|
-
const s = this.ee.listeners("trainStep");
|
|
228
|
-
for (const r of s)
|
|
229
|
-
await r(o);
|
|
230
|
-
}), this._trainer && this._trainer !== e && this._trainer.removeAllListeners(), this._trainer = e, e;
|
|
231
|
-
}
|
|
232
|
-
async train(t, i, e) {
|
|
233
|
-
const o = this.trainer(e, i);
|
|
234
|
-
await o.prepare(t), await o.train();
|
|
235
|
-
}
|
|
236
|
-
async trainTokeniser(t) {
|
|
237
|
-
if (!this._tokeniser)
|
|
238
|
-
throw new Error("tokeniser_not_initialized.");
|
|
239
|
-
const i = await this._tokeniser.train(t);
|
|
240
|
-
return this._status === "awaitingTokens" && this.setStatus("ready"), i;
|
|
241
|
-
}
|
|
242
|
-
generator() {
|
|
243
|
-
if (!this._model || !this._tokeniser)
|
|
244
|
-
throw new Error("model_or_tokeniser_not_initialized.");
|
|
245
|
-
const t = new f(this._model, this._tokeniser);
|
|
246
|
-
return t.on("start", () => {
|
|
247
|
-
this.status === "ready" && this.setStatus("busy");
|
|
248
|
-
}), t.on("stop", () => {
|
|
249
|
-
this.status === "busy" && this.setStatus("ready");
|
|
250
|
-
}), t;
|
|
251
|
-
}
|
|
252
|
-
generateText(t, i) {
|
|
253
|
-
return Array.isArray(t) ? this.generator().generate(t, i) : this.generator().generate([], i);
|
|
254
|
-
}
|
|
255
|
-
dispose() {
|
|
256
|
-
this._trainer && (this._trainer.dispose(), this._trainer = null), this._model?.dispose(), this.ee.removeAllListeners();
|
|
257
|
-
}
|
|
258
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
259
|
-
on(t, i) {
|
|
260
|
-
if (t === "loaded" && this.loaded) {
|
|
261
|
-
setTimeout(() => i(), 0);
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
this.ee.on(t, i);
|
|
265
|
-
}
|
|
266
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
267
|
-
off(t, i) {
|
|
268
|
-
this.ee.off(t, i);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
export {
|
|
272
|
-
l as default
|
|
273
|
-
};
|
|
1
|
+
import { i as e } from "./main-CPjeMv0G.js";
|
|
2
|
+
export { e as default };
|
package/dist/Trainer.js
CHANGED
|
@@ -1,244 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { createTrainValidationSplit as f } from "./training/validation.js";
|
|
4
|
-
import g from "./training/SFTTrainer.js";
|
|
5
|
-
const s = [];
|
|
6
|
-
for (let n = 0; n < 256; ++n)
|
|
7
|
-
s.push((n + 256).toString(16).slice(1));
|
|
8
|
-
function T(n, t = 0) {
|
|
9
|
-
return (s[n[t + 0]] + s[n[t + 1]] + s[n[t + 2]] + s[n[t + 3]] + "-" + s[n[t + 4]] + s[n[t + 5]] + "-" + s[n[t + 6]] + s[n[t + 7]] + "-" + s[n[t + 8]] + s[n[t + 9]] + "-" + s[n[t + 10]] + s[n[t + 11]] + s[n[t + 12]] + s[n[t + 13]] + s[n[t + 14]] + s[n[t + 15]]).toLowerCase();
|
|
10
|
-
}
|
|
11
|
-
const p = new Uint8Array(16);
|
|
12
|
-
function k() {
|
|
13
|
-
return crypto.getRandomValues(p);
|
|
14
|
-
}
|
|
15
|
-
function m(n, t, e) {
|
|
16
|
-
return crypto.randomUUID ? crypto.randomUUID() : L(n);
|
|
17
|
-
}
|
|
18
|
-
function L(n, t, e) {
|
|
19
|
-
n = n || {};
|
|
20
|
-
const i = n.random ?? n.rng?.() ?? k();
|
|
21
|
-
if (i.length < 16)
|
|
22
|
-
throw new Error("Random bytes length must be >= 16");
|
|
23
|
-
return i[6] = i[6] & 15 | 64, i[8] = i[8] & 63 | 128, T(i);
|
|
24
|
-
}
|
|
25
|
-
class u extends w {
|
|
26
|
-
trainer;
|
|
27
|
-
trainingType = "pretraining";
|
|
28
|
-
hasTrained = !1;
|
|
29
|
-
trainDataset;
|
|
30
|
-
validationDataset;
|
|
31
|
-
totalTokens = 0;
|
|
32
|
-
tokensProcessed = 0;
|
|
33
|
-
log = [];
|
|
34
|
-
progress = null;
|
|
35
|
-
options = {
|
|
36
|
-
batchSize: 32,
|
|
37
|
-
sftMode: "full",
|
|
38
|
-
logInterval: 10
|
|
39
|
-
};
|
|
40
|
-
tokenizer;
|
|
41
|
-
constructor(t, e, i, a, o) {
|
|
42
|
-
if (super(), t instanceof u) {
|
|
43
|
-
const r = e || t.options, h = t.options;
|
|
44
|
-
let l = !1;
|
|
45
|
-
if (t.trainingType === "sft" && r.sftMode !== h.sftMode && (l = !0), t.trainer instanceof g && t.trainer.loraName && r.loraName !== t.trainer.loraName && (l = !0), i !== void 0 && i !== t.trainingType && (l = !0), l) {
|
|
46
|
-
if (t.trainingType === "sft") {
|
|
47
|
-
const d = new g(t.model, t.tokenizer, r);
|
|
48
|
-
this.trainer = d, d.loraName = r.loraName;
|
|
49
|
-
} else
|
|
50
|
-
this.trainer = new c(t.model, t.tokenizer, r);
|
|
51
|
-
this.trainingType = i || t.trainingType, this.options = r, this.tokenizer = t.tokenizer;
|
|
52
|
-
} else
|
|
53
|
-
this.trainer = t.trainer, this.trainingType = i || t.trainingType, this.options = r, this.trainer.updateOptimizer(this.options), this.log = t.log, this.progress = t.progress, this.totalTokens = t.totalTokens, this.tokenizer = t.tokenizer, r.batchSize === h.batchSize && (this.trainDataset = t.trainDataset, this.validationDataset = t.validationDataset);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (!e)
|
|
57
|
-
throw new Error("Tokeniser must be provided when initializing Trainer with a model");
|
|
58
|
-
if (!t)
|
|
59
|
-
throw new Error("Model must be provided when initializing Trainer");
|
|
60
|
-
if (this.options = a || {
|
|
61
|
-
batchSize: 32,
|
|
62
|
-
sftMode: "full"
|
|
63
|
-
}, i === "sft") {
|
|
64
|
-
const r = new g(t, e, a, o);
|
|
65
|
-
this.trainer = r, r.loraName = a?.loraName;
|
|
66
|
-
} else
|
|
67
|
-
this.trainer = new c(t, e, a, o);
|
|
68
|
-
this.trainingType = i || "pretraining", this.tokenizer = e;
|
|
69
|
-
}
|
|
70
|
-
get model() {
|
|
71
|
-
return this.trainer.model;
|
|
72
|
-
}
|
|
73
|
-
get optimizer() {
|
|
74
|
-
return this.trainer.optimizer;
|
|
75
|
-
}
|
|
76
|
-
stop() {
|
|
77
|
-
this.trainer.stop();
|
|
78
|
-
}
|
|
79
|
-
reset() {
|
|
80
|
-
this.hasTrained = !1, this.log = [], this.trainer.reset();
|
|
81
|
-
}
|
|
82
|
-
dispose() {
|
|
83
|
-
this.trainer.dispose(), this.removeAllListeners();
|
|
84
|
-
}
|
|
85
|
-
getTotalTokens() {
|
|
86
|
-
return this.totalTokens;
|
|
87
|
-
}
|
|
88
|
-
setOptions(t) {
|
|
89
|
-
const e = new Set(
|
|
90
|
-
Object.keys(t).filter(
|
|
91
|
-
(i) => t[i] !== this.options[i]
|
|
92
|
-
)
|
|
93
|
-
);
|
|
94
|
-
if (this.trainer.isRunning) {
|
|
95
|
-
if (e.has("batchSize"))
|
|
96
|
-
throw new Error("Cannot change batch size during training");
|
|
97
|
-
if (e.has("sftMode"))
|
|
98
|
-
throw new Error("Cannot change SFT mode during training");
|
|
99
|
-
if (e.has("loraConfig"))
|
|
100
|
-
throw new Error("Cannot change LoRA configuration during training");
|
|
101
|
-
if (e.has("validationSplit"))
|
|
102
|
-
throw new Error("Cannot change validation split during training");
|
|
103
|
-
if (e.has("trainableWeights"))
|
|
104
|
-
throw new Error("Cannot change trainable weights during training");
|
|
105
|
-
if (e.has("mixedPrecision"))
|
|
106
|
-
throw new Error("Cannot change mixed precision setting during training");
|
|
107
|
-
if (e.has("gradientCheckpointing"))
|
|
108
|
-
throw new Error("Cannot change gradient checkpointing setting during training");
|
|
109
|
-
}
|
|
110
|
-
this.options = {
|
|
111
|
-
...this.options,
|
|
112
|
-
...t
|
|
113
|
-
}, this.trainer.updateOptimizer(this.options), e.has("metrics") && this.trainer.setMetrics(t.metrics || []);
|
|
114
|
-
}
|
|
115
|
-
async prepare(t = [], e) {
|
|
116
|
-
const i = this.options;
|
|
117
|
-
if (e && (this.model.metaData.pretrainingData = e.map((a) => ({
|
|
118
|
-
id: a.id,
|
|
119
|
-
name: a.name
|
|
120
|
-
}))), this.trainingType === "pretraining" && this.trainer instanceof c) {
|
|
121
|
-
const { trainDataset: a, validationDataset: o, size: r } = await f(
|
|
122
|
-
t,
|
|
123
|
-
this.trainer.tokenizer,
|
|
124
|
-
this.trainer.datasetBuilder,
|
|
125
|
-
i?.batchSize || 32,
|
|
126
|
-
i?.validationSplit || 0.1,
|
|
127
|
-
i?.maskedLoss ?? !1
|
|
128
|
-
), h = r * (1 - (i?.validationSplit || 0));
|
|
129
|
-
this.trainDataset = a, this.validationDataset = o, this.totalTokens = h, this.options.epochSteps = Math.ceil(
|
|
130
|
-
this.totalTokens / ((i?.batchSize || 32) * this.model.config.blockSize)
|
|
131
|
-
), this.trainer.updateOptimizer(this.options);
|
|
132
|
-
} else if (this.trainingType === "sft" && this.trainer instanceof g) {
|
|
133
|
-
if (t instanceof Uint16Array)
|
|
134
|
-
throw new Error("SFT training requires Task[] input");
|
|
135
|
-
const { trainDataset: a, validationDataset: o, size: r } = await f(
|
|
136
|
-
t,
|
|
137
|
-
this.trainer.tokenizer,
|
|
138
|
-
this.trainer.datasetBuilder,
|
|
139
|
-
i?.batchSize || 32,
|
|
140
|
-
i?.validationSplit || 0.1,
|
|
141
|
-
i?.maskedLoss ?? !0
|
|
142
|
-
), h = r * (1 - (i?.validationSplit || 0));
|
|
143
|
-
this.trainDataset = a, this.validationDataset = o, this.totalTokens = h, this.options.epochSteps = Math.ceil(
|
|
144
|
-
this.totalTokens / ((i?.batchSize || 32) * this.model.config.blockSize)
|
|
145
|
-
), this.trainer.updateOptimizer(this.options);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
configureModel(t) {
|
|
149
|
-
const e = t?.sftMode || "full";
|
|
150
|
-
if (this.trainingType === "pretraining" && (this.trainer.model.hasLoRA() && this.trainer.model.detachLoRA(), this.trainer.model.weightStore.setTrainable(["*"])), this.trainingType === "sft") {
|
|
151
|
-
if (e === "lora") {
|
|
152
|
-
const i = this.trainer.model;
|
|
153
|
-
if (console.log("Configuring model for LoRA fine-tuning with options:", t), t?.loraName)
|
|
154
|
-
if (i.hasLoRA(t.loraName)) {
|
|
155
|
-
if (i.attachLoRA(t.loraName), t.loraConfig) {
|
|
156
|
-
const a = i.lora;
|
|
157
|
-
(a.alpha !== t.loraConfig.alpha || a.rank !== t.loraConfig.rank) && (i.detachLoRA(), i.deleteLoRA(t.loraName), i.createLoRA(t.loraName, t.loraConfig), i.attachLoRA(t.loraName), console.warn("Resetting LoRA with new configuration."));
|
|
158
|
-
}
|
|
159
|
-
} else if (t.loraConfig)
|
|
160
|
-
i.createLoRA(t.loraName, t.loraConfig), i.attachLoRA(t.loraName);
|
|
161
|
-
else
|
|
162
|
-
throw new Error(
|
|
163
|
-
`LoRA configuration must be provided to create LoRA with name ${t.loraName}`
|
|
164
|
-
);
|
|
165
|
-
else if (t?.loraConfig)
|
|
166
|
-
if (i.hasLoRA()) {
|
|
167
|
-
const a = i.lora;
|
|
168
|
-
if (a.alpha !== t.loraConfig.alpha || a.rank !== t.loraConfig.rank) {
|
|
169
|
-
i.detachLoRA();
|
|
170
|
-
const o = t.loraName || m();
|
|
171
|
-
i.createLoRA(o, t.loraConfig), i.attachLoRA(o);
|
|
172
|
-
}
|
|
173
|
-
} else {
|
|
174
|
-
const a = t.loraName || m();
|
|
175
|
-
i.createLoRA(a, t.loraConfig), i.attachLoRA(a);
|
|
176
|
-
}
|
|
177
|
-
else if (!i.hasLoRA()) throw new Error("LoRA configuration must be provided for lora SFT mode");
|
|
178
|
-
} else
|
|
179
|
-
this.trainer.model.hasLoRA() && this.trainer.model.detachLoRA();
|
|
180
|
-
e === "last-layer" ? this.trainer.model.weightStore.setTrainable([
|
|
181
|
-
`block_${this.trainer.model.config.nLayer - 1}_*`,
|
|
182
|
-
"token_embedding"
|
|
183
|
-
]) : e === "full" && this.trainer.model.weightStore.setTrainable(["*"]);
|
|
184
|
-
}
|
|
185
|
-
t?.trainableWeights && this.trainer.model.weightStore.setTrainable(t.trainableWeights);
|
|
186
|
-
}
|
|
187
|
-
async train() {
|
|
188
|
-
const t = this.options;
|
|
189
|
-
if (!this.trainDataset)
|
|
190
|
-
throw new Error("Dataset not prepared");
|
|
191
|
-
this.hasTrained || this.trainer.setLearningRate(t?.learningRate || 1e-3), this.hasTrained = !0, this.emit("start"), this.model.metaData.pretrainingSettings = t;
|
|
192
|
-
const e = Date.now();
|
|
193
|
-
this.log.length > 0 && this.trainer.resumeFromLog(this.log[this.log.length - 1]), this.trainer.setGradientCheckpointing(t?.gradientCheckpointing || !1), this.trainer.setMixedPrecision(t?.mixedPrecision || !1), this.trainer.setLabelSmoothing(t?.labelSmoothing || 0), this.trainer.setDropout(t?.dropout || 0), this.trainer.setLayerDrop(t?.layerDrop || 0), this.configureModel(t), await this.trainer.trainOnDataset(
|
|
194
|
-
this.trainDataset,
|
|
195
|
-
{
|
|
196
|
-
...t,
|
|
197
|
-
onStep: async (a) => {
|
|
198
|
-
this.log.push(a), this.progress = {
|
|
199
|
-
lastLog: a,
|
|
200
|
-
progress: a.totalTokens / this.totalTokens,
|
|
201
|
-
remaining: Math.max(0, (this.totalTokens - a.totalTokens) / a.totalTokens * a.duration)
|
|
202
|
-
}, this.tokensProcessed = a.totalTokens;
|
|
203
|
-
const o = this.listeners("log");
|
|
204
|
-
for (const r of o)
|
|
205
|
-
await r(a, this.progress);
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
this.validationDataset
|
|
209
|
-
), this.model.metaData.actionLog = this.model.metaData.actionLog || [];
|
|
210
|
-
const i = Date.now();
|
|
211
|
-
this.model.metaData.actionLog.push({
|
|
212
|
-
action: "pretrain",
|
|
213
|
-
timestamp: i,
|
|
214
|
-
duration: i - e,
|
|
215
|
-
tokensProcessed: this.tokensProcessed,
|
|
216
|
-
options: t
|
|
217
|
-
}), this.emit("stop");
|
|
218
|
-
}
|
|
219
|
-
async step(t) {
|
|
220
|
-
if (!this.trainDataset)
|
|
221
|
-
throw new Error("Dataset not prepared");
|
|
222
|
-
this.hasTrained || this.trainer.setLearningRate(t?.learningRate || 1e-3), this.hasTrained = !0, this.emit("start");
|
|
223
|
-
const { log: e } = await this.trainer.stepDataset(this.trainDataset, t || {}, this.validationDataset), i = this.listeners("log");
|
|
224
|
-
for (const a of i)
|
|
225
|
-
await a(e, {
|
|
226
|
-
lastLog: e,
|
|
227
|
-
progress: e.totalTokens / this.totalTokens,
|
|
228
|
-
remaining: Math.max(0, (this.totalTokens - e.totalTokens) / e.totalTokens * e.duration)
|
|
229
|
-
});
|
|
230
|
-
this.emit("stop");
|
|
231
|
-
}
|
|
232
|
-
getLog() {
|
|
233
|
-
return this.log;
|
|
234
|
-
}
|
|
235
|
-
getProgress() {
|
|
236
|
-
return this.progress;
|
|
237
|
-
}
|
|
238
|
-
isPrepared() {
|
|
239
|
-
return this.trainDataset !== void 0 && this.validationDataset !== void 0;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
export {
|
|
243
|
-
u as default
|
|
244
|
-
};
|
|
1
|
+
import { a as e } from "./main-CPjeMv0G.js";
|
|
2
|
+
export { e as default };
|
package/dist/backend.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { ai as e, ci as t, ui as n } from "./dist-BewPQWjc.js";
|
|
2
|
+
//#region lib/backend.ts
|
|
3
|
+
async function r(r, i) {
|
|
4
|
+
if (e() !== r) {
|
|
5
|
+
if (r === "webgpu") {
|
|
6
|
+
let { registerWebGPUBackend: e } = await import("./patches/webgpu_base.js");
|
|
7
|
+
e(i), await import("./dist-DVmq73nz.js"), await import("./ops/webgpu/index.js");
|
|
8
|
+
}
|
|
9
|
+
await n(r), await t(), console.log(`Backend set to ${r}`);
|
|
10
|
+
}
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { r as selectBackend };
|