Spaces:
Running
Running
Update index.html
Browse files- index.html +145 -136
index.html
CHANGED
|
@@ -12,15 +12,15 @@
|
|
| 12 |
display: flex;
|
| 13 |
flex-direction: row;
|
| 14 |
height: 100vh;
|
| 15 |
-
background: linear-gradient(
|
| 16 |
-
color: #
|
| 17 |
}
|
| 18 |
|
| 19 |
.console {
|
| 20 |
width: 30%;
|
| 21 |
padding: 20px;
|
| 22 |
-
background-color: #
|
| 23 |
-
border-right: 2px solid #
|
| 24 |
overflow-y: auto;
|
| 25 |
}
|
| 26 |
|
|
@@ -34,73 +34,39 @@
|
|
| 34 |
width: 100%;
|
| 35 |
border-collapse: collapse;
|
| 36 |
margin-bottom: 20px;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
}
|
| 38 |
|
| 39 |
th, td {
|
| 40 |
border: 1px solid #ddd;
|
| 41 |
padding: 8px;
|
| 42 |
-
text-align:
|
| 43 |
}
|
| 44 |
|
| 45 |
th {
|
| 46 |
-
background-color: #
|
| 47 |
-
color: #
|
|
|
|
| 48 |
}
|
| 49 |
|
| 50 |
.highlight {
|
| 51 |
-
background-color: #
|
| 52 |
-
color: #
|
| 53 |
padding: 10px;
|
| 54 |
margin: 20px 0;
|
| 55 |
-
border: 1px solid #
|
| 56 |
-
border-radius:
|
| 57 |
-
}
|
| 58 |
-
|
| 59 |
-
h3 {
|
| 60 |
-
color: #4a154b;
|
| 61 |
-
}
|
| 62 |
-
|
| 63 |
-
label, input, select {
|
| 64 |
-
display: block;
|
| 65 |
-
margin-bottom: 10px;
|
| 66 |
-
width: 100%;
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
input, select {
|
| 70 |
-
padding: 8px;
|
| 71 |
-
border: 1px solid #d1c1f2;
|
| 72 |
-
border-radius: 4px;
|
| 73 |
-
background: #fef4fc;
|
| 74 |
-
color: #4a154b;
|
| 75 |
-
}
|
| 76 |
-
|
| 77 |
-
button {
|
| 78 |
-
background-color: #d1c1f2;
|
| 79 |
-
color: white;
|
| 80 |
-
padding: 10px 20px;
|
| 81 |
-
border: none;
|
| 82 |
-
border-radius: 4px;
|
| 83 |
-
cursor: pointer;
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
button:hover {
|
| 87 |
-
background-color: #bfa8e3;
|
| 88 |
}
|
| 89 |
|
| 90 |
.section-title {
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
| 93 |
text-align: center;
|
| 94 |
-
padding: 5px 0;
|
| 95 |
-
margin-bottom: 5px;
|
| 96 |
-
}
|
| 97 |
-
|
| 98 |
-
.sub-table {
|
| 99 |
-
margin-top: 10px;
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
.no-bias {
|
| 103 |
-
display: none;
|
| 104 |
}
|
| 105 |
</style>
|
| 106 |
<script>
|
|
@@ -109,33 +75,25 @@
|
|
| 109 |
const intermediateSize = parseInt(document.getElementById('intermediate_size').value);
|
| 110 |
const vocabSize = parseInt(document.getElementById('vocab_size').value);
|
| 111 |
const numKeyValueHeads = parseInt(document.getElementById('num_key_value_heads').value);
|
| 112 |
-
const numAttentionHeads = parseInt(document.getElementById('num_attention_heads').value);
|
| 113 |
const numHiddenLayers = parseInt(document.getElementById('num_hidden_layers').value);
|
| 114 |
const includeBias = document.getElementById('include_bias').value === 'yes';
|
| 115 |
|
| 116 |
// Attention calculations
|
| 117 |
-
const
|
| 118 |
-
const
|
| 119 |
-
const
|
| 120 |
-
const
|
| 121 |
-
const
|
| 122 |
-
const attentionBv = includeBias ? numKeyValueHeads : 0;
|
| 123 |
-
const attentionQOutput = hiddenSize;
|
| 124 |
-
const attentionKOutput = numKeyValueHeads;
|
| 125 |
-
const attentionVOutput = numKeyValueHeads;
|
| 126 |
-
const attentionTotal = 2 * (attentionQ + attentionBq) + 2 * (attentionK + attentionBk) + 2 * (attentionV + attentionBv);
|
| 127 |
|
| 128 |
// Feed Forward calculations
|
| 129 |
-
const switchW = hiddenSize * intermediateSize;
|
| 130 |
-
const switchB = includeBias ? intermediateSize : 0;
|
| 131 |
-
const
|
| 132 |
-
const
|
| 133 |
-
const
|
| 134 |
-
const projB = includeBias ? hiddenSize : 0;
|
| 135 |
-
const feedForwardTotal = switchW + switchB + luW + luB + projW + projB;
|
| 136 |
|
| 137 |
// Embedding
|
| 138 |
-
const
|
| 139 |
|
| 140 |
// 1 layer parameters
|
| 141 |
const oneLayerParams = attentionTotal + feedForwardTotal;
|
|
@@ -144,36 +102,107 @@
|
|
| 144 |
const fullLayersParams = oneLayerParams * numHiddenLayers;
|
| 145 |
|
| 146 |
// Full size (includes embedding)
|
| 147 |
-
const fullSize = fullLayersParams +
|
| 148 |
-
|
| 149 |
-
//
|
| 150 |
-
const attentionTable =
|
| 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 |
</script>
|
| 179 |
</head>
|
|
@@ -181,52 +210,32 @@
|
|
| 181 |
|
| 182 |
<div class="console">
|
| 183 |
<h3>Input Parameters</h3>
|
| 184 |
-
<label for="hidden_size">Hidden size:</label>
|
| 185 |
-
<input type="number" id="hidden_size" value="2048">
|
| 186 |
-
|
| 187 |
-
<label for="intermediate_size">Intermediate size:</label>
|
| 188 |
-
<input type="number" id="intermediate_size" value="16384">
|
| 189 |
|
| 190 |
-
<label for="
|
| 191 |
-
<input type="number" id="
|
| 192 |
|
| 193 |
-
<label for="
|
| 194 |
-
<input type="number" id="
|
| 195 |
|
| 196 |
-
<label for="
|
| 197 |
-
<input type="number" id="
|
| 198 |
|
| 199 |
-
<label for="num_hidden_layers">Number of hidden layers:</label>
|
| 200 |
-
<input type="number" id="num_hidden_layers" value="64">
|
| 201 |
|
| 202 |
-
<label for="include_bias">Include bias?</label>
|
| 203 |
<select id="include_bias">
|
| 204 |
<option value="yes">Yes</option>
|
| 205 |
<option value="no">No</option>
|
| 206 |
-
</select>
|
| 207 |
|
| 208 |
<button onclick="calculateParameters()">Calculate</button>
|
| 209 |
</div>
|
| 210 |
|
| 211 |
-
<div class="output">
|
| 212 |
<h3>Model Parameter Results</h3>
|
| 213 |
-
|
| 214 |
-
<div class="section-title">1 Layer Parameters</div>
|
| 215 |
-
<div><strong>1 Layer Parameters:</strong> <span id="one_layer_params">0</span></div>
|
| 216 |
-
<div><strong>Full Layers Parameters:</strong> <span id="full_layers_params">0</span></div>
|
| 217 |
-
|
| 218 |
-
<div class="section-title">Attention Parameters</div>
|
| 219 |
-
<table id="attention_table" class="sub-table"></table>
|
| 220 |
-
|
| 221 |
-
<div class="section-title">Feed Forward Parameters</div>
|
| 222 |
-
<table id="feed_forward_table" class="sub-table"></table>
|
| 223 |
-
|
| 224 |
-
<div class="section-title">Embedding Parameters</div>
|
| 225 |
-
<table id="embedding_table" class="sub-table"></table>
|
| 226 |
-
|
| 227 |
-
<div class="highlight">
|
| 228 |
-
<strong>Complete Model Size:</strong> <span id="full_size">0</span>
|
| 229 |
-
</div>
|
| 230 |
</div>
|
| 231 |
|
| 232 |
</body>
|
|
|
|
| 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 |
|
|
|
|
| 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>
|
|
|
|
| 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 |
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>
|
|
|
|
| 210 |
|
| 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>
|