@mineproness/tensorloop 2.1.61 → 2.1.62

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": "@mineproness/tensorloop",
3
- "version": "2.1.61",
3
+ "version": "2.1.62",
4
4
  "description": "Raw-JAVASCRIPT Based Matirx and AI LLM Package called Tensorloop.",
5
5
  "keywords": [
6
6
  "ai",
@@ -1,4 +1,5 @@
1
- // import { config } from "process";
1
+ import { config } from "process";
2
+
2
3
  import { SaveVector, getVector } from '../getVec.js'
3
4
  import { OperationManager } from "../OperationManager.js";
4
5
 
@@ -130,7 +131,7 @@ export class Embedding {
130
131
  }
131
132
  ]
132
133
  })
133
- await this.gpu.WriteBuffer(this.tokenBuffer, new Float32Array(token));
134
+ await this.gpu.WriteBuffer(this.tokenBuffer, new Uint32Array(token));
134
135
  await this.gpu.RunPipline(encoder, this.backwardPipline, bind, Math.ceil((this.embeddingSize * token.length) / 256))
135
136
  this.device.queue.submit([encoder.finish()])
136
137
  inputGradient.destroy()
@@ -152,7 +152,7 @@ export class Softmax {
152
152
  },
153
153
  ]
154
154
  })
155
- await this.gpu.RunPipline(encoder, this.lossPipline, bind, Math.ceil((this.vocabSize * tokenCount) / 256))
155
+ await this.gpu.RunPipline(encoder, this.lossPipline, bind, Math.ceil((tokenCount / 4)))
156
156
  const outputLoss = await this.gpu.createBuffer(4)
157
157
  const reduceBind = await this.gpu.createBindGroup(this.reduceFn, 0, [loss, outputLoss, this.paramsForward])
158
158
  await this.gpu.RunPipline(encoder, this.reduceFn, reduceBind, 1);
@@ -5,7 +5,7 @@ struct Params {
5
5
 
6
6
  @group(0) @binding(0)
7
7
 
8
- var <storage, read> probs : vec2<f32>;
8
+ var <storage, read> probs : array<f32>;
9
9
 
10
10
  @group(0) @binding(1)
11
11
 
@@ -13,14 +13,14 @@ var <storage, read> targetToken : array<f32>;
13
13
 
14
14
  @group(0) @binding(2)
15
15
 
16
- var <storage, read_write> loss : vec2<f32>;
16
+ var <storage, read_write> loss : array<f32>;
17
17
 
18
18
  @group(0) @binding(3)
19
19
 
20
20
  var <uniform> params: Params;
21
21
 
22
22
 
23
- @compute @workgroup_size(256)
23
+ @compute @workgroup_size(4)
24
24
 
25
25
  fn main(@builtin(global_invocation_id) id : vec3<u32>) {
26
26
  let index = id.x;
@@ -30,6 +30,6 @@ fn main(@builtin(global_invocation_id) id : vec3<u32>) {
30
30
  let end = start + params.vocabSize;
31
31
  var targetIndex = targetToken[token];
32
32
  let total: u32 = params.tokenCount * params.vocabSize;
33
- let probalitils = probs[u32(targetIndex)];
33
+ let probalitils = probs[token * params.vocabSize + u32(targetIndex)];
34
34
  loss[index] = -log(probalitils + 1e-15);
35
35
  }
@@ -28,5 +28,5 @@ fn main(@builtin(global_invocation_id) id: vec3<u32>) {
28
28
  let grad = outGradient[token * u32(params.vocabSize) + i];
29
29
  gradInput += grad * w;
30
30
  }
31
- dInput[index] = max(-1.0, min(1.0,gradInput));
31
+ dInput[index] = max(-7.0, min(7.0,gradInput));
32
32
  }
@@ -1,31 +1,33 @@
1
- struct Params{
1
+ struct Params {
2
2
  lr: f32
3
3
  }
4
4
 
5
-
6
5
  @group(0) @binding(0)
7
6
 
8
- var <storage, read_write> embeddings: array<f32>;
7
+ var<storage, read_write> embeddings: array<f32>;
9
8
 
10
9
  @group(0) @binding(1)
11
10
 
12
- var <storage, read_write> outputGradient: array<f32>;
11
+ var<storage, read_write> outputGradient: array<f32>;
13
12
 
14
13
  @group(0) @binding(2)
15
14
 
16
- var <storage, read_write> tokens: array<u32>;
15
+ var<storage, read_write> tokens: array<u32>;
17
16
 
18
17
  @group(0) @binding(3)
19
- var <uniform> params : Params;
18
+ var<uniform> params: Params;
20
19
 
21
- const embeddingSize = %embeddingSize%u;
20
+ const embeddingSize = % embeddingSize % u;
22
21
 
23
22
  @compute @workgroup_size(256)
24
23
 
25
- fn main(@builtin(global_invocation_id) id : vec3<u32>){
24
+ fn main(@builtin(global_invocation_id) id: vec3<u32>) {
26
25
  let dim = id.x % embeddingSize;
26
+ if (id.x >= arrayLength(&outputGradient)) {
27
+ return;
28
+ }
27
29
  let tokenIndex = id.x / embeddingSize;
28
30
  let tokenID = tokens[tokenIndex];
29
31
  let embeddingIDx = tokenID * embeddingSize + dim;
30
- embeddings[embeddingIDx] -= params.lr * outputGradient[id.x];
32
+ embeddings[embeddingIDx] -= params.lr * outputGradient[id.x];
31
33
  }
@@ -44,14 +44,14 @@ fn main(@builtin(global_invocation_id) id: vec3<u32>) {
44
44
  let dW = inputValue * gradient;
45
45
  dWeights += f32(dW);
46
46
  }
47
- let vClap = weight[index] - params.lr * max(- 3.0, min(3.0, dWeights));
47
+ let vClap = weight[index] - params.lr * max(- 7.0, min(7.0, dWeights));
48
48
  weight[index] = vClap;
49
49
  if (inputIndex == 0u) {
50
50
  var dBias = 0.0;
51
51
  for (var token = 0u; token < u32(params.tokenCount); token++) {
52
52
  dBias += f32(outGradient[token * u32(params.vocabSize) + outputIndex]);
53
53
  }
54
- bias[outputIndex] = bias[outputIndex] - params.lr * max(- 3.0, min(3.0, dBias));
54
+ bias[outputIndex] = bias[outputIndex] - params.lr * max(- 7.0, min(7.0, dBias));
55
55
 
56
56
  }
57
57
  }