@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
|
@@ -1,49 +1,45 @@
|
|
|
1
|
-
import { Task as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
async estimateTokens(t) {
|
|
44
|
-
return (await t.encodeConversation(this.conversationFromString(this.rawText[0]))).length * this.length;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
export {
|
|
48
|
-
a as default
|
|
1
|
+
import { Task as e } from "./Task.js";
|
|
2
|
+
//#region lib/training/tasks/StartSentenceTask.ts
|
|
3
|
+
var t = class extends e {
|
|
4
|
+
rawText;
|
|
5
|
+
index = 0;
|
|
6
|
+
get length() {
|
|
7
|
+
return this.rawText.length;
|
|
8
|
+
}
|
|
9
|
+
constructor(e) {
|
|
10
|
+
super(), this.rawText = e;
|
|
11
|
+
}
|
|
12
|
+
hasMoreConversations() {
|
|
13
|
+
return this.index < this.rawText.length;
|
|
14
|
+
}
|
|
15
|
+
nextConversation() {
|
|
16
|
+
if (this.index >= this.rawText.length) return null;
|
|
17
|
+
let e = this.rawText[this.index];
|
|
18
|
+
return this.index++, this.conversationFromString(e);
|
|
19
|
+
}
|
|
20
|
+
nextTokens(e, t) {
|
|
21
|
+
let n = this.nextConversation();
|
|
22
|
+
return n ? e.encodeConversation(n, !1, t) : null;
|
|
23
|
+
}
|
|
24
|
+
shuffle() {
|
|
25
|
+
this.index = 0;
|
|
26
|
+
}
|
|
27
|
+
conversationFromString(e) {
|
|
28
|
+
let t = e.indexOf(".");
|
|
29
|
+
return t === -1 ? [{
|
|
30
|
+
role: "assistant",
|
|
31
|
+
content: this.rawText[this.index]
|
|
32
|
+
}] : [{
|
|
33
|
+
role: "user",
|
|
34
|
+
content: e.slice(0, t + 1).trim()
|
|
35
|
+
}, {
|
|
36
|
+
role: "assistant",
|
|
37
|
+
content: e.slice(t + 1).trim()
|
|
38
|
+
}];
|
|
39
|
+
}
|
|
40
|
+
async estimateTokens(e) {
|
|
41
|
+
return (await e.encodeConversation(this.conversationFromString(this.rawText[0]))).length * this.length;
|
|
42
|
+
}
|
|
49
43
|
};
|
|
44
|
+
//#endregion
|
|
45
|
+
export { t as default };
|
|
@@ -1,68 +1,55 @@
|
|
|
1
|
-
import { yieldIfNeeded as
|
|
2
|
-
|
|
1
|
+
import { yieldIfNeeded as e } from "../../utilities/yielder.js";
|
|
2
|
+
//#region lib/training/tasks/Task.ts
|
|
3
|
+
var t = class {};
|
|
4
|
+
function n(e, t, n, r, i, a) {
|
|
5
|
+
for (let o of e) {
|
|
6
|
+
let e = o.nextTokens(n, a ? !0 : void 0);
|
|
7
|
+
if (e) {
|
|
8
|
+
let n = Array.isArray(e) ? e : e.tokens;
|
|
9
|
+
r.total += n.length;
|
|
10
|
+
let o = t[t.length - 1], s = a ? a[a.length - 1] : null;
|
|
11
|
+
if (r.offset + n.length > o.length) {
|
|
12
|
+
let c = o.length - r.offset;
|
|
13
|
+
o.set(n.slice(0, c), r.offset);
|
|
14
|
+
let l = new Uint16Array(Math.floor(i * .1) + 100);
|
|
15
|
+
if (l.set(n.slice(c), 0), t.push(l), a && s && !Array.isArray(e)) {
|
|
16
|
+
s.set(e.mask.slice(0, c).map((e) => +!!e), r.offset);
|
|
17
|
+
let t = new Uint8Array(l.length);
|
|
18
|
+
t.set(e.mask.slice(c).map((e) => +!!e), 0), a.push(t);
|
|
19
|
+
}
|
|
20
|
+
r.offset = n.length - c;
|
|
21
|
+
} else o.set(n, r.offset), s && !Array.isArray(e) && s.set(e.mask.map((e) => +!!e), r.offset), r.offset += n.length;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
3
24
|
}
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
}
|
|
25
|
+
async function r(t, r, i, a) {
|
|
26
|
+
let o = Math.min((await Promise.all(t.map((e) => e.estimateTokens(r)))).reduce((e, t) => e + t, 0), r.vocabSize * 1e4), s = [new Uint16Array(o)], c = a ? [new Uint8Array(o)] : null, l = {
|
|
27
|
+
offset: 0,
|
|
28
|
+
total: 0
|
|
29
|
+
}, u = performance.now();
|
|
30
|
+
for (; l.offset < o && (n(t, s, r, l, o, c || void 0), !t.every((e) => !e.hasMoreConversations()));) u = await e(u, i, l.total);
|
|
31
|
+
if (s.length === 1) return c ? {
|
|
32
|
+
tokens: s[0].subarray(0, l.offset),
|
|
33
|
+
mask: c[0].subarray(0, l.offset)
|
|
34
|
+
} : s[0].subarray(0, l.offset);
|
|
35
|
+
let d = s.reduce((e, t) => e + t.length, 0) - (s[s.length - 1].length - l.offset), f = new Uint16Array(d), p = 0;
|
|
36
|
+
for (let e = 0; e < s.length; e++) {
|
|
37
|
+
let t = s[e];
|
|
38
|
+
e === s.length - 1 ? (f.set(t.subarray(0, l.offset), p), p += l.offset) : (f.set(t, p), p += t.length);
|
|
39
|
+
}
|
|
40
|
+
if (c) {
|
|
41
|
+
let e = new Uint8Array(d);
|
|
42
|
+
p = 0;
|
|
43
|
+
for (let t = 0; t < c.length; t++) {
|
|
44
|
+
let n = c[t];
|
|
45
|
+
t === c.length - 1 ? (e.set(n.subarray(0, l.offset), p), p += l.offset) : (e.set(n, p), p += n.length);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
tokens: f,
|
|
49
|
+
mask: e
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return f;
|
|
34
53
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
(await Promise.all(y.map((t) => t.estimateTokens(i)))).reduce((t, r) => t + r, 0),
|
|
38
|
-
i.vocabSize * 1e4
|
|
39
|
-
), n = [new Uint16Array(g)], a = o ? [new Uint8Array(g)] : null, e = {
|
|
40
|
-
offset: 0,
|
|
41
|
-
total: 0
|
|
42
|
-
};
|
|
43
|
-
let f = performance.now();
|
|
44
|
-
for (; e.offset < g && (m(y, n, i, e, g, a || void 0), !y.every((t) => !t.hasMoreConversations())); )
|
|
45
|
-
f = await k(f, u, e.total);
|
|
46
|
-
if (n.length === 1)
|
|
47
|
-
return a ? { tokens: n[0].subarray(0, e.offset), mask: a[0].subarray(0, e.offset) } : n[0].subarray(0, e.offset);
|
|
48
|
-
const c = n.reduce((t, r) => t + r.length, 0) - (n[n.length - 1].length - e.offset), l = new Uint16Array(c);
|
|
49
|
-
let s = 0;
|
|
50
|
-
for (let t = 0; t < n.length; t++) {
|
|
51
|
-
const r = n[t];
|
|
52
|
-
t === n.length - 1 ? (l.set(r.subarray(0, e.offset), s), s += e.offset) : (l.set(r, s), s += r.length);
|
|
53
|
-
}
|
|
54
|
-
if (a) {
|
|
55
|
-
const t = new Uint8Array(c);
|
|
56
|
-
s = 0;
|
|
57
|
-
for (let r = 0; r < a.length; r++) {
|
|
58
|
-
const h = a[r];
|
|
59
|
-
r === a.length - 1 ? (t.set(h.subarray(0, e.offset), s), s += e.offset) : (t.set(h, s), s += h.length);
|
|
60
|
-
}
|
|
61
|
-
return { tokens: l, mask: t };
|
|
62
|
-
}
|
|
63
|
-
return l;
|
|
64
|
-
}
|
|
65
|
-
export {
|
|
66
|
-
w as Task,
|
|
67
|
-
p as tokensFromTasks
|
|
68
|
-
};
|
|
54
|
+
//#endregion
|
|
55
|
+
export { t as Task, r as tokensFromTasks };
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
validation: new s(a)
|
|
17
|
-
};
|
|
1
|
+
import e from "./ConversationTask.js";
|
|
2
|
+
//#region lib/training/tasks/splitter.ts
|
|
3
|
+
function t(t, n) {
|
|
4
|
+
if (n <= 0 || n >= 1) throw Error("validationSplit must be between 0 and 1");
|
|
5
|
+
t.forEach((e) => e.shuffle());
|
|
6
|
+
let r = [], i = [];
|
|
7
|
+
for (let e of t) for (; e.hasMoreConversations();) {
|
|
8
|
+
let t = e.nextConversation();
|
|
9
|
+
if (!t) break;
|
|
10
|
+
Math.random() < n ? i.push(t) : r.push(t);
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
training: new e(r),
|
|
14
|
+
validation: new e(i)
|
|
15
|
+
};
|
|
18
16
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { t as default };
|
package/dist/training/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TensorStatistics } from '
|
|
2
|
-
import { LoRAConfig } from '
|
|
1
|
+
import { TensorStatistics } from '../../checks/weights';
|
|
2
|
+
import { LoRAConfig } from '../../models/config';
|
|
3
3
|
import { NamedTensorMap, Tensor } from '@tensorflow/tfjs-core';
|
|
4
4
|
export interface Metrics {
|
|
5
5
|
accuracy?: number;
|
package/dist/training/types.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1,84 +1,2 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
|
|
3
|
-
import "../zeros_like-CWjDdwr-.js";
|
|
4
|
-
import "../Generator.js";
|
|
5
|
-
import "../index-Cp39cXWe.js";
|
|
6
|
-
import "../dataset-CGGp1z9P.js";
|
|
7
|
-
import "../ops/cpu/attentionMask.js";
|
|
8
|
-
import "../ops/webgl/attentionMask.js";
|
|
9
|
-
import "../ops/grads/attentionMask.js";
|
|
10
|
-
import "../ops/cpu/rope.js";
|
|
11
|
-
import "../ops/webgl/rope.js";
|
|
12
|
-
import "../rope-DcrZM_e6.js";
|
|
13
|
-
import "../ops/cpu/appendCache.js";
|
|
14
|
-
import "../ops/webgl/appendCache.js";
|
|
15
|
-
import "../ops/grads/softmax16.js";
|
|
16
|
-
import "../matMul16-BcVC_E62.js";
|
|
17
|
-
import "../ops/webgl/matMul16.js";
|
|
18
|
-
import "../ops/cpu/matMul16.js";
|
|
19
|
-
import "../pack16-bqltoUlR.js";
|
|
20
|
-
import "../ops/transpose16.js";
|
|
21
|
-
import "../ops/reshape16.js";
|
|
22
|
-
import "../ops/cpu/qkv.js";
|
|
23
|
-
import "../ops/webgl/qkv.js";
|
|
24
|
-
import "../ops/grads/qkv.js";
|
|
25
|
-
import "../ops/cpu/normRMS.js";
|
|
26
|
-
import "../ops/webgl/normRMS.js";
|
|
27
|
-
import "../ops/grads/normRMS.js";
|
|
28
|
-
import "../ops/dropout16.js";
|
|
29
|
-
import "../ops/webgl/dropout16.js";
|
|
30
|
-
import "../ops/grads/add16.js";
|
|
31
|
-
import "../jszip.min-BZhlzntC.js";
|
|
32
|
-
import "../index-DvYrXKkX.js";
|
|
33
|
-
import "../ops/cpu/adamAdjust.js";
|
|
34
|
-
import "../ops/webgl/adamAdjust.js";
|
|
35
|
-
import "../ops/cpu/adamMoments.js";
|
|
36
|
-
import "../ops/webgl/adamMoments.js";
|
|
37
|
-
import "../ops/cpu/gatherSub.js";
|
|
38
|
-
import "../ops/webgl/gatherSub.js";
|
|
39
|
-
import "../ops/cpu/scatterSub.js";
|
|
40
|
-
import "../ops/webgl/scatterSub.js";
|
|
41
|
-
import { PAGE_FACTOR as a, shuffle as k } from "./DatasetBuilder.js";
|
|
42
|
-
import "../papaparse.min-C0cScC2i.js";
|
|
43
|
-
import { tokensFromTasks as y } from "./tasks/Task.js";
|
|
44
|
-
import "../ops/cpu/matMulGelu.js";
|
|
45
|
-
import "../matMulGelu-JNLZqKQp.js";
|
|
46
|
-
import "../ops/grads/matMulGelu.js";
|
|
47
|
-
import "../ops/cpu/gelu.js";
|
|
48
|
-
import "../ops/webgl/gelu.js";
|
|
49
|
-
import "../gelu-B220X1Go.js";
|
|
50
|
-
import "../ops/webgl/log.js";
|
|
51
|
-
import "../checks/normRMS.js";
|
|
52
|
-
import "../checks/normRMSGrad.js";
|
|
53
|
-
async function Mt(n, x, o, l, c = 0.1, d) {
|
|
54
|
-
const r = n instanceof Uint16Array ? n : await y(n, x, void 0, d), i = r instanceof Uint16Array ? r : r.tokens, f = r instanceof Uint16Array ? void 0 : r.mask, m = /* @__PURE__ */ new Set();
|
|
55
|
-
if (c > 0) {
|
|
56
|
-
const t = Math.floor(i.length / (o.blockSize * a)), s = Math.max(1, Math.floor(t * c));
|
|
57
|
-
for (; m.size < s; ) {
|
|
58
|
-
const M = Math.floor(Math.random() * t);
|
|
59
|
-
m.add(M);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
const p = new Uint32Array(
|
|
63
|
-
i.length - m.size * o.blockSize * a
|
|
64
|
-
), e = new Uint32Array(m.size * o.blockSize * a);
|
|
65
|
-
let h = 0, g = 0;
|
|
66
|
-
for (let t = 0; t < i.length; t++) {
|
|
67
|
-
const s = Math.floor(t / (o.blockSize * a));
|
|
68
|
-
m.has(s) ? g < e.length && (e[g++] = t) : h < p.length && (p[h++] = t);
|
|
69
|
-
}
|
|
70
|
-
const { dataset: v, state: w } = await o.createTextDataset(
|
|
71
|
-
i,
|
|
72
|
-
l,
|
|
73
|
-
k(p),
|
|
74
|
-
f || void 0
|
|
75
|
-
), { dataset: z, state: A } = await o.createTextDataset(
|
|
76
|
-
i,
|
|
77
|
-
l,
|
|
78
|
-
k(e)
|
|
79
|
-
);
|
|
80
|
-
return { trainDataset: v, validationDataset: z, size: i.length, validationState: A, trainState: w };
|
|
81
|
-
}
|
|
82
|
-
export {
|
|
83
|
-
Mt as createTrainValidationSplit
|
|
84
|
-
};
|
|
1
|
+
import { o as e } from "../main-CPjeMv0G.js";
|
|
2
|
+
export { e as createTrainValidationSplit };
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return t = Math.max(t, n), t;
|
|
15
|
-
} else
|
|
16
|
-
return Number.POSITIVE_INFINITY;
|
|
1
|
+
//#region lib/utilities/arrayClose.ts
|
|
2
|
+
function e(t, n) {
|
|
3
|
+
let r = 0;
|
|
4
|
+
if ((Array.isArray(t) || t instanceof Float32Array) && (Array.isArray(n) || n instanceof Float32Array)) {
|
|
5
|
+
if (t.length !== n.length) return Infinity;
|
|
6
|
+
for (let i = 0; i < t.length; ++i) r = Math.max(r, e(t[i], n[i]));
|
|
7
|
+
return r;
|
|
8
|
+
} else if (typeof t == "number" && typeof n == "number") {
|
|
9
|
+
if (isNaN(t) && isNaN(n)) return 0;
|
|
10
|
+
if (!isFinite(t) || !isFinite(n)) return t === n ? 0 : Infinity;
|
|
11
|
+
let e = Math.abs(t - n);
|
|
12
|
+
return r = Math.max(r, e), r;
|
|
13
|
+
} else return Infinity;
|
|
17
14
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { e as arraysClose };
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
g(n);
|
|
17
|
-
return "dataset__" + (e >>> 0).toString(36) + "_" + (o >>> 0).toString(36);
|
|
1
|
+
//#region lib/utilities/datasetID.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
let t = e.map((e) => String(e.id)).sort(), n = 2166136261, r = 2654435769, i = (e) => {
|
|
4
|
+
n ^= e & 255, n = Math.imul(n, 16777619), r ^= e & 255, r = Math.imul(r, 2246822507);
|
|
5
|
+
}, a = (e) => {
|
|
6
|
+
let t = e.length >>> 0;
|
|
7
|
+
i(t & 255), i(t >>> 8 & 255), i(t >>> 16 & 255), i(t >>> 24 & 255);
|
|
8
|
+
for (let t = 0; t < e.length; t++) {
|
|
9
|
+
let n = e.charCodeAt(t);
|
|
10
|
+
i(n & 255), i(n >>> 8 & 255);
|
|
11
|
+
}
|
|
12
|
+
}, o = t.length >>> 0;
|
|
13
|
+
i(o & 255), i(o >>> 8 & 255), i(o >>> 16 & 255), i(o >>> 24 & 255);
|
|
14
|
+
for (let e of t) a(e);
|
|
15
|
+
return "dataset__" + (n >>> 0).toString(36) + "_" + (r >>> 0).toString(36);
|
|
18
16
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { e as default };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { default as Model, ModelForwardAttributes } from '
|
|
1
|
+
import { default as Model, ModelForwardAttributes } from '../../models/model';
|
|
2
2
|
export declare function dummyPassAsync(model: Model<ModelForwardAttributes>): Promise<void>;
|
|
3
3
|
export interface MemoryRequirements {
|
|
4
4
|
perBatch: number;
|
package/dist/utilities/dummy.js
CHANGED
|
@@ -1,43 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
async function
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { ii as e, kt as t, qt as n, si as r } from "../dist-BewPQWjc.js";
|
|
2
|
+
//#region lib/utilities/dummy.ts
|
|
3
|
+
async function i(e) {
|
|
4
|
+
let n = t([1, e.config.blockSize], "int32"), r = e.forward({ training: !1 }, n);
|
|
5
|
+
await r.data(), r.dispose(), n.dispose();
|
|
6
6
|
}
|
|
7
|
-
async function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} catch (i) {
|
|
31
|
-
console.error("Error during dummy training pass:", i), a.dispose();
|
|
32
|
-
}
|
|
33
|
-
return e;
|
|
7
|
+
async function a(a) {
|
|
8
|
+
let o = r(), s = o.numBytesInGPUAllocated ?? o.numBytesAllocatedInGPU ?? o.numBytes;
|
|
9
|
+
await i(a);
|
|
10
|
+
let c = t([1, a.config.blockSize], "int32"), l = {
|
|
11
|
+
perBatch: 0,
|
|
12
|
+
tapeSize: 0,
|
|
13
|
+
gradients: a.getNumParams() * 4
|
|
14
|
+
};
|
|
15
|
+
try {
|
|
16
|
+
let { value: t, grads: i } = n(() => {
|
|
17
|
+
let t = a.forward({ training: !0 }, c), n = e().state.activeTape, r = 0;
|
|
18
|
+
if (n) for (let e of n) r += e.saved?.reduce((e, t) => e + t.size * 4, 0) || 0;
|
|
19
|
+
l.tapeSize = r;
|
|
20
|
+
let i = t.mean();
|
|
21
|
+
return t.dispose(), i;
|
|
22
|
+
}), o = r();
|
|
23
|
+
l.perBatch = (o.numBytesInGPUAllocated ?? o.numBytesAllocatedInGPU ?? o.numBytes) - s - l.gradients, await t.data(), t.dispose();
|
|
24
|
+
for (let e in i) i[e].dispose();
|
|
25
|
+
c.dispose();
|
|
26
|
+
} catch (e) {
|
|
27
|
+
console.error("Error during dummy training pass:", e), c.dispose();
|
|
28
|
+
}
|
|
29
|
+
return l;
|
|
34
30
|
}
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
function o(e) {
|
|
32
|
+
let n = t([1, e.config.blockSize], "int32");
|
|
33
|
+
e.forward({ training: !1 }, n).dispose(), n.dispose();
|
|
38
34
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
w as dummyPassAsync,
|
|
42
|
-
b as dummyPassTrainAsync
|
|
43
|
-
};
|
|
35
|
+
//#endregion
|
|
36
|
+
export { o as dummyPass, i as dummyPassAsync, a as dummyPassTrainAsync };
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (r += n[t], o < r)
|
|
8
|
-
return e([[t]], [1, 1], "int32");
|
|
9
|
-
return e([[n.length - 1]], [1, 1], "int32");
|
|
1
|
+
import { I as e } from "../dist-BewPQWjc.js";
|
|
2
|
+
//#region lib/utilities/multinomialCPU.ts
|
|
3
|
+
function t(t, n) {
|
|
4
|
+
let r = 0, i = n ?? Math.random();
|
|
5
|
+
for (let n = 0; n < t.length; n++) if (r += t[n], i < r) return e([[n]], [1, 1], "int32");
|
|
6
|
+
return e([[t.length - 1]], [1, 1], "int32");
|
|
10
7
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
8
|
+
//#endregion
|
|
9
|
+
export { t as default };
|
package/dist/utilities/naming.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/dist/utilities/packed.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ii as e } from "../dist-BewPQWjc.js";
|
|
2
|
+
//#region lib/utilities/packed.ts
|
|
3
|
+
function t() {
|
|
4
|
+
return e().backendName === "webgpu";
|
|
4
5
|
}
|
|
5
|
-
function
|
|
6
|
-
|
|
6
|
+
function n(e) {
|
|
7
|
+
return e.dtype === "packedF16";
|
|
7
8
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
9
|
+
function r(e) {
|
|
10
|
+
return n(e);
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
a as isPackedTensor,
|
|
14
|
-
o as packingSupported
|
|
15
|
-
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { n as isPackableTensor, r as isPackedTensor, t as packingSupported };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GPTConfig } from '
|
|
1
|
+
import { GPTConfig } from '../../models/config';
|
|
2
2
|
export declare function estimateLayerParameters(config: GPTConfig): number;
|
|
3
3
|
export declare function estimateParameterCount(config: GPTConfig): number;
|
|
4
4
|
export declare function estimateMemoryUsage(config: GPTConfig): number;
|