Spaces:
Running
Running
Create model_weights.js
Browse files- model_weights.js +47 -0
model_weights.js
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var oReq = new XMLHttpRequest();
|
2 |
+
oReq.open("GET", "weights.bin", true);
|
3 |
+
oReq.responseType = "arraybuffer";
|
4 |
+
|
5 |
+
var weights_meta={'rnn/~/conv1_d__b': [[0, 73], [73]], 'rnn/~/conv1_d__w': [[73, 26718], [5, 73, 73]], 'rnn/~/embed__embeddings': [[26718, 64094], [512, 73]], 'rnn/~/embed_1__embeddings': [[64094, 69423], [73, 73]], 'rnn/~/linear__b': [[69423, 69454], [31]], 'rnn/~/linear__w': [[69454, 85326], [512, 31]], 'rnn/~/lstm_attention_core/~/gru__b': [[85326, 86862], [1536]], 'rnn/~/lstm_attention_core/~/gru__w_h': [[86862, 873294], [512, 1536]], 'rnn/~/lstm_attention_core/~/gru__w_i': [[873294, 990030], [76, 1536]], 'rnn/~/lstm_attention_core/~/gru_1__b': [[990030, 991566], [1536]], 'rnn/~/lstm_attention_core/~/gru_1__w_h': [[991566, 1777998], [512, 1536]], 'rnn/~/lstm_attention_core/~/gru_1__w_i': [[1777998, 2681166], [588, 1536]], 'rnn/~/lstm_attention_core/~/linear__b': [[2681166, 2681169], [3]], 'rnn/~/lstm_attention_core/~/linear__w': [[2681169, 2682933], [588, 3]]};
|
6 |
+
|
7 |
+
var WEIGHTS = {};
|
8 |
+
var weight_buffer = null;
|
9 |
+
var W = null;
|
10 |
+
var w32 = null;
|
11 |
+
var w16 = null;
|
12 |
+
|
13 |
+
oReq.onload = function (oEvent) {
|
14 |
+
var arrayBuffer = oReq.response; // Note: not oReq.responseText
|
15 |
+
if (arrayBuffer) {
|
16 |
+
// convert bfloat16 to float32
|
17 |
+
// w16 = new Uint16Array(arrayBuffer)
|
18 |
+
// weight_buffer = new SharedArrayBuffer(2*arrayBuffer.byteLength);
|
19 |
+
// w32 = new Uint16Array(weight_buffer);
|
20 |
+
// for(var i=0; i < w16.length; i++) {
|
21 |
+
// w32[i * 2 + 1] = w16[i];
|
22 |
+
// }
|
23 |
+
W = new Float32Array(arrayBuffer);
|
24 |
+
document.getElementById("btn").innerText = "Buffer arrieved";
|
25 |
+
|
26 |
+
for(var k in weights_meta) {
|
27 |
+
info = weights_meta[k];
|
28 |
+
offset = info[0];
|
29 |
+
shape = info[1];
|
30 |
+
WEIGHTS[k] = tf.tensor(W.subarray(offset[0], offset[1]), shape);
|
31 |
+
}
|
32 |
+
|
33 |
+
document.getElementById("btn").disabled = false;
|
34 |
+
tf.engine().startScope();
|
35 |
+
setTimeout(function() {
|
36 |
+
cur_run = cur_run + 1;
|
37 |
+
dojob(cur_run);
|
38 |
+
}, 0);
|
39 |
+
|
40 |
+
document.getElementById("btn").innerText = "Generate";
|
41 |
+
}
|
42 |
+
};
|
43 |
+
|
44 |
+
tf.ready().then( function() {
|
45 |
+
tf.enableProdMode();
|
46 |
+
oReq.send(null);
|
47 |
+
});
|