-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1157 lines (1063 loc) · 52.1 KB
/
index.html
File metadata and controls
1157 lines (1063 loc) · 52.1 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="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vortex: Democratizing Sparse Attention</title>
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- React & ReactDOM (Stable 18.2.0) -->
<script src="https://unpkg.com/react@18.2.0/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@18.2.0/umd/react-dom.development.js" crossorigin></script>
<!-- Prop-Types (Required for Recharts) -->
<script src="https://unpkg.com/prop-types/prop-types.min.js"></script>
<!-- Babel for JSX -->
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<!-- Recharts (Stable 2.12.7) -->
<script src="https://unpkg.com/recharts@2.12.7/umd/Recharts.js"></script>
<style>
body { font-family: 'Inter', sans-serif; }
.loader {
border: 4px solid #f3f3f3;
border-top: 4px solid #3b82f6;
border-radius: 50%;
width: 30px;
height: 30px;
animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
</style>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css"
/>
<script
defer
src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js"
></script>
</head>
<body class="bg-slate-50">
<div id="root" class="min-h-screen flex items-center justify-center">
<div class="text-slate-400 flex flex-col items-center gap-4">
<div class="loader"></div>
<p>Loading Vortex Blog...</p>
</div>
</div>
<script type="text/babel">
try {
if (!window.React || !window.ReactDOM || !window.Recharts) {
throw new Error("External libraries failed to load.");
}
const { useState, useEffect } = React;
const { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, Cell } = Recharts;
// --- Icons ---
const Icon = ({ name, className }) => {
const paths = {
ArrowRight: "M5 12h14M12 5l7 7-7 7",
Layers: "M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",
Cpu: "M12 2v2M12 20v2M2 12h2M20 12h2M5 5h14v14H5zM8.5 8.5h7v7h-7z",
Zap: "M13 2L3 14h9l-1 8 10-12h-9l1-8z",
Box: "M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16zM3.27 6.96L12 12.01l8.73-5.05M12 22.08V12",
Lock: "M19 11H5a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-6a2 2 0 0 0-2-2zm-7-9a6 6 0 0 1 6 6v3h-12v-3a6 6 0 0 1 6-6z",
AlertTriangle: "M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0zM12 9v4M12 17h.01",
Code: "M16 18l6-6-6-6M8 6l-6 6 6 6",
Server: "M2 12h20M2 18h20M2 6h20M6 6v12M18 6v12",
Database: "M3 6h18M3 12h18M3 18h18",
GitBranch: "M6 3v12",
Check: "M20 6L9 17l-5-5",
User: "M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2M12 7a4 4 0 1 0 0-8 4 4 0 0 0 0 8z",
Clock: "M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zM12 6v6l4 2",
Activity: "M22 12h-4l-3 9L9 3l-3 9H2",
Brain: "M9.5 2A2.5 2.5 0 0 1 12 4.5v15a2.5 2.5 0 0 1-4.96.44 2.5 2.5 0 0 1-2.96-3.08 3 3 0 0 1-.34-5.58 2.5 2.5 0 0 1 1.32-4.24 2.5 2.5 0 0 1 4.44-4zM14.5 2A2.5 2.5 0 0 0 12 4.5v15a2.5 2.5 0 0 0 4.96.44 2.5 2.5 0 0 0 2.96-3.08 3 3 0 0 0 .34-5.58 2.5 2.5 0 0 0-1.32-4.24 2.5 2.5 0 0 0-4.44-4z",
FileText: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8zM14 2v6h6M10 11h6M10 15h6M10 19h4"
};
return (
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" className={className}>
{paths[name] ? <path d={paths[name]} /> : <circle cx="12" cy="12" r="10"/>}
{name === 'Check' && <polyline points="20 6 9 17 5 12" />}
{name === 'GitBranch' && <g><line x1="6" y1="3" x2="6" y2="15"></line><circle cx="18" cy="6" r="3"></circle><circle cx="6" cy="18" r="3"></circle><path d="M18 9a9 9 0 0 1-9 9"></path></g>}
{name === 'Layers' && <polyline points="2 17 12 22 22 17" />}
{name === 'Layers' && <polyline points="2 12 12 17 22 12" />}
</svg>
);
};
// --- Data ---
// --- Components ---
const SectionHeader = ({ title }) => (
<div className="flex items-center gap-3 mb-6 mt-12">
<h2 className="text-2xl font-bold text-slate-900 tracking-tight">{title}</h2>
</div>
);
const Callout = ({ title, children, type = "default" }) => {
const colors = {
default: "bg-slate-50 border-slate-200 text-slate-700",
warning: "bg-amber-50 border-amber-200 text-amber-800",
success: "bg-green-50 border-green-200 text-green-800",
};
const icons = {
default: "Box",
warning: "AlertTriangle",
success: "Zap",
};
return (
<div className={`p-6 rounded-lg mb-8 border ${colors[type]}`}>
<h3 className="font-bold text-sm uppercase tracking-wide mb-3 flex items-center gap-2">
<Icon name={icons[type]} className="w-4 h-4" /> {title}
</h3>
<div className="text-sm leading-relaxed opacity-90">{children}</div>
</div>
);
};
const SystemDilemma = () => (
<div className="grid md:grid-cols-2 gap-6 my-8">
<div className="border border-slate-200 rounded-xl p-6 bg-white hover:shadow-md transition-shadow">
<div className="w-10 h-10 bg-slate-100 rounded-lg flex items-center justify-center mb-4">
<Icon name="Lock" className="w-5 h-5 text-slate-600" />
</div>
<h4 className="font-bold text-slate-900 mb-2">Full Stack Builder</h4>
<p className="text-xs text-slate-500 mb-4">Tight coupling of algo & kernel.</p>
<ul className="text-sm text-slate-600 space-y-2">
<li className="flex gap-2"><span className="text-green-500">✓</span> High Performance</li>
<li className="flex gap-2"><span className="text-red-500">✗</span> Zero Flexibility</li>
<li className="flex gap-2"><span className="text-red-500">✗</span> Maintenance Nightmare</li>
</ul>
</div>
<div className="border border-slate-200 rounded-xl p-6 bg-white hover:shadow-md transition-shadow">
<div className="w-10 h-10 bg-slate-100 rounded-lg flex items-center justify-center mb-4">
<Icon name="Server" className="w-5 h-5 text-slate-600" />
</div>
<h4 className="font-bold text-slate-900 mb-2">General Purpose Builder</h4>
<p className="text-xs text-slate-500 mb-4">Broad platform support.</p>
<ul className="text-sm text-slate-600 space-y-2">
<li className="flex gap-2"><span className="text-green-500">✓</span> Stable Platform</li>
<li className="flex gap-2"><span className="text-red-500">✗</span> Slow Adoption</li>
<li className="flex gap-2"><span className="text-red-500">✗</span> Limited Algorithm Support</li>
</ul>
</div>
</div>
);
const DeepLearningArchitecture = () => (
// Outer Container (Mimics Terminal Window)
<div className="my-10 bg-slate-900 rounded-xl shadow-2xl ring-1 ring-slate-900/5">
{/* Title Bar */}
<div className="bg-slate-800/50 px-6 py-3 border-b border-slate-700/50 flex justify-between items-center">
<h3 className="text-sm font-bold text-slate-300 uppercase tracking-wide">Deep Learning System</h3>
<div className="flex gap-1.5">
<div className="w-2.5 h-2.5 rounded-full bg-red-500/50"></div>
<div className="w-2.5 h-2.5 rounded-full bg-yellow-500/50"></div>
<div className="w-2.5 h-2.5 rounded-full bg-green-500/50"></div>
</div>
</div>
{/* Content Area */}
<div className="p-8 relative">
<div className="flex flex-col gap-8 max-w-lg mx-auto relative z-10">
{/* 1. Frontend Layer (User Interface) */}
<div className="bg-slate-800 border border-purple-500/50 p-5 rounded-lg flex flex-col shadow-lg transform transition-transform hover:-translate-y-1">
<div className="flex items-center gap-4 mb-3">
{/* Icon: Brain/User */}
<div className="p-2 bg-purple-500/10 rounded-lg">
<svg xmlns="http://www.w3.org/2000/svg" className="w-6 h-6 text-purple-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
<path strokeLinecap="round" strokeLinejoin="round" d="M11 4a2 2 0 110 4m0 0v10a2 2 0 004 0V8a2 2 0 10-4 0m0 0a2 2 0 01-4 0V8a2 2 0 114 0m-4 0a2 2 0 004 0V4a2 2 0 11-4 0" />
</svg>
</div>
<h4 className="font-bold text-slate-200 text-lg">1. Frontend</h4>
</div>
<p className="text-sm text-slate-400">
<strong>High-Level Abstraction:</strong> Simple, elegant, and Pythonic interface (e.g., PyTorch, TensorFlow APIs) for model/module definitions.
</p>
</div>
{/* Arrow Down */}
<div className="flex justify-center -my-2">
<div className="h-8 w-px bg-gradient-to-b from-purple-500 to-blue-500"></div>
</div>
{/* 2. Operator/Graph Layer (Optimization & Scheduling) */}
<div className="bg-blue-900/20 border border-blue-500/50 p-5 rounded-lg relative backdrop-blur-sm transform transition-transform hover:-translate-y-1">
<div className="absolute -top-3 left-4 px-2 py-0.5 bg-blue-600 text-white text-[10px] font-bold rounded shadow-sm">OPTIMIZER 1</div>
<div className="flex items-start gap-4">
{/* Icon: Layers/Branch */}
<svg xmlns="http://www.w3.org/2000/svg" className="w-8 h-8 text-blue-400 mt-1" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
<path strokeLinecap="round" strokeLinejoin="round" d="M4 7v10a4 4 0 004 4h4m-4 0v-4m0 4h-4m4-10v4m0-4h4m4 10v4m0-4h-4m4-4V7a4 4 0 00-4-4h-4a4 4 0 00-4 4v3" />
</svg>
<div className="flex-1">
<h4 className="font-bold text-blue-100 text-lg mb-2">2. Computation Graph</h4>
<ul className="list-disc list-inside text-sm text-slate-300 ml-2 space-y-1">
<li><strong>Graph Construction:</strong> Converts model definition into a computational graph.</li>
<li><strong>Optimization:</strong> Performs operator <strong>fusion</strong>, <strong>parallelization</strong>, and memory management.</li>
</ul>
</div>
</div>
</div>
{/* Arrow Down */}
<div className="flex justify-center -my-2">
<div className="h-8 w-px bg-gradient-to-b from-blue-500 to-green-500"></div>
</div>
{/* 3. Kernel/Hardware Layer (Execution Engine) */}
<div className="bg-slate-800 border border-green-500/50 p-5 rounded-lg flex flex-col shadow-lg opacity-90 transform transition-transform hover:-translate-y-1">
<div className="absolute -top-3 left-4 px-2 py-0.5 bg-blue-600 text-white text-[10px] font-bold rounded shadow-sm">OPTIMIZER 2</div>
<div className="flex items-center gap-4 mb-3">
{/* Icon: CPU/Hardware */}
<div className="p-2 bg-green-500/10 rounded-lg">
<svg xmlns="http://www.w3.org/2000/svg" className="w-6 h-6 text-green-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect>
<line x1="8" y1="8" x2="16" y2="8"></line>
<line x1="8" y1="12" x2="16" y2="12"></line>
<line x1="8" y1="16" x2="16" y2="16"></line>
</svg>
</div>
<h4 className="font-bold text-slate-200 text-lg">3. Kernel</h4>
</div>
<p className="text-sm text-slate-400">
<strong>Low-Level Implementation:</strong> Generates highly optimized <strong>Kernels</strong> (e.g., CUDA, ROCm) for seamless deployment across various hardware.
</p>
{/* 图示: Hardware */}
<div className="mt-3 flex justify-around p-3 bg-slate-950 rounded border border-slate-700 shadow-inner">
<span className="text-sm text-red-400 font-medium flex items-center gap-1">
<svg xmlns="http://www.w3.org/2000/svg" className="w-4 h-4" viewBox="0 0 24 24" strokeWidth="2" stroke="currentColor" fill="none" strokeLinecap="round" strokeLinejoin="round"><path d="M7 10h3v4h-3v-4zM14 7h7m-7 4h7m-7 4h7" /><rect x="3" y="7" width="4" height="10" rx="1"></rect></svg>
GPU
</span>
<span className="text-sm text-cyan-400 font-medium flex items-center gap-1">
<svg xmlns="http://www.w3.org/2000/svg" className="w-4 h-4" viewBox="0 0 24 24" strokeWidth="2" stroke="currentColor" fill="none" strokeLinecap="round" strokeLinejoin="round"><path d="M5 21l7-14 7 14M9 10l6 0" /></svg>
CPU
</span>
<span className="text-sm text-yellow-400 font-medium flex items-center gap-1">
<svg xmlns="http://www.w3.org/2000/svg" className="w-4 h-4" viewBox="0 0 24 24" strokeWidth="2" stroke="currentColor" fill="none" strokeLinecap="round" strokeLinejoin="round"><path d="M4 10h4l2 3v-3h2l2 3v-3h2l2 3v-3h2v4a3 3 0 0 1-3 3h-14a3 3 0 0 1-3-3v-4" /></svg>
NPU/ASIC
</span>
</div>
</div>
</div>
{/* Background Glows (For Aesthetic Effect) */}
<div className="absolute top-1/4 left-10 w-48 h-48 bg-blue-500/10 rounded-full blur-[60px]"></div>
<div className="absolute bottom-10 right-10 w-40 h-40 bg-purple-500/10 rounded-full blur-[60px]"></div>
</div>
</div>
);
const CoreChallenges = () => {
const colors = ["bg-yellow-50", "bg-green-50", "bg-purple-50"];
return (
<div className="my-10 space-y-4">
{[
{ title: "Determining what to cache", desc: "Centroids should be cached. Otherwise, all the key cache will be accessed every step.", icon: "Database" },
{ title: "Dispatching the right ops", desc: "Operators like mv, topk while semantically same as torch ops, the underlying storage of input tensor(might have a page or ragged format) they process is different.", icon: "GitBranch" },
{ title: "Leveraging Infrastructure", desc: "Attention kernels and memory manager are super-optimized. Reuse them.", icon: "Server" }
].map((item, i) => (
<div
key={i}
className={`flex items-start gap-4 p-4 rounded-lg border border-slate-100 ${colors[i]}`}
>
<div className="bg-white p-2 rounded shadow-sm">
<Icon name={item.icon} className="w-5 h-5 text-blue-500" />
</div>
<div>
<h4 className="font-bold text-slate-800 text-sm">{item.title}</h4>
<p className="text-sm text-slate-600">{item.desc}</p>
</div>
</div>
))}
</div>
);
};
const MathBlock = ({ latex, title }) => {
const mathRef = React.useRef(null);
useEffect(() => {
if (mathRef.current && window.katex) {
try {
window.katex.render(latex, mathRef.current, {
displayMode: true,
throwOnError: false,
});
} catch (e) {
console.error("KaTeX rendering error:", e);
mathRef.current.innerHTML = `<span style="color:red;">Error rendering formula: ${e.message}</span>`;
}
}
}, [latex]);
return (
<div className="my-8 p-6 bg-blue-50 border-2 border-blue-200 rounded-xl shadow-inner">
{title && (
<h3 className="font-bold text-sm text-blue-700 uppercase tracking-wider mb-3 border-b border-blue-200 pb-2">
{title}
</h3>
)}
<div ref={mathRef} className="text-xl text-slate-800 text-center py-2">
{latex}
</div>
</div>
);
};
const BlockSparseAttentionVortexExample = () => (
// Outer Container (Mimics IDE/Terminal Window)
<div className="my-10 w-full max-w-xl mx-auto bg-slate-900 rounded-xl shadow-2xl ring-1 ring-slate-900/5">
{/* Title Bar */}
<div className="bg-slate-800/50 px-4 sm:px-6 py-3 border-b border-slate-700/50 flex justify-between items-center">
<h3 className="text-xs sm:text-sm font-bold text-slate-300 uppercase tracking-wide">
BlockSparseAttention.py
</h3>
<div className="flex gap-1.5">
<div className="w-2.5 h-2.5 rounded-full bg-red-500/50" />
<div className="w-2.5 h-2.5 rounded-full bg-yellow-500/50" />
<div className="w-2.5 h-2.5 rounded-full bg-green-500/50" />
</div>
</div>
{/* Code Content */}
<pre
className="
p-3 sm:p-5
font-mono text-[11px] sm:text-sm text-slate-300
whitespace-pre-wrap break-words
max-w-full
"
>
<code className="block whitespace-pre-wrap break-words">
<span className="text-yellow-400">@register</span>(
<span className="text-green-500">"block_sparse_attention"</span>)
<br />
<span className="text-blue-500">class</span>{" "}
<span className="text-cyan-400">BlockSparseAttention</span>(
<span className="text-cyan-400">vFlow</span>):
<br />
<br />
<span className="text-blue-500">def</span>{" "}
<span className="text-yellow-400">__init__</span>(
<span className="text-orange-400">self</span>):
<br />
super().
<span className="text-yellow-400">__init__</span>()
<br />
<br />
<span className="text-orange-400">self</span>.
<span className="text-red-400">gemv</span> = GeMV()
<br />
<span className="text-orange-400">self</span>.
<span className="text-red-400">output_func</span> = topK()
<br />
<span className="text-orange-400">self</span>.
<span className="text-red-400">reduction</span> = Mean(
<span className="text-orange-400">dim</span>=
<span className="text-purple-400">1</span>)
<br />
<br />
<span className="text-blue-500">def</span>{" "}
<span className="text-yellow-400">forward_indexer</span>(
<span className="text-orange-400">self</span>, q, o,
<br />
cache, ctx):
<br />
<span className="text-red-400">q_mean</span> = q.
<span className="text-yellow-400">mean</span>(
<span className="text-orange-400">dim</span>=
<span className="text-purple-400">1</span>,{" "}
<span className="text-orange-400">keepdim</span>=
<span className="text-blue-400">True</span>)
<br />
<span className="text-red-400">score</span> ={" "}
<span className="text-orange-400">self</span>.
<span className="text-yellow-400">gemv</span>(
<span className="text-red-400">q_mean</span>,
<br />
cache[
<span className="text-green-500">"centroids"</span>],{" "}
<span className="text-orange-400">ctx</span>=
<span className="text-red-400">ctx</span>)
<br />
<span className="text-orange-400">self</span>.
<span className="text-red-400">output_func</span>(
<span className="text-red-400">score</span>, o,
<br />
<span className="text-orange-400">ctx</span>=
<span className="text-red-400">ctx</span>)
<br />
<br />
<span className="text-blue-500">def</span>{" "}
<span className="text-yellow-400">forward_cache</span>(
<span className="text-orange-400">self</span>,
<br />
cache: Dict[
<span className="text-green-500">"str"</span>, torch.
<span className="text-cyan-400">Tensor</span>],
<br />
loc: torch.
<span className="text-cyan-400">Tensor</span>, ctx:
<span className="text-cyan-400">ContextBase</span>):
<br />
<span className="text-orange-400">self</span>.
<span className="text-red-400">reduction</span>(
<br />
cache[
<span className="text-green-500">"k"</span>], cache[
<span className="text-green-500">"centroids"</span>],
<br />
loc=
<span className="text-red-400">loc</span>,{" "}
<span className="text-orange-400">ctx</span>=
<span className="text-red-400">ctx</span>)
<br />
<br />
<span className="text-blue-500">def</span>{" "}
<span className="text-yellow-400">create_cache</span>(
<span className="text-orange-400">self</span>,
<br />
page_size:{" "}
<span className="text-cyan-400">int</span>, head_dim:{" "}
<span className="text-cyan-400">int</span>):
<br />
<span className="text-blue-400">return</span>{" "}
{"{"}
<br />
<span className="text-green-500">"centroids"</span>
<span className="text-slate-400">: </span>(
<span className="text-purple-400">1</span>,{" "}
<span className="text-red-400">head_dim</span>)
<br />
{"}"}
</code>
</pre>
</div>
);
const BlockSparseAttentionExample = () => {
// Tailwind classes for code highlighting
const Highlight = ({ children, color }) => {
const colors = {
yellow: "bg-amber-200/50 text-slate-900", // Soft Amber
green: "bg-green-200/50 text-slate-900", // Soft Green
purple: "bg-indigo-200/50 text-slate-900" // Soft Indigo
};
return (
<span className={`px-1 py-0.5 rounded ${colors[color]}`}>
{children}
</span>
);
};
return (
<div className="my-10 max-w-full">
<h3 className="text-base sm:text-lg font-bold text-slate-900 mb-4 flex items-center gap-2">
<Icon name="Code" className="w-5 h-5 text-blue-500" />
Block Sparse Attention Code Example
</h3>
<div
className="
bg-slate-800
p-3 sm:p-4 md:p-6
rounded-xl shadow-xl
text-[11px] sm:text-xs md:text-sm
font-mono text-slate-200
border border-slate-700
max-w-full
"
>
<pre className="whitespace-pre-wrap break-words">
<span className="text-blue-400">import</span> torch{"\n"}
{"\n"}
<span className="text-blue-400">def</span>{" "}
<span className="text-yellow-300">block_sparse_attention</span>(q, k, v):{"\n"}
{" "}
<Highlight color="yellow">centroids = k.mean(dim=-2)</Highlight>{"\n"}
{" "}
<span className="text-slate-500"># save in cache</span>{"\n"}
{"\n"}
{" "}
score = <Highlight color="green">torch.mv(centroids, q)</Highlight>{"\n"}
{" "}
indices = <Highlight color="green">torch.topk(score)</Highlight>{"\n"}
{" "}
<span className="text-slate-500"># customized op</span>{"\n"}
{"\n"}
{" "}
o = <Highlight color="purple">attention</Highlight>(
q, <Highlight color="purple">k[indices]</Highlight>,{" "}
<Highlight color="purple">v[indices]</Highlight>){"\n"}
{" "}
<span className="text-slate-500">
# call attention backend & memory
</span>{"\n"}
{" "}
<span className="text-slate-500">
# manager in the serving system
</span>{"\n"}
{"\n"}
{" "}
<span className="text-blue-400">return</span> o{"\n"}
</pre>
</div>
</div>
);
};
// --- END NEW COMPONENT ---
const VortexArchitectureDiagram = () => (
<div className="my-10 bg-slate-900 rounded-xl overflow-hidden shadow-2xl ring-1 ring-slate-900/5 text-slate-300">
<div className="bg-slate-800/50 px-6 py-3 border-b border-slate-700/50 flex justify-between items-center">
<h3 className="text-sm font-bold text-white uppercase tracking-wide">Vortex Architecture</h3>
<span className="text-xs font-mono text-blue-400">v1.0</span>
</div>
<div className="p-8 relative grid gap-6">
{/* Top: PyTorch Interface */}
<div className="relative z-10">
<div className="absolute -left-4 top-1/2 -translate-y-1/2 -rotate-90 text-[10px] font-bold text-slate-500 tracking-widest uppercase">User</div>
<div className="bg-slate-800 border border-slate-600 p-4 rounded-lg">
<div className="flex items-center gap-2 mb-2">
<Icon name="Code" className="w-4 h-4 text-green-400" />
<span className="text-sm font-bold text-slate-100">PyTorch Frontend</span>
</div>
<p className="text-xs text-slate-400">Write sparse attention logic in Python. Use standard ops.</p>
</div>
</div>
{/* Middle: The Bridge */}
<div className="flex justify-center -my-3 relative z-0">
<div className="h-8 w-0.5 bg-gradient-to-b from-slate-600 to-blue-500"></div>
</div>
{/* Middle: Vortex Core */}
<div className="relative z-10">
<div className="absolute -left-4 top-1/2 -translate-y-1/2 -rotate-90 text-[10px] font-bold text-blue-500 tracking-widest uppercase">Vortex</div>
<div className="grid grid-cols-2 gap-4">
<div className="bg-blue-900/20 border border-blue-500/50 p-4 rounded-lg">
<span className="text-xs font-mono text-blue-300 block mb-1">Phase 1</span>
<h4 className="font-bold text-white text-sm">forward_cache</h4>
<p className="text-[10px] text-slate-400 mt-1">Computes centroids, keys, & layout.</p>
</div>
<div className="bg-blue-900/20 border border-blue-500/50 p-4 rounded-lg">
<span className="text-xs font-mono text-blue-300 block mb-1">Phase 2</span>
<h4 className="font-bold text-white text-sm">forward_indexer</h4>
<p className="text-[10px] text-slate-400 mt-1">Selects indices (top-K, sampling).</p>
</div>
</div>
</div>
{/* Bottom: System */}
<div className="flex justify-center -my-3 relative z-0">
<div className="h-8 w-0.5 bg-gradient-to-b from-blue-500 to-slate-600"></div>
</div>
<div className="relative z-10">
<div className="absolute -left-4 top-1/2 -translate-y-1/2 -rotate-90 text-[10px] font-bold text-slate-500 tracking-widest uppercase">System</div>
<div className="bg-slate-800 border border-slate-600 p-4 rounded-lg flex divide-x divide-slate-700">
<div className="flex-1 px-4 text-center">
<Icon name="Database" className="w-5 h-5 text-purple-400 mx-auto mb-2" />
<h4 className="text-xs font-bold text-slate-300">Memory Manager</h4>
<p className="text-[10px] text-slate-500">KV Cache / Paging</p>
</div>
<div className="flex-1 px-4 text-center">
<Icon name="Cpu" className="w-5 h-5 text-green-400 mx-auto mb-2" />
<h4 className="text-xs font-bold text-slate-300">Attention Backend</h4>
<p className="text-[10px] text-slate-500">CUDA / Triton Kernels</p>
</div>
</div>
</div>
</div>
</div>
);
const TensorInterfaceVisual = () => (
<div className="my-8 p-6 bg-slate-100 rounded-xl border border-slate-200 font-mono text-sm shadow-inner">
<div className="flex items-center gap-2 mb-4 text-slate-500 text-xs uppercase font-bold tracking-wider">
<Icon name="Code" className="w-3 h-3" /> The Extended Tensor Abstraction
</div>
<div className="text-slate-800">
<span className="text-purple-600">class</span> <span className="text-yellow-600">vTensor</span>(Tensor):<br/>
<span className="text-slate-500"># Standard PyTorch data</span><br/>
self.data = data<br/>
<span className="text-slate-500"># The magic field</span><br/>
self.<span className="text-blue-600 font-bold">storage_format</span> = format <span className="text-slate-400">// e.g. Flat, Paged, Ragged</span>
</div>ß
</div>
);
// 示例数据:吞吐量,单位可以理解为 tokens/s
const performanceData = [
{
name: "H100 · Qwen3-0.6B",
baseline: 3071,
vortex: 8514,
},
{
name: "H100 · Qwen3-1.7B",
baseline: 2950,
vortex: 7550,
},
{
name: "H100 · Qwen3-4B",
baseline: 1786,
vortex: 4864,
},
{
name: "A100 · Qwen3-0.6B",
baseline: 1785,
vortex: 5087,
},
{
name: "A100 · Qwen3-1.7B",
baseline: 1694,
vortex: 4317,
},
{
name: "A100 · Qwen3-4B",
baseline: 1120,
vortex: 2760,
},
{
name: "L40 · Qwen3-0.6B",
baseline: 815,
vortex: 3326,
},
{
name: "A40 · Qwen3-0.6B",
baseline: 666,
vortex: 2670,
},
{
name: "A40 · Qwen3-1.7B",
baseline: 596,
vortex: 1943,
},
];
const chunkData = (data, size) => {
const result = [];
for (let i = 0; i < data.length; i += size) {
result.push(data.slice(i, i + size));
}
return result;
};
const PerformanceChart = () => {
const rows = chunkData(performanceData, 3); // 9 组 data -> 3 行,每行 3 个
return (
<div className="my-10 p-6 bg-white border border-slate-200 rounded-xl shadow-sm">
<h3 className="text-sm font-bold text-slate-500 uppercase tracking-wide mb-6">
Vortex Sparse Attention vs. Full Attention
</h3>
{/* 3 行 BarChart,每行显示 3 个柱子 */}
<div className="space-y-6">
{rows.map((rowData, rowIndex) => (
<div key={rowIndex} className="h-40 w-full">
<ResponsiveContainer width="100%" height="100%">
<BarChart
data={rowData}
margin={{ top: 10, right: 20, left: 10, bottom: 0 }}
>
<CartesianGrid
strokeDasharray="3 3"
vertical={false}
stroke="#f1f5f9"
/>
<XAxis
dataKey="name"
tick={{ fontSize: 12, fill: "#64748b" }}
axisLine={false}
tickLine={false}
/>
<YAxis hide />
<Tooltip
cursor={{ fill: "#f8fafc" }}
contentStyle={{
borderRadius: "8px",
border: "none",
boxShadow: "0 4px 6px -1px rgb(0 0 0 / 0.1)",
}}
/>
<Bar
dataKey="baseline"
name="Baseline"
fill="#e2e8f0"
radius={[4, 4, 0, 0]}
/>
<Bar
dataKey="vortex"
name="Vortex"
fill="#3b82f6"
radius={[4, 4, 0, 0]}
>
{rowData.map((entry, index) => {
const globalIndex = rowIndex * 3 + index; // 把行/列 index 映射回原来的 index
return (
<Cell
key={`cell-${rowIndex}-${index}`}
fill="#3b82f6"
/>
);
})}
</Bar>
</BarChart>
</ResponsiveContainer>
</div>
))}
</div>
{/* 汇总数值 */}
<div className="flex justify-center gap-8 mt-4">
<div className="text-center">
<p className="text-2xl font-bold text-slate-700">2.8x</p>
<p className="text-xs text-slate-500">Gain on H100</p>
</div>
<div className="text-center">
<p className="text-2xl font-bold text-slate-700">2.9x</p>
<p className="text-xs text-slate-500">Gain on A100</p>
</div>
<div className="text-center">
<p className="text-2xl font-bold text-slate-700">4.1x</p>
<p className="text-xs text-slate-500">Gain on L40</p>
</div>
<div className="text-center">
<p className="text-2xl font-bold text-slate-700">4.0x</p>
<p className="text-xs text-slate-500">Gain on A40</p>
</div>
</div>
{/* 基准说明 */}
<p className="mt-3 text-[11px] text-slate-500 text-center">
Benchmark: AIME24@8, 16K-token generation; Vortex with block size 16, 32 blocks each step; higher is better.
</p>
</div>
);
};
const VortexConfigurationDiagram = () => (
<div className="my-10 max-w-xl mx-auto bg-slate-900 rounded-xl shadow-2xl ring-1 ring-slate-900/5 p-8 relative overflow-hidden">
{/* Title/Description Area */}
<div className="text-center mb-8">
<h3 className="text-xl font-bold text-slate-200 mb-2">vFlow</h3>
</div>
{/* 三个竖直排列的 block */}
<div className="flex flex-col items-stretch gap-4 relative z-10">
{/* 1. create_cache */}
<div className="flex flex-col items-center text-center p-4 bg-slate-800 border border-yellow-500/50 rounded-lg shadow-md hover:shadow-xl transition-shadow duration-300 transform hover:-translate-y-1 w-full">
<div className="p-3 bg-yellow-500/10 rounded-full mb-3">
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-8 w-8 text-yellow-400"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={2}
>
<path strokeLinecap="round" strokeLinejoin="round" d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4" />
</svg>
</div>
<h4 className="font-bold text-yellow-300 text-base mb-1">1. create_cache()</h4>
<p className="text-xs text-slate-500 leading-tight">
<strong>Initialize Cache:</strong> Specifies the size and name of each page cache.
</p>
</div>
{/* 2. forward_cache */}
<div className="flex flex-col items-center text-center p-4 bg-slate-800 border border-red-500/50 rounded-lg shadow-md hover:shadow-xl transition-shadow duration-300 transform hover:-translate-y-1 w-full">
<div className="p-3 bg-red-500/10 rounded-full mb-3">
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-6 w-6 text-red-400"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={2}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M4 7v10a4 4 0 004 4h4m-4 0v-4m0 4h-4m4-10v4m0-4h4m4 10v4m0-4h-4m4-4V7a4 4 0 00-4-4h-4a4 4 0 00-4 4v3"
/>
</svg>
</div>
<h4 className="font-bold text-red-300 text-sm mb-1">2. forward_cache()</h4>
<p className="text-xs text-slate-500 leading-tight">Computes & Updates Cache Values.</p>
</div>
{/* 3. forward_indexer */}
<div className="flex flex-col items-center text-center p-4 bg-slate-800 border border-green-500/50 rounded-lg shadow-md hover:shadow-xl transition-shadow duration-300 transform hover:-translate-y-1 w-full">
<div className="p-3 bg-green-500/10 rounded-full mb-3">
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-6 w-6 text-green-400"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={2}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"
/>
</svg>
</div>
<h4 className="font-bold text-green-300 text-sm mb-1">3. forward_indexer()</h4>
<p className="text-xs text-slate-500 leading-tight">Consumes Cache to Compute Indices.</p>
</div>
</div>
{/* Background Glows */}
<div className="absolute top-1/4 left-10 w-48 h-48 bg-blue-500/10 rounded-full blur-[60px]"></div>
<div className="absolute bottom-10 right-10 w-40 h-40 bg-purple-500/10 rounded-full blur-[60px]"></div>
</div>
);
// --- Main Component ---
const App = () => {
const [mounted, setMounted] = useState(false);
useEffect(() => setMounted(true), []);
if (!mounted) return null;
return (
<div className="min-h-screen bg-slate-50 font-sans text-slate-800 leading-relaxed">
<div className="max-w-3xl mx-auto bg-white min-h-screen shadow-lg border-x border-slate-100">
{/* Header */}
<header className="pt-16 pb-8 px-8 md:px-12">
<div className="flex gap-3 mb-6">
<span className="px-3 py-1 bg-blue-100 text-blue-700 text-xs font-bold uppercase tracking-wide rounded-full">ML Systems</span>
<span className="px-3 py-1 bg-purple-100 text-purple-700 text-xs font-bold uppercase tracking-wide rounded-full">Research</span>
</div>
<h1 className="text-4xl md:text-5xl font-extrabold mb-6 text-slate-900 tracking-tight leading-tight">
Vortex: Democratizing <br/>
<span className="text-blue-600">Sparse Attention</span>
</h1>
<div className="flex flex-wrap items-center gap-4 text-sm text-slate-500 mb-8">
<a
href="https://github.com/Infini-AI-Lab/vortex_torch/tree/v1"
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-2 hover:text-blue-600 transition-colors"
>
<Icon name="Code" className="w-4 h-4" />
<span>Code</span>
</a>
<a
href="https://infini-ai-lab.github.io/vortex_torch/"
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-2 hover:text-blue-600 transition-colors"
>
<Icon name="FileText" className="w-4 h-4" />
<span>Document</span>
</a>
</div>
</header>
<main className="px-8 md:px-12 pb-20">
{}
<PerformanceChart />
{/* 两张图片的竖直叠放块 */}
<div className="my-10 max-w-xl mx-auto bg-white rounded-xl shadow-2xl ring-1 ring-slate-900/5 p-6">
<h3 className="text-sm font-bold text-slate-500 uppercase tracking-wide mb-6">
Sparse Attention RL with Vortex
</h3>
<div className="space-y-3">
<img
src="reward.jpg"
alt="Reward Curve"
className="w-full rounded-lg border border-slate-800 object-cover"
/>
<img
src="aime24.jpg"
alt="AIME24 Curve"
className="w-full rounded-lg border border-slate-800 object-cover"
/>
</div>
<p className="mt-4 text-xs text-slate-400 text-center">
Model: Qwen3-4B; Generation Length: 8192; Dataset: Polaris-53K
</p>
</div>
{/* 结束:竖直图片 block */}
{/* Motivation */}
<SectionHeader title="1. Motivation" />
<p className="text-lg text-slate-700 mb-6">
The rise of sparse attention models, such as DeepSeek DSA, MoBA, and NSA, coupled with dramatic cost reductions and performance gains, underscores the need to develop these techniques.
</p>
<p className="text-slate-700 mb-6">
However, a disconnect exists. ML developers introduce algorithms that never reach production, while system developers are forced into an unavoidable trade-off.
</p>
<SystemDilemma />
<p className="text-slate-700 mb-6 italic border-l-4 border-blue-500 pl-4 py-2 bg-slate-50">
"Progress slows not because the ideas aren’t good, but because making them run in scale is exhausting."
</p>
{/* Ideal Framework */}
<SectionHeader title="2. What is an ideal framework?" />
<p className="text-slate-700 mb-6">
A helpful analogy comes from the evolution of Deep Learning. <strong>PyTorch</strong> succeeded because it separated concerns:
</p>
<DeepLearningArchitecture />
<p className="text-slate-700">
In contrast, to play with a sparse attention algorithm, users need to be a full-stack expert: from algorithm design to kernel implementation. Definitely, Sparse attention deserves the same kind of ecosystem as deep learning.
</p>
{/* Challenges */}
<SectionHeader title="3. Core Challenges" />
<p className="text-slate-700">
Establishing a proper abstraction for sparse attention models has extra difficulty from torch. Torch focuses on one-time computation where everything is explicit, while we need to consider the tensors are coming from a serving system. To make this clear, we introduce the core challenges from a well-known example of sparse attention, e.g., block sparse attention.
</p>
{/* --- NEW PLACEMENT --- */}
<BlockSparseAttentionExample />
<p className="text-slate-700 mb-6">
The code above, while algorithmically correct, faces the following three challenges when attempting to run efficiently and faithfully.
</p>
<CoreChallenges />
{/* Vortex Solution */}
<SectionHeader title="4. Vortex" />
<p className="text-slate-700 mb-6">
Vortex is the bridge. It lets developers write sparse attention like standard PyTorch, yet gives serving systems the structure they need to execute efficiently.
</p>
<p className="text-slate-700 mb-6">
Below is the block sparse attention written in Vortex, where we introduce 3 nice features.
</p>
<BlockSparseAttentionVortexExample />
<h3 className="font-bold text-lg text-slate-900 mt-8 mb-4">4.1 Simple Entry and Definition</h3>
<div className="mb-6 rounded-lg border border-slate-200 bg-slate-50 px-4 py-3 text-sm leading-relaxed text-slate-700">
<p>
Users define a sparse attention algorithm by subclassing{" "}
<span className="font-semibold text-slate-900">vFlow</span>. The subclass exposes three key entry points:
</p>
<ul className="mt-2 list-disc list-inside space-y-1">
<li>
<span className="font-mono text-xs bg-slate-200/70 px-1.5 py-0.5 rounded">
create_cache
</span>
<span className="ml-1">
defines the shape and name of the cache.
</span>
</li>
<li>
<span className="font-mono text-xs bg-slate-200/70 px-1.5 py-0.5 rounded">
forward_cache
</span>
<span className="ml-1">
specifies how the cache is computed and updated.
</span>
</li>
<li>
<span className="font-mono text-xs bg-slate-200/70 px-1.5 py-0.5 rounded">
forward_indexer