@imaduddin/fastbrain 1.0.9 → 1.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imaduddin/fastbrain",
3
- "version": "1.0.9",
3
+ "version": "1.1.0",
4
4
  "description": "Raw-JAVASCRIPT Based Matirx and AI LLM Package called fastBrain.",
5
5
  "keywords": [
6
6
  "ai",
@@ -45,11 +45,16 @@ export class PositionEmbedding {
45
45
  this.vecBuffer = await this.gpu.createBuffer(Float32Array.BYTES_PER_ELEMENT * this.contextSize * this.embeddingSize);
46
46
  await this.gpu.WriteBuffer(this.vecBuffer, this.vectors)
47
47
  }
48
+ if(!this.output) this.output = await this.gpu.ManageBuffer(input.size);
49
+ if(this.output.size !== input.size || this.output.isDestroyed()){
50
+ this.output.destroy()
51
+ this.output = await this.gpu.ManageBuffer(input.size)
52
+ }
48
53
  const size = Math.ceil((input.size / 4) / 64);
49
- const bindGroup = await this.gpu.createBindGroup(this.forwardShader, 0, [this.vecBuffer, input.mainBuffer])
54
+ const bindGroup = await this.gpu.createBindGroup(this.forwardShader, 0, [this.vecBuffer, input.mainBuffer, this.output.mainBuffer])
50
55
  await this.gpu.RunPipline(encoder, this.forwardShader, bindGroup, size);
51
56
  if(!en2) await this.gpu.submitQueue(encoder);
52
- return input
57
+ return this.output
53
58
  }
54
59
  async backward(outputGradient, lr, en2){
55
60
  const encoder = en2 ? en2 : await this.gpu.CreateEncoder()
@@ -69,8 +69,8 @@ export class model {
69
69
  for (let i = this.blocks.length - 1; i >= 0; i--) {
70
70
  dInput = await this.blocks[i].backward(dInput, lr, encoder)
71
71
  };
72
- await this.embedding.backward(dInput, lr)
73
- await this.PosEmbedding.backward(dInput, lr)
72
+ await this.embedding.backward(dInput, lr, encoder)
73
+ await this.PosEmbedding.backward(dInput, lr, encoder)
74
74
  await this.op.submitQueue(encoder)
75
75
  return { acc, loss }
76
76
 
@@ -6,6 +6,11 @@ var <storage, read> posVec: array<f32>;
6
6
  var <storage, read_write> vecs : array<f32>;
7
7
 
8
8
 
9
+ @group(0) @binding(2)
10
+
11
+ var <storage, read_write> output : array<f32>;
12
+
13
+
9
14
 
10
15
 
11
16
  @compute @workgroup_size(64)
@@ -15,5 +20,5 @@ fn main(@builtin(global_invocation_id) id : vec3<u32>){
15
20
  if(x >= arrayLength(&vecs)){
16
21
  return;
17
22
  }
18
- vecs[x] = vecs[x] + posVec[x];
23
+ output[x] = vecs[x] + posVec[x];
19
24
  }