@imaduddin/fastbrain 1.0.8 → 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
|
@@ -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
|
|
57
|
+
return this.output
|
|
53
58
|
}
|
|
54
59
|
async backward(outputGradient, lr, en2){
|
|
55
60
|
const encoder = en2 ? en2 : await this.gpu.CreateEncoder()
|
package/src/Softmax/index.js
CHANGED
|
@@ -124,7 +124,7 @@ export class Softmax {
|
|
|
124
124
|
if(!encoder2) await this.gpu.submitQueue(encoder)
|
|
125
125
|
return this.dLogits
|
|
126
126
|
}
|
|
127
|
-
async crossEntropy(probs, target) {
|
|
127
|
+
async crossEntropy(probs, target, encoderMain) {
|
|
128
128
|
const encoder = encoderMain ? encoderMain : this.device.createCommandEncoder();
|
|
129
129
|
const tokenCount = probs.size / (this.vocabSize * Float32Array.BYTES_PER_ELEMENT);
|
|
130
130
|
if (!Number.isInteger(tokenCount) || tokenCount <= 0) {
|
package/src/model/index.js
CHANGED
|
@@ -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
|
|
package/src/shaders/LB.wgsl
CHANGED
|
@@ -47,7 +47,7 @@ fn main(@builtin(workgroup_id) wid: vec3<u32>, @builtin(local_invocation_id) lid
|
|
|
47
47
|
|
|
48
48
|
if (tokens > 0u) {
|
|
49
49
|
let idx = weightBase + j;
|
|
50
|
-
weight[idx] -= params.lr *
|
|
50
|
+
weight[idx] -= params.lr * grad;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -66,6 +66,6 @@ fn main(@builtin(workgroup_id) wid: vec3<u32>, @builtin(local_invocation_id) lid
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
if (tid == 0u && tokens > 0u) {
|
|
69
|
-
bias[outputIndex] -= params.lr *
|
|
69
|
+
bias[outputIndex] -= params.lr * sharedBias[0];
|
|
70
70
|
}
|
|
71
71
|
}
|
package/src/shaders/PF.wgsl
CHANGED
|
@@ -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
|
-
|
|
23
|
+
output[x] = vecs[x] + posVec[x];
|
|
19
24
|
}
|