File size: 18,141 Bytes
feba2ad |
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 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
// Global variables
let trainingData = null;
let charts = {};
// Color palette for different runs
const colors = [
'#667eea', '#764ba2', '#f093fb', '#f5576c', '#4facfe', '#00f2fe',
'#43e97b', '#38f9d7', '#fa7093', '#fee140', '#a8edea', '#fed6e3'
];
// Initialize the dashboard
document.addEventListener('DOMContentLoaded', function() {
loadData();
setupEventListeners();
});
// Load training data from JSON file
async function loadData() {
try {
const response = await fetch('data.json');
trainingData = await response.json();
// Merge continuation logs from the same model run
mergeContinuationLogs();
populateRunSelector();
createCharts();
updateRunSummary();
updateConfigDetails();
console.log('Data loaded and merged successfully:', trainingData);
} catch (error) {
console.error('Error loading data:', error);
document.body.innerHTML = '<div class="loading">Error loading training data. Please check the console for details.</div>';
}
}
// Merge continuation logs from the same model run
function mergeContinuationLogs() {
const runGroups = {};
// Group runs by base model name
trainingData.runs.forEach(run => {
const baseName = run.run_name;
if (!runGroups[baseName]) {
runGroups[baseName] = [];
}
runGroups[baseName].push(run);
});
// Merge runs with the same base name
const mergedRuns = [];
Object.entries(runGroups).forEach(([baseName, runs]) => {
if (runs.length === 1) {
// Single run, no merging needed
mergedRuns.push(runs[0]);
} else {
// Multiple runs to merge
console.log(`Merging ${runs.length} continuation logs for ${baseName}`);
const mergedRun = {
run_name: baseName,
log_files: runs.map(r => r.log_file),
training_metrics: [],
evaluation_results: [],
config: runs[0].config || {}
};
// Merge training metrics (they should be continuous)
runs.forEach(run => {
if (run.training_metrics) {
mergedRun.training_metrics.push(...run.training_metrics);
}
});
// Merge evaluation results (they should be continuous)
runs.forEach(run => {
if (run.evaluation_results) {
mergedRun.evaluation_results.push(...run.evaluation_results);
}
});
// Sort by step number to ensure proper ordering
mergedRun.training_metrics.sort((a, b) => a.step - b.step);
mergedRun.evaluation_results.sort((a, b) => a.step - b.step);
// Remove duplicates based on step number
mergedRun.training_metrics = mergedRun.training_metrics.filter((metric, index, self) =>
index === 0 || metric.step !== self[index - 1].step
);
mergedRun.evaluation_results = mergedRun.evaluation_results.filter((result, index, self) =>
index === 0 || result.step !== self[index - 1].step
);
console.log(`Merged ${baseName}: ${mergedRun.training_metrics.length} training points, ${mergedRun.evaluation_results.length} eval points`);
mergedRuns.push(mergedRun);
}
});
trainingData.runs = mergedRuns;
}
// Setup event listeners for controls
function setupEventListeners() {
document.getElementById('runSelect').addEventListener('change', function() {
updateCharts();
updateRunSummary();
updateConfigDetails();
});
document.getElementById('showTraining').addEventListener('change', updateCharts);
document.getElementById('showLearningRate').addEventListener('change', updateCharts);
document.getElementById('showEvaluation').addEventListener('change', updateCharts);
}
// Populate run selector dropdown
function populateRunSelector() {
const select = document.getElementById('runSelect');
const runs = trainingData.runs;
// Clear existing options
select.innerHTML = '<option value="all">All Runs</option>';
runs.forEach((run, index) => {
const option = document.createElement('option');
option.value = index;
option.textContent = run.run_name;
select.appendChild(option);
});
}
// Create all charts
function createCharts() {
createLossChart();
createLRChart();
createEvalChart();
createCombinedChart();
}
// Create training loss chart
function createLossChart() {
const ctx = document.getElementById('lossChart').getContext('2d');
charts.loss = new Chart(ctx, {
type: 'line',
data: getChartData('loss'),
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
title: {
display: true,
text: 'Training Loss Over Time'
},
legend: {
position: 'top'
}
},
scales: {
x: {
type: 'linear',
title: {
display: true,
text: 'Training Step'
}
},
y: {
title: {
display: true,
text: 'Loss'
},
beginAtZero: false
}
},
interaction: {
intersect: false,
mode: 'index'
}
}
});
}
// Create learning rate chart
function createLRChart() {
const ctx = document.getElementById('lrChart').getContext('2d');
charts.lr = new Chart(ctx, {
type: 'line',
data: getChartData('lr'),
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
title: {
display: true,
text: 'Learning Rate Schedule'
},
legend: {
position: 'top'
}
},
scales: {
x: {
type: 'linear',
title: {
display: true,
text: 'Training Step'
}
},
y: {
title: {
display: true,
text: 'Learning Rate'
},
type: 'logarithmic'
}
},
interaction: {
intersect: false,
mode: 'index'
}
}
});
}
// Create evaluation chart
function createEvalChart() {
const ctx = document.getElementById('evalChart').getContext('2d');
charts.eval = new Chart(ctx, {
type: 'line',
data: getChartData('eval'),
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
title: {
display: true,
text: 'Paloma Evaluation Metrics'
},
legend: {
position: 'top'
}
},
scales: {
x: {
type: 'linear',
title: {
display: true,
text: 'Training Step'
}
},
y: {
title: {
display: true,
text: 'Perplexity'
},
type: 'logarithmic'
}
},
interaction: {
intersect: false,
mode: 'index'
}
}
});
}
// Create combined chart
function createCombinedChart() {
const ctx = document.getElementById('combinedChart').getContext('2d');
charts.combined = new Chart(ctx, {
type: 'line',
data: getCombinedChartData(),
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
title: {
display: true,
text: 'Combined Training Metrics'
},
legend: {
position: 'top'
}
},
scales: {
x: {
type: 'linear',
title: {
display: true,
text: 'Training Step'
}
},
y: {
title: {
display: true,
text: 'Value'
}
}
},
interaction: {
intersect: false,
mode: 'index'
}
}
});
}
// Get chart data for specific metric type
function getChartData(metricType) {
const selectedRun = document.getElementById('runSelect').value;
const runs = selectedRun === 'all' ? trainingData.runs : [trainingData.runs[selectedRun]];
const datasets = [];
console.log(`Getting ${metricType} data for ${runs.length} runs:`, runs.map(r => r.run_name));
runs.forEach((run, runIndex) => {
const color = colors[runIndex % colors.length];
if (metricType === 'loss') {
if (run.training_metrics && run.training_metrics.length > 0) {
const data = run.training_metrics.map(m => ({ x: m.step, y: m.loss }));
console.log(`Loss data for ${run.run_name}:`, data.slice(0, 5), '...', data.slice(-5));
datasets.push({
label: run.run_name,
data: data,
borderColor: color,
backgroundColor: color + '20',
borderWidth: 2,
fill: false,
tension: 0.1
});
}
} else if (metricType === 'lr') {
if (run.training_metrics && run.training_metrics.length > 0) {
const data = run.training_metrics.map(m => ({ x: m.step, y: m.learning_rate }));
console.log(`LR data for ${run.run_name}:`, data.slice(0, 5), '...', data.slice(-5));
datasets.push({
label: run.run_name,
data: data,
borderColor: color,
backgroundColor: color + '20',
borderWidth: 2,
fill: false,
tension: 0.1
});
}
} else if (metricType === 'eval') {
if (run.evaluation_results && run.evaluation_results.length > 0) {
const data = run.evaluation_results.map(m => ({ x: m.step, y: m.paloma }));
console.log(`Eval data for ${run.run_name}:`, data.slice(0, 5), '...', data.slice(-5));
datasets.push({
label: run.run_name,
data: data,
borderColor: color,
backgroundColor: color + '20',
borderWidth: 2,
fill: false,
tension: 0.1
});
}
}
});
console.log(`Final ${metricType} datasets:`, datasets);
return { datasets };
}
// Get combined chart data
function getCombinedChartData() {
const selectedRun = document.getElementById('runSelect').value;
const runs = selectedRun === 'all' ? trainingData.runs : [trainingData.runs[selectedRun]];
const datasets = [];
runs.forEach((run, runIndex) => {
const color = colors[runIndex % colors.length];
// Training loss
if (run.training_metrics && run.training_metrics.length > 0) {
datasets.push({
label: `${run.run_name} - Loss`,
data: run.training_metrics.map(m => ({ x: m.step, y: m.loss })),
borderColor: color,
backgroundColor: color + '20',
borderWidth: 2,
fill: false,
tension: 0.1
});
}
// Learning rate (scaled)
if (run.training_metrics && run.training_metrics.length > 0) {
const maxLR = Math.max(...run.training_metrics.map(m => m.learning_rate));
const maxLoss = Math.max(...run.training_metrics.map(m => m.loss));
const scaleFactor = maxLoss / maxLR;
datasets.push({
label: `${run.run_name} - LR (scaled)`,
data: run.training_metrics.map(m => ({ x: m.step, y: m.learning_rate * scaleFactor })),
borderColor: color + '80',
backgroundColor: color + '10',
borderWidth: 1,
fill: false,
tension: 0.1
});
}
});
return { datasets };
}
// Update all charts based on current selection
function updateCharts() {
if (charts.loss) {
charts.loss.data = getChartData('loss');
charts.loss.update();
}
if (charts.lr) {
charts.lr.data = getChartData('lr');
charts.lr.update();
}
if (charts.eval) {
charts.eval.data = getChartData('eval');
charts.eval.update();
}
if (charts.combined) {
charts.combined.data = getCombinedChartData();
charts.combined.update();
}
}
// Update run summary section
function updateRunSummary() {
const container = document.getElementById('runSummary');
const selectedRun = document.getElementById('runSelect').value;
const runs = selectedRun === 'all' ? trainingData.runs : [trainingData.runs[selectedRun]];
let html = '<div class="run-grid">';
runs.forEach(run => {
const trainingPoints = run.training_metrics ? run.training_metrics.length : 0;
const evalPoints = run.evaluation_results ? run.evaluation_results.length : 0;
let finalLoss = 'N/A';
let finalLR = 'N/A';
let finalPaloma = 'N/A';
let stepRange = 'N/A';
if (run.training_metrics && run.training_metrics.length > 0) {
const first = run.training_metrics[0];
const last = run.training_metrics[run.training_metrics.length - 1];
finalLoss = last.loss.toFixed(4);
finalLR = last.learning_rate.toExponential(2);
stepRange = `${first.step} → ${last.step}`;
}
if (run.evaluation_results && run.evaluation_results.length > 0) {
const last = run.evaluation_results[run.evaluation_results.length - 1];
if (isFinite(last.paloma)) {
finalPaloma = last.paloma.toExponential(2);
} else {
finalPaloma = '∞';
}
}
const logFiles = run.log_files ? run.log_files.join(', ') : run.log_file;
html += `
<div class="run-card">
<h4>${run.run_name}</h4>
<p><strong>Logs:</strong> ${logFiles}</p>
<div class="metric">
<span>Step Range:</span>
<span class="value">${stepRange}</span>
</div>
<div class="metric">
<span>Training Points:</span>
<span class="value">${trainingPoints}</span>
</div>
<div class="metric">
<span>Evaluation Points:</span>
<span class="value">${evalPoints}</span>
</div>
<div class="metric">
<span>Final Loss:</span>
<span class="value">${finalLoss}</span>
</div>
<div class="metric">
<span>Final LR:</span>
<span class="value">${finalLR}</span>
</div>
<div class="metric">
<span>Final Paloma:</span>
<span class="value">${finalPaloma}</span>
</div>
</div>
`;
});
html += '</div>';
container.innerHTML = html;
}
// Update configuration details section
function updateConfigDetails() {
const container = document.getElementById('configDetails');
const selectedRun = document.getElementById('runSelect').value;
const runs = selectedRun === 'all' ? trainingData.runs : [trainingData.runs[selectedRun]];
let html = '<div class="config-grid">';
// Get unique config keys
const allKeys = new Set();
runs.forEach(run => {
if (run.config) {
Object.keys(run.config).forEach(key => allKeys.add(key));
}
});
allKeys.forEach(key => {
const values = runs.map(run => run.config && run.config[key] !== undefined ? run.config[key] : 'N/A');
const uniqueValues = [...new Set(values)];
const displayValue = uniqueValues.length === 1 ? uniqueValues[0] : `${uniqueValues.join(' / ')}`;
html += `
<div class="config-item">
<div class="label">${key.replace(/_/g, ' ').toUpperCase()}</div>
<div class="value">${displayValue}</div>
</div>
`;
});
html += '</div>';
container.innerHTML = html;
}
// Utility function to format large numbers
function formatNumber(num) {
if (num >= 1e9) return (num / 1e9).toFixed(2) + 'B';
if (num >= 1e6) return (num / 1e6).toFixed(2) + 'M';
if (num >= 1e3) return (num / 1e3).toFixed(2) + 'K';
return num.toString();
}
|