@mineproness/tensorloop 2.1.57 → 2.1.59
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/OperationManager.js +10 -10
- package/src/getVec.js +16 -14
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)
|
package/src/OperationManager.js
CHANGED
|
@@ -42,7 +42,7 @@ export class OperationManager {
|
|
|
42
42
|
return result
|
|
43
43
|
}
|
|
44
44
|
getShaderPipline(filename, value = { "embedding": 123 }, entryPoint = "main") {
|
|
45
|
-
let readShaderCode = fs.readFileSync(path.join(__dirname, filename), "utf-8");
|
|
45
|
+
let readShaderCode = fs.readFileSync(path.join(__dirname, `../${filename}`), "utf-8");
|
|
46
46
|
if (value) {
|
|
47
47
|
for (const a in value) {
|
|
48
48
|
readShaderCode = readShaderCode.replaceAll(`%${a}%`, value[a])
|
|
@@ -67,10 +67,10 @@ export class OperationManager {
|
|
|
67
67
|
const pass = encoder.beginComputePass();
|
|
68
68
|
pass.setPipeline(pipline)
|
|
69
69
|
pass.setBindGroup(0, binding)
|
|
70
|
-
pass.dispatchWorkgroups(dispatchWorkgroups, y
|
|
70
|
+
pass.dispatchWorkgroups(dispatchWorkgroups, y, z)
|
|
71
71
|
pass.end()
|
|
72
72
|
}
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
async MakeACopyBuffer(encoder, sourceBuffer) {
|
|
75
75
|
const buffer = this.device.createBuffer({
|
|
76
76
|
size: sourceBuffer.size,
|
|
@@ -79,22 +79,22 @@ export class OperationManager {
|
|
|
79
79
|
encoder.copyBufferToBuffer(sourceBuffer, 0, buffer, 0, sourceBuffer.size);
|
|
80
80
|
return buffer
|
|
81
81
|
}
|
|
82
|
-
CreateEncoder(){
|
|
82
|
+
CreateEncoder() {
|
|
83
83
|
return this.device.createCommandEncoder()
|
|
84
84
|
}
|
|
85
|
-
createBindGroup(shader,groupNum,ent){
|
|
85
|
+
createBindGroup(shader, groupNum, ent) {
|
|
86
86
|
return this.device.createBindGroup({
|
|
87
87
|
layout: shader.getBindGroupLayout(groupNum),
|
|
88
|
-
entries: ent.map((e, x)=>{
|
|
88
|
+
entries: ent.map((e, x) => {
|
|
89
89
|
return {
|
|
90
|
-
binding
|
|
91
|
-
resource: e
|
|
90
|
+
binding: x,
|
|
91
|
+
resource: e
|
|
92
92
|
}
|
|
93
93
|
})
|
|
94
94
|
})
|
|
95
95
|
}
|
|
96
|
-
async submitQueue(encoder){
|
|
97
|
-
|
|
96
|
+
async submitQueue(encoder) {
|
|
97
|
+
this.device.queue.submit([encoder.finish()])
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
}
|
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) {
|