@mineproness/tensorloop 2.1.63 → 2.1.65

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.63",
3
+ "version": "2.1.65",
4
4
  "description": "Raw-JAVASCRIPT Based Matirx and AI LLM Package called Tensorloop.",
5
5
  "keywords": [
6
6
  "ai",
@@ -98,7 +98,7 @@ export class Embedding {
98
98
  this.param = await this.gpu.createUniFormBuffer(this.oldParam.byteLength);
99
99
  this.tokenBuffer = await this.gpu.createBuffer(4 * token.length)
100
100
  }
101
- if (this.oldParam[1] !== lr) {
101
+ if (this.oldParam[0] !== lr) {
102
102
  this.oldParam = new Float32Array([lr, 0]);
103
103
  this.gpu.WriteBuffer(this.param, this.oldParam)
104
104
  }
@@ -123,7 +123,7 @@ export class Softmax {
123
123
  const targetBuffer = await this.gpu.createBuffer(target.length * Float32Array.BYTES_PER_ELEMENT)
124
124
  const loss = await this.gpu.createBuffer(4 * tokenCount)
125
125
  const acc = await this.gpu.createBuffer(4 * 2)
126
- await this.gpu.WriteBuffer(targetBuffer, new Float32Array(target))
126
+ await this.gpu.WriteBuffer(targetBuffer, new Uint32Array(target))
127
127
  const bind = await this.device.createBindGroup({
128
128
  layout: await this.lossPipline.getBindGroupLayout(0),
129
129
  entries: [
@@ -27,7 +27,7 @@ export class Tokenizer {
27
27
  const output = []
28
28
  for (let a = 0; a < splitedWords.length; a++) {
29
29
  const word = splitedWords[a]
30
- if (this.WordtoID[word]) {
30
+ if (this.WordtoID[word] !== undefined) {
31
31
  output.push(word)
32
32
  } else {
33
33
  let max = word.length
@@ -36,7 +36,7 @@ export class Tokenizer {
36
36
  const regPatten = new RegExp(`.{0,${max}}`, "g")
37
37
  const wordsliced = word.match(regPatten).filter((e) => e.length > 0)
38
38
  const matched = wordsliced.flatMap(e => {
39
- if (this.WordtoID[e]) {
39
+ if (this.WordtoID[e] !== undefined) {
40
40
  return true
41
41
  }
42
42
  return false
@@ -23,13 +23,8 @@ var <uniform> params: Params;
23
23
  @compute @workgroup_size(4)
24
24
 
25
25
  fn main(@builtin(global_invocation_id) id : vec3<u32>) {
26
- let index = id.x;
27
- let token = index / params.vocabSize;
28
- let vocabIndex = index % params.vocabSize;
29
- let start = token * params.vocabSize;
30
- let end = start + params.vocabSize;
31
- var targetIndex = targetToken[token];
32
- let total: u32 = params.tokenCount * params.vocabSize;
33
- let probalitils = probs[token * params.vocabSize + u32(targetIndex)];
26
+ let index = id.x;
27
+ var targetIndex = targetToken[index];
28
+ let probalitils = probs[index * params.vocabSize + u32(targetIndex)];
34
29
  loss[index] = -log(probalitils + 1e-15);
35
30
  }
@@ -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(-7.0, min(7.0,gradInput));
31
+ dInput[index] = gradInput;
32
32
  }
@@ -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(- 7.0, min(7.0, dWeights));
47
+ let vClap = weight[index] - params.lr * max(- 15.0, min(15.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(- 7.0, min(7.0, dBias));
54
+ bias[outputIndex] = bias[outputIndex] - params.lr * max(- 15.0, min(15.0, dBias));
55
55
 
56
56
  }
57
57
  }
@@ -32,6 +32,6 @@ fn main(@builtin(global_invocation_id) id: vec3<u32>) {
32
32
  output[index] = grad;
33
33
  }
34
34
  else {
35
- output[index] = grad * 0.02;
35
+ output[index] = 0;
36
36
  }
37
37
  }
@@ -28,6 +28,6 @@ fn main(@builtin(global_invocation_id) id: vec3<u32>) {
28
28
  output[index] = x;
29
29
  }
30
30
  else {
31
- output[index] = x * 0.02;
31
+ output[index] = 0;
32
32
  }
33
33
  }
@@ -27,6 +27,10 @@ fn main(@builtin(global_invocation_id) id: vec3<u32>) {
27
27
  let vocabIndex = index % params.vocabSize;
28
28
  let start = token * params.vocabSize;
29
29
  let end = start + params.vocabSize;
30
+ let total = params.tokenCount * params.vocabSize;
31
+ if (index >= total) {
32
+ return;
33
+ }
30
34
  var targetIndex = targetToken[token];
31
35
  let total: u32 = params.tokenCount * params.vocabSize;
32
36
  output[index] = probs[index];