1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 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 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
|
document.addEventListener('DOMContentLoaded', function() {
jsonData = null
// build module level tree
function buildTree(data, level = 0) {
let html = `<ul class = "tree">`;
// build module node
data.forEach(node => {
// check json forward pass information
html += `<li><span class="caret"><b>${node.fqn}</b></span>`
if (node.module_type.length > 0 || node.parameters.length > 0) {
html += `<br><span class="forward-pass"><span class="caret" id="${node.fqn}-module-information-caret">Module Information</span></span></br>`
html += `<div style = "display: none;" id="${node.fqn}-module-information">`
html += `<span class="forward-pass">`
html += `<span style="margin-left: 20px;">module type: ${node.module_type}</span>`
if (node.parameters.length > 0){
html += `<table style="margin-left: 60px;">`
html += `<tr>`
html += `<th>Parameter</th>`
html += `<th>Sharding</th>`
html += `</tr>`
for (parameter_info of node.parameters) {
html += `<tr>`
html += `<td> ${parameter_info[0]} </td>`
html += `<td> ${parameter_info[1]} </td>`
html += `</tr>`
}
html += `</table>`
}
html += `</span>`
html += `</div>`
}
if (node.collectives_forward.length > 0 || node.operations_forward.length > 0) {
html += `<br><span class="forward-pass">Forward Pass</span><br>`
// build forward module collective count table
if (node.collectives_forward.length > 0){
html += `<span class="forward-pass">`
html += `<table>`
html += `<tr>`
html += `<th>Collective</th>`
html += `<th>Count</th>`
html += `</tr>`
for (collective_entry of node.collectives_forward){
html += `<tr>`
html += `<td> ${collective_entry[0]} </td>`
html += `<td> ${collective_entry[1]} </td>`
html += `</tr>`
}
html += `</table>`
html += `</span>`
}
// build forward module operation table
if(node.operations_forward.length > 0){
html += `<span class="forward-pass">`
html += `<span class="caret" id="${node.fqn}-forward-operations-caret">Operations</span>`
html += `<span class="forward-pass">`
html += `<table style="margin-left: 60px; display: none;" id="${node.fqn}-forward-operations-list">`
html += `<tr>`
html += `<th>Operation</th>`
html += `<th>Input Shape</th>`
html += `<th>Input Sharding</th>`
html += `<th>Device Mesh</th>`
html += `</tr>`
for (operation_entry of node.operations_forward) {
html += `<tr>`
html += `<td> ${operation_entry.name} </td>`
html += `<td>`
for (shape of operation_entry.input_shape) {
html += `<p> ${shape} </p>`
}
html += `</td>`
html += `<td>`
for (sharding of operation_entry.input_sharding) {
html += `<p> ${sharding} </p>`
}
html += `</td>`
html += `<td> ${operation_entry.device_mesh} </td>`
html += `</tr>`
}
html += `</table>`
html += `</span>`
html += `</span>`
}
}
// check json backward pass information
if (node.collectives_backward.length > 0 || node.operations_backward.length > 0) {
html += `<br><span class="forward-pass">Backward Pass</span><br>`
// build backward module collective count table
if (node.collectives_backward.length > 0){
html += `<span class="forward-pass">`
html += `<table>`
html += `<tr>`
html += `<th>Collective</th>`
html += `<th>Count</th>`
html += `</tr>`
for (collective_entry of node.collectives_backward){
html += `<tr>`
html += `<td> ${collective_entry[0]} </td>`
html += `<td> ${collective_entry[1]} </td>`
html += `</tr>`
}
html += `</table>`
html += `</span>`
}
// build forward module operation table
if(node.operations_backward.length > 0){
html += `<span class="forward-pass">`
html += `<span class="caret" id="${node.fqn}-backward-operations-caret">Operations</span>`
html += `<span class="forward-pass">`
html += `<table style="margin-left: 60px; display: none;" id="${node.fqn}-backward-operations-list">`
html += `<tr>`
html += `<th>Operation</th>`
html += `<th>Input Shape</th>`
html += `<th>Input Sharding</th>`
html += `<th>Device Mesh</th>`
html += `</tr>`
for (operation_entry of node.operations_backward) {
html += `<tr>`
html += `<td> ${operation_entry.name} </td>`
html += `<td>`
for (shape of operation_entry.input_shape) {
html += `<p> ${shape} </p>`
}
html += `</td>`
html += `<td>`
for (sharding of operation_entry.input_sharding) {
html += `<p> ${sharding} </p>`
}
html += `</td>`
html += `<td> ${operation_entry.device_mesh} </td>`
html += `</tr>`
}
html += `</table>`
html += `</span>`
html += `</span>`
}
}
// check json activation checkpointing information
if(node.operations_checkpointing.length > 0){
html += `<br><span class="forward-pass">Activation Checkpointing</span><br>`
html += `<span class="forward-pass">`
html += `<span class="caret" id="${node.fqn}-checkpointing-operations-caret">Operations</span>`
html += `<span class="forward-pass">`
html += `<table style="margin-left: 60px; display: none;" id="${node.fqn}-checkpointing-operations-list">`
html += `<tr>`
html += `<th>Operation</th>`
html += `<th>Input Shape</th>`
html += `<th>Input Sharding</th>`
html += `<th>Device Mesh</th>`
html += `</tr>`
for (operation_entry of node.operations_checkpointing) {
html += `<tr>`
html += `<td> ${operation_entry.name} </td>`
html += `<td>`
for (shape of operation_entry.input_shape) {
html += `<p> ${shape} </p>`
}
html += `</td>`
html += `<td>`
for (sharding of operation_entry.input_sharding) {
html += `<p> ${sharding} </p>`
}
html += `</td>`
html += `<td> ${operation_entry.device_mesh} </td>`
html += `</tr>`
}
html += `</table>`
html += `</span>`
html += `</span>`
}
// checks for sub-modules and builds tree recursively
if (node.children.length > 0) {
html += `<ul class = "nested">`;
html += buildTree(node.children, level + 1);
html += `</ul>`;
}
html += `</li>`;
});
html += `</ul>`;
return html
}
const container = document.getElementById('tree-container');
const dropArea = document.getElementById('drop-area');
const fileInput = document.getElementById('file-input');
// controls operation table visibility
document.addEventListener('click', function(event) {
if (event.target.id.includes('forward-operations-caret')) {
const fqn = event.target.id.split('-')[0];
const operationsListId = `${fqn}-forward-operations-list`;
const operationsList = document.getElementById(operationsListId);
if (operationsList) {
operationsList.style.display = operationsList.style.display === 'none' ? 'block' : 'none';
}
}
if (event.target.id.includes('backward-operations-caret')) {
const fqn = event.target.id.split('-')[0];
const operationsListId = `${fqn}-backward-operations-list`;
const operationsList = document.getElementById(operationsListId);
if (operationsList) {
operationsList.style.display = operationsList.style.display === 'none' ? 'block' : 'none';
}
}
if (event.target.id.includes('checkpointing-operations-caret')) {
const fqn = event.target.id.split('-')[0];
const operationsListId = `${fqn}-checkpointing-operations-list`;
const operationsList = document.getElementById(operationsListId);
if (operationsList) {
operationsList.style.display = operationsList.style.display === 'none' ? 'block' : 'none';
}
}
if (event.target.id.includes('module-information-caret')) {
const fqn = event.target.id.split('-')[0];
const operationsListId = `${fqn}-module-information`;
const operationsList = document.getElementById(operationsListId);
if (operationsList) {
operationsList.style.display = operationsList.style.display === 'none' ? 'block' : 'none';
}
}
});
// controls module visibility
container.addEventListener('click', function(event) {
const target = event.target
if (target && target.classList.contains('caret')) {
target.classList.toggle('caret-down');
const nestedList = target.parentElement.querySelector('.nested');
if (nestedList) {
nestedList.classList.toggle('active')
}
}
});
// allows user to choose file via drag and drop
dropArea.addEventListener('drop', (event) => {
event.preventDefault();
const files = event.dataTransfer.files;
const file = files[0];
// Read the contents of the JSON file
const reader = new FileReader();
reader.onload = () => {
const jsonData = JSON.parse(reader.result);
container.innerHTML = buildTree([jsonData]);
};
reader.readAsText(file);
});
// allows user to choose file via file selector
fileInput.addEventListener('change', (event) => {
const file = event.target.files[0];
// Read the contents of the JSON file
const reader = new FileReader();
reader.onload = () => {
const jsonData = JSON.parse(reader.result);
container.innerHTML = buildTree([jsonData]);
};
reader.readAsText(file);
});
// prevents users from dragging and dropping file outside selection zone and opening file in new tab
document.addEventListener('drop', function(event) {
event.preventDefault();
});
});
|