@genai-fi/nanogpt 0.16.1 → 0.17.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/Generator.d.ts +5 -0
- package/dist/Generator.js +193 -168
- package/dist/Trainer.js +89 -40
- package/dist/layers/LoRA.d.ts +5 -3
- package/dist/layers/LoRA.js +38 -32
- package/dist/loader/load.js +39 -39
- package/dist/loader/loadTransformers.js +11 -10
- package/dist/loader/save.js +17 -16
- package/dist/loader/types.d.ts +2 -1
- package/dist/models/config.d.ts +2 -1
- package/dist/models/config.js +24 -17
- package/dist/models/model.d.ts +9 -2
- package/dist/models/model.js +57 -19
- package/dist/training/types.d.ts +1 -0
- package/package.json +3 -2
package/dist/models/model.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import i from "../layers/BaseLayer.js";
|
|
2
2
|
import "../index-CUXkjxiT.js";
|
|
3
3
|
import "../random_width-DN5ZtQkM.js";
|
|
4
4
|
import "../zeros_like-CWjDdwr-.js";
|
|
@@ -40,7 +40,7 @@ import "../ops/webgl/adamAdjust.js";
|
|
|
40
40
|
import "../ops/cpu/adamMoments.js";
|
|
41
41
|
import "../ops/webgl/adamMoments.js";
|
|
42
42
|
import "../papaparse.min-C0cScC2i.js";
|
|
43
|
-
import { estimateParameterCount as
|
|
43
|
+
import { estimateParameterCount as a } from "../utilities/parameters.js";
|
|
44
44
|
import "../ops/cpu/matMulGelu.js";
|
|
45
45
|
import "../matMulGelu-JNLZqKQp.js";
|
|
46
46
|
import "../ops/grads/matMulGelu.js";
|
|
@@ -50,37 +50,75 @@ import "../gelu-B220X1Go.js";
|
|
|
50
50
|
import "../ops/webgl/log.js";
|
|
51
51
|
import "../checks/normRMS.js";
|
|
52
52
|
import "../checks/normRMSGrad.js";
|
|
53
|
-
import
|
|
54
|
-
class
|
|
53
|
+
import e from "../layers/LoRA.js";
|
|
54
|
+
class st extends i {
|
|
55
55
|
lossScaling = 128;
|
|
56
56
|
trainingState = null;
|
|
57
57
|
metaData = { version: 2, application: "@genai-fi/nanogpt" };
|
|
58
58
|
loraLayer;
|
|
59
|
-
/*
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
loraMap = /* @__PURE__ */ new Map();
|
|
60
|
+
constructor(t) {
|
|
61
|
+
super(t), t.loraConfig && (console.log(t.loraConfig), t.loraConfig.forEach((r, o) => {
|
|
62
|
+
this.createLoRA(o, r);
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
createLoRA(t, r) {
|
|
66
|
+
if (this.loraMap.has(t))
|
|
67
|
+
return;
|
|
68
|
+
const o = new e(t, this.weightStore, r.alpha, r.rank, r.variables);
|
|
69
|
+
this.loraMap.set(t, o), this.config.loraConfig = this.config.loraConfig || /* @__PURE__ */ new Map(), this.config.loraConfig.set(t, r), console.log(`Created LoRA ${t} with rank ${r.rank} and alpha ${r.alpha}`);
|
|
70
|
+
}
|
|
71
|
+
deleteLoRA(t) {
|
|
72
|
+
const r = this.loraMap.get(t);
|
|
73
|
+
if (!r)
|
|
74
|
+
throw new Error(`No LoRA with name ${t} exists.`);
|
|
75
|
+
this.loraLayer === r && this.detachLoRA(), r.dispose(), this.loraMap.delete(t), this.config.loraConfig && this.config.loraConfig.delete(t);
|
|
76
|
+
}
|
|
77
|
+
renameLoRA(t, r) {
|
|
78
|
+
if (!this.loraMap.has(t))
|
|
79
|
+
throw new Error(`No LoRA with name ${t} exists.`);
|
|
80
|
+
if (this.loraMap.has(r))
|
|
81
|
+
throw new Error(`LoRA with name ${r} already exists.`);
|
|
82
|
+
const o = this.loraMap.get(t);
|
|
83
|
+
this.loraMap.set(r, o), this.loraMap.delete(t), this.config.loraConfig && (this.config.loraConfig.delete(t), this.config.loraConfig.set(r, {
|
|
84
|
+
rank: o.rank,
|
|
85
|
+
alpha: o.alpha,
|
|
86
|
+
variables: Array.from(o.variables)
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
mergeLoRA(t) {
|
|
90
|
+
const r = this.loraMap.get(t);
|
|
91
|
+
if (!r)
|
|
92
|
+
throw new Error(`No LoRA with name ${t} exists.`);
|
|
93
|
+
r.merge(), this.deleteLoRA(t);
|
|
94
|
+
}
|
|
66
95
|
attachLoRA(t) {
|
|
67
|
-
if (this.loraLayer)
|
|
68
|
-
|
|
69
|
-
|
|
96
|
+
if (this.loraLayer) {
|
|
97
|
+
if (this.loraLayer.name === t)
|
|
98
|
+
return;
|
|
99
|
+
this.detachLoRA();
|
|
100
|
+
}
|
|
101
|
+
const r = this.loraMap.get(t);
|
|
102
|
+
if (!r)
|
|
103
|
+
throw new Error(`No LoRA with name ${t} exists.`);
|
|
104
|
+
r.attach(), this.loraLayer = r, this.config.loraName = t;
|
|
70
105
|
}
|
|
71
106
|
detachLoRA() {
|
|
72
107
|
if (!this.loraLayer)
|
|
73
108
|
throw new Error("No LoRA layer is attached to this model.");
|
|
74
|
-
this.loraLayer.
|
|
109
|
+
this.loraLayer.detach(), this.loraLayer = void 0, this.config.loraName = void 0;
|
|
110
|
+
}
|
|
111
|
+
hasLoRA(t) {
|
|
112
|
+
return t ? this.loraMap.has(t) : !!this.loraLayer;
|
|
75
113
|
}
|
|
76
|
-
|
|
77
|
-
return
|
|
114
|
+
listLoRAs() {
|
|
115
|
+
return Array.from(this.loraMap.keys());
|
|
78
116
|
}
|
|
79
117
|
get lora() {
|
|
80
118
|
return this.loraLayer || null;
|
|
81
119
|
}
|
|
82
120
|
getNumParams() {
|
|
83
|
-
return
|
|
121
|
+
return a(this.config);
|
|
84
122
|
}
|
|
85
123
|
validateInput(t) {
|
|
86
124
|
if (t.shape.length !== 2)
|
|
@@ -92,5 +130,5 @@ class et extends r {
|
|
|
92
130
|
}
|
|
93
131
|
}
|
|
94
132
|
export {
|
|
95
|
-
|
|
133
|
+
st as default
|
|
96
134
|
};
|
package/dist/training/types.d.ts
CHANGED
|
@@ -51,6 +51,7 @@ export interface TrainingOptions extends Partial<AdamWOptimizerConfig> {
|
|
|
51
51
|
mixedPrecision?: boolean;
|
|
52
52
|
trainableWeights?: string[];
|
|
53
53
|
loraConfig?: LoRAConfig;
|
|
54
|
+
loraName?: string;
|
|
54
55
|
sftMode: 'full' | 'lora' | 'last-layer';
|
|
55
56
|
maskedLoss?: boolean;
|
|
56
57
|
metrics?: TrainingMetrics[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genai-fi/nanogpt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"types": "dist/main.d.ts",
|
|
@@ -58,6 +58,7 @@
|
|
|
58
58
|
"papaparse": "^5.5.3",
|
|
59
59
|
"patch-package": "^8.0.1",
|
|
60
60
|
"pdfjs-dist": "^5.4.149",
|
|
61
|
-
"picomatch": "^4.0.3"
|
|
61
|
+
"picomatch": "^4.0.3",
|
|
62
|
+
"uuid": "^14.0.0"
|
|
62
63
|
}
|
|
63
64
|
}
|