Spaces:
Running
Running
Update index.html
Browse files- 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:
|
21 |
padding: 20px;
|
22 |
-
background-color: #
|
23 |
-
border-right: 2px solid #ff9a9e;
|
24 |
overflow-y: auto;
|
|
|
25 |
}
|
26 |
|
27 |
.output {
|
28 |
-
width:
|
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: #
|
38 |
-
border
|
39 |
-
overflow: hidden;
|
40 |
-
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
|
41 |
}
|
42 |
|
43 |
th, td {
|
44 |
-
border: 1px solid #
|
45 |
padding: 8px;
|
46 |
text-align: center;
|
47 |
}
|
48 |
|
49 |
th {
|
50 |
-
background-color: #
|
51 |
-
color: #fff;
|
52 |
-
text-transform: uppercase;
|
53 |
}
|
54 |
|
55 |
.highlight {
|
56 |
-
background-color: #
|
57 |
-
color: #
|
58 |
padding: 10px;
|
59 |
margin: 20px 0;
|
60 |
-
border: 1px solid #
|
61 |
-
border-radius:
|
|
|
|
|
|
|
|
|
|
|
62 |
}
|
63 |
|
64 |
-
.section
|
65 |
-
margin-
|
66 |
-
|
|
|
67 |
font-weight: bold;
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
// Feed Forward calculations
|
89 |
-
const switchW =
|
90 |
-
const switchB = includeBias ?
|
91 |
-
const
|
92 |
-
const
|
93 |
-
const
|
|
|
|
|
|
|
94 |
|
95 |
// Embedding
|
96 |
-
const
|
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 +
|
106 |
-
|
107 |
-
//
|
108 |
-
const
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
<
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
<
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
</
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
<
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
</
|
192 |
-
</
|
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
|
204 |
</div>
|
205 |
-
|
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="
|
215 |
|
216 |
<label for="intermediate_size">Intermediate size:</label><br>
|
217 |
-
<input type="number" id="intermediate_size" value="
|
218 |
|
219 |
<label for="vocab_size">Vocab size:</label><br>
|
220 |
-
<input type="number" id="vocab_size" value="
|
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="
|
|
|
|
|
|
|
224 |
|
225 |
<label for="num_hidden_layers">Number of hidden layers:</label><br>
|
226 |
-
<input type="number" id="num_hidden_layers" value="
|
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 |
-
<
|
|
|
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>
|