@imaduddin/fastbrain 1.0.3 → 1.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imaduddin/fastbrain",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Raw-JAVASCRIPT Based Matirx and AI LLM Package called fastBrain.",
5
5
  "keywords": [
6
6
  "ai",
@@ -24,6 +24,9 @@ export class model {
24
24
  dirname: string,
25
25
  vocabFile: string
26
26
  })
27
+ getLoss : Function
28
+ getAcc: Function
29
+ clearLoss : Function
27
30
  async forward(input: number[], target: number[]): Promise<{
28
31
  read: function(): Promise<Float32Array>,
29
32
  mainBuffer: GPUBuffer,
@@ -36,4 +39,5 @@ export class model {
36
39
  isDestroyed: function(): Boolean,
37
40
  destroy: function(): void
38
41
  }, target: number[], lr : number)
42
+ async Save() : Promise<void>
39
43
  }
@@ -5,7 +5,7 @@ import { Softmax } from "../Softmax/index.js"
5
5
  import { Tokenizer } from "../Tokenizer/index.js"
6
6
  import { join } from 'path'
7
7
  import { TransformerBlock } from "../TransformerBlock/index.js"
8
- import {OperationManager} from '../OperationManager.js'
8
+ import { OperationManager } from '../OperationManager.js'
9
9
  export class model {
10
10
  tokenizer
11
11
  embedding
@@ -58,22 +58,30 @@ export class model {
58
58
  let logits = await this.linear.forward(vec, encoder)
59
59
  let probs = await this.softmax.forward(logits, encoder)
60
60
  await this.op.submitQueue(encoder)
61
- const {acc,clear,loss} = await this.softmax.crossEntropy(probs, target)
61
+ const { acc, clear, loss } = await this.softmax.crossEntropy(probs, target)
62
62
  this.getAcc = acc;
63
63
  this.getLoss = loss;
64
64
  this.clearLoss = clear;
65
65
  return probs
66
66
  }
67
- async backward(x, target, lr){
67
+ async backward(x, target, lr) {
68
68
  const encoder = await this.op.CreateEncoder()
69
69
  let dLogits = await this.softmax.backward(x, target, encoder)
70
70
  let dInput = await this.linear.backward(dLogits, lr, encoder)
71
71
  for (let i = this.blocks.length - 1; i >= 0; i--) {
72
- dInput = await this.blocks[i].backward(dInput, lr, encoder)
72
+ dInput = await this.blocks[i].backward(dInput, lr, encoder)
73
73
  };
74
74
  await this.embedding.backward(dInput, lr)
75
75
  await this.PosEmbedding.backward(dInput, lr)
76
76
  await this.op.submitQueue(encoder)
77
-
77
+
78
+ }
79
+ async Save() {
80
+ await this.PosEmbedding.Save()
81
+ await this.embedding.Save()
82
+ await this.linear.Save()
83
+ for (let i = this.blocks.length - 1; i >= 0; i--) {
84
+ await this.blocks[i].Save()
85
+ };
78
86
  }
79
87
  }