@genai-fi/nanogpt 1.1.0 → 1.1.2
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/TeachableLLM.d.ts +1 -0
- package/dist/TeachableLLM.js +17 -8
- package/dist/api/responses.d.ts +1 -0
- package/dist/api/responses.js +3 -0
- package/dist/backend.js +1 -1
- package/dist/{dist-9wGF4ci9.js → dist-BGVm64AY.js} +224 -224
- package/dist/ops/webgpu/adamAdjust.js +4 -4
- package/dist/ops/webgpu/adamMoments.js +4 -4
- package/dist/ops/webgpu/appendCache.js +10 -10
- package/dist/ops/webgpu/attentionMask32_program.js +6 -6
- package/dist/ops/webgpu/concat16.js +4 -4
- package/dist/ops/webgpu/dropout16.js +4 -4
- package/dist/ops/webgpu/gatherSub.js +4 -4
- package/dist/ops/webgpu/gelu.js +8 -8
- package/dist/ops/webgpu/normRMSGrad.js +6 -6
- package/dist/ops/webgpu/pack16_program.js +18 -18
- package/dist/ops/webgpu/rope.js +12 -12
- package/dist/ops/webgpu/scatterSub.js +4 -4
- package/dist/ops/webgpu/slice16.js +7 -7
- package/dist/ops/webgpu/softmax16_program.js +5 -5
- package/dist/ops/webgpu/softmax16_subgroup_program.js +10 -10
- package/dist/ops/webgpu/transpose16_program.js +15 -15
- package/dist/ops/webgpu/transpose16_shared_program.js +14 -14
- package/dist/ops/webgpu/unpack16.js +4 -4
- package/dist/ops/webgpu/utils/binary_op.js +10 -10
- package/dist/ops/webgpu/utils/reductions.js +6 -6
- package/dist/patches/webgpu_backend.js +8 -8
- package/dist/patches/webgpu_base.d.ts +1 -0
- package/dist/patches/webgpu_base.js +20 -14
- package/dist/training/BasicTrainer.js +5 -1
- package/dist/{webgpu-B19Tw8Nd.js → webgpu-IAn9VotJ.js} +8 -8
- package/package.json +1 -1
package/dist/TeachableLLM.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { default as Training } from './api/training';
|
|
|
11
11
|
import { GPUOptions } from './patches/webgpu_base';
|
|
12
12
|
type TeachableLLMStatus = 'warmup' | 'awaitingTokens' | 'ready' | 'training' | 'loading' | 'busy' | 'error';
|
|
13
13
|
export default class TeachableLLM {
|
|
14
|
+
static instances: Set<TeachableLLM>;
|
|
14
15
|
private ee;
|
|
15
16
|
private _config?;
|
|
16
17
|
private _model?;
|
package/dist/TeachableLLM.js
CHANGED
|
@@ -10,8 +10,10 @@ import c from "./utilities/profile.js";
|
|
|
10
10
|
import l from "./api/responses.js";
|
|
11
11
|
import u from "./api/training.js";
|
|
12
12
|
import { selectBackend as d } from "./backend.js";
|
|
13
|
+
import { getBackendDevice as f } from "./patches/webgpu_base.js";
|
|
13
14
|
//#region lib/TeachableLLM.ts
|
|
14
|
-
var
|
|
15
|
+
var p = class p {
|
|
16
|
+
static instances = /* @__PURE__ */ new Set();
|
|
15
17
|
ee = new e();
|
|
16
18
|
_config;
|
|
17
19
|
_model;
|
|
@@ -24,11 +26,18 @@ var f = class f {
|
|
|
24
26
|
version: 2,
|
|
25
27
|
application: "@genai-fi/nanogpt"
|
|
26
28
|
};
|
|
27
|
-
static selectBackend(e, t) {
|
|
28
|
-
|
|
29
|
+
static async selectBackend(e, t) {
|
|
30
|
+
if (await d(e, t), e === "webgpu") {
|
|
31
|
+
let e = f();
|
|
32
|
+
e && e.lost.then(() => {
|
|
33
|
+
console.warn("WebGPU device lost"), p.instances.forEach((e) => {
|
|
34
|
+
e.setStatus("error"), e.ee.emit("lost");
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
29
38
|
}
|
|
30
39
|
constructor(e, t) {
|
|
31
|
-
this._config = t?.config, this._tokeniser = e, this._model = t, t?.metaData && (this.meta = t.metaData);
|
|
40
|
+
this._config = t?.config, this._tokeniser = e, this._model = t, t?.metaData && (this.meta = t.metaData), p.instances.add(this);
|
|
32
41
|
}
|
|
33
42
|
get vocab() {
|
|
34
43
|
return this._tokeniser?.getVocab() || [];
|
|
@@ -115,7 +124,7 @@ var f = class f {
|
|
|
115
124
|
} : void 0);
|
|
116
125
|
}
|
|
117
126
|
static loadModel(e, t) {
|
|
118
|
-
let n = new
|
|
127
|
+
let n = new p();
|
|
119
128
|
return o(e, t).then(({ model: e, tokeniser: t, metaData: a, optimizer: o, log: s }) => {
|
|
120
129
|
r(e.config), n._model = e, n._tokeniser = t, n._config = e.config, a && (n.meta = a), n.setStatus("warmup"), i(e).then((t) => {
|
|
121
130
|
n._memoryRequirements = t, o && e.metaData.pretrainingSettings && e.metaData.pretrainingData && n.training.restore(e.metaData.pretrainingSettings, s || [], o, e.metaData.pretrainingData), n.setStatus("ready"), n.ee.emit("loaded"), n.ee.emit("mode", n.mode);
|
|
@@ -128,7 +137,7 @@ var f = class f {
|
|
|
128
137
|
}
|
|
129
138
|
static create(e, o) {
|
|
130
139
|
r(o);
|
|
131
|
-
let s = o, c = e === "char" ? new t(s.vocabSize) : e === "bpe" ? new n(s.vocabSize) : e, l = a(s), u = new
|
|
140
|
+
let s = o, c = e === "char" ? new t(s.vocabSize) : e === "bpe" ? new n(s.vocabSize) : e, l = a(s), u = new p(c, l);
|
|
132
141
|
return u.setStatus("warmup"), i(l).then((e) => {
|
|
133
142
|
u._memoryRequirements = e, u.tokeniser.trained ? (u.setStatus("ready"), u.ee.emit("loaded"), u.ee.emit("mode", u.mode)) : (u.setStatus("awaitingTokens"), u.ee.emit("loaded"), u.ee.emit("mode", u.mode), u.tokeniser.once("trainStatus", (e) => {
|
|
134
143
|
e === "trained" && u.setStatus("ready");
|
|
@@ -184,7 +193,7 @@ var f = class f {
|
|
|
184
193
|
return this._training;
|
|
185
194
|
}
|
|
186
195
|
dispose() {
|
|
187
|
-
this._responses &&= (this._responses.dispose(), null), this._training &&= (this._training.dispose(), null), this._model?.dispose(), this.ee.removeAllListeners();
|
|
196
|
+
this._responses &&= (this._responses.dispose(), null), this._training &&= (this._training.dispose(), null), this._model?.dispose(), this.ee.removeAllListeners(), p.instances.delete(this);
|
|
188
197
|
}
|
|
189
198
|
on(e, t) {
|
|
190
199
|
if (e === "loaded" && this.loaded) {
|
|
@@ -198,4 +207,4 @@ var f = class f {
|
|
|
198
207
|
}
|
|
199
208
|
};
|
|
200
209
|
//#endregion
|
|
201
|
-
export {
|
|
210
|
+
export { p as default };
|
package/dist/api/responses.d.ts
CHANGED
|
@@ -66,6 +66,7 @@ export default class Responses {
|
|
|
66
66
|
* @returns `true` if the response exists and was hooked, otherwise `false`
|
|
67
67
|
*/
|
|
68
68
|
hook(id: string): boolean;
|
|
69
|
+
unhook(id: string): void;
|
|
69
70
|
/**
|
|
70
71
|
* Resume a previously hooked response, releasing a single paused chunk.
|
|
71
72
|
* @param id Response ID to resume
|
package/dist/api/responses.js
CHANGED
|
@@ -151,6 +151,9 @@ var r = class {
|
|
|
151
151
|
hook(e) {
|
|
152
152
|
return this._responses.has(e) ? (this._hookedResponses.add(e), !0) : !1;
|
|
153
153
|
}
|
|
154
|
+
unhook(e) {
|
|
155
|
+
this._hookedResponses.delete(e), (this._resumeWaiters.get(e) || []).forEach((e) => e()), this._resumeWaiters.delete(e);
|
|
156
|
+
}
|
|
154
157
|
resume(e) {
|
|
155
158
|
let t = this._resumeWaiters.get(e);
|
|
156
159
|
if (!t || t.length === 0) return this._hookedResponses.has(e);
|
package/dist/backend.js
CHANGED
|
@@ -4,7 +4,7 @@ async function r(r, i) {
|
|
|
4
4
|
if (e() !== r) {
|
|
5
5
|
if (r === "webgpu") {
|
|
6
6
|
let { registerWebGPUBackend: e } = await import("./patches/webgpu_base.js");
|
|
7
|
-
e(i), await import("./dist-
|
|
7
|
+
e(i), await import("./dist-BGVm64AY.js"), await import("./ops/webgpu/index.js");
|
|
8
8
|
}
|
|
9
9
|
await n(r), await t(), console.log(`Backend set to ${r}`);
|
|
10
10
|
}
|