-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtrain.html
More file actions
741 lines (678 loc) · 25.9 KB
/
train.html
File metadata and controls
741 lines (678 loc) · 25.9 KB
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
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Training Memory Visualization - The GPU Memory Challenge</title>
<style>
:root {
--primary-red: #ff4444;
--light-red: #ff8888;
--accent-orange: #ffa500;
--accent-yellow: #ffd700;
--dark-ink: #0b1026;
--surface: rgba(10, 16, 44, 0.92);
--surface-2: rgba(13, 22, 58, 0.85);
--border: rgba(255, 100, 100, 0.45);
--text-primary: #eaf2ff;
--text-secondary: #ffd4d4;
--text-muted: #e0a5a5;
--accent-warn: #ff6b00;
--success-green: #4caf50;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', monospace;
background: linear-gradient(135deg, #0a0a0a 0%, #1a0a0a 100%);
color: var(--text-primary);
overflow: hidden;
position: relative;
}
canvas {
display: block;
}
.header {
position: absolute;
top: 20px;
left: 50%;
transform: translateX(-50%);
text-align: center;
z-index: 10;
}
h1 {
font-size: 2.8em;
margin-bottom: 8px;
background: linear-gradient(135deg, var(--primary-red) 0%, var(--accent-orange) 100%);
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
text-shadow: 0 2px 20px rgba(255, 68, 68, 0.3);
font-weight: 800;
letter-spacing: -0.02em;
}
.subtitle {
color: var(--text-secondary);
font-size: 1.1em;
opacity: 0.9;
}
.info-panel {
position: absolute;
top: 100px;
left: 30px;
background: var(--surface);
border: 1px solid var(--border);
border-radius: 14px;
padding: 15px 18px;
backdrop-filter: blur(10px);
box-shadow: 0 10px 40px rgba(255, 68, 68, 0.2);
max-width: 290px;
}
.info-panel h3 {
color: var(--light-red);
margin-bottom: 12px;
font-size: 0.85em;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.info-item {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
font-size: 0.8em;
}
.info-label {
color: var(--text-muted);
}
.info-value {
color: var(--text-primary);
font-weight: bold;
}
.controls {
position: fixed; /* Fixed instead of absolute */
bottom: 30px;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 12px;
z-index: 20;
flex-wrap: wrap;
justify-content: center;
max-width: 90%;
height: auto; /* Explicit height */
}
button {
background: linear-gradient(180deg, rgba(255, 68, 68, 0.2), rgba(255, 68, 68, 0.1));
border: 2px solid var(--primary-red);
color: var(--text-primary);
padding: 10px 18px;
border-radius: 22px;
cursor: pointer;
transition: all 0.3s ease;
font-weight: 600;
font-size: 0.85em;
text-transform: uppercase;
letter-spacing: 0.5px;
backdrop-filter: blur(5px);
font-family: inherit;
min-width: 140px; /* Prevent size changes */
}
#playPause {
min-width: 180px; /* Larger for play/pause button */
}
/* Fixed widths for buttons that change content to prevent layout jumping */
#speedControl {
width: 120px;
}
#modelControl {
width: 160px;
}
#batchControl {
width: 100px;
}
#seqControl {
width: 110px;
}
#optimizerControl {
width: 150px;
}
#gpuControl {
width: 150px;
}
#gpuCountControl {
width: 100px;
}
#interconnectControl {
width: 140px;
}
#worldDCControl {
width: 160px;
}
button:hover {
background: linear-gradient(180deg, rgba(255, 68, 68, 0.35), rgba(255, 68, 68, 0.25));
transform: translateY(-2px);
box-shadow: 0 5px 20px rgba(255, 68, 68, 0.3);
}
.btn-two-line {
display: flex;
flex-direction: column;
line-height: 1.1;
align-items: center;
}
.btn-two-line .caption {
font-size: 0.72em;
opacity: 0.9;
text-transform: none;
letter-spacing: 0;
}
.btn-two-line.enabled {
background: linear-gradient(135deg, var(--accent-orange), var(--primary-red)) !important;
border-color: var(--accent-orange) !important;
box-shadow: 0 0 15px rgba(255, 165, 0, 0.4) !important;
}
.memory-breakdown {
position: absolute;
top: 100px;
right: 30px;
background: var(--surface);
border: 1px solid var(--border);
border-radius: 14px;
padding: 15px 18px;
backdrop-filter: blur(10px);
max-width: 260px;
}
.memory-bar {
width: 100%;
height: 20px;
background: rgba(255, 255, 255, 0.05);
border-radius: 10px;
overflow: hidden;
margin: 5px 0;
display: flex;
}
.memory-segment {
height: 100%;
transition: width 0.3s ease;
position: relative;
}
.loss-curve {
position: absolute;
bottom: 120px;
right: 30px;
background: var(--surface);
border: 1px solid var(--border);
border-radius: 14px;
padding: 15px;
width: 280px;
height: 150px;
}
#warning {
position: absolute;
top: 20px;
right: 20px;
transform: none;
background: rgba(255, 100, 0, 0.2);
border: 2px solid var(--accent-warn);
padding: 20px 30px;
border-radius: 15px;
font-size: 0.9em;
font-weight: 600;
visibility: hidden;
opacity: 0;
transition:
opacity 0.3s ease,
visibility 0.3s ease;
backdrop-filter: blur(10px);
z-index: 5;
pointer-events: none;
text-align: center;
max-width: 600px;
}
/* Navigation link */
.nav-link {
position: absolute;
bottom: 10px;
left: 10px;
font-size: 10px;
z-index: 5;
}
.nav-link a {
color: rgba(255, 136, 136, 0.6);
text-decoration: none;
opacity: 0.7;
transition: opacity 0.3s;
}
.nav-link a:hover {
opacity: 1;
}
/* Mobile responsiveness */
@media (max-width: 768px) {
body {
overflow: hidden;
position: fixed;
width: 100%;
height: 100%;
}
h1 {
font-size: 1.8em;
}
.subtitle {
font-size: 0.9em;
}
/* Make canvas fullscreen behind panels */
canvas {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
z-index: 1;
}
/* Panels flow as content above canvas */
.info-panel,
.memory-breakdown,
.training-interconnect-metrics,
.training-performance-box {
position: static !important;
margin: 10px;
max-width: calc(100% - 20px);
z-index: 2;
}
.loss-curve {
display: none;
}
/* Hide nav and center attribution on mobile */
.nav-link {
display: none !important;
}
div[style*='bottom: 10px'][style*='left: 50%'] {
display: none !important;
}
/* Bottom control bar: horizontal scroll with safe-area padding */
.controls {
position: fixed;
bottom: 0;
left: 0;
right: 0;
transform: none;
padding: 12px 16px;
padding-bottom: calc(12px + constant(safe-area-inset-bottom));
padding-bottom: calc(12px + env(safe-area-inset-bottom));
background: linear-gradient(
0deg,
rgba(26, 10, 10, 0.98) 0%,
rgba(26, 10, 10, 0.95) 80%,
rgba(26, 10, 10, 0.85) 100%
);
backdrop-filter: blur(12px);
border-top: 1px solid var(--border);
z-index: 100;
display: flex;
flex-wrap: nowrap;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
gap: 8px;
box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.3);
scroll-snap-type: x proximity;
justify-content: flex-start;
max-width: none;
height: auto;
}
.controls::-webkit-scrollbar {
display: none;
}
.controls {
scrollbar-width: none;
-ms-overflow-style: none;
}
button {
padding: 10px 10px;
font-size: 0.75em;
min-width: unset;
border-width: 1.5px;
white-space: nowrap;
flex: 0 0 auto;
scroll-snap-align: start;
}
#playPause {
min-width: 140px;
}
/* Mobile warning placement below header */
#warning {
position: fixed;
top: calc(var(--mobile-header-bottom, 56px) + 12px);
left: 16px;
right: 16px;
margin: 0;
padding: 12px 14px;
border-radius: 10px;
font-size: 0.85em;
z-index: 99;
}
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<div class="header">
<h1>Training Memory Explosion</h1>
<div class="subtitle">Watch GPU memory consumed by weights, gradients, optimizer states & activations</div>
</div>
<div class="info-panel">
<h3>Training Configuration</h3>
<div class="info-item">
<span class="info-label">Model:</span>
<span class="info-value" id="modelName">Llama-3.2-1B</span>
</div>
<div class="info-item">
<span class="info-label">Parameters:</span>
<span class="info-value" id="paramCount">1.2B</span>
</div>
<div class="info-item">
<span class="info-label">Batch Size:</span>
<span class="info-value" id="batchInfo">4</span>
</div>
<div class="info-item">
<span class="info-label">Sequence Length:</span>
<span class="info-value" id="seqLength">1024</span>
</div>
<div class="info-item">
<span class="info-label">Learning Rate:</span>
<span class="info-value" id="learningRate">5e-5</span>
</div>
<div class="info-item">
<span class="info-label">Step:</span>
<span class="info-value" id="stepCount">0 / 100K</span>
</div>
<div class="info-item">
<span class="info-label">Total Memory:</span>
<span class="info-value" id="totalMem">0 GiB</span>
</div>
<div class="info-item">
<span class="info-label">GPU Required:</span>
<span class="info-value" id="gpuCount">1× H100</span>
</div>
</div>
<!-- Training Interconnect Metrics box -->
<div
class="training-interconnect-metrics"
id="trainingInterconnectMetrics"
style="
position: absolute;
top: 350px;
left: 30px;
background: var(--surface);
border: 1px solid var(--border);
border-radius: 14px;
padding: 15px 18px;
backdrop-filter: blur(10px);
max-width: 290px;
"
>
<h3
style="
color: var(--light-red);
margin-bottom: 12px;
font-size: 0.85em;
text-transform: uppercase;
letter-spacing: 0.05em;
"
>
Interconnect Impact
</h3>
<div id="interconnectMetricsContent" style="font-size: 0.8em; line-height: 1.4">
<div class="info-item">
<span class="info-label">Throughput:</span>
<span class="info-value" id="trainingThroughput">100%</span>
</div>
<div class="info-item">
<span class="info-label">Step Time:</span>
<span class="info-value" id="stepTime">250ms</span>
</div>
<div class="info-item">
<span class="info-label">Data Movement:</span>
<span class="info-value" id="dataMovement">0.8 GB/s</span>
</div>
<div class="info-item">
<span class="info-label">Efficiency:</span>
<span class="info-value" id="trainingEfficiency">95%</span>
</div>
</div>
</div>
<div class="memory-breakdown">
<h3 style="color: var(--light-red); margin-bottom: 12px; font-size: 0.85em">Memory Breakdown</h3>
<div class="info-item">
<span class="info-label">Model Weights:</span>
<span class="info-value" id="weightsSize">16 GiB</span>
</div>
<div class="memory-bar">
<div class="memory-segment" id="weightsBar" style="background: #9c27b0; width: 25%"></div>
</div>
<div class="info-item">
<span class="info-label">Gradients:</span>
<span class="info-value" id="gradientsSize">16 GiB</span>
</div>
<div class="memory-bar">
<div class="memory-segment" id="gradientsBar" style="background: #ff9800; width: 25%"></div>
</div>
<div class="info-item">
<span class="info-label">Optimizer (Adam):</span>
<span class="info-value" id="optimizerSize">32 GiB</span>
</div>
<div class="memory-bar">
<div class="memory-segment" id="optimizerBar" style="background: #f44336; width: 50%"></div>
</div>
<div class="info-item">
<span class="info-label">Activations:</span>
<span class="info-value" id="activationsSize">8 GiB</span>
</div>
<div class="memory-bar">
<div class="memory-segment" id="activationsBar" style="background: #4caf50; width: 12.5%"></div>
</div>
</div>
<div class="loss-curve">
<h3 style="color: var(--light-red); margin-bottom: 10px; font-size: 0.85em">Training Loss</h3>
<canvas id="lossCanvas" width="250" height="100"></canvas>
</div>
<!-- Training Performance Impact box -->
<div
class="training-performance-box"
id="trainingPerformanceBox"
style="
display: none;
position: absolute;
top: 350px;
left: 30px;
background: var(--surface);
border: 1px solid var(--border);
border-radius: 14px;
padding: 15px 18px;
backdrop-filter: blur(10px);
max-width: 260px;
"
>
<h3
style="
color: var(--light-red);
margin-bottom: 12px;
font-size: 0.85em;
text-transform: uppercase;
letter-spacing: 0.05em;
"
>
Training Impact
</h3>
<div id="trainingMetricsContent" style="font-size: 0.72em; line-height: 1.4">
<!-- Will be populated by JavaScript -->
</div>
</div>
<div class="controls">
<button id="playPause">▶️ Start Training</button>
<button id="speedControl">Speed: 50x</button>
<button id="modelControl">Model: Llama-1B</button>
<button id="batchControl">Batch: 4</button>
<button id="seqControl">Seq: 1024</button>
<button id="optimizerControl">Optimizer: AdamW</button>
<button
id="gcToggle"
class="btn-two-line enabled"
title="Gradient Checkpointing - trade compute for memory"
>
<span>GC: ON</span>
<span class="caption">grad checkpoint</span>
</button>
<button
id="mpToggle"
class="btn-two-line enabled"
title="Mixed Precision - FP16 compute with FP32 master weights"
>
<span>MP: ON</span>
<span class="caption">mixed precision</span>
</button>
<button id="zeroToggle" class="btn-two-line" title="ZeRO Optimization - shard optimizer states">
<span>ZeRO: OFF</span>
<span class="caption">DeepSpeed ZeRO</span>
</button>
<button id="fsdpToggle" class="btn-two-line" title="Fully Sharded Data Parallel">
<span>FSDP: OFF</span>
<span class="caption">fully sharded</span>
</button>
<button id="gaToggle" class="btn-two-line" title="Gradient Accumulation - simulate larger batches">
<span>GA: OFF</span>
<span class="caption">grad accumulation</span>
</button>
<button id="gpuControl">GPU: H100 80G</button>
<button id="gpuCountControl" title="Number of GPUs for distributed training">GPUs: 1</button>
<button id="interconnectControl" title="Select PCIe generation or interconnect type">Link: PCIe 5.0</button>
<button id="worldDCControl" title="Simulate famous training clusters">DC: None</button>
</div>
<!-- Navigation back to inference -->
<div class="nav-link">
<a href="inference.html">← Inference (KV Cache) Simulation</a>
</div>
<div
style="
position: absolute;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
text-align: center;
color: #999;
font-size: 11px;
z-index: 5;
"
>
<div>
Training Memory Visualization |
<a
href="https://github.com/LMCache/kvcache-view"
target="_blank"
style="color: var(--light-red); text-decoration: none"
>
kvcache-view
</a>
</div>
</div>
<script src="train-visualization.js"></script>
<script>
// --- Mobile helpers to set header offset and compact control labels ---
function setMobileHeaderBottomVar() {
if (window.innerWidth > 768) return
const header = document.querySelector('.header')
if (!header) return
const rect = header.getBoundingClientRect()
document.documentElement.style.setProperty('--mobile-header-bottom', rect.bottom + 'px')
}
function storeOriginal(el) {
if (el && el.dataset && el.dataset.originalText === undefined) {
el.dataset.originalText = el.innerText
}
}
function shortenControlLabels() {
if (window.innerWidth > 768) return
const mapStatic = {
modelControl: 'Model',
interconnectControl: 'Link',
worldDCControl: 'DC',
}
Object.entries(mapStatic).forEach(([id, label]) => {
const el = document.getElementById(id)
if (el) {
storeOriginal(el)
el.innerText = label
}
})
const pairs = [
['speedControl', /^Speed:/, 'Spd:'],
['batchControl', /^Batch:\s*/, 'Batch: '],
['seqControl', /^Seq(ence)?:\s*/i, 'Seq: '],
['optimizerControl', /^Optimizer:\s*/i, 'Opt: '],
['gpuControl', /^Device:/, 'GPU:'],
['gpuCountControl', /^GPUs:\s*/, 'GPUs: '],
]
pairs.forEach(([id, re, rep]) => {
const el = document.getElementById(id)
if (el) {
storeOriginal(el)
el.innerText = el.innerText.replace(re, rep)
}
})
}
function restoreControlLabels() {
const ids = [
'playPause',
'speedControl',
'modelControl',
'seqControl',
'batchControl',
'optimizerControl',
'gpuControl',
'gpuCountControl',
'interconnectControl',
'worldDCControl',
]
ids.forEach((id) => {
const el = document.getElementById(id)
if (el && el.dataset && el.dataset.originalText !== undefined) {
el.innerText = el.dataset.originalText
delete el.dataset.originalText
}
})
}
function setupControlsObserver() {
const controls = document.querySelector('.controls')
if (!controls || window._trainControlsObserver) return
const mo = new MutationObserver(() => {
if (window.innerWidth <= 768) {
shortenControlLabels()
setMobileHeaderBottomVar()
}
})
mo.observe(controls, { subtree: true, childList: true, characterData: true })
window._trainControlsObserver = mo
}
function teardownControlsObserver() {
if (window._trainControlsObserver) {
window._trainControlsObserver.disconnect()
window._trainControlsObserver = null
}
}
function updateMobileLayout() {
if (window.innerWidth <= 768) {
setMobileHeaderBottomVar()
shortenControlLabels()
setupControlsObserver()
} else {
restoreControlLabels()
document.documentElement.style.removeProperty('--mobile-header-bottom')
teardownControlsObserver()
}
}
window.addEventListener('load', updateMobileLayout)
window.addEventListener('resize', updateMobileLayout)
</script>
</body>
</html>