@genai-fi/nanogpt 0.21.0 → 0.23.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-B9UGNQT5.js → DatasetBuilder-C0iJT29K.js} +122 -93
- package/dist/Generator.js +2 -2
- package/dist/TeachableLLM.d.ts +2 -1
- package/dist/TeachableLLM.js +1 -1
- package/dist/Trainer-DBsyWJ4s.js +228 -0
- package/dist/Trainer.d.ts +2 -1
- package/dist/Trainer.js +1 -1
- package/dist/data/stream.d.ts +24 -0
- package/dist/data/stream.js +2 -0
- package/dist/data/textLoader.d.ts +2 -2
- package/dist/data/textLoader.js +28 -67
- package/dist/{BaseTokeniser-C9TSv4th.js → eventemitter3-D_qV3Lof.js} +2 -132
- package/dist/loader/load.js +2 -2
- 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-DdsoTJAW.js → main-BSaDGH7I.js} +2686 -2912
- package/dist/main.d.ts +4 -0
- package/dist/main.js +20 -16
- 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-BjdpSNqB.js +2296 -0
- package/dist/tokeniser/BaseTokeniser.d.ts +2 -1
- package/dist/tokeniser/BaseTokeniser.js +135 -2
- package/dist/tokeniser/CharTokeniser.d.ts +2 -2
- package/dist/tokeniser/CharTokeniser.js +10 -14
- package/dist/tokeniser/bpe.d.ts +2 -2
- package/dist/tokeniser/bpe.js +23 -32
- package/dist/tokeniser/type.d.ts +3 -2
- package/dist/training/DatasetBuilder.d.ts +17 -1
- 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/ConversationTask.d.ts +9 -10
- package/dist/training/tasks/ConversationTask.js +15 -24
- package/dist/training/tasks/PretrainingTask.d.ts +4 -4
- package/dist/training/tasks/PretrainingTask.js +2 -2
- package/dist/training/tasks/StartSentenceTask.d.ts +4 -4
- package/dist/training/tasks/StartSentenceTask.js +3 -3
- package/dist/training/tasks/Task.d.ts +19 -12
- package/dist/training/tasks/Task.js +25 -30
- package/dist/training/tasks/TokenStore.d.ts +46 -0
- package/dist/training/tasks/TokenStore.js +215 -0
- package/dist/training/tasks/splitter.d.ts +2 -2
- package/dist/training/tasks/splitter.js +11 -11
- package/dist/training/validation.d.ts +4 -2
- package/dist/training/validation.js +21 -2
- package/dist/utilities/tokens.d.ts +2 -0
- package/dist/utilities/tokens.js +40 -0
- package/dist/utilities/topP.js +6 -0
- package/package.json +2 -1
|
@@ -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 { tokensFromTasks as i } from "./training/tasks/Task.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
|
@@ -5,6 +5,7 @@ import { Task } from './training/tasks/Task';
|
|
|
5
5
|
import { TrainingOptions, TrainingLogEntry } from './training/types';
|
|
6
6
|
import { AdamWOptimizer } from './training/AdamW';
|
|
7
7
|
import { DatasetMetadata } from './loader/types';
|
|
8
|
+
import { TokenStore } from './training/tasks/TokenStore';
|
|
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?: Task[] | Uint16Array, datasets?: DatasetMetadata[]): Promise<void>;
|
|
37
|
+
prepare(tasks?: Task[] | 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-DBsyWJ4s.js";
|
|
2
2
|
export { e as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Conversation } from '../../tokeniser/type';
|
|
2
|
+
export interface ConversationCursor {
|
|
3
|
+
next(): Promise<Conversation[] | null>;
|
|
4
|
+
}
|
|
5
|
+
export interface ConversationStream {
|
|
6
|
+
cursor(): ConversationCursor;
|
|
7
|
+
}
|
|
8
|
+
export declare class MemoryConversationStream implements ConversationStream {
|
|
9
|
+
private conversations;
|
|
10
|
+
constructor(conversations: Conversation[][]);
|
|
11
|
+
cursor(): ConversationCursor;
|
|
12
|
+
}
|
|
13
|
+
declare class JSONLFromReadableStream implements ConversationStream {
|
|
14
|
+
private sourceFactory;
|
|
15
|
+
constructor(sourceFactory: () => Promise<ReadableStream<Uint8Array>>);
|
|
16
|
+
cursor(): ConversationCursor;
|
|
17
|
+
}
|
|
18
|
+
export declare class JSONLConversationStream extends JSONLFromReadableStream {
|
|
19
|
+
constructor(file: File);
|
|
20
|
+
}
|
|
21
|
+
export declare class ZipJSONLConversationStream extends JSONLFromReadableStream {
|
|
22
|
+
constructor(file: File, preferredEntryName?: string);
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConversationStream } from './stream';
|
|
2
2
|
export interface DataOptions {
|
|
3
3
|
maxSize?: number;
|
|
4
4
|
column?: string;
|
|
5
5
|
hasHeader?: boolean;
|
|
6
6
|
}
|
|
7
|
-
export default function loadTextData(file: File, options?: DataOptions
|
|
7
|
+
export default function loadTextData(file: File, options?: DataOptions): Promise<ConversationStream>;
|
package/dist/data/textLoader.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { i as e, t } from "../chunk-CWhphoD1.js";
|
|
2
2
|
import { loadPDF as n } from "./pdf.js";
|
|
3
|
-
import { loadDOCX as r
|
|
3
|
+
import { loadDOCX as r } from "./docx.js";
|
|
4
|
+
import { n as i, r as a, t as o } from "../stream-BjdpSNqB.js";
|
|
4
5
|
//#endregion
|
|
5
6
|
//#region lib/data/textLoader.ts
|
|
6
|
-
var
|
|
7
|
+
var s = /* @__PURE__ */ e((/* @__PURE__ */ t(((e, t) => {
|
|
7
8
|
((n, r) => {
|
|
8
9
|
typeof define == "function" && define.amd ? define([], r) : typeof t == "object" && e !== void 0 ? t.exports = r() : n.Papa = r();
|
|
9
10
|
})(e, function e() {
|
|
@@ -496,19 +497,19 @@ var a = /* @__PURE__ */ e((/* @__PURE__ */ t(((e, t) => {
|
|
|
496
497
|
});
|
|
497
498
|
}), (l.prototype = Object.create(c.prototype)).constructor = l, (u.prototype = Object.create(c.prototype)).constructor = u, (d.prototype = Object.create(d.prototype)).constructor = d, (f.prototype = Object.create(c.prototype)).constructor = f, s;
|
|
498
499
|
});
|
|
499
|
-
})))(), 1)
|
|
500
|
-
function
|
|
500
|
+
})))(), 1);
|
|
501
|
+
function c(e, t) {
|
|
501
502
|
let n = e.findIndex((e) => e.toLowerCase() === t.toLowerCase());
|
|
502
503
|
return n === -1 ? 0 : n;
|
|
503
504
|
}
|
|
504
|
-
function
|
|
505
|
+
function l(e) {
|
|
505
506
|
return e.every((e) => e.length < 64);
|
|
506
507
|
}
|
|
507
|
-
function
|
|
508
|
+
function u(e) {
|
|
508
509
|
return e.split(".").pop() || "";
|
|
509
510
|
}
|
|
510
|
-
function
|
|
511
|
-
switch (
|
|
511
|
+
function d(e) {
|
|
512
|
+
switch (u(e)) {
|
|
512
513
|
case "json": return "application/json";
|
|
513
514
|
case "jsonl": return "application/jsonl";
|
|
514
515
|
case "parquet": return "application/parquet";
|
|
@@ -520,19 +521,14 @@ function u(e) {
|
|
|
520
521
|
default: return "unknown";
|
|
521
522
|
}
|
|
522
523
|
}
|
|
523
|
-
function
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
let l = e.type === "" ? u(e.name) : e.type;
|
|
530
|
-
if (l === "application/parquet") throw Error("Parquet loading is not currently supported in the browser. Please convert your data to JSONL format.");
|
|
531
|
-
if (l === "application/pdf") return n(e, t?.maxSize);
|
|
532
|
-
if (l === "application/vnd.openxmlformats-officedocument.wordprocessingml.document") return r(e);
|
|
533
|
-
if (l === "application/json") {
|
|
524
|
+
async function f(e, t) {
|
|
525
|
+
let u = e.type === "" ? d(e.name) : e.type;
|
|
526
|
+
if (u === "application/parquet") throw Error("Parquet loading is not currently supported in the browser. Please convert your data to JSONL format.");
|
|
527
|
+
if (u === "application/pdf") return new i(await n(e, t?.maxSize));
|
|
528
|
+
if (u === "application/vnd.openxmlformats-officedocument.wordprocessingml.document") return new i(await r(e));
|
|
529
|
+
if (u === "application/json") {
|
|
534
530
|
let t = await e.text(), n = JSON.parse(t);
|
|
535
|
-
if (Array.isArray(n)) return n.map((e) => [typeof e == "string" ? {
|
|
531
|
+
if (Array.isArray(n)) return new i(n.map((e) => [typeof e == "string" ? {
|
|
536
532
|
role: "text",
|
|
537
533
|
content: e
|
|
538
534
|
} : "text" in e ? {
|
|
@@ -541,61 +537,26 @@ async function f(e, t, i) {
|
|
|
541
537
|
} : {
|
|
542
538
|
role: "text",
|
|
543
539
|
content: JSON.stringify(e)
|
|
544
|
-
}]);
|
|
540
|
+
}]));
|
|
545
541
|
throw Error("Expected JSON array");
|
|
546
542
|
}
|
|
547
|
-
if (
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
i && t % 1e3 == 0 && i(.1 + t / n.length * .9);
|
|
551
|
-
try {
|
|
552
|
-
let t = JSON.parse(e);
|
|
553
|
-
return d(t) ? t : [typeof t == "string" ? {
|
|
554
|
-
role: "text",
|
|
555
|
-
content: t
|
|
556
|
-
} : "text" in t ? {
|
|
557
|
-
role: "text",
|
|
558
|
-
content: t.text
|
|
559
|
-
} : {
|
|
560
|
-
role: "text",
|
|
561
|
-
content: JSON.stringify(t)
|
|
562
|
-
}];
|
|
563
|
-
} catch {
|
|
564
|
-
return [{
|
|
565
|
-
role: "text",
|
|
566
|
-
content: e
|
|
567
|
-
}];
|
|
568
|
-
}
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
if (l === "application/zip") {
|
|
572
|
-
let n = await o.default.loadAsync(e), r = [], a = Object.keys(n.files);
|
|
573
|
-
for (let e = 0; e < a.length; e++) {
|
|
574
|
-
let o = a[e], s = n.file(o);
|
|
575
|
-
if (s) {
|
|
576
|
-
let n = await s.async("blob", (t) => {
|
|
577
|
-
i && i(.1 + (t.percent / 100 * .9 / a.length + e / a.length * .9));
|
|
578
|
-
}), c = await f(new File([n], o), t);
|
|
579
|
-
i && i(.1 + (e + 1) / a.length * .9), r = r.concat(c);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
return r;
|
|
583
|
-
}
|
|
584
|
-
if (l === "text/csv") {
|
|
543
|
+
if (u === "application/jsonl") return new o(e);
|
|
544
|
+
if (u === "application/zip") return new a(e);
|
|
545
|
+
if (u === "text/csv") {
|
|
585
546
|
let n = await e.text();
|
|
586
|
-
return
|
|
587
|
-
|
|
547
|
+
return new Promise((e, r) => {
|
|
548
|
+
s.default.parse(n, {
|
|
588
549
|
header: !1,
|
|
589
550
|
skipEmptyLines: !0,
|
|
590
551
|
delimiter: ",",
|
|
591
552
|
complete: (n) => {
|
|
592
553
|
if (n.errors.length > 0) console.error(n.errors), r(/* @__PURE__ */ Error("Error parsing file"));
|
|
593
554
|
else {
|
|
594
|
-
let r =
|
|
595
|
-
e((t?.hasHeader ??
|
|
555
|
+
let r = c(n.data[0], t?.column || "text");
|
|
556
|
+
e(new i((t?.hasHeader ?? l(n.data[0]) ? n.data.slice(1) : n.data).map((e) => [{
|
|
596
557
|
role: "text",
|
|
597
558
|
content: e[r]
|
|
598
|
-
}]));
|
|
559
|
+
}])));
|
|
599
560
|
}
|
|
600
561
|
},
|
|
601
562
|
error: (e) => {
|
|
@@ -603,11 +564,11 @@ async function f(e, t, i) {
|
|
|
603
564
|
}
|
|
604
565
|
});
|
|
605
566
|
});
|
|
606
|
-
} else if (
|
|
567
|
+
} else if (u === "text/plain") return new i([[{
|
|
607
568
|
role: "text",
|
|
608
569
|
content: await e.text()
|
|
609
|
-
}]];
|
|
610
|
-
throw Error(`Unsupported file type: ${
|
|
570
|
+
}]]);
|
|
571
|
+
throw Error(`Unsupported file type: ${u}`);
|
|
611
572
|
}
|
|
612
573
|
//#endregion
|
|
613
574
|
export { f as default };
|
|
@@ -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 {
|
|
2
|
-
export {
|
|
1
|
+
import { c as e, l as t } from "../main-BSaDGH7I.js";
|
|
2
|
+
export { e as VERSION, t as loadModel };
|
package/dist/loader/loadHF.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { u as e } from "../main-BSaDGH7I.js";
|
|
2
2
|
export { e as default };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { f as e, p as t } from "../main-BSaDGH7I.js";
|
|
2
|
+
export { e as default, t as mapTransformersConfigToGPTConfig };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as e } from "../main-BSaDGH7I.js";
|
|
2
2
|
export { e as default };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { m as e } from "../main-BSaDGH7I.js";
|
|
2
2
|
export { e as default };
|
package/dist/loader/save.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { s as e } from "../main-BSaDGH7I.js";
|
|
2
2
|
export { e as saveModel };
|