UlrickBL commited on
Commit
01bae5c
·
verified ·
1 Parent(s): f23606c

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +199 -139
index.html CHANGED
@@ -12,20 +12,18 @@
12
  display: flex;
13
  flex-direction: row;
14
  height: 100vh;
15
- background: linear-gradient(to right, #ff9a9e, #fad0c4);
16
- color: #4b0082;
17
  }
18
 
19
  .console {
20
- width: 30%;
21
  padding: 20px;
22
- background-color: #fdfdfd;
23
- border-right: 2px solid #ff9a9e;
24
  overflow-y: auto;
 
25
  }
26
 
27
  .output {
28
- width: 70%;
29
  padding: 20px;
30
  overflow-y: auto;
31
  }
@@ -34,66 +32,112 @@
34
  width: 100%;
35
  border-collapse: collapse;
36
  margin-bottom: 20px;
37
- background-color: #ffffff;
38
- border-radius: 8px;
39
- overflow: hidden;
40
- box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
41
  }
42
 
43
  th, td {
44
- border: 1px solid #ddd;
45
  padding: 8px;
46
  text-align: center;
47
  }
48
 
49
  th {
50
- background-color: #ff9a9e;
51
- color: #fff;
52
- text-transform: uppercase;
53
  }
54
 
55
  .highlight {
56
- background-color: #fdf2ff;
57
- color: #800080;
58
  padding: 10px;
59
  margin: 20px 0;
60
- border: 1px solid #ff9a9e;
61
- border-radius: 8px;
 
 
 
 
 
62
  }
63
 
64
- .section-title {
65
- margin-top: 30px;
66
- font-size: 1.2em;
 
67
  font-weight: bold;
68
- color: #800080;
69
- text-align: center;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  }
71
  </style>
72
  <script>
73
  function calculateParameters() {
74
  const hiddenSize = parseInt(document.getElementById('hidden_size').value);
 
 
75
  const intermediateSize = parseInt(document.getElementById('intermediate_size').value);
76
  const vocabSize = parseInt(document.getElementById('vocab_size').value);
77
- const numKeyValueHeads = parseInt(document.getElementById('num_key_value_heads').value);
78
  const numHiddenLayers = parseInt(document.getElementById('num_hidden_layers').value);
79
  const includeBias = document.getElementById('include_bias').value === 'yes';
80
 
 
 
 
81
  // Attention calculations
82
- const attentionQW = [hiddenSize, hiddenSize, hiddenSize * hiddenSize];
83
- const attentionV = [hiddenSize, numKeyValueHeads, hiddenSize * numKeyValueHeads];
84
- const attentionBq = includeBias ? [hiddenSize, 1, hiddenSize] : [0, 0, 0];
85
- const attentionBv = includeBias ? [numKeyValueHeads, 1, numKeyValueHeads] : [0, 0, 0];
86
- const attentionTotal = attentionQW[2] + attentionV[2] + attentionBq[2] + attentionBv[2];
 
 
 
 
 
 
 
87
 
88
  // Feed Forward calculations
89
- const switchW = [hiddenSize, intermediateSize, hiddenSize * intermediateSize];
90
- const switchB = includeBias ? [intermediateSize, 1, intermediateSize] : [0, 0, 0];
91
- const projW = [intermediateSize, hiddenSize, intermediateSize * hiddenSize];
92
- const projB = includeBias ? [hiddenSize, 1, hiddenSize] : [0, 0, 0];
93
- const feedForwardTotal = switchW[2] + switchB[2] + projW[2] + projB[2];
 
 
 
94
 
95
  // Embedding
96
- const embedding = [vocabSize, hiddenSize, vocabSize * hiddenSize];
97
 
98
  // 1 layer parameters
99
  const oneLayerParams = attentionTotal + feedForwardTotal;
@@ -102,107 +146,119 @@
102
  const fullLayersParams = oneLayerParams * numHiddenLayers;
103
 
104
  // Full size (includes embedding)
105
- const fullSize = fullLayersParams + embedding[2];
106
-
107
- // Generate tables
108
- const attentionTable = `
109
- <table>
110
- <tr>
111
- <th>Attention</th>
112
- <th>Input Size</th>
113
- <th>Output Size</th>
114
- <th>Total Size</th>
115
- </tr>
116
- <tr>
117
- <td>Q / Wq</td>
118
- <td>${attentionQW[0]}</td>
119
- <td>${attentionQW[1]}</td>
120
- <td>${attentionQW[2].toLocaleString()}</td>
121
- </tr>
122
- <tr>
123
- <td>V / Wv</td>
124
- <td>${attentionV[0]}</td>
125
- <td>${attentionV[1]}</td>
126
- <td>${attentionV[2].toLocaleString()}</td>
127
- </tr>
128
- ${includeBias ? `
129
- <tr>
130
- <td>Bq</td>
131
- <td>${attentionBq[0]}</td>
132
- <td>${attentionBq[1]}</td>
133
- <td>${attentionBq[2].toLocaleString()}</td>
134
- </tr>
135
- <tr>
136
- <td>Bv</td>
137
- <td>${attentionBv[0]}</td>
138
- <td>${attentionBv[1]}</td>
139
- <td>${attentionBv[2].toLocaleString()}</td>
140
- </tr>
141
- ` : ''}
142
- </table>`;
143
-
144
- const feedForwardTable = `
145
- <table>
146
- <tr>
147
- <th>Feed Forward</th>
148
- <th>Input Size</th>
149
- <th>Output Size</th>
150
- <th>Total Size</th>
151
- </tr>
152
- <tr>
153
- <td>Switch / W</td>
154
- <td>${switchW[0]}</td>
155
- <td>${switchW[1]}</td>
156
- <td>${switchW[2].toLocaleString()}</td>
157
- </tr>
158
- ${includeBias ? `<tr>
159
- <td>Switch / b</td>
160
- <td>${switchB[0]}</td>
161
- <td>${switchB[1]}</td>
162
- <td>${switchB[2].toLocaleString()}</td>
163
- </tr>` : ''}
164
- <tr>
165
- <td>Proj / W</td>
166
- <td>${projW[0]}</td>
167
- <td>${projW[1]}</td>
168
- <td>${projW[2].toLocaleString()}</td>
169
- </tr>
170
- ${includeBias ? `<tr>
171
- <td>Proj / b</td>
172
- <td>${projB[0]}</td>
173
- <td>${projB[1]}</td>
174
- <td>${projB[2].toLocaleString()}</td>
175
- </tr>` : ''}
176
- </table>`;
177
-
178
- const embeddingTable = `
179
- <table>
180
- <tr>
181
- <th>Embedding</th>
182
- <th>Input Size</th>
183
- <th>Output Size</th>
184
- <th>Total Size</th>
185
- </tr>
186
- <tr>
187
- <td>Embedding</td>
188
- <td>${embedding[0]}</td>
189
- <td>${embedding[1]}</td>
190
- <td>${embedding[2].toLocaleString()}</td>
191
- </tr>
192
- </table>`;
193
-
194
- // Update output
195
- document.getElementById('output').innerHTML = `
196
  <div class="highlight">
197
- <strong>1 Layer Parameters:</strong> ${oneLayerParams.toLocaleString()}<br>
198
- <strong>Full Layers Parameters:</strong> ${fullLayersParams.toLocaleString()}<br>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  </div>
200
- ${attentionTable}
201
- ${feedForwardTable}
202
  <div class="highlight">
203
- <strong>Complete Model Size:</strong> ${fullSize.toLocaleString()}
204
  </div>
205
- ${embeddingTable}`;
206
  }
207
  </script>
208
  </head>
@@ -211,31 +267,35 @@
211
  <div class="console">
212
  <h3>Input Parameters</h3>
213
  <label for="hidden_size">Hidden size:</label><br>
214
- <input type="number" id="hidden_size" value="2048"><br><br>
215
 
216
  <label for="intermediate_size">Intermediate size:</label><br>
217
- <input type="number" id="intermediate_size" value="16384"><br><br>
218
 
219
  <label for="vocab_size">Vocab size:</label><br>
220
- <input type="number" id="vocab_size" value="64000"><br><br>
221
 
222
  <label for="num_key_value_heads">Number of key-value heads:</label><br>
223
- <input type="number" id="num_key_value_heads" value="80"><br><br>
 
 
 
224
 
225
  <label for="num_hidden_layers">Number of hidden layers:</label><br>
226
- <input type="number" id="num_hidden_layers" value="64"><br><br>
227
 
228
  <label for="include_bias">Include bias?</label><br>
229
  <select id="include_bias">
230
- <option value="yes">Yes</option>
231
  <option value="no">No</option>
 
232
  </select><br><br>
233
 
234
  <button onclick="calculateParameters()">Calculate</button>
235
  </div>
236
 
237
  <div class="output" id="output">
238
- <h3>Model Parameter Results</h3>
 
239
  </div>
240
 
241
  </body>
 
12
  display: flex;
13
  flex-direction: row;
14
  height: 100vh;
 
 
15
  }
16
 
17
  .console {
18
+ width: 20%;
19
  padding: 20px;
20
+ background-color: #f6b5b5;
 
21
  overflow-y: auto;
22
+ border-right: 2px solid #ee4a4f;
23
  }
24
 
25
  .output {
26
+ width: 80%;
27
  padding: 20px;
28
  overflow-y: auto;
29
  }
 
32
  width: 100%;
33
  border-collapse: collapse;
34
  margin-bottom: 20px;
35
+ background-color: #fff7f9;
36
+ border: 1px solid #f6b5b5;
 
 
37
  }
38
 
39
  th, td {
40
+ border: 1px solid #f6b5b5;
41
  padding: 8px;
42
  text-align: center;
43
  }
44
 
45
  th {
46
+ background-color: #f6d4d4;
 
 
47
  }
48
 
49
  .highlight {
50
+ background-color: #ffe8e8;
51
+ color: #ad0d0d;
52
  padding: 10px;
53
  margin: 20px 0;
54
+ border: 1px solid #f6b5b5;
55
+ border-radius: 4px;
56
+ text-align: center;
57
+ }
58
+
59
+ h3 {
60
+ color: #ad0d0d;
61
  }
62
 
63
+ .section {
64
+ margin-bottom: 20px;
65
+ }
66
+ label {
67
  font-weight: bold;
68
+ font-size: 0.9rem;
69
+ }
70
+
71
+ input[type="number"], select {
72
+ width: 100%;
73
+ padding: 8px;
74
+ border: 1px solid #ddd;
75
+ border-radius: 5px;
76
+ box-sizing: border-box;
77
+ font-size: 0.9rem;
78
+ }
79
+
80
+ input[type="number"]:focus, select:focus {
81
+ border-color: #ff6666;
82
+ outline: none;
83
+ box-shadow: 0px 0px 5px rgba(255, 102, 102, 0.5);
84
+ }
85
+
86
+ button {
87
+ background-color: #ff6666;
88
+ color: white;
89
+ border: none;
90
+ border-radius: 5px;
91
+ padding: 5px;
92
+ width: 100%;
93
+ font-size: 1rem;
94
+ cursor: pointer;
95
+ transition: background-color 0.3s ease;
96
+ }
97
+
98
+ button:hover {
99
+ background-color: #e60000;
100
  }
101
  </style>
102
  <script>
103
  function calculateParameters() {
104
  const hiddenSize = parseInt(document.getElementById('hidden_size').value);
105
+ const num_kv_heads = parseInt(document.getElementById('num_key_value_heads').value);
106
+ const num_heads = parseInt(document.getElementById('num_heads').value);
107
  const intermediateSize = parseInt(document.getElementById('intermediate_size').value);
108
  const vocabSize = parseInt(document.getElementById('vocab_size').value);
 
109
  const numHiddenLayers = parseInt(document.getElementById('num_hidden_layers').value);
110
  const includeBias = document.getElementById('include_bias').value === 'yes';
111
 
112
+ const calcTotal = (input, output) => input * output;
113
+ const calcKVdim = (hiddenSize, num_heads,num_kv_heads) => hiddenSize * num_kv_heads / num_heads;
114
+
115
  // Attention calculations
116
+ const attention = [
117
+ { name: 'Query', input: hiddenSize, output: hiddenSize },
118
+ { name: 'Key', input: hiddenSize, output: calcKVdim(hiddenSize, num_heads,num_kv_heads) },
119
+ { name: 'Value', input: hiddenSize, output: calcKVdim(hiddenSize, num_heads,num_kv_heads) },
120
+ { name: 'Projection', input: hiddenSize, output: hiddenSize }
121
+ ].map(entry => ({
122
+ ...entry,
123
+ wTotal: calcTotal(entry.input, entry.output),
124
+ bTotal: includeBias ? entry.output : 0
125
+ }));
126
+
127
+ const attentionTotal = attention.reduce((sum, entry) => sum + entry.wTotal + entry.bTotal, 0);
128
 
129
  // Feed Forward calculations
130
+ const switchW = calcTotal(hiddenSize, intermediateSize);
131
+ const switchB = includeBias ? intermediateSize : 0;
132
+ const luW = calcTotal(hiddenSize, intermediateSize);
133
+ const luB = includeBias ? intermediateSize : 0;
134
+ const projW = calcTotal(intermediateSize, hiddenSize);
135
+ const projB = includeBias ? hiddenSize : 0;
136
+
137
+ const feedForwardTotal = switchW + switchB + luW + luB + projW + projB;
138
 
139
  // Embedding
140
+ const embeddingTotal = calcTotal(vocabSize, hiddenSize);
141
 
142
  // 1 layer parameters
143
  const oneLayerParams = attentionTotal + feedForwardTotal;
 
146
  const fullLayersParams = oneLayerParams * numHiddenLayers;
147
 
148
  // Full size (includes embedding)
149
+ const fullSize = fullLayersParams + embeddingTotal;
150
+
151
+ // Display results
152
+ const outputDiv = document.getElementById('output');
153
+ outputDiv.innerHTML = `
154
+ <h1>Model Parameter Calculator</h1>
155
+ <div class="section">
156
+ <h3>Attention</h3>
157
+ <table>
158
+ <tr>
159
+ <th>Parameter</th>
160
+ <th>Input Size</th>
161
+ <th>Output Size</th>
162
+ <th>Total parameters (input*ouput)</th>
163
+ </tr>
164
+ ${attention.map(entry => `
165
+ <tr>
166
+ <td>${entry.name} - W</td>
167
+ <td>${entry.input.toLocaleString()}</td>
168
+ <td>${entry.output.toLocaleString()}</td>
169
+ <td>${entry.wTotal.toLocaleString()}</td>
170
+ </tr>
171
+ ${includeBias ? `
172
+ <tr>
173
+ <td>${entry.name} - b</td>
174
+ <td>-</td>
175
+ <td>${entry.output.toLocaleString()}</td>
176
+ <td>${entry.bTotal.toLocaleString()}</td>
177
+ </tr>
178
+ ` : ''}
179
+ `).join('')}
180
+ <tr>
181
+ <th colspan="3">Total attention parameters</th>
182
+ <td colspan="2">${attentionTotal.toLocaleString()}</td>
183
+ </tr>
184
+ </table>
185
+ </div>
186
+ <div class="section">
187
+ <h3>Feed Forward</h3>
188
+ <table>
189
+ <tr>
190
+ <th>Parameter</th>
191
+ <th>Input Size</th>
192
+ <th>Output Size</th>
193
+ <th>Total (input*output)</th>
194
+ </tr>
195
+ <tr>
196
+ <td>Swish - W</td>
197
+ <td>${hiddenSize.toLocaleString()}</td>
198
+ <td>${intermediateSize.toLocaleString()}</td>
199
+ <td>${switchW.toLocaleString()}</td>
200
+ </tr>
201
+ ${includeBias ? `<tr>
202
+ <td>Swish - b</td>
203
+ <td>-</td>
204
+ <td>${intermediateSize.toLocaleString()}</td>
205
+ <td>${switchB.toLocaleString()}</td>
206
+ </tr>` : ''}
207
+ <tr>
208
+ <td>GLU W</td>
209
+ <td>${hiddenSize.toLocaleString()}</td>
210
+ <td>${intermediateSize.toLocaleString()}</td>
211
+ <td>${luW.toLocaleString()}</td>
212
+ </tr>
213
+ ${includeBias ? `<tr>
214
+ <td>GLU - b</td>
215
+ <td>-</td>
216
+ <td>${intermediateSize.toLocaleString()}</td>
217
+ <td>${luB.toLocaleString()}</td>
218
+ </tr>` : ''}
219
+ <tr>
220
+ <td>Projection - W</td>
221
+ <td>${intermediateSize.toLocaleString()}</td>
222
+ <td>${hiddenSize.toLocaleString()}</td>
223
+ <td>${projW.toLocaleString()}</td>
224
+ </tr>
225
+ ${includeBias ? `<tr>
226
+ <td>Projection - b</td>
227
+ <td>-</td>
228
+ <td>${hiddenSize.toLocaleString()}</td>
229
+ <td>${projB.toLocaleString()}</td>
230
+ </tr>` : ''}
231
+ <tr>
232
+ <th colspan="3">Total Feed Forward parameters</th>
233
+ <td>${feedForwardTotal.toLocaleString()}</td>
234
+ </tr>
235
+ </table>
236
+ </div>
 
 
 
237
  <div class="highlight">
238
+ <strong>1 Layer Parameters (sum of attention and FFN):</strong> ${oneLayerParams.toLocaleString()}<br>
239
+ <strong>Full Layers Parameters (1 layer parameters * num layers):</strong> ${fullLayersParams.toLocaleString()}<br>
240
+ </div>
241
+ <div class="section">
242
+ <h3>Embedding</h3>
243
+ <table>
244
+ <tr>
245
+ <th>Parameter</th>
246
+ <th>Vocab Size</th>
247
+ <th>Hidden Size</th>
248
+ <th>Total (vocab * hidden)</th>
249
+ </tr>
250
+ <tr>
251
+ <td>Embedding</td>
252
+ <td>${vocabSize.toLocaleString()}</td>
253
+ <td>${hiddenSize.toLocaleString()}</td>
254
+ <td>${embeddingTotal.toLocaleString()}</td>
255
+ </tr>
256
+ </table>
257
  </div>
 
 
258
  <div class="highlight">
259
+ <strong>Complete Model Parmeters (embedding size + full layers size):</strong> ${fullSize.toLocaleString()}
260
  </div>
261
+ `;
262
  }
263
  </script>
264
  </head>
 
267
  <div class="console">
268
  <h3>Input Parameters</h3>
269
  <label for="hidden_size">Hidden size:</label><br>
270
+ <input type="number" id="hidden_size" value="896"><br><br>
271
 
272
  <label for="intermediate_size">Intermediate size:</label><br>
273
+ <input type="number" id="intermediate_size" value="4864"><br><br>
274
 
275
  <label for="vocab_size">Vocab size:</label><br>
276
+ <input type="number" id="vocab_size" value="151646"><br><br>
277
 
278
  <label for="num_key_value_heads">Number of key-value heads:</label><br>
279
+ <input type="number" id="num_key_value_heads" value="2"><br><br>
280
+
281
+ <label for="num_heads">Number of attention (query) heads:</label><br>
282
+ <input type="number" id="num_heads" value="14"><br><br>
283
 
284
  <label for="num_hidden_layers">Number of hidden layers:</label><br>
285
+ <input type="number" id="num_hidden_layers" value="24"><br><br>
286
 
287
  <label for="include_bias">Include bias?</label><br>
288
  <select id="include_bias">
 
289
  <option value="no">No</option>
290
+ <option value="yes">Yes</option>
291
  </select><br><br>
292
 
293
  <button onclick="calculateParameters()">Calculate</button>
294
  </div>
295
 
296
  <div class="output" id="output">
297
+ <h1>Model Parameter Calculator</h1>
298
+ <h3>Enter model parameters in the console and press calculate</h3>
299
  </div>
300
 
301
  </body>