@mineproness/tensorloop 2.1.58 → 2.1.60
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 +1 -1
- package/src/Linear/index.js +1 -1
- package/src/SelfAttention/index.js +2 -3
- package/src/getVec.js +16 -14
- package/src/shaders/SoftmaxBackward.wgsl +1 -1
package/package.json
CHANGED
package/src/Linear/index.js
CHANGED
|
@@ -42,7 +42,7 @@ export class Linear {
|
|
|
42
42
|
let total = embeddingSize * vocabSize;
|
|
43
43
|
if (configs && configs.save) {
|
|
44
44
|
const w = getVector(configs.save.filename[0], total);
|
|
45
|
-
const b = getVector(configs.save.filename[1],
|
|
45
|
+
const b = getVector(configs.save.filename[1], vocabSize, true)
|
|
46
46
|
if (!w && !b) {
|
|
47
47
|
this.bias = GenerateBias(vocabSize)
|
|
48
48
|
this.weights = GenerateVectors(embeddingSize, vocabSize)
|
|
@@ -63,7 +63,6 @@ export class SelfAttention {
|
|
|
63
63
|
const finalOutput = await this.gpu.createBuffer(tokenCount * this.embeddingSize * 4)
|
|
64
64
|
const outputBind = await this.gpu.createBindGroup(this.outputForward, 0, [this.weights, this.value, finalOutput, this.asParams]);
|
|
65
65
|
await this.gpu.RunPipline(encoder, this.outputForward, outputBind, Math.ceil((tokenCount * this.embeddingSize) / 256))
|
|
66
|
-
|
|
67
66
|
await this.gpu.submitQueue(encoder)
|
|
68
67
|
scroes.destroy()
|
|
69
68
|
return finalOutput
|
|
@@ -114,7 +113,7 @@ export class SelfAttention {
|
|
|
114
113
|
}
|
|
115
114
|
async Save(){
|
|
116
115
|
await this.q.Save()
|
|
117
|
-
await this.
|
|
118
|
-
await this.
|
|
116
|
+
await this.k.Save()
|
|
117
|
+
await this.v.Save()
|
|
119
118
|
}
|
|
120
119
|
}
|
package/src/getVec.js
CHANGED
|
@@ -5,21 +5,23 @@ export function getVector(filename, size, bias) {
|
|
|
5
5
|
if (!fs.existsSync(filename)) {
|
|
6
6
|
return null;
|
|
7
7
|
}
|
|
8
|
-
const
|
|
9
|
-
const r = new Float32Array(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}else{
|
|
17
|
-
output[a] = bias ? 0 : (Math.random() * 2 - 1) * 0.02
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
} else {
|
|
21
|
-
return r
|
|
8
|
+
const buffer = fs.readFileSync(filename);
|
|
9
|
+
const r = new Float32Array(
|
|
10
|
+
buffer.buffer,
|
|
11
|
+
buffer.byteOffset,
|
|
12
|
+
buffer.byteLength / 4
|
|
13
|
+
);
|
|
14
|
+
if (r.length >= size) {
|
|
15
|
+
return r;
|
|
22
16
|
}
|
|
17
|
+
const output = new Float32Array(size);
|
|
18
|
+
output.set(r);
|
|
19
|
+
if (!bias) {
|
|
20
|
+
for (let i = r.length; i < size; i++) {
|
|
21
|
+
output[i] = (Math.random() * 2 - 1) * 0.02;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return output;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
export function SaveVector(filename, vectors) {
|