@imaduddin/fastbrain 2.0.0 → 2.0.2
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/dist/Embedding/index.js +4 -1
- package/dist/Gelu/index.js +4 -1
- package/dist/Linear/index.js +4 -1
- package/dist/RMSNorm/index.js +4 -1
- package/dist/SelfAttention/index.js +4 -2
- package/dist/Softmax/index.js +4 -1
- package/dist/residualConnection/index.js +4 -1
- package/package.json +7 -1
- package/src/Embedding/index.ts +6 -1
- package/src/Gelu/index.ts +5 -1
- package/src/Linear/index.ts +5 -1
- package/src/RMSNorm/index.ts +5 -1
- package/src/SelfAttention/index.ts +6 -2
- package/src/Softmax/index.ts +5 -1
- package/src/residualConnection/index.ts +5 -1
package/dist/Embedding/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { GetVectorsForFile, SaveFileVector, initRandomVector } from '../fileManager.js';
|
|
2
2
|
import { GPUManager } from '@imaduddin/webgpu-manager';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import path, { join } from 'node:path';
|
|
5
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
3
6
|
export class Embedding {
|
|
4
7
|
device;
|
|
5
8
|
embeddingSize;
|
|
@@ -38,7 +41,7 @@ export class Embedding {
|
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
43
|
this.gpu = new GPUManager(device, {
|
|
41
|
-
shaderDir: "
|
|
44
|
+
shaderDir: join(__dirname, "shaders/")
|
|
42
45
|
});
|
|
43
46
|
}
|
|
44
47
|
async forward(input, encoderShared) {
|
package/dist/Gelu/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { GPUManager } from "@imaduddin/webgpu-manager";
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import path, { join } from 'node:path';
|
|
4
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
2
5
|
export class Gelu {
|
|
3
6
|
device;
|
|
4
7
|
hiddenSize;
|
|
@@ -13,7 +16,7 @@ export class Gelu {
|
|
|
13
16
|
this.device = device;
|
|
14
17
|
this.hiddenSize = hiddenSize;
|
|
15
18
|
this.gpu = new GPUManager(device, {
|
|
16
|
-
shaderDir: "./shaders/relu"
|
|
19
|
+
shaderDir: join(__dirname, "./shaders/relu")
|
|
17
20
|
});
|
|
18
21
|
}
|
|
19
22
|
async forward(input, encoderShared) {
|
package/dist/Linear/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { GPUManager } from "@imaduddin/webgpu-manager";
|
|
2
2
|
import { GetVectorsForFile, SaveFileVector, initRandomVector, getParameter } from '../fileManager.js';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import path, { join } from 'node:path';
|
|
5
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
3
6
|
export class Linear {
|
|
4
7
|
device;
|
|
5
8
|
embeddingSize;
|
|
@@ -49,7 +52,7 @@ export class Linear {
|
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
54
|
this.gpu = new GPUManager(device, {
|
|
52
|
-
shaderDir: "
|
|
55
|
+
shaderDir: join(__dirname, "shaders/")
|
|
53
56
|
});
|
|
54
57
|
}
|
|
55
58
|
getParameter() {
|
package/dist/RMSNorm/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { GPUManager } from "@imaduddin/webgpu-manager";
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import path, { join } from 'node:path';
|
|
4
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
2
5
|
export class RMSNorm {
|
|
3
6
|
device;
|
|
4
7
|
embeddingSize;
|
|
@@ -14,7 +17,7 @@ export class RMSNorm {
|
|
|
14
17
|
this.device = device;
|
|
15
18
|
this.embeddingSize = embeddingSize;
|
|
16
19
|
this.gpu = new GPUManager(device, {
|
|
17
|
-
shaderDir: "./shaders/rmsnorm"
|
|
20
|
+
shaderDir: join(__dirname, "./shaders/rmsnorm")
|
|
18
21
|
});
|
|
19
22
|
}
|
|
20
23
|
async forward(input, encoderShared) {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
1
|
import { Linear } from "../Linear/index.js";
|
|
3
2
|
import { GPUManager } from "@imaduddin/webgpu-manager";
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import path, { join } from 'node:path';
|
|
5
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
4
6
|
export class SelfAttention {
|
|
5
7
|
device;
|
|
6
8
|
embeddingSize;
|
|
@@ -47,7 +49,7 @@ export class SelfAttention {
|
|
|
47
49
|
filename: [join(configs.dirname, "LINEAR_KEY_WEIGHTS.bin"), join(configs.dirname, "LINEAR_KEY_BIAS.bin")]
|
|
48
50
|
});
|
|
49
51
|
this.gpu = new GPUManager(device, {
|
|
50
|
-
shaderDir: "
|
|
52
|
+
shaderDir: join(__dirname, "shaders/")
|
|
51
53
|
});
|
|
52
54
|
}
|
|
53
55
|
async softmaxBackward(weights, dWeigths, output, tokenCount, enocder) {
|
package/dist/Softmax/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { GPUManager } from "@imaduddin/webgpu-manager";
|
|
2
2
|
import { isBufferOrNumber } from '../fileManager.js';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import path, { join } from 'node:path';
|
|
5
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
3
6
|
export class Softmax {
|
|
4
7
|
device;
|
|
5
8
|
VocabSize;
|
|
@@ -16,7 +19,7 @@ export class Softmax {
|
|
|
16
19
|
this.device = device;
|
|
17
20
|
this.VocabSize = VocabSize;
|
|
18
21
|
this.gpu = new GPUManager(device, {
|
|
19
|
-
shaderDir: './shaders/softmax'
|
|
22
|
+
shaderDir: join(__dirname, './shaders/softmax')
|
|
20
23
|
});
|
|
21
24
|
}
|
|
22
25
|
async forward(logit, encoderShared) {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { GPUManager } from "@imaduddin/webgpu-manager";
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import path, { join } from 'node:path';
|
|
4
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
2
5
|
export class residualConnection {
|
|
3
6
|
device;
|
|
4
7
|
output;
|
|
@@ -7,7 +10,7 @@ export class residualConnection {
|
|
|
7
10
|
constructor(device) {
|
|
8
11
|
this.device = device;
|
|
9
12
|
this.gpu = new GPUManager(device, {
|
|
10
|
-
shaderDir: "./shaders"
|
|
13
|
+
shaderDir: join(__dirname, "./shaders")
|
|
11
14
|
});
|
|
12
15
|
}
|
|
13
16
|
async add(a, b) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imaduddin/fastbrain",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Raw-JAVASCRIPT Based Matirx and AI LLM Package called fastBrain.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -12,6 +12,12 @@
|
|
|
12
12
|
"Language",
|
|
13
13
|
"Model"
|
|
14
14
|
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
15
21
|
"license": "MIT",
|
|
16
22
|
"author": "mineproness",
|
|
17
23
|
"type": "module",
|
package/src/Embedding/index.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { GetVectorsForFile, SaveFileVector, initRandomVector } from '../fileManager.js'
|
|
2
2
|
import { Buffer, GPUManager } from '@imaduddin/webgpu-manager';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import path, { join } from 'node:path';
|
|
6
|
+
|
|
7
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
3
8
|
|
|
4
9
|
|
|
5
10
|
export class Embedding {
|
|
@@ -31,7 +36,7 @@ export class Embedding {
|
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
this.gpu = new GPUManager(device, {
|
|
34
|
-
shaderDir: "
|
|
39
|
+
shaderDir: join(__dirname, "shaders/")
|
|
35
40
|
})
|
|
36
41
|
}
|
|
37
42
|
async forward(input: number[], encoderShared: GPUCommandEncoder | undefined) {
|
package/src/Gelu/index.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Buffer, GPUManager } from "@imaduddin/webgpu-manager";
|
|
2
2
|
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import path, { join } from 'node:path';
|
|
3
6
|
|
|
7
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
4
8
|
export class Gelu {
|
|
5
9
|
input: Buffer | undefined;
|
|
6
10
|
output: Buffer | undefined;
|
|
@@ -11,7 +15,7 @@ export class Gelu {
|
|
|
11
15
|
gpu: GPUManager | undefined;
|
|
12
16
|
constructor(public device: GPUDevice, public hiddenSize: number) {
|
|
13
17
|
this.gpu = new GPUManager(device, {
|
|
14
|
-
shaderDir: "./shaders/relu"
|
|
18
|
+
shaderDir: join(__dirname,"./shaders/relu")
|
|
15
19
|
})
|
|
16
20
|
}
|
|
17
21
|
async forward(input: Buffer, encoderShared: GPUCommandEncoder | undefined) {
|
package/src/Linear/index.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { GPUManager, Buffer } from "@imaduddin/webgpu-manager";
|
|
2
2
|
import { GetVectorsForFile, SaveFileVector, initRandomVector, getParameter } from '../fileManager.js'
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import path, { join } from 'node:path';
|
|
3
6
|
|
|
7
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
4
8
|
|
|
5
9
|
export class Linear {
|
|
6
10
|
bias: Float32Array | undefined;
|
|
@@ -42,7 +46,7 @@ export class Linear {
|
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
48
|
this.gpu = new GPUManager(device, {
|
|
45
|
-
shaderDir: "
|
|
49
|
+
shaderDir: join(__dirname, "shaders/")
|
|
46
50
|
})
|
|
47
51
|
}
|
|
48
52
|
getParameter(){
|
package/src/RMSNorm/index.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { GPUManager, Buffer } from "@imaduddin/webgpu-manager";
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import path, { join } from 'node:path';
|
|
2
5
|
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
3
7
|
|
|
4
8
|
export class RMSNorm {
|
|
5
9
|
rms: Buffer | undefined
|
|
@@ -12,7 +16,7 @@ export class RMSNorm {
|
|
|
12
16
|
gpu: GPUManager | undefined
|
|
13
17
|
constructor(public device: GPUDevice, public embeddingSize: number) {
|
|
14
18
|
this.gpu = new GPUManager(device, {
|
|
15
|
-
shaderDir: "./shaders/rmsnorm"
|
|
19
|
+
shaderDir: join(__dirname, "./shaders/rmsnorm")
|
|
16
20
|
})
|
|
17
21
|
}
|
|
18
22
|
async forward(input: Buffer, encoderShared: GPUCommandEncoder | undefined) {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
import { Linear } from "../Linear/index.js";
|
|
3
3
|
import { GPUManager, Buffer } from "@imaduddin/webgpu-manager";
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import path, { join } from 'node:path';
|
|
4
7
|
|
|
8
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
5
9
|
export class SelfAttention {
|
|
6
10
|
query: Linear | undefined
|
|
7
11
|
value: Linear | undefined
|
|
@@ -44,7 +48,7 @@ export class SelfAttention {
|
|
|
44
48
|
filename: [join(configs.dirname, "LINEAR_KEY_WEIGHTS.bin"), join(configs.dirname, "LINEAR_KEY_BIAS.bin")]
|
|
45
49
|
})
|
|
46
50
|
this.gpu = new GPUManager(device, {
|
|
47
|
-
shaderDir: "
|
|
51
|
+
shaderDir: join(__dirname, "shaders/")
|
|
48
52
|
})
|
|
49
53
|
}
|
|
50
54
|
async softmaxBackward(weights: Buffer, dWeigths: Buffer, output: Buffer, tokenCount: number, enocder: GPUCommandEncoder) {
|
package/src/Softmax/index.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { GPUManager, Buffer } from "@imaduddin/webgpu-manager";
|
|
2
2
|
import { isBufferOrNumber } from '../fileManager.js'
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import path, { join } from 'node:path';
|
|
3
6
|
|
|
7
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
4
8
|
export class Softmax {
|
|
5
9
|
forwardShader: GPUComputePipeline | undefined;
|
|
6
10
|
lossShader: GPUComputePipeline | undefined;
|
|
@@ -13,7 +17,7 @@ export class Softmax {
|
|
|
13
17
|
targetBuffer: Buffer | undefined;
|
|
14
18
|
constructor(public device: GPUDevice, public VocabSize: number) {
|
|
15
19
|
this.gpu = new GPUManager(device, {
|
|
16
|
-
shaderDir: './shaders/softmax'
|
|
20
|
+
shaderDir: join(__dirname,'./shaders/softmax')
|
|
17
21
|
})
|
|
18
22
|
}
|
|
19
23
|
async forward(logit: Buffer | number[], encoderShared: GPUCommandEncoder | undefined) {
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import {Buffer,GPUManager} from "@imaduddin/webgpu-manager"
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import path, { join } from 'node:path';
|
|
2
5
|
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
3
7
|
|
|
4
8
|
export class residualConnection{
|
|
5
9
|
output: Buffer | undefined;
|
|
@@ -7,7 +11,7 @@ export class residualConnection{
|
|
|
7
11
|
addShader: GPUComputePipeline | undefined;
|
|
8
12
|
constructor(public device : GPUDevice){
|
|
9
13
|
this.gpu = new GPUManager(device, {
|
|
10
|
-
shaderDir: "./shaders"
|
|
14
|
+
shaderDir: join(__dirname, "./shaders")
|
|
11
15
|
})
|
|
12
16
|
}
|
|
13
17
|
async add(a: Buffer, b: Buffer){
|