@mineproness/tensorloop 2.1.61 → 2.1.63
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
package/src/Embedding/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
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
|
|
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()
|
package/src/Softmax/index.js
CHANGED
|
@@ -152,7 +152,7 @@ export class Softmax {
|
|
|
152
152
|
},
|
|
153
153
|
]
|
|
154
154
|
})
|
|
155
|
-
await this.gpu.RunPipline(encoder, this.lossPipline, bind, Math.ceil((
|
|
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 :
|
|
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 :
|
|
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(
|
|
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
|
}
|
package/src/shaders/EB.wgsl
CHANGED
|
@@ -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
|
|
7
|
+
var<storage, read_write> embeddings: array<f32>;
|
|
9
8
|
|
|
10
9
|
@group(0) @binding(1)
|
|
11
10
|
|
|
12
|
-
var
|
|
11
|
+
var<storage, read_write> outputGradient: array<f32>;
|
|
13
12
|
|
|
14
13
|
@group(0) @binding(2)
|
|
15
14
|
|
|
16
|
-
var
|
|
15
|
+
var<storage, read_write> tokens: array<u32>;
|
|
17
16
|
|
|
18
17
|
@group(0) @binding(3)
|
|
19
|
-
var
|
|
18
|
+
var<uniform> params: Params;
|
|
20
19
|
|
|
21
20
|
const embeddingSize = %embeddingSize%u;
|
|
22
21
|
|
|
23
22
|
@compute @workgroup_size(256)
|
|
24
23
|
|
|
25
|
-
fn main(@builtin(global_invocation_id) id
|
|
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] -=
|
|
32
|
+
embeddings[embeddingIDx] -= params.lr * outputGradient[id.x];
|
|
31
33
|
}
|
package/src/shaders/LB.wgsl
CHANGED
|
@@ -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(-
|
|
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(-
|
|
54
|
+
bias[outputIndex] = bias[outputIndex] - params.lr * max(- 7.0, min(7.0, dBias));
|
|
55
55
|
|
|
56
56
|
}
|
|
57
57
|
}
|