@mineproness/tensorloop 2.1.51 → 2.1.52
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/Model/index.js +11 -1
- package/src/gpiInit.js +24 -0
package/package.json
CHANGED
package/src/Model/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Embedding, PositionEmbedding, Linear, Tokenizer, TransformerBlock, Softmax } from '../../index.js'
|
|
2
2
|
import path, { join } from 'path'
|
|
3
|
+
import {GPUThings} from '../gpiInit.js'
|
|
3
4
|
export default class Model {
|
|
4
5
|
embedding;
|
|
5
6
|
linear;
|
|
@@ -9,9 +10,11 @@ export default class Model {
|
|
|
9
10
|
block1;
|
|
10
11
|
block2;
|
|
11
12
|
contextSize;
|
|
13
|
+
gpuThings;
|
|
12
14
|
constructor(embeddingSize, contextSize, configs) {
|
|
13
15
|
this.tokenizer = new Tokenizer()
|
|
14
16
|
this.contextSize = contextSize
|
|
17
|
+
this.gpuThings = new GPUThings(vocabSize, contextSize)
|
|
15
18
|
this.embedding = new Embedding(embeddingSize, this.tokenizer.vocabSize, contextSize, {
|
|
16
19
|
save: {
|
|
17
20
|
filename: path.join(configs.dirname, "vectors.bin")
|
|
@@ -78,7 +81,14 @@ export default class Model {
|
|
|
78
81
|
const percentense = (((a + 1) / trainingPair.length) * 100).toFixed(2)
|
|
79
82
|
const filted = Math.round((percentense / 100) * 20);
|
|
80
83
|
const empty = 20 - filted
|
|
81
|
-
|
|
84
|
+
const correctAccu = this.gpuThings.calculateAvgMax(logits, target)
|
|
85
|
+
let correct = 0;
|
|
86
|
+
for(let a = 0; a < correctAccu.length; a++){
|
|
87
|
+
correct += correctAccu[a]
|
|
88
|
+
}
|
|
89
|
+
correct /= target.length
|
|
90
|
+
correct *= 100
|
|
91
|
+
process.stdout.write(`\rEPOCHS: ${i} [${"=".repeat(filted)}${" ".repeat(empty)}] ${percentense}% (${a + 1}/${trainingPair.length}) | loss ${(totalLoss / (a + 1)).toFixed(2)} | Accuray: ${correct}`)
|
|
82
92
|
}
|
|
83
93
|
console.log("")
|
|
84
94
|
this.embedding.Save()
|
package/src/gpiInit.js
CHANGED
|
@@ -758,4 +758,28 @@ export class GPUPosition {
|
|
|
758
758
|
Save(){
|
|
759
759
|
return this.posVectors.toArray()
|
|
760
760
|
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
export class GPUThings{
|
|
765
|
+
vocabSize;
|
|
766
|
+
calculateAvgMax;
|
|
767
|
+
constructor(vocabSize, contextSize){
|
|
768
|
+
this.calculateAvgMax = gpu.createKernel(function(logits, target){
|
|
769
|
+
let maxIDX = 0;
|
|
770
|
+
let maxLogit = logits[this.thread.x][0]
|
|
771
|
+
for(let a = 0; a < vocabSize; a++){
|
|
772
|
+
if(maxLogit <= logits[this.thread.x][a]){
|
|
773
|
+
maxIDX = a;
|
|
774
|
+
maxLogit = logits[this.thread.x][a]
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
return maxIDX == target[this.thread.x] ? 1 : 0
|
|
778
|
+
}, {
|
|
779
|
+
output: [contextSize],
|
|
780
|
+
constants: {
|
|
781
|
+
vocabSize
|
|
782
|
+
}
|
|
783
|
+
})
|
|
784
|
+
}
|
|
761
785
|
}
|