@genai-fi/nanogpt 0.22.0 → 0.24.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-Ctb425Id.js → DatasetBuilder-DU1G1OKX.js} +143 -117
- package/dist/Generator.js +1 -1
- package/dist/TeachableLLM.d.ts +1 -2
- package/dist/TeachableLLM.js +1 -1
- package/dist/Trainer-Cr7csbTD.js +228 -0
- package/dist/Trainer.d.ts +3 -2
- package/dist/Trainer.js +1 -1
- package/dist/data/stream.d.ts +6 -6
- package/dist/data/stream.js +1 -1
- package/dist/data/textLoader.js +1 -1
- package/dist/{BaseTokeniser-C9TSv4th.js → eventemitter3-D_qV3Lof.js} +2 -132
- package/dist/loader/load.js +1 -1
- package/dist/loader/loadHF.js +1 -1
- package/dist/loader/loadTransformers.js +2 -2
- package/dist/loader/newZipLoad.js +1 -1
- package/dist/loader/oldZipLoad.js +1 -1
- package/dist/loader/save.js +1 -1
- package/dist/{main-Bgc7_9kb.js → main-Dz72vadm.js} +2742 -2976
- package/dist/main.d.ts +3 -10
- package/dist/main.js +12 -10
- package/dist/models/NanoGPTV1.js +1 -1
- package/dist/models/NanoGPTV2.js +1 -1
- package/dist/models/factory.js +1 -1
- package/dist/models/model.js +1 -1
- package/dist/{stream-DKl3GTDL.js → stream-BpAwcvHz.js} +563 -550
- package/dist/tokeniser/BaseTokeniser.js +135 -2
- package/dist/tokeniser/CharTokeniser.js +17 -19
- package/dist/tokeniser/bpe.js +16 -20
- package/dist/training/DatasetBuilder.d.ts +19 -3
- package/dist/training/DatasetBuilder.js +2 -2
- package/dist/training/PreTrainer.js +1 -1
- package/dist/training/SFTTrainer.js +1 -1
- package/dist/training/tasks/TokenStore.d.ts +47 -0
- package/dist/training/tasks/TokenStore.js +218 -0
- package/dist/training/tasks/tokenStream.d.ts +16 -0
- package/dist/training/tasks/tokenStream.js +46 -0
- package/dist/training/validation.d.ts +4 -2
- package/dist/training/validation.js +23 -2
- package/dist/utilities/random.d.ts +1 -0
- package/dist/utilities/random.js +19 -0
- package/package.json +1 -1
- package/dist/training/tasks/ConversationTask.d.ts +0 -17
- package/dist/training/tasks/ConversationTask.js +0 -29
- package/dist/training/tasks/PretrainingTask.d.ts +0 -17
- package/dist/training/tasks/PretrainingTask.js +0 -42
- package/dist/training/tasks/StartSentenceTask.d.ts +0 -18
- package/dist/training/tasks/StartSentenceTask.js +0 -45
- package/dist/training/tasks/Task.d.ts +0 -20
- package/dist/training/tasks/Task.js +0 -42
- package/dist/training/tasks/splitter.d.ts +0 -5
- package/dist/training/tasks/splitter.js +0 -18
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { packingSupported as e } from "./utilities/packed.js";
|
|
2
|
+
import { t } from "./eventemitter3-D_qV3Lof.js";
|
|
3
|
+
import n from "./training/PreTrainer.js";
|
|
4
|
+
import { TokenStore as r } from "./training/tasks/TokenStore.js";
|
|
5
|
+
import { tokensFromStreams as i } from "./training/tasks/tokenStream.js";
|
|
6
|
+
import { createTrainValidationDatasets as a, storeFromArray as o } from "./training/validation.js";
|
|
7
|
+
import s from "./training/SFTTrainer.js";
|
|
8
|
+
//#region node_modules/uuid/dist/stringify.js
|
|
9
|
+
var c = [];
|
|
10
|
+
for (let e = 0; e < 256; ++e) c.push((e + 256).toString(16).slice(1));
|
|
11
|
+
function l(e, t = 0) {
|
|
12
|
+
return (c[e[t + 0]] + c[e[t + 1]] + c[e[t + 2]] + c[e[t + 3]] + "-" + c[e[t + 4]] + c[e[t + 5]] + "-" + c[e[t + 6]] + c[e[t + 7]] + "-" + c[e[t + 8]] + c[e[t + 9]] + "-" + c[e[t + 10]] + c[e[t + 11]] + c[e[t + 12]] + c[e[t + 13]] + c[e[t + 14]] + c[e[t + 15]]).toLowerCase();
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region node_modules/uuid/dist/rng.js
|
|
16
|
+
var u = new Uint8Array(16);
|
|
17
|
+
function d() {
|
|
18
|
+
return crypto.getRandomValues(u);
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region node_modules/uuid/dist/v4.js
|
|
22
|
+
function f(e, t, n) {
|
|
23
|
+
return !t && !e && crypto.randomUUID ? crypto.randomUUID() : p(e, t, n);
|
|
24
|
+
}
|
|
25
|
+
function p(e, t, n) {
|
|
26
|
+
e ||= {};
|
|
27
|
+
let r = e.random ?? e.rng?.() ?? d();
|
|
28
|
+
if (r.length < 16) throw Error("Random bytes length must be >= 16");
|
|
29
|
+
if (r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, t) {
|
|
30
|
+
if (n ||= 0, n < 0 || n + 16 > t.length) throw RangeError(`UUID byte range ${n}:${n + 15} is out of buffer bounds`);
|
|
31
|
+
for (let e = 0; e < 16; ++e) t[n + e] = r[e];
|
|
32
|
+
return t;
|
|
33
|
+
}
|
|
34
|
+
return l(r);
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region lib/Trainer.ts
|
|
38
|
+
var m = class c extends t {
|
|
39
|
+
trainer;
|
|
40
|
+
trainingType = "pretraining";
|
|
41
|
+
hasTrained = !1;
|
|
42
|
+
trainDataset;
|
|
43
|
+
validationDataset;
|
|
44
|
+
totalTokens = 0;
|
|
45
|
+
tokensProcessed = 0;
|
|
46
|
+
log = [];
|
|
47
|
+
progress = null;
|
|
48
|
+
options = {
|
|
49
|
+
batchSize: 32,
|
|
50
|
+
sftMode: "full",
|
|
51
|
+
logInterval: 10
|
|
52
|
+
};
|
|
53
|
+
tokenizer;
|
|
54
|
+
constructor(t, r, i, a, o) {
|
|
55
|
+
if (super(), t instanceof c) {
|
|
56
|
+
let e = r || t.options, a = t.options, o = !1;
|
|
57
|
+
if (t.trainingType === "sft" && e.sftMode !== a.sftMode && (o = !0), t.trainer instanceof s && t.trainer.loraName && e.loraName !== t.trainer.loraName && (o = !0), i !== void 0 && i !== t.trainingType && (o = !0), o) {
|
|
58
|
+
if (t.trainingType === "sft") {
|
|
59
|
+
let n = new s(t.model, t.tokenizer, e);
|
|
60
|
+
this.trainer = n, n.loraName = e.loraName;
|
|
61
|
+
} else this.trainer = new n(t.model, t.tokenizer, e);
|
|
62
|
+
this.trainingType = i || t.trainingType, this.options = e, this.tokenizer = t.tokenizer;
|
|
63
|
+
} else this.trainer = t.trainer, this.trainingType = i || t.trainingType, this.options = e, this.trainer.updateOptimizer(this.options), this.log = t.log, this.progress = t.progress, this.totalTokens = t.totalTokens, this.tokenizer = t.tokenizer, e.batchSize === a.batchSize && (this.trainDataset = t.trainDataset, this.validationDataset = t.validationDataset);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (!r) throw Error("Tokeniser must be provided when initializing Trainer with a model");
|
|
67
|
+
if (!t) throw Error("Model must be provided when initializing Trainer");
|
|
68
|
+
this.options = a || {
|
|
69
|
+
batchSize: 32,
|
|
70
|
+
sftMode: "full"
|
|
71
|
+
};
|
|
72
|
+
let l = this.options.mixedPrecision && e();
|
|
73
|
+
if (this.options.lossScaling = l ? t.lossScaling : 1, i === "sft") {
|
|
74
|
+
let e = new s(t, r, this.options, o);
|
|
75
|
+
this.trainer = e, e.loraName = a?.loraName;
|
|
76
|
+
} else this.trainer = new n(t, r, this.options, o);
|
|
77
|
+
this.trainingType = i || "pretraining", this.tokenizer = r;
|
|
78
|
+
}
|
|
79
|
+
get model() {
|
|
80
|
+
return this.trainer.model;
|
|
81
|
+
}
|
|
82
|
+
get optimizer() {
|
|
83
|
+
return this.trainer.optimizer;
|
|
84
|
+
}
|
|
85
|
+
get isTraining() {
|
|
86
|
+
return this.trainer.isRunning;
|
|
87
|
+
}
|
|
88
|
+
stop() {
|
|
89
|
+
this.trainer.stop();
|
|
90
|
+
}
|
|
91
|
+
reset() {
|
|
92
|
+
this.hasTrained = !1, this.log = [], this.trainer.reset();
|
|
93
|
+
}
|
|
94
|
+
dispose() {
|
|
95
|
+
this.trainer.dispose(), this.removeAllListeners();
|
|
96
|
+
}
|
|
97
|
+
getTotalTokens() {
|
|
98
|
+
return this.totalTokens;
|
|
99
|
+
}
|
|
100
|
+
setOptions(e) {
|
|
101
|
+
let t = new Set(Object.keys(e).filter((t) => e[t] !== this.options[t]));
|
|
102
|
+
if (this.trainer.isRunning) {
|
|
103
|
+
if (t.has("batchSize")) throw Error("Cannot change batch size during training");
|
|
104
|
+
if (t.has("sftMode")) throw Error("Cannot change SFT mode during training");
|
|
105
|
+
if (t.has("loraConfig")) throw Error("Cannot change LoRA configuration during training");
|
|
106
|
+
if (t.has("validationSplit")) throw Error("Cannot change validation split during training");
|
|
107
|
+
if (t.has("trainableWeights")) throw Error("Cannot change trainable weights during training");
|
|
108
|
+
if (t.has("mixedPrecision")) throw Error("Cannot change mixed precision setting during training");
|
|
109
|
+
if (t.has("gradientCheckpointing")) throw Error("Cannot change gradient checkpointing setting during training");
|
|
110
|
+
}
|
|
111
|
+
this.options = {
|
|
112
|
+
...this.options,
|
|
113
|
+
...e
|
|
114
|
+
}, this.trainer.updateOptimizer(this.options), t.has("metrics") && this.trainer.setMetrics(e.metrics || []);
|
|
115
|
+
}
|
|
116
|
+
async prepare(e = [], t, n) {
|
|
117
|
+
let c = this.options, l = c.loraName || c.loraConfig;
|
|
118
|
+
if (n && l) throw Error("Cannot specify datasets when using LoRA fine-tuning");
|
|
119
|
+
if (!n && !l) throw Error("Must specify datasets for non-LoRA training");
|
|
120
|
+
if (n) {
|
|
121
|
+
let e = this.model.metaData.pretrainingData || [], t = [...e], r = !1;
|
|
122
|
+
for (let i of n) e.some((e) => e.id === i.id) || t.push({
|
|
123
|
+
id: i.id,
|
|
124
|
+
name: i.name,
|
|
125
|
+
conversational: i.conversational
|
|
126
|
+
}), i.conversational && (r = !0);
|
|
127
|
+
this.model.metaData.pretrainingData = t, r ? this.model.metaData.mode = "conversational" : this.model.metaData.mode !== "conversational" && (this.model.metaData.mode = "completion");
|
|
128
|
+
} else this.model.metaData.mode !== "conversational" && (this.model.metaData.mode = "completion");
|
|
129
|
+
let u = c.maskedLoss ?? this.trainingType === "sft";
|
|
130
|
+
if (this.trainingType === "sft" && this.trainer instanceof s && e instanceof Uint16Array) throw Error("SFT training requires Task[] input");
|
|
131
|
+
let d, f = t;
|
|
132
|
+
if (Array.isArray(e)) if (e[0] instanceof Uint16Array) d = e;
|
|
133
|
+
else {
|
|
134
|
+
let n = await i(e, this.trainer.tokenizer, {
|
|
135
|
+
masking: u,
|
|
136
|
+
validationSplit: c.validationSplit
|
|
137
|
+
});
|
|
138
|
+
d = n.trainingTokens, t || (f = n.validationTokens);
|
|
139
|
+
}
|
|
140
|
+
else d = e;
|
|
141
|
+
let p = d instanceof r ? d.getTokenCount() : d.reduce((e, t) => e + t.length, 0);
|
|
142
|
+
if (f) {
|
|
143
|
+
let { trainDataset: e, validationDataset: t } = await a(d, f, this.trainer.tokenizer, this.trainer.datasetBuilder, c?.batchSize || 32);
|
|
144
|
+
this.trainDataset = e, this.validationDataset = t;
|
|
145
|
+
} else {
|
|
146
|
+
let e = d instanceof r ? d : await o(d, this.trainer.tokenizer);
|
|
147
|
+
this.trainDataset = (await this.trainer.datasetBuilder.createTextDataset(e, c)).dataset;
|
|
148
|
+
}
|
|
149
|
+
this.totalTokens = p, this.options.epochSteps = Math.ceil(this.totalTokens / ((c?.batchSize || 32) * this.model.config.blockSize)), this.trainer.updateOptimizer(this.options);
|
|
150
|
+
}
|
|
151
|
+
configureModel(e) {
|
|
152
|
+
let t = e?.sftMode || "full";
|
|
153
|
+
if (this.trainingType === "pretraining" && (this.trainer.model.hasLoRA() && this.trainer.model.detachLoRA(), this.trainer.model.weightStore.setTrainable(["*"])), this.trainingType === "sft") {
|
|
154
|
+
if (t === "lora") {
|
|
155
|
+
let t = this.trainer.model;
|
|
156
|
+
if (e?.loraName) {
|
|
157
|
+
if (!t.hasLoRA(e.loraName)) if (e.loraConfig) t.createLoRA(e.loraName, e.loraConfig), t.attachLoRA(e.loraName);
|
|
158
|
+
else throw Error(`LoRA configuration must be provided to create LoRA with name ${e.loraName}`);
|
|
159
|
+
else if (t.attachLoRA(e.loraName), e.loraConfig) {
|
|
160
|
+
let n = t.lora;
|
|
161
|
+
(n.alpha !== e.loraConfig.alpha || n.rank !== e.loraConfig.rank) && (t.detachLoRA(), t.deleteLoRA(e.loraName), t.createLoRA(e.loraName, e.loraConfig), t.attachLoRA(e.loraName), console.warn("Resetting LoRA with new configuration."));
|
|
162
|
+
}
|
|
163
|
+
} else if (e?.loraConfig) if (t.hasLoRA()) {
|
|
164
|
+
let n = t.lora;
|
|
165
|
+
if (n.alpha !== e.loraConfig.alpha || n.rank !== e.loraConfig.rank) {
|
|
166
|
+
t.detachLoRA();
|
|
167
|
+
let n = e.loraName || f();
|
|
168
|
+
t.createLoRA(n, e.loraConfig), t.attachLoRA(n);
|
|
169
|
+
}
|
|
170
|
+
} else {
|
|
171
|
+
let n = e.loraName || f();
|
|
172
|
+
t.createLoRA(n, e.loraConfig), t.attachLoRA(n);
|
|
173
|
+
}
|
|
174
|
+
else if (!t.hasLoRA()) throw Error("LoRA configuration must be provided for lora SFT mode");
|
|
175
|
+
} else this.trainer.model.hasLoRA() && this.trainer.model.detachLoRA();
|
|
176
|
+
t === "last-layer" ? this.trainer.model.weightStore.setTrainable([`block_${this.trainer.model.config.nLayer - 1}_*`, "token_embedding"]) : t === "full" && this.trainer.model.weightStore.setTrainable(["*"]);
|
|
177
|
+
}
|
|
178
|
+
e?.trainableWeights && this.trainer.model.weightStore.setTrainable(e.trainableWeights);
|
|
179
|
+
}
|
|
180
|
+
async train() {
|
|
181
|
+
let e = this.options;
|
|
182
|
+
if (!this.trainDataset) throw Error("Dataset not prepared");
|
|
183
|
+
this.hasTrained || this.trainer.setLearningRate(e?.learningRate || .001), this.hasTrained = !0, this.emit("start"), this.model.metaData.pretrainingSettings = e;
|
|
184
|
+
let t = Date.now();
|
|
185
|
+
this.log.length > 0 && this.trainer.resumeFromLog(this.log[this.log.length - 1]), this.trainer.setGradientCheckpointing(e?.gradientCheckpointing || !1), this.trainer.setMixedPrecision(e?.mixedPrecision || !1), this.trainer.setLabelSmoothing(e?.labelSmoothing || 0), this.trainer.setDropout(e?.dropout || 0), this.trainer.setLayerDrop(e?.layerDrop || 0), this.configureModel(e), await this.trainer.trainOnDataset(this.trainDataset, {
|
|
186
|
+
...e,
|
|
187
|
+
onStep: async (e) => {
|
|
188
|
+
this.log.push(e), this.progress = {
|
|
189
|
+
lastLog: e,
|
|
190
|
+
progress: e.totalTokens / this.totalTokens,
|
|
191
|
+
remaining: Math.max(0, (this.totalTokens - e.totalTokens) / e.totalTokens * e.duration)
|
|
192
|
+
}, this.tokensProcessed = e.totalTokens;
|
|
193
|
+
let t = this.listeners("log");
|
|
194
|
+
for (let n of t) await n(e, this.progress);
|
|
195
|
+
}
|
|
196
|
+
}, this.validationDataset), this.model.metaData.actionLog = this.model.metaData.actionLog || [];
|
|
197
|
+
let n = Date.now();
|
|
198
|
+
this.model.metaData.actionLog.push({
|
|
199
|
+
action: "pretrain",
|
|
200
|
+
timestamp: n,
|
|
201
|
+
duration: n - t,
|
|
202
|
+
tokensProcessed: this.tokensProcessed,
|
|
203
|
+
options: e
|
|
204
|
+
}), this.emit("stop");
|
|
205
|
+
}
|
|
206
|
+
async step(e) {
|
|
207
|
+
if (!this.trainDataset) throw Error("Dataset not prepared");
|
|
208
|
+
this.hasTrained || this.trainer.setLearningRate(e?.learningRate || .001), this.hasTrained = !0, this.emit("start");
|
|
209
|
+
let { log: t } = await this.trainer.stepDataset(this.trainDataset, e || {}, this.validationDataset), n = this.listeners("log");
|
|
210
|
+
for (let e of n) await e(t, {
|
|
211
|
+
lastLog: t,
|
|
212
|
+
progress: t.totalTokens / this.totalTokens,
|
|
213
|
+
remaining: Math.max(0, (this.totalTokens - t.totalTokens) / t.totalTokens * t.duration)
|
|
214
|
+
});
|
|
215
|
+
this.emit("stop");
|
|
216
|
+
}
|
|
217
|
+
getLog() {
|
|
218
|
+
return this.log;
|
|
219
|
+
}
|
|
220
|
+
getProgress() {
|
|
221
|
+
return this.progress;
|
|
222
|
+
}
|
|
223
|
+
isPrepared() {
|
|
224
|
+
return this.trainDataset !== void 0 && this.validationDataset !== void 0;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
//#endregion
|
|
228
|
+
export { m as t };
|
package/dist/Trainer.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ITokeniser } from './tokeniser/type';
|
|
2
2
|
import { default as EE } from 'eventemitter3';
|
|
3
3
|
import { default as Model, ModelForwardAttributes } from './models/model';
|
|
4
|
-
import { Task } from './training/tasks/Task';
|
|
5
4
|
import { TrainingOptions, TrainingLogEntry } from './training/types';
|
|
6
5
|
import { AdamWOptimizer } from './training/AdamW';
|
|
7
6
|
import { DatasetMetadata } from './loader/types';
|
|
7
|
+
import { TokenStore } from './training/tasks/TokenStore';
|
|
8
|
+
import { ConversationStream } from './data/stream';
|
|
8
9
|
interface TrainingProgress {
|
|
9
10
|
lastLog: TrainingLogEntry;
|
|
10
11
|
progress: number;
|
|
@@ -33,7 +34,7 @@ export default class Trainer extends EE<'start' | 'stop' | 'log'> {
|
|
|
33
34
|
dispose(): void;
|
|
34
35
|
getTotalTokens(): number;
|
|
35
36
|
setOptions(options: TrainingOptions): void;
|
|
36
|
-
prepare(tasks?:
|
|
37
|
+
prepare(tasks?: ConversationStream[] | Uint16Array[] | TokenStore, validation?: Uint16Array[] | TokenStore, datasets?: DatasetMetadata[]): Promise<void>;
|
|
37
38
|
private configureModel;
|
|
38
39
|
train(): Promise<void>;
|
|
39
40
|
step(options?: TrainingOptions): Promise<void>;
|
package/dist/Trainer.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as e } from "./Trainer-Cr7csbTD.js";
|
|
2
2
|
export { e as default };
|
package/dist/data/stream.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { Conversation } from '../../tokeniser/type';
|
|
2
|
-
export interface ConversationCursor {
|
|
3
|
-
next(): Promise<Conversation[] | null>;
|
|
4
|
-
}
|
|
5
2
|
export interface ConversationStream {
|
|
6
|
-
|
|
3
|
+
begin(cb: (conv: Conversation[]) => void, yieldCb?: () => void): Promise<void>;
|
|
4
|
+
step(cb: (conv: Conversation[]) => void): Promise<() => Promise<boolean>>;
|
|
7
5
|
}
|
|
8
6
|
export declare class MemoryConversationStream implements ConversationStream {
|
|
9
7
|
private conversations;
|
|
10
8
|
constructor(conversations: Conversation[][]);
|
|
11
|
-
|
|
9
|
+
step(cb: (conv: Conversation[]) => void): Promise<() => Promise<boolean>>;
|
|
10
|
+
begin(cb: (conv: Conversation[]) => void, yieldCb?: () => void): Promise<void>;
|
|
12
11
|
}
|
|
13
12
|
declare class JSONLFromReadableStream implements ConversationStream {
|
|
14
13
|
private sourceFactory;
|
|
15
14
|
constructor(sourceFactory: () => Promise<ReadableStream<Uint8Array>>);
|
|
16
|
-
|
|
15
|
+
step(cb: (conv: Conversation[]) => void): Promise<() => Promise<boolean>>;
|
|
16
|
+
begin(cb: (conv: Conversation[]) => void, yieldCb?: () => void): Promise<void>;
|
|
17
17
|
}
|
|
18
18
|
export declare class JSONLConversationStream extends JSONLFromReadableStream {
|
|
19
19
|
constructor(file: File);
|
package/dist/data/stream.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as e, r as t, t as n } from "../stream-
|
|
1
|
+
import { n as e, r as t, t as n } from "../stream-BpAwcvHz.js";
|
|
2
2
|
export { n as JSONLConversationStream, e as MemoryConversationStream, t as ZipJSONLConversationStream };
|
package/dist/data/textLoader.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as e, t } from "../chunk-CWhphoD1.js";
|
|
2
2
|
import { loadPDF as n } from "./pdf.js";
|
|
3
3
|
import { loadDOCX as r } from "./docx.js";
|
|
4
|
-
import { n as i, r as a, t as o } from "../stream-
|
|
4
|
+
import { n as i, r as a, t as o } from "../stream-BpAwcvHz.js";
|
|
5
5
|
//#endregion
|
|
6
6
|
//#region lib/data/textLoader.ts
|
|
7
7
|
var s = /* @__PURE__ */ e((/* @__PURE__ */ t(((e, t) => {
|
|
@@ -86,136 +86,6 @@ var n = (/* @__PURE__ */ e((/* @__PURE__ */ t(((e, t) => {
|
|
|
86
86
|
var t;
|
|
87
87
|
return e ? (t = r ? r + e : e, this._events[t] && s(this, t)) : (this._events = new i(), this._eventsCount = 0), this;
|
|
88
88
|
}, c.prototype.off = c.prototype.removeListener, c.prototype.addListener = c.prototype.on, c.prefixed = r, c.EventEmitter = c, t !== void 0 && (t.exports = c);
|
|
89
|
-
})))(), 1)).default
|
|
90
|
-
"<eos>",
|
|
91
|
-
"<bos>",
|
|
92
|
-
"",
|
|
93
|
-
"<pad>",
|
|
94
|
-
"<|user_start|>",
|
|
95
|
-
"<|user_end|>",
|
|
96
|
-
"<|assistant_start|>",
|
|
97
|
-
"<|assistant_end|>",
|
|
98
|
-
"<|system_start|>",
|
|
99
|
-
"<|system_end|>"
|
|
100
|
-
], i = class extends n {
|
|
101
|
-
id = "untrained";
|
|
102
|
-
datasetID;
|
|
103
|
-
specialTokens = /* @__PURE__ */ new Map();
|
|
104
|
-
specialTokenSet = /* @__PURE__ */ new Set();
|
|
105
|
-
isSpecialToken(e) {
|
|
106
|
-
return this.specialTokenSet.has(e);
|
|
107
|
-
}
|
|
108
|
-
addSpecialTokens() {
|
|
109
|
-
r.forEach((e, t) => {
|
|
110
|
-
this.addToken(e, t), this.specialTokens.set(e, t), this.specialTokenSet.add(t);
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
addSpecialToken(e, t) {
|
|
114
|
-
this.specialTokens.set(e, t), this.specialTokenSet.add(t);
|
|
115
|
-
}
|
|
116
|
-
generateID() {
|
|
117
|
-
let e = this.getVocab(), t = 2166136261, n = 2654435769;
|
|
118
|
-
if (e.length === 0) {
|
|
119
|
-
this.id = "untrained";
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
for (let r = 0; r < e.length; r++) {
|
|
123
|
-
let i = e[r];
|
|
124
|
-
t ^= i.length, t = Math.imul(t, 16777619), n ^= r, n = Math.imul(n, 2246822507);
|
|
125
|
-
for (let e = 0; e < i.length; e++) {
|
|
126
|
-
let r = i.charCodeAt(e);
|
|
127
|
-
t ^= r, t = Math.imul(t, 16777619), n ^= r, n = Math.imul(n, 3266489909);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
let r = (t >>> 0).toString(36), i = (n >>> 0).toString(36);
|
|
131
|
-
this.id = "tokeniser_" + r + "_" + i;
|
|
132
|
-
}
|
|
133
|
-
encodeSequence(e) {
|
|
134
|
-
let t = this.encode(e);
|
|
135
|
-
return [
|
|
136
|
-
this.bosToken,
|
|
137
|
-
...t,
|
|
138
|
-
this.eosToken
|
|
139
|
-
];
|
|
140
|
-
}
|
|
141
|
-
encodeAsSequence(e, t) {
|
|
142
|
-
let n = e.flatMap((e) => this.encode(e.content));
|
|
143
|
-
return t ? [
|
|
144
|
-
this.bosToken,
|
|
145
|
-
...n,
|
|
146
|
-
this.eosToken,
|
|
147
|
-
this.bosToken
|
|
148
|
-
] : [
|
|
149
|
-
this.bosToken,
|
|
150
|
-
...n,
|
|
151
|
-
this.eosToken
|
|
152
|
-
];
|
|
153
|
-
}
|
|
154
|
-
encodeConversation(e, t, n) {
|
|
155
|
-
let r = [[this.bosToken]], i;
|
|
156
|
-
n && (i = [[!1]]);
|
|
157
|
-
let a = [
|
|
158
|
-
this.getSpecialTokenIndex("<|user_start|>"),
|
|
159
|
-
this.getSpecialTokenIndex("<|assistant_start|>"),
|
|
160
|
-
this.getSpecialTokenIndex("<|system_start|>")
|
|
161
|
-
], o = [
|
|
162
|
-
this.getSpecialTokenIndex("<|user_end|>"),
|
|
163
|
-
this.getSpecialTokenIndex("<|assistant_end|>"),
|
|
164
|
-
this.getSpecialTokenIndex("<|system_end|>")
|
|
165
|
-
];
|
|
166
|
-
for (let t of e) {
|
|
167
|
-
let e = !1, s = this.encode(t.content);
|
|
168
|
-
switch (t.role) {
|
|
169
|
-
case "user":
|
|
170
|
-
r.push([a[0]]), e = !0;
|
|
171
|
-
break;
|
|
172
|
-
case "assistant":
|
|
173
|
-
r.push([a[1]]);
|
|
174
|
-
break;
|
|
175
|
-
case "system":
|
|
176
|
-
r.push([a[2]]), e = !0;
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
switch (r.push(s), t.role) {
|
|
180
|
-
case "user":
|
|
181
|
-
r.push([o[0]]);
|
|
182
|
-
break;
|
|
183
|
-
case "assistant":
|
|
184
|
-
r.push([o[1]]);
|
|
185
|
-
break;
|
|
186
|
-
case "system":
|
|
187
|
-
r.push([o[2]]);
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
n && i && e ? (i.push([!1]), i.push(s.map(() => !1)), i.push([!1])) : n && i && (i.push([!1]), i.push(s.map(() => !0)), i.push([!0]));
|
|
191
|
-
}
|
|
192
|
-
let s = r.flat();
|
|
193
|
-
return t ? (s.push(a[1]), n && i && i.push([!1])) : (s.push(this.eosToken), n && i && i.push([!0])), n && i ? {
|
|
194
|
-
tokens: s,
|
|
195
|
-
mask: i.flat()
|
|
196
|
-
} : s;
|
|
197
|
-
}
|
|
198
|
-
decodeConversation(e) {
|
|
199
|
-
let t = [], n = 0;
|
|
200
|
-
for (; n < e.length;) {
|
|
201
|
-
let r = e[n], i = null;
|
|
202
|
-
if (r === this.getSpecialTokenIndex("<|user_start|>") ? i = "user" : r === this.getSpecialTokenIndex("<|assistant_start|>") ? i = "assistant" : r === this.getSpecialTokenIndex("<|system_start|>") ? i = "system" : r === this.bosToken || (r === this.eosToken ? i = null : (i = "text", n--)), i) {
|
|
203
|
-
n++;
|
|
204
|
-
let r = [];
|
|
205
|
-
for (; n < e.length && e[n] !== this.getSpecialTokenIndex(`<|${i}_end|>`) && e[n] !== this.eosToken;) r.push(e[n]), n++;
|
|
206
|
-
let a = this.decode(r);
|
|
207
|
-
t.push({
|
|
208
|
-
role: i,
|
|
209
|
-
content: a
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
n++;
|
|
213
|
-
}
|
|
214
|
-
return t;
|
|
215
|
-
}
|
|
216
|
-
getSpecialTokenIndex(e) {
|
|
217
|
-
return this.specialTokens.get(e);
|
|
218
|
-
}
|
|
219
|
-
};
|
|
89
|
+
})))(), 1)).default;
|
|
220
90
|
//#endregion
|
|
221
|
-
export {
|
|
91
|
+
export { n as t };
|
package/dist/loader/load.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as e, s as t } from "../main-Dz72vadm.js";
|
|
2
2
|
export { t as VERSION, e as loadModel };
|
package/dist/loader/loadHF.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as e } from "../main-Dz72vadm.js";
|
|
2
2
|
export { e as default };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { d as e, f as t } from "../main-Dz72vadm.js";
|
|
2
|
+
export { e as default, t as mapTransformersConfigToGPTConfig };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { u as e } from "../main-Dz72vadm.js";
|
|
2
2
|
export { e as default };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { p as e } from "../main-Dz72vadm.js";
|
|
2
2
|
export { e as default };
|
package/dist/loader/save.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as e } from "../main-Dz72vadm.js";
|
|
2
2
|
export { e as saveModel };
|