@mineproness/tensorloop 2.1.70 → 2.1.72
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/Model/index.js
CHANGED
|
@@ -46,7 +46,7 @@ export class Model {
|
|
|
46
46
|
})
|
|
47
47
|
}
|
|
48
48
|
this.posEmbedding = new PositionEmbedding(this.device, this.dimSize, this.configs.contextSize, {
|
|
49
|
-
save:{
|
|
49
|
+
save: {
|
|
50
50
|
filename: join(this.configs.dirname, "posVec.bin")
|
|
51
51
|
}
|
|
52
52
|
})
|
|
@@ -61,7 +61,7 @@ export class Model {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
async forward(input, readBack) {
|
|
64
|
-
if(this.configs.contextSize < input.length) throw new Error("The Input is larger then contextSize")
|
|
64
|
+
if (this.configs.contextSize < input.length) throw new Error("The Input is larger then contextSize")
|
|
65
65
|
this.tokens = input;
|
|
66
66
|
await this.ClearInputCache()
|
|
67
67
|
let vec = await this.embedding.forward(input)
|
|
@@ -77,7 +77,7 @@ export class Model {
|
|
|
77
77
|
const loss = await this.softmax.crossEntropy(outputGradient, target)
|
|
78
78
|
const dLogits = await this.softmax.backward(outputGradient, target);
|
|
79
79
|
let DInput = await this.linear.backward(dLogits, lr);
|
|
80
|
-
for (let a = this.blockSize - 1; a
|
|
80
|
+
for (let a = this.blockSize - 1; a >= 0; a--) {
|
|
81
81
|
DInput = await this.blocks[a].backward(DInput, lr);
|
|
82
82
|
}
|
|
83
83
|
this.embedding.backward(this.tokens, DInput, lr);
|
|
@@ -87,7 +87,7 @@ export class Model {
|
|
|
87
87
|
async Save() {
|
|
88
88
|
await this.embedding.Save()
|
|
89
89
|
await this.linear.Save()
|
|
90
|
-
for (let a = this.blockSize - 1; a
|
|
90
|
+
for (let a = this.blockSize - 1; a >= 0; a--) {
|
|
91
91
|
await this.blocks[a].Save();
|
|
92
92
|
}
|
|
93
93
|
await this.posEmbedding.Save()
|
package/src/RMSNorm/index.js
CHANGED
|
@@ -49,7 +49,7 @@ export class RMSNorm {
|
|
|
49
49
|
const output = await this.op.createBuffer(input.size);
|
|
50
50
|
const bindGroup = await this.op.createBindGroup(this.reductionShader, 0, [input, outputReduce])
|
|
51
51
|
const encoder = await this.op.CreateEncoder()
|
|
52
|
-
await this.op.RunPipline(encoder, this.reductionShader, bindGroup, Math.ceil(
|
|
52
|
+
await this.op.RunPipline(encoder, this.reductionShader, bindGroup, Math.ceil(input.size / (this.embeddingSize * 4)))
|
|
53
53
|
const bindGroup1 = await this.op.createBindGroup(this.forwardShader, 0, [outputReduce, input, output, this.gammabuffer])
|
|
54
54
|
await this.op.RunPipline(encoder, this.forwardShader, bindGroup1, Math.ceil((input.size / 4) / 64));
|
|
55
55
|
await this.op.submitQueue(encoder);
|
|
@@ -68,7 +68,7 @@ export class RMSNorm {
|
|
|
68
68
|
const bindGroup = await this.op.createBindGroup(this.backwardShader, 0, [this.input, outputGradient, this.rms, this.gammabuffer, output]);
|
|
69
69
|
const bindGroup2 = await this.op.createBindGroup(this.updateGamma, 0, [this.input, outputGradient, this.rms, this.gammabuffer, params]);
|
|
70
70
|
const encoder = await this.op.CreateEncoder()
|
|
71
|
-
await this.op.RunPipline(encoder, this.backwardShader, bindGroup, Math.ceil((this.input.size /
|
|
71
|
+
await this.op.RunPipline(encoder, this.backwardShader, bindGroup, Math.ceil((this.input.size) / (this.embeddingSize * 4)))
|
|
72
72
|
await this.op.RunPipline(encoder, this.updateGamma, bindGroup2, this.embeddingSize)
|
|
73
73
|
await this.op.submitQueue(encoder)
|
|
74
74
|
if (this.prevOut) this.prevOut.destroy()
|
|
@@ -13,9 +13,9 @@ var<storage, read> gamma: array<f32>;
|
|
|
13
13
|
@group(0) @binding(4)
|
|
14
14
|
var<storage, read_write> gradInput: array<f32>;
|
|
15
15
|
|
|
16
|
-
var<workgroup> partial: array<f32,
|
|
16
|
+
var<workgroup> partial: array<f32, 64>;
|
|
17
17
|
|
|
18
|
-
@compute @workgroup_size(
|
|
18
|
+
@compute @workgroup_size(64)
|
|
19
19
|
fn main(@builtin(local_invocation_index) lid: u32, @builtin(workgroup_id) wid: vec3<u32>) {
|
|
20
20
|
let D = %embeddingSize%u;
|
|
21
21
|
let token = wid.x;
|