@genai-fi/nanogpt 0.2.1 → 0.2.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/Generator.js CHANGED
@@ -1,4 +1,4 @@
1
- import { E as u } from "./index-SOhdqzHq.js";
1
+ import { E as u } from "./index-Dwqa6Zy2.js";
2
2
  class p extends u {
3
3
  constructor(s, e) {
4
4
  super(), this.model = s, this.tokeniser = e;
@@ -3,7 +3,7 @@ import $ from "./layers/TransformerBlock.js";
3
3
  import S from "./layers/TiedEmbedding.js";
4
4
  import I from "./layers/RoPECache.js";
5
5
  import _ from "./layers/RMSNorm.js";
6
- class M {
6
+ class x {
7
7
  config;
8
8
  wte;
9
9
  // Token embeddings
@@ -166,21 +166,21 @@ class M {
166
166
  ), f = r ? this.config.blockSize - c.shape[1] : 0, a = f > 0 ? this.tf.pad(c, [
167
167
  [0, 0],
168
168
  [0, f]
169
- ]) : c, { logits: d, attention: g } = this.forward(a, void 0, !1, l, e), m = d.shape[1] - 1 - f, p = d.slice([0, m, 0], [d.shape[0], 1, d.shape[2]]), w = g ? g.slice([0, m, 0], [g.shape[0], 1, g.shape[2]]) : void 0, u = p.div(i);
170
- let b;
169
+ ]) : c, { logits: d, attention: g } = this.forward(a, void 0, !1, l, e), m = d.shape[1] - 1 - f, p = d.slice([0, m, 0], [d.shape[0], 1, d.shape[2]]), w = g ? g.slice([0, m, 0], [g.shape[0], 1, g.shape[2]]) : void 0, b = p.div(i);
170
+ let u;
171
171
  if (s) {
172
- const { values: E, indices: v } = this.tf.topk(u, s), y = this.tf.multinomial(E.squeeze([1]), 1);
173
- b = this.tf.gather(v.squeeze([1]), y, 1);
172
+ const { values: E, indices: v } = this.tf.topk(b, s), y = this.tf.multinomial(E.squeeze([1]), 1);
173
+ u = this.tf.gather(v.squeeze([1]), y, 1);
174
174
  } else
175
- b = this.tf.multinomial(u.squeeze([1]), 1);
175
+ u = this.tf.multinomial(b.squeeze([1]), 1);
176
176
  let k;
177
- return o?.includeProbabilities && (k = this.tf.softmax(u.squeeze([1]))), b = b.reshape([1, 1]), { output: b, attention: w?.squeeze([1]), probabilities: k };
177
+ return o?.includeProbabilities && (k = this.tf.softmax(b.squeeze([1]))), u = u.reshape([1, 1]), { output: u, attention: w?.squeeze([1]), probabilities: k };
178
178
  });
179
179
  }
180
180
  getNumParams() {
181
- const t = this.config.vocabSize * this.config.nEmbed + this.config.blockSize * this.config.nEmbed, e = this.config.nLayer * (4 * this.config.nEmbed * this.config.nEmbed + // qkv + proj
182
- 2 * this.config.nEmbed), o = this.config.nLayer * (4 * this.config.nEmbed * this.config.nEmbed + // fc
183
- this.config.nEmbed * 4 * this.config.nEmbed), i = this.config.nEmbed + this.config.vocabSize * this.config.nEmbed;
181
+ const t = this.config.vocabSize * this.config.nEmbed, e = this.config.nLayer * (4 * this.config.nEmbed * this.config.nEmbed + // qkv + proj
182
+ 2 * this.config.nEmbed), o = this.config.nLayer * (this.config.mlpFactor * this.config.nEmbed * this.config.nEmbed + // fc
183
+ this.config.nEmbed * this.config.mlpFactor * this.config.nEmbed), i = this.config.nEmbed;
184
184
  return t + e + o + i;
185
185
  }
186
186
  dispose() {
@@ -188,5 +188,5 @@ class M {
188
188
  }
189
189
  }
190
190
  export {
191
- M as default
191
+ x as default
192
192
  };
@@ -4,9 +4,10 @@ import { saveModel as m } from "./utilities/save.js";
4
4
  import { loadModel as l } from "./utilities/load.js";
5
5
  import f from "./Generator.js";
6
6
  import _ from "./Trainer.js";
7
- import { E as c } from "./index-SOhdqzHq.js";
7
+ import { E as c } from "./index-Dwqa6Zy2.js";
8
8
  import { dummyPassAsync as h } from "./utilities/dummy.js";
9
9
  import g from "./tokeniser/CharTokeniser.js";
10
+ import "./papaparse.min-C8l2Kvo1.js";
10
11
  class a extends c {
11
12
  _config;
12
13
  _model;
package/dist/Trainer.js CHANGED
@@ -1,4 +1,4 @@
1
- import { E as l } from "./index-SOhdqzHq.js";
1
+ import { E as l } from "./index-Dwqa6Zy2.js";
2
2
  import h from "./training/FullTrainer.js";
3
3
  class m extends l {
4
4
  trainer;
@@ -0,0 +1,33 @@
1
+ var u = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
2
+ function a(e) {
3
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
4
+ }
5
+ function f(e) {
6
+ if (Object.prototype.hasOwnProperty.call(e, "__esModule")) return e;
7
+ var n = e.default;
8
+ if (typeof n == "function") {
9
+ var t = function r() {
10
+ var o = !1;
11
+ try {
12
+ o = this instanceof r;
13
+ } catch {
14
+ }
15
+ return o ? Reflect.construct(n, arguments, this.constructor) : n.apply(this, arguments);
16
+ };
17
+ t.prototype = n.prototype;
18
+ } else t = {};
19
+ return Object.defineProperty(t, "__esModule", { value: !0 }), Object.keys(e).forEach(function(r) {
20
+ var o = Object.getOwnPropertyDescriptor(e, r);
21
+ Object.defineProperty(t, r, o.get ? o : {
22
+ enumerable: !0,
23
+ get: function() {
24
+ return e[r];
25
+ }
26
+ });
27
+ }), t;
28
+ }
29
+ export {
30
+ f as a,
31
+ u as c,
32
+ a as g
33
+ };
@@ -0,0 +1 @@
1
+ export declare function loadParquet(file: File, maxSize?: number, column?: string): Promise<string[]>;
@@ -0,0 +1,12 @@
1
+ async function p(s, f = 104857600, e = "text") {
2
+ const r = await (await import("../parquet-DpcqBLb0.js").then((t) => t.p)).ParquetReader.openBuffer(Buffer.from(await s.arrayBuffer())), a = [], i = r.getCursor([[e]]);
3
+ let o = 0;
4
+ for (; ; ) {
5
+ const t = await i.next();
6
+ if (!t || !t[e] || typeof t[e] != "string" || (a.push(t[e]), o += t[e].length, o > f)) break;
7
+ }
8
+ return r.close(), a;
9
+ }
10
+ export {
11
+ p as loadParquet
12
+ };
@@ -0,0 +1,6 @@
1
+ export interface DataOptions {
2
+ maxSize?: number;
3
+ column?: string;
4
+ hasHeader?: boolean;
5
+ }
6
+ export default function loadTextData(file: File, options?: DataOptions): Promise<string[]>;
@@ -0,0 +1,39 @@
1
+ import { p as s } from "../papaparse.min-C8l2Kvo1.js";
2
+ import { loadParquet as l } from "./parquet.js";
3
+ function m(e, t) {
4
+ const a = e.findIndex((n) => n.toLowerCase() === t.toLowerCase());
5
+ return a === -1 ? 0 : a;
6
+ }
7
+ function u(e) {
8
+ return e.every((t) => t.length < 64);
9
+ }
10
+ async function w(e, t) {
11
+ const a = e.type;
12
+ if (a === "application/parquet")
13
+ return l(e, t?.maxSize, t?.column);
14
+ if (a === "text/csv") {
15
+ const n = "FileReaderSync" in global ? e : await e.text();
16
+ return new Promise((c, o) => {
17
+ s.parse(n, {
18
+ header: !1,
19
+ skipEmptyLines: !0,
20
+ complete: (r) => {
21
+ if (r.errors.length > 0)
22
+ o(new Error("Error parsing file"));
23
+ else {
24
+ const i = m(r.data[0], t?.column || "text"), d = t?.hasHeader ?? u(r.data[0]) ? r.data.slice(1) : r.data;
25
+ c(d.map((p) => p[i]));
26
+ }
27
+ },
28
+ error: (r) => {
29
+ o(r);
30
+ }
31
+ });
32
+ });
33
+ } else if (a === "text/plain")
34
+ return [await e.text()];
35
+ throw new Error(`Unsupported file type: ${a}`);
36
+ }
37
+ export {
38
+ w as default
39
+ };
@@ -1,4 +1,4 @@
1
- import { g as L } from "./_commonjsHelpers-DaMA6jEr.js";
1
+ import { g as L } from "./_commonjsHelpers-ByX85dGu.js";
2
2
  var x = { exports: {} }, E;
3
3
  function C() {
4
4
  return E || (E = 1, function(g) {
@@ -1,4 +1,4 @@
1
- import { c as bt, g as It } from "./_commonjsHelpers-DaMA6jEr.js";
1
+ import { c as bt, g as It } from "./_commonjsHelpers-ByX85dGu.js";
2
2
  function vt(yt) {
3
3
  throw new Error('Could not dynamically require "' + yt + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
4
4
  }
package/dist/main.d.ts CHANGED
@@ -2,6 +2,7 @@ export { default as NanoGPT } from './NanoGPTModel';
2
2
  export { default as TeachableLLM } from './TeachableLLM';
3
3
  export { default as CharTokeniser } from './tokeniser/CharTokeniser';
4
4
  export { default as waitForModel } from './utilities/waitForModel';
5
+ export { default as loadTextData } from './data/textLoader';
5
6
  export type { ITrainerOptions } from './Trainer';
6
7
  export type { IGenerateOptions } from './Generator';
7
8
  export type { TrainingLogEntry } from './NanoGPTModel';
package/dist/main.js CHANGED
@@ -2,9 +2,11 @@ import { default as o } from "./NanoGPTModel.js";
2
2
  import { default as t } from "./TeachableLLM.js";
3
3
  import { default as l } from "./tokeniser/CharTokeniser.js";
4
4
  import { default as s } from "./utilities/waitForModel.js";
5
+ import { default as m } from "./data/textLoader.js";
5
6
  export {
6
7
  l as CharTokeniser,
7
8
  o as NanoGPT,
8
9
  t as TeachableLLM,
10
+ m as loadTextData,
9
11
  s as waitForModel
10
12
  };