@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
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
import { t as e } from "../v4-
|
|
2
|
-
|
|
1
|
+
import { t as e } from "../v4-YCkfo8OR.js";
|
|
2
|
+
// lib/training/configure.ts
|
|
3
3
|
function t(t, n) {
|
|
4
4
|
let r = n?.method.supervised || "full", i = n?.method.type || "pretraining";
|
|
5
5
|
if (i === "pretraining" && (t.hasLoRA() && t.detachLoRA(), t.weightStore.setTrainable(["*"]), n && (t.metaData.pretrainingSettings = n)), i === "supervised") {
|
|
6
6
|
if (r === "lora") {
|
|
7
7
|
if (n?.loraName) {
|
|
8
|
-
if (!t.hasLoRA(n.loraName))
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
if (!t.hasLoRA(n.loraName)) {
|
|
9
|
+
if (n.loraConfig) t.createLoRA(n.loraName, n.loraConfig), t.attachLoRA(n.loraName);
|
|
10
|
+
else throw Error(`LoRA configuration must be provided to create LoRA with name ${n.loraName}`);
|
|
11
|
+
} else if (t.attachLoRA(n.loraName), n.loraConfig) {
|
|
11
12
|
let e = t.lora;
|
|
12
13
|
(e.alpha !== n.loraConfig.alpha || e.rank !== n.loraConfig.rank) && (t.detachLoRA(), t.deleteLoRA(n.loraName), t.createLoRA(n.loraName, n.loraConfig), t.attachLoRA(n.loraName), console.warn("Resetting LoRA with new configuration."));
|
|
13
14
|
}
|
|
14
|
-
} else if (n?.loraConfig)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
} else if (n?.loraConfig) {
|
|
16
|
+
if (t.hasLoRA()) {
|
|
17
|
+
let r = t.lora;
|
|
18
|
+
if (r.alpha !== n.loraConfig.alpha || r.rank !== n.loraConfig.rank) {
|
|
19
|
+
t.detachLoRA();
|
|
20
|
+
let r = n.loraName || e();
|
|
21
|
+
t.createLoRA(r, n.loraConfig), t.attachLoRA(r);
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
18
24
|
let r = n.loraName || e();
|
|
19
25
|
t.createLoRA(r, n.loraConfig), t.attachLoRA(r);
|
|
20
26
|
}
|
|
21
|
-
} else
|
|
22
|
-
let r = n.loraName || e();
|
|
23
|
-
t.createLoRA(r, n.loraConfig), t.attachLoRA(r);
|
|
24
|
-
}
|
|
25
|
-
else if (!t.hasLoRA()) throw Error("LoRA configuration must be provided for lora SFT mode");
|
|
27
|
+
} else if (!t.hasLoRA()) throw Error("LoRA configuration must be provided for lora SFT mode");
|
|
26
28
|
} else t.hasLoRA() && t.detachLoRA();
|
|
27
29
|
r === "last-layer" ? t.weightStore.setTrainable([`block_${t.config.nLayer - 1}_*`, "token_embedding"]) : r === "full" && t.weightStore.setTrainable(["*"]);
|
|
28
30
|
}
|
|
29
31
|
n?.trainableWeights && t.weightStore.setTrainable(n.trainableWeights);
|
|
30
32
|
}
|
|
31
|
-
//#endregion
|
|
32
33
|
export { t as default };
|
package/dist/training/factory.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import e from "./SFTTrainer.js";
|
|
2
2
|
import t from "./PreTrainer.js";
|
|
3
|
-
|
|
3
|
+
// lib/training/factory.ts
|
|
4
4
|
function n(n, r, i, a) {
|
|
5
5
|
return i?.method.type === "supervised" ? new e(n, r, i, a) : new t(n, r, i, a);
|
|
6
6
|
}
|
|
7
|
-
//#endregion
|
|
8
7
|
export { n as default };
|
package/dist/training/loss.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createSoftmaxCrossEntropyWithGrad as e } from "./sparseCrossEntropy.js";
|
|
2
|
-
|
|
2
|
+
// lib/training/loss.ts
|
|
3
3
|
function t(t, n, r, i, a) {
|
|
4
4
|
try {
|
|
5
5
|
return e(r, i, a && a > 0 ? a : void 0)(t, n);
|
|
@@ -15,5 +15,4 @@ function n(e, t) {
|
|
|
15
15
|
throw console.error("Error computing accuracy:", e), Error("Accuracy computation failed.", { cause: e });
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
//#endregion
|
|
19
18
|
export { n as calculateAccuracy, t as calculateLoss };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { Y as e } from "../dist-CMMLi-qO.js";
|
|
2
|
+
// lib/training/orthoGrad.ts
|
|
3
3
|
function t(t, n, r) {
|
|
4
4
|
return e(() => {
|
|
5
5
|
let e = t.reshape([-1]), i = n.reshape([-1]), a = e.mul(e).sum().add(r), o = e.mul(i).sum().div(a), s = i.sub(e.mul(o)), c = i.norm(), l = s.norm().add(r);
|
|
6
6
|
return s.mul(c.div(l)).reshape(n.shape);
|
|
7
7
|
});
|
|
8
8
|
}
|
|
9
|
-
//#endregion
|
|
10
9
|
export { t as orthogonalizeGradient };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TokenStore as e } from "./tasks/TokenStore.js";
|
|
2
2
|
import { tokensFromStreams as t } from "./tasks/tokenStream.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
3
|
+
import { createTrainValidationDatasets as n, storeFromArray as r } from "./validation.js";
|
|
4
|
+
import { t as i } from "../DatasetBuilder-DRDW8tcM.js";
|
|
5
|
+
// lib/training/prepareData.ts
|
|
6
6
|
async function a(a, o, s, c, l, u, d) {
|
|
7
7
|
let f = a.loraName || a.loraConfig;
|
|
8
8
|
if (!d && !f) throw Error("Must specify datasets for non-LoRA training");
|
|
@@ -17,28 +17,30 @@ async function a(a, o, s, c, l, u, d) {
|
|
|
17
17
|
}))), e ? o.metaData.mode = "conversational" : o.metaData.mode !== "conversational" && (o.metaData.mode = "completion");
|
|
18
18
|
} else o.metaData.mode !== "conversational" && (o.metaData.mode = "completion");
|
|
19
19
|
let p = a.maskedLoss ?? a.method.type === "supervised", m, h = u;
|
|
20
|
-
if (Array.isArray(c))
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
if (Array.isArray(c)) {
|
|
21
|
+
if (c[0] instanceof Uint16Array) m = c;
|
|
22
|
+
else {
|
|
23
|
+
let e = await t(c, s, l, {
|
|
24
|
+
masking: p,
|
|
25
|
+
validationSplit: a.validationSplit
|
|
26
|
+
});
|
|
27
|
+
m = e.trainingTokens, u || (h = e.validationTokens);
|
|
28
|
+
}
|
|
29
|
+
} else m = c;
|
|
29
30
|
console.log("Training tokens", m);
|
|
30
31
|
let g = m instanceof e ? m.getTokenCount() : m.reduce((e, t) => e + t.length, 0);
|
|
31
32
|
a.epochSteps = Math.max(1, Math.floor(g / ((a?.batchSize || 32) * o.config.blockSize)));
|
|
32
|
-
let _ = new
|
|
33
|
+
let _ = new i(s, o.config.blockSize);
|
|
33
34
|
if (h) {
|
|
34
|
-
let { trainDataset: e, validationDataset: t } = await
|
|
35
|
+
let { trainDataset: e, validationDataset: t } = await n(m, h, s, _, a?.batchSize || 32);
|
|
35
36
|
return {
|
|
36
37
|
trainDataset: e,
|
|
37
38
|
validationDataset: t,
|
|
38
39
|
totalTokens: g
|
|
39
40
|
};
|
|
40
|
-
}
|
|
41
|
-
|
|
41
|
+
}
|
|
42
|
+
{
|
|
43
|
+
let t = m instanceof e ? m : await r(m, s);
|
|
42
44
|
return {
|
|
43
45
|
trainDataset: (await _.createTextDataset(t, a)).dataset,
|
|
44
46
|
validationDataset: void 0,
|
|
@@ -46,5 +48,4 @@ async function a(a, o, s, c, l, u, d) {
|
|
|
46
48
|
};
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
|
-
//#endregion
|
|
50
51
|
export { a as default };
|
|
@@ -1,47 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
import { gatherSub as e } from "../ops/gatherSub.js";
|
|
2
|
+
import { n as t, o as n, r, s as i, t as a } from "../not_equal-Bu3O8rh_.js";
|
|
3
|
+
import { t as o } from "../sum-C8qNbFNp.js";
|
|
4
|
+
import { t as s } from "../softmax-Dpav_dWw.js";
|
|
5
|
+
import { scatterSub as c } from "../ops/scatterSub.js";
|
|
6
|
+
import { O as l, S as u, Y as d, b as f, j as p, k as m, m as h, p as g } from "../dist-CMMLi-qO.js";
|
|
7
|
+
// lib/training/sparseCrossEntropy.ts
|
|
8
|
+
function _(i, a, s, c, u, f = 0) {
|
|
9
|
+
return d(() => {
|
|
10
|
+
let d = i.shape[i.shape.length - 1], h = u || i.shape.slice(0, -1), _ = h.reduce((e, t) => e * t, 1), v = i.shape.length > 2 ? i.reshape([_, d]) : i, y = a.shape.length > 1 ? a.reshape([_]).cast("int32") : a.cast("int32"), b = n(v, -1, !0), x = g(v, b), S = r(x, -1), C = e(S, y, x), w;
|
|
11
|
+
if (f > 0) {
|
|
12
|
+
let e = g(S, t(x, -1));
|
|
13
|
+
w = p(l(C, 1 - f), l(e, f));
|
|
14
|
+
} else w = C;
|
|
15
|
+
if (s) {
|
|
16
|
+
if (w = l(w, s), c) {
|
|
17
|
+
let e = o(s.reshape(h), -1);
|
|
18
|
+
w = m(o(w.reshape(h), -1), e);
|
|
19
|
+
} else {
|
|
20
|
+
let e = o(s);
|
|
21
|
+
w = m(o(w), e);
|
|
22
|
+
}
|
|
23
|
+
} else w = c ? t(w.reshape(h), -1) : t(w);
|
|
24
|
+
return w;
|
|
21
25
|
});
|
|
22
26
|
}
|
|
23
|
-
function v(e,
|
|
24
|
-
return
|
|
25
|
-
let h =
|
|
27
|
+
function v(e, t, n = 0) {
|
|
28
|
+
return h((r, p, m) => {
|
|
29
|
+
let h = r.shape[r.shape.length - 1], v = r.shape.slice(0, -1), y = v.reduce((e, t) => e * t, 1), b = r.reshape([y, h]), x = p.reshape([y]).cast("int32"), S, C = null;
|
|
26
30
|
if (e) {
|
|
27
|
-
let e =
|
|
28
|
-
C = t.cast("float32"), S = i(t, x,
|
|
31
|
+
let e = f(65535, "int32"), t = a(x, e);
|
|
32
|
+
C = t.cast("float32"), S = i(t, x, u(x)), e.dispose(), t.dispose();
|
|
29
33
|
} else S = x;
|
|
30
|
-
let w = _(b, S, C || void 0,
|
|
34
|
+
let w = _(b, S, C || void 0, t, v, n);
|
|
31
35
|
return m(C ? [
|
|
32
36
|
b,
|
|
33
37
|
S,
|
|
34
38
|
C
|
|
35
39
|
] : [b, S]), b.dispose(), x.dispose(), {
|
|
36
40
|
value: w,
|
|
37
|
-
gradFunc: (
|
|
38
|
-
let
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
gradFunc: (t, i) => d(() => {
|
|
42
|
+
let a = i[0], d = i[1], m = e ? i[2] : void 0, _ = s(a), v = m ? o(m) : f(a.shape[0], "float32"), y = t.div(v).broadcastTo([a.shape[0]]), b = m && e ? l(y, m) : y, x;
|
|
43
|
+
if (n > 0) {
|
|
44
|
+
let e = n / h, t = g(_, e);
|
|
45
|
+
x = c(t, d, l(b, 1 - n));
|
|
46
|
+
} else x = c(_, d, b);
|
|
47
|
+
let S = u(p);
|
|
48
|
+
return [x.reshape(r.shape), S];
|
|
42
49
|
})
|
|
43
50
|
};
|
|
44
51
|
});
|
|
45
52
|
}
|
|
46
|
-
//#endregion
|
|
47
53
|
export { v as createSoftmaxCrossEntropyWithGrad, _ as sparseSoftmaxCrossEntropy };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
var e =
|
|
1
|
+
// lib/training/tasks/TokenStore.ts
|
|
2
|
+
var e = class {
|
|
3
3
|
name;
|
|
4
4
|
tokeniserId;
|
|
5
5
|
datasetId;
|
|
@@ -7,13 +7,13 @@ var e = "llm-tokenstore", t = class {
|
|
|
7
7
|
masks;
|
|
8
8
|
shardCount = 0;
|
|
9
9
|
lastShardLength = -1;
|
|
10
|
-
_shardSize =
|
|
10
|
+
_shardSize = 8192e3;
|
|
11
11
|
dirHandle = null;
|
|
12
12
|
opfsAvailable = !1;
|
|
13
13
|
lru = /* @__PURE__ */ new Map();
|
|
14
14
|
maxCachedShards;
|
|
15
|
-
constructor(t, n, r
|
|
16
|
-
this.tokeniserId =
|
|
15
|
+
constructor(e, t, n, r = 2, i = 8192e3) {
|
|
16
|
+
this.tokeniserId = e, this.datasetId = t, this.maxCachedShards = Math.max(1, Math.trunc(r)), this._shardSize = Math.max(1, Math.trunc(i)), this.name = n ?? "llm-tokenstore";
|
|
17
17
|
}
|
|
18
18
|
get shardSize() {
|
|
19
19
|
return this._shardSize;
|
|
@@ -74,7 +74,7 @@ var e = "llm-tokenstore", t = class {
|
|
|
74
74
|
await t.write(JSON.stringify(e)), await t.close();
|
|
75
75
|
}
|
|
76
76
|
async readManifest() {
|
|
77
|
-
if (
|
|
77
|
+
if (this.opfsAvailable && this.dirHandle) try {
|
|
78
78
|
let e = await (await (await this.dirHandle.getFileHandle("manifest.json")).getFile()).text();
|
|
79
79
|
return JSON.parse(e);
|
|
80
80
|
} catch {
|
|
@@ -98,7 +98,7 @@ var e = "llm-tokenstore", t = class {
|
|
|
98
98
|
await r.write(t.buffer), await r.close();
|
|
99
99
|
}
|
|
100
100
|
async readShardFromOPFS(e) {
|
|
101
|
-
if (
|
|
101
|
+
if (this.opfsAvailable && this.dirHandle) try {
|
|
102
102
|
let t = await (await (await this.dirHandle.getFileHandle(this.shardFilename(e))).getFile()).arrayBuffer();
|
|
103
103
|
return new Uint16Array(t);
|
|
104
104
|
} catch {
|
|
@@ -106,7 +106,7 @@ var e = "llm-tokenstore", t = class {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
async readMaskFromOPFS(e) {
|
|
109
|
-
if (
|
|
109
|
+
if (this.opfsAvailable && this.dirHandle) try {
|
|
110
110
|
let t = await (await (await this.dirHandle.getFileHandle(this.maskFilename(e))).getFile()).arrayBuffer();
|
|
111
111
|
return new Uint8Array(t);
|
|
112
112
|
} catch {
|
|
@@ -191,14 +191,14 @@ var e = "llm-tokenstore", t = class {
|
|
|
191
191
|
await this.writeManifest();
|
|
192
192
|
} catch {}
|
|
193
193
|
}
|
|
194
|
-
},
|
|
195
|
-
function
|
|
196
|
-
let i =
|
|
197
|
-
return i && i.tokeniserId ===
|
|
194
|
+
}, t = /* @__PURE__ */ new Map();
|
|
195
|
+
function n(e, n, r) {
|
|
196
|
+
let i = t.get(e);
|
|
197
|
+
return i && i.tokeniserId === n && i.datasetId === r ? i : null;
|
|
198
198
|
}
|
|
199
|
-
async function
|
|
200
|
-
let
|
|
201
|
-
if (
|
|
199
|
+
async function r(e) {
|
|
200
|
+
let n = t.get(e);
|
|
201
|
+
if (n) await n.dispose(), t.delete(e);
|
|
202
202
|
else try {
|
|
203
203
|
let t = globalThis.navigator;
|
|
204
204
|
if (t?.storage?.getDirectory) {
|
|
@@ -207,12 +207,11 @@ async function i(e) {
|
|
|
207
207
|
}
|
|
208
208
|
} catch {}
|
|
209
209
|
}
|
|
210
|
-
async function
|
|
211
|
-
let o =
|
|
210
|
+
async function i(n, r, i, a) {
|
|
211
|
+
let o = t.get(n);
|
|
212
212
|
if (o && o.tokeniserId === r && o.datasetId === i) return o;
|
|
213
|
-
o && (await o.dispose(),
|
|
214
|
-
let s = new
|
|
215
|
-
return a?.noOPFS || await s.init(),
|
|
213
|
+
o && (await o.dispose(), t.delete(n));
|
|
214
|
+
let s = new e(r, i, n, a?.maxCachedShards, a?.shardSize);
|
|
215
|
+
return a?.noOPFS || await s.init(), t.set(n, s), s;
|
|
216
216
|
}
|
|
217
|
-
|
|
218
|
-
export { t as TokenStore, a as createTokenStore, i as deleteTokenStore, r as getTokenStore };
|
|
217
|
+
export { e as TokenStore, i as createTokenStore, r as deleteTokenStore, n as getTokenStore };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createTokenStore as e, deleteTokenStore as t } from "./TokenStore.js";
|
|
2
2
|
import { seededRng as n } from "../../utilities/random.js";
|
|
3
|
-
|
|
3
|
+
// lib/training/tasks/tokenStream.ts
|
|
4
4
|
function r(e, t, n, r, i, a) {
|
|
5
5
|
let o = n.encodeConversation(e, !1, !!a);
|
|
6
6
|
if (o) {
|
|
@@ -42,5 +42,4 @@ async function i(i, a, o, s) {
|
|
|
42
42
|
validationTokens: p ? l : void 0
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
//#endregion
|
|
46
45
|
export { i as tokensFromStreams };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// lib/training/validateOptions.ts
|
|
2
2
|
function e(e, t, n) {
|
|
3
3
|
let r = new Set(Object.keys(e).filter((t) => e[t] !== n?.[t]));
|
|
4
4
|
if (t) {
|
|
@@ -15,5 +15,4 @@ function e(e, t, n) {
|
|
|
15
15
|
...e
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
//#endregion
|
|
19
18
|
export { e as default };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TokenStore as e, createTokenStore as t } from "./tasks/TokenStore.js";
|
|
2
|
-
|
|
2
|
+
// lib/training/validation.ts
|
|
3
3
|
async function n(e, n) {
|
|
4
4
|
let r = await t("training-tokens", n.id, n.datasetID ?? "");
|
|
5
5
|
return e.forEach((e) => {
|
|
@@ -27,5 +27,4 @@ async function r(t, r, i, a, o) {
|
|
|
27
27
|
trainState: d
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
//#endregion
|
|
31
30
|
export { r as createTrainValidationDatasets, n as storeFromArray };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Fn as e, Q as t, Y as n, Z as r, br as i, di as a, rt as o, yi as s } from "./dist-CMMLi-qO.js";
|
|
2
|
+
import { t as c } from "./complex-Cl904TqN.js";
|
|
3
|
+
// node_modules/@tensorflow/tfjs-core/dist/ops/imag.js
|
|
4
|
+
function l(n) {
|
|
5
|
+
let r = { input: t(n, "input", "imag") };
|
|
6
|
+
return o.runKernel(e, r);
|
|
7
|
+
}
|
|
8
|
+
var u = /* @__PURE__ */ r({ imag_: l });
|
|
9
|
+
// node_modules/@tensorflow/tfjs-core/dist/ops/neg.js
|
|
10
|
+
function d(e) {
|
|
11
|
+
let n = { x: t(e, "x", "neg") };
|
|
12
|
+
return o.runKernel("Neg", n);
|
|
13
|
+
}
|
|
14
|
+
var f = /* @__PURE__ */ r({ neg_: d });
|
|
15
|
+
// node_modules/@tensorflow/tfjs-core/dist/ops/real.js
|
|
16
|
+
function p(e) {
|
|
17
|
+
let n = { input: t(e, "input", "real") };
|
|
18
|
+
return o.runKernel(i, n);
|
|
19
|
+
}
|
|
20
|
+
var m = /* @__PURE__ */ r({ real_: p });
|
|
21
|
+
// node_modules/@tensorflow/tfjs-core/dist/ops/transpose.js
|
|
22
|
+
function h(e, r, i) {
|
|
23
|
+
let l = t(e, "x", "transpose");
|
|
24
|
+
if (r ??= l.shape.map((e, t) => t).reverse(), s(l.rank === r.length, () => `Error in transpose: rank of input ${l.rank} must match length of perm ${r}.`), r.forEach((e) => {
|
|
25
|
+
s(e >= 0 && e < l.rank, () => `All entries in 'perm' must be between 0 and ${l.rank - 1} but got ${r}`);
|
|
26
|
+
}), l.rank <= 1) return l.clone();
|
|
27
|
+
let d = { x: l }, p = { perm: r };
|
|
28
|
+
return l.dtype === "complex64" ? n(() => {
|
|
29
|
+
let e = m(l), t = u(l);
|
|
30
|
+
return e = o.runKernel(a, { x: e }, p), t = o.runKernel(a, { x: t }, p), i && (t = f(t)), c(e, t);
|
|
31
|
+
}) : o.runKernel(a, d, p);
|
|
32
|
+
}
|
|
33
|
+
var g = /* @__PURE__ */ r({ transpose_: h });
|
|
34
|
+
export { u as i, m as n, f as r, g as t };
|