Spaces:
Running
Running
Create model_weights.js
Browse files- model_weights.js +49 -0
model_weights.js
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var oReq = new XMLHttpRequest();
|
2 |
+
oReq.open("GET", "weights.bin", true);
|
3 |
+
oReq.responseType = "arraybuffer";
|
4 |
+
|
5 |
+
var weights_meta={'rnn/~/attention_core/~/gru__b': [[0, 1200], [1200]], 'rnn/~/attention_core/~/gru__w_h': [[1200, 481200], [400, 1200]], 'rnn/~/attention_core/~/gru__w_i': [[481200, 682800], [168, 1200]], 'rnn/~/attention_core/~/gru_1__b': [[682800, 684000], [1200]], 'rnn/~/attention_core/~/gru_1__w_h': [[684000, 1164000], [400, 1200]], 'rnn/~/attention_core/~/gru_1__w_i': [[1164000, 1845600], [568, 1200]], 'rnn/~/attention_core/~/gru_2__b': [[1845600, 1846800], [1200]], 'rnn/~/attention_core/~/gru_2__w_h': [[1846800, 2326800], [400, 1200]], 'rnn/~/attention_core/~/gru_2__w_i': [[2326800, 3008400], [568, 1200]], 'rnn/~/attention_core/~/linear__b': [[3008400, 3008430], [30]], 'rnn/~/attention_core/~/linear__w': [[3008430, 3025470], [568, 30]], 'rnn/~/conv1_d__b': [[3025470, 3025635], [165]], 'rnn/~/conv1_d__w': [[3025635, 3161760], [5, 165, 165]], 'rnn/~/embed__embeddings': [[3161760, 3246240], [512, 165]], 'rnn/~/embed_1__embeddings': [[3246240, 3273465], [165, 165]], 'rnn/~/linear__b': [[3273465, 3273586], [121]], 'rnn/~/linear__w': [[3273586, 3321986], [400, 121]]};
|
6 |
+
|
7 |
+
console.log(weights_meta);
|
8 |
+
|
9 |
+
var WEIGHTS = {};
|
10 |
+
var weight_buffer = null;
|
11 |
+
var W = null;
|
12 |
+
var w32 = null;
|
13 |
+
var w16 = null;
|
14 |
+
|
15 |
+
oReq.onload = function (oEvent) {
|
16 |
+
var arrayBuffer = oReq.response; // Note: not oReq.responseText
|
17 |
+
if (arrayBuffer) {
|
18 |
+
// convert bfloat16 to float32
|
19 |
+
// w16 = new Uint16Array(arrayBuffer)
|
20 |
+
// weight_buffer = new SharedArrayBuffer(2*arrayBuffer.byteLength);
|
21 |
+
// w32 = new Uint16Array(weight_buffer);
|
22 |
+
// for(var i=0; i < w16.length; i++) {
|
23 |
+
// w32[i * 2 + 1] = w16[i];
|
24 |
+
// }
|
25 |
+
W = new Float32Array(arrayBuffer);
|
26 |
+
document.getElementById("btn").innerText = "Buffer arrieved";
|
27 |
+
|
28 |
+
for(var k in weights_meta) {
|
29 |
+
info = weights_meta[k];
|
30 |
+
offset = info[0];
|
31 |
+
shape = info[1];
|
32 |
+
WEIGHTS[k] = tf.tensor(W.subarray(offset[0], offset[1]), shape);
|
33 |
+
}
|
34 |
+
|
35 |
+
document.getElementById("btn").disabled = false;
|
36 |
+
tf.engine().startScope();
|
37 |
+
setTimeout(function() {
|
38 |
+
cur_run = cur_run + 1;
|
39 |
+
dojob(cur_run);
|
40 |
+
}, 0);
|
41 |
+
|
42 |
+
document.getElementById("btn").innerText = "Generate";
|
43 |
+
}
|
44 |
+
};
|
45 |
+
|
46 |
+
tf.ready().then( function() {
|
47 |
+
tf.enableProdMode();
|
48 |
+
oReq.send(null);
|
49 |
+
});
|