@mineproness/tensorloop 1.5.6 → 1.5.8
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/readme.md +1 -0
- package/src/Embedding/index.js +5 -3
- package/src/GPU.js +31 -3
- package/src/Linear/index.js +3 -2
- package/model/ffnBias.bin +0 -0
- package/model/ffnBias1.bin +0 -0
- package/model/ffnWeights.bin +0 -0
- package/model/ffnWeights1.bin +0 -0
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -15,6 +15,7 @@ A high-performance JavaScript library that provides essential AI and Large Langu
|
|
|
15
15
|
- **Text Processing**: Built-in **Tokenizer** to convert raw text into token IDs and back.
|
|
16
16
|
- **Special Tokens**: Native support for `<PAD>` and `<EOS>`.
|
|
17
17
|
- **FFN BLOCK**: It add a layer to understand Complex Patterns.
|
|
18
|
+
- ***GPU SUPPORT** GPU Can support it without any configure
|
|
18
19
|
---
|
|
19
20
|
|
|
20
21
|
## 🏗 Core Architecture
|
package/src/Embedding/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs, { existsSync } from 'fs'
|
|
2
2
|
import { SaveVectors, LoadVectors } from '../GetConfigs.js'
|
|
3
|
+
import { GPUEmbedding } from '../GPU.js'
|
|
3
4
|
// import { config } from 'process'
|
|
4
5
|
|
|
5
6
|
function GenerateVectors(embeddingSize, vocabSize) {
|
|
@@ -17,6 +18,7 @@ export class Embedding {
|
|
|
17
18
|
vectors = []
|
|
18
19
|
configs;
|
|
19
20
|
embeddingSize = 0
|
|
21
|
+
|
|
20
22
|
constructor(embeddingSize, vocabSize, configs) {
|
|
21
23
|
this.configs = configs
|
|
22
24
|
this.embeddingSize = embeddingSize
|
|
@@ -25,12 +27,12 @@ export class Embedding {
|
|
|
25
27
|
this.vectors = LoadVectors(configs.save.filename, embeddingSize)
|
|
26
28
|
} else {
|
|
27
29
|
this.vectors = GenerateVectors(embeddingSize, vocabSize)
|
|
28
|
-
this.
|
|
30
|
+
SaveVectors(this.vectors, this.configs.save.filename)
|
|
29
31
|
}
|
|
30
32
|
} else {
|
|
31
33
|
this.vectors = GenerateVectors(embeddingSize, vocabSize)
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
+
|
|
35
|
+
}
|
|
34
36
|
}
|
|
35
37
|
forward(token) {
|
|
36
38
|
if (Array.isArray(token)) {
|
package/src/GPU.js
CHANGED
|
@@ -9,8 +9,8 @@ const kernel = gpu.createKernel(function () {
|
|
|
9
9
|
|
|
10
10
|
kernel()
|
|
11
11
|
const gl = kernel.context
|
|
12
|
-
|
|
13
|
-
export function splitMatrix(matrix, chunksSizes =
|
|
12
|
+
const maxSize = gl ? gl.getParameter(gl.MAX_TEXTURE_SIZE) : 1200
|
|
13
|
+
export function splitMatrix(matrix, chunksSizes = maxSize) {
|
|
14
14
|
const chunks = []
|
|
15
15
|
for (let a = 0; a < matrix.length; a += chunksSizes) {
|
|
16
16
|
chunks.push(matrix.slice(a, a + chunksSizes))
|
|
@@ -104,7 +104,6 @@ export class GPULinear {
|
|
|
104
104
|
|
|
105
105
|
|
|
106
106
|
|
|
107
|
-
|
|
108
107
|
}
|
|
109
108
|
CalculateLinearForward(input) {
|
|
110
109
|
const result = []
|
|
@@ -123,10 +122,39 @@ export class GPULinear {
|
|
|
123
122
|
for (let i = 0; i < outGradient.length; i++) {
|
|
124
123
|
inputGradient[i] += outGradient[i]
|
|
125
124
|
}
|
|
125
|
+
const oldW = this.Weights[a]
|
|
126
|
+
const oldB = this.Bias[a]
|
|
126
127
|
this.Weights[a] = this.cacheLBWeights[a](this.Weights[a], out, input, learningRate)
|
|
127
128
|
this.Bias[a] = this.cacheLBIas[a](this.Bias[a], out, learningRate)
|
|
129
|
+
if(oldW && typeof oldW.delete === "function"){
|
|
130
|
+
oldW.delete()
|
|
131
|
+
}
|
|
132
|
+
if(oldB && typeof oldB.delete === "function"){
|
|
133
|
+
oldB.delete()
|
|
134
|
+
}
|
|
128
135
|
|
|
129
136
|
}
|
|
130
137
|
return inputGradient
|
|
131
138
|
}
|
|
139
|
+
GetWeightsAndBias(){
|
|
140
|
+
const weight = []
|
|
141
|
+
const bias = []
|
|
142
|
+
this.Weights.map((e)=> weight.push(...e.toArray()))
|
|
143
|
+
this.Bias.map((e)=> bias.push(...e.toArray()))
|
|
144
|
+
return { weights: weight, bias: new Float32Array(bias)}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export class GPUEmbedding{
|
|
149
|
+
cacheEF;
|
|
150
|
+
constructor(embeddingSize){
|
|
151
|
+
this.cacheEF = gpu.createKernel(function(inputGradient, learningRate, tokenVector){
|
|
152
|
+
return tokenVector[this.thread.x] - (learningRate * inputGradient[this.thread.x])
|
|
153
|
+
}).setOutput([embeddingSize])
|
|
154
|
+
}
|
|
155
|
+
backward(tokenVector, inputGradient, learingRate){
|
|
156
|
+
return this.cacheEF(inputGradient, learingRate, tokenVector)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
|
|
132
160
|
}
|
package/src/Linear/index.js
CHANGED
|
@@ -44,8 +44,9 @@ export class Linear {
|
|
|
44
44
|
this.gpu.InitKernel(this.Weights, this.Bias, embeddingSize)
|
|
45
45
|
}
|
|
46
46
|
Save() {
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
const {bias, weights} = this.gpu.GetWeightsAndBias()
|
|
48
|
+
SaveVectors(weights, this.configs.save.filename[0])
|
|
49
|
+
SaveBias(bias, this.configs.save.filename[1])
|
|
49
50
|
}
|
|
50
51
|
forward(input) {
|
|
51
52
|
this.input.push(input)
|
package/model/ffnBias.bin
DELETED
|
Binary file
|
package/model/ffnBias1.bin
DELETED
|
Binary file
|
package/model/ffnWeights.bin
DELETED
|
Binary file
|
package/model/ffnWeights1.bin
DELETED
|
Binary file
|