vizmatic 0.1.37 → 0.1.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,166 @@
1
- import type { ThemeMode } from 'vizmatic'
2
- import { createNcclAnimation, createNcclFrame } from './_shared/nccl-collective'
1
+ import {
2
+ defineAnimation,
3
+ getReadableToneColor,
4
+ getReadableTextColor,
5
+ getThemeColors,
6
+ getToneColor,
7
+ hold,
8
+ tween,
9
+ type ThemeMode,
10
+ } from 'vizmatic'
3
11
 
4
- export { height, width } from './_shared/nccl-collective'
12
+ export const width = 1040
13
+ export const height = 500
14
+
15
+ type State = { progress: number }
16
+ type Colors = ReturnType<typeof getThemeColors>
17
+
18
+ const clamp = (value: number) => Math.max(0, Math.min(1, value))
19
+ const rankY = (rank: number) => 100 + rank * 54
20
+
21
+ function Token({ x, y, label, color, textColor, opacity = 1 }: { x: number; y: number; label: string; color: string; textColor: string; opacity?: number }) {
22
+ return (
23
+ <div style={{
24
+ display: 'flex',
25
+ position: 'absolute',
26
+ left: x - 15,
27
+ top: y - 15,
28
+ width: 30,
29
+ height: 30,
30
+ alignItems: 'center',
31
+ justifyContent: 'center',
32
+ borderRadius: 8,
33
+ backgroundColor: color,
34
+ color: textColor,
35
+ fontFamily: 'JetBrains Mono',
36
+ fontSize: 11,
37
+ fontWeight: 900,
38
+ opacity,
39
+ }}>
40
+ {label}
41
+ </div>
42
+ )
43
+ }
44
+
45
+ function RankLanes({ c }: { c: Colors }) {
46
+ return (
47
+ <div style={{ display: 'flex', position: 'absolute', inset: 0 }}>
48
+ {[0, 1, 2, 3].map((rank) => (
49
+ <div key={rank} style={{ display: 'flex', position: 'absolute', inset: 0 }}>
50
+ <div style={{
51
+ display: 'flex',
52
+ position: 'absolute',
53
+ left: 22,
54
+ top: rankY(rank) - 16,
55
+ width: 122,
56
+ height: 32,
57
+ alignItems: 'center',
58
+ gap: 10,
59
+ paddingLeft: 12,
60
+ borderRadius: 9,
61
+ backgroundColor: c.bgCardAlt,
62
+ border: `1px solid ${c.borderSubtle}`,
63
+ color: c.textPrimary,
64
+ fontFamily: c.fontMono,
65
+ fontSize: 12,
66
+ fontWeight: 800,
67
+ }}>
68
+ <span style={{ width: 10, height: 10, borderRadius: 10, backgroundColor: c.neutralLight }} />
69
+ rank {rank}
70
+ </div>
71
+ <div style={{ display: 'flex', position: 'absolute', left: 170, top: rankY(rank) - 1, width: 780, height: 2, backgroundColor: c.borderSubtle }} />
72
+ </div>
73
+ ))}
74
+ </div>
75
+ )
76
+ }
77
+
78
+ function Frame({ theme, progress }: { theme: ThemeMode; progress: number }) {
79
+ const c = getThemeColors(theme)
80
+ const color = getToneColor('blue', c)
81
+ const semanticColor = getReadableToneColor('blue', c, c.bgCard)
82
+ const textColor = getReadableTextColor(color, c)
83
+ const p = clamp(progress)
84
+ const gather = clamp(p / 0.5)
85
+ const replicate = clamp((p - 0.44) / 0.56)
86
+ const inputOpacity = 1 - clamp((p - 0.46) / 0.12)
87
+ const centerX = 548
88
+ const centerY = 181
89
+ const sourceX = 226
90
+ const outputX = 730
91
+ const labels = ['A', 'B', 'C', 'D']
92
+ const phase = p < 0.46 ? 'gather rank-owned shards' : p < 0.92 ? 'replicate ordered tensor' : 'A · B · C · D on every rank'
93
+
94
+ return (
95
+ <div style={{ display: 'flex', position: 'relative', width, height, backgroundColor: c.bg, fontFamily: c.fontSans }}>
96
+ <div style={{ display: 'flex', width, height, opacity: 0 }} />
97
+ <div style={{ display: 'flex', position: 'absolute', top: 18, width: '100%', justifyContent: 'center', color: c.textPrimary, fontSize: 36, fontWeight: 800 }}>NCCL · AllGather</div>
98
+ <div style={{ display: 'flex', position: 'absolute', top: 62, width: '100%', justifyContent: 'center', color: c.textSecondary, fontFamily: c.fontMono, fontSize: 14 }}>Every GPU contributes one shard and receives complete ordered tensor</div>
99
+
100
+ <div style={{ display: 'flex', position: 'absolute', left: 26, top: 100, width: 988, height: 374, overflow: 'hidden', borderRadius: 14, backgroundColor: c.bgCard, border: `1px solid ${c.borderSubtle}` }}>
101
+ <div style={{ display: 'flex', position: 'absolute', left: 22, top: 18, alignItems: 'center', gap: 10 }}>
102
+ <span style={{ width: 6, height: 28, borderRadius: 6, backgroundColor: color }} />
103
+ <span style={{ color: c.textPrimary, fontSize: 20, fontWeight: 800 }}>AllGather</span>
104
+ <span style={{ color: c.textMuted, fontFamily: c.fontMono, fontSize: 11 }}>collect shards in rank order</span>
105
+ </div>
106
+ <div style={{ display: 'flex', position: 'absolute', right: 22, top: 24, color: semanticColor, fontFamily: c.fontMono, fontSize: 12, fontWeight: 900 }}>ALL → ALL · CONCAT</div>
107
+
108
+ <RankLanes c={c} />
109
+ <div style={{ display: 'flex', position: 'absolute', left: centerX - 58, top: centerY - 48, width: 116, height: 96, alignItems: 'center', justifyContent: 'center', borderRadius: 12, backgroundColor: c.bgCardAlt, border: `2px dashed ${color}`, opacity: 0.82 }} />
110
+ <div style={{ display: 'flex', position: 'absolute', left: centerX - 25, top: centerY - 65, color: c.textMuted, fontFamily: c.fontMono, fontSize: 11, fontWeight: 900 }}>CONCAT</div>
111
+ {inputOpacity > 0.01 && labels.map((label, rank) => {
112
+ const slotX = centerX - 36 + rank * 24
113
+ return (
114
+ <Token
115
+ key={`input-${rank}`}
116
+ x={sourceX + (slotX - sourceX) * gather}
117
+ y={rankY(rank) + (centerY - rankY(rank)) * gather}
118
+ label={label}
119
+ color={color}
120
+ textColor={textColor}
121
+ opacity={inputOpacity}
122
+ />
123
+ )
124
+ })}
125
+ {[0, 1, 2, 3].flatMap((target) => labels.map((label, source) => {
126
+ const slotX = centerX - 36 + source * 24
127
+ return (
128
+ <Token
129
+ key={`output-${target}-${source}`}
130
+ x={slotX + (outputX + source * 40 - slotX) * replicate}
131
+ y={centerY + (rankY(target) - centerY) * replicate}
132
+ label={label}
133
+ color={color}
134
+ textColor={textColor}
135
+ opacity={replicate}
136
+ />
137
+ )
138
+ }))}
139
+
140
+ <div style={{ display: 'flex', position: 'absolute', left: 22, top: 326, color: c.textMuted, fontFamily: c.fontMono, fontSize: 11 }}>{phase}</div>
141
+ <div style={{ display: 'flex', position: 'absolute', left: 170, top: 332, width: 780, height: 6, borderRadius: 6, backgroundColor: c.borderSubtle }}>
142
+ <div style={{ display: 'flex', width: `${Math.round(p * 100)}%`, height: 6, borderRadius: 6, backgroundColor: color }} />
143
+ </div>
144
+ </div>
145
+ </div>
146
+ )
147
+ }
5
148
 
6
149
  export function createAnimation(theme: ThemeMode) {
7
- return createNcclAnimation(theme, 'all-gather')
150
+ return defineAnimation<State>({
151
+ initial: { progress: 0 },
152
+ timeline: [
153
+ hold(800, 'one shard per rank'),
154
+ tween<Partial<State>>({ progress: 1 }, { duration: 3000, easing: 'ease-in-out', label: 'gather and replicate' }),
155
+ hold(1000, 'complete tensors'),
156
+ ],
157
+ fps: 20,
158
+ render: (state) => <Frame theme={theme} progress={state.progress} />,
159
+ })
8
160
  }
9
161
 
10
162
  export function create(theme: ThemeMode = 'dark') {
11
- return createNcclFrame(theme, 'all-gather')
163
+ return <Frame theme={theme} progress={1} />
12
164
  }
13
165
 
14
166
  export default create('dark')
@@ -1,14 +1,159 @@
1
- import type { ThemeMode } from 'vizmatic'
2
- import { createNcclAnimation, createNcclFrame } from './_shared/nccl-collective'
1
+ import {
2
+ defineAnimation,
3
+ getReadableToneColor,
4
+ getReadableTextColor,
5
+ getThemeColors,
6
+ getToneColor,
7
+ hold,
8
+ tween,
9
+ type ThemeMode,
10
+ } from 'vizmatic'
3
11
 
4
- export { height, width } from './_shared/nccl-collective'
12
+ export const width = 1040
13
+ export const height = 500
14
+
15
+ type State = { progress: number }
16
+ type Colors = ReturnType<typeof getThemeColors>
17
+
18
+ const clamp = (value: number) => Math.max(0, Math.min(1, value))
19
+ const rankY = (rank: number) => 100 + rank * 54
20
+
21
+ function Token({ x, y, label, color, textColor, opacity = 1 }: { x: number; y: number; label: string; color: string; textColor: string; opacity?: number }) {
22
+ return (
23
+ <div style={{
24
+ display: 'flex',
25
+ position: 'absolute',
26
+ left: x - 18,
27
+ top: y - 16,
28
+ width: 36,
29
+ height: 32,
30
+ alignItems: 'center',
31
+ justifyContent: 'center',
32
+ borderRadius: 16,
33
+ backgroundColor: color,
34
+ color: textColor,
35
+ fontFamily: 'JetBrains Mono',
36
+ fontSize: 11,
37
+ fontWeight: 900,
38
+ opacity,
39
+ }}>
40
+ {label}
41
+ </div>
42
+ )
43
+ }
44
+
45
+ function RankLanes({ c }: { c: Colors }) {
46
+ return (
47
+ <div style={{ display: 'flex', position: 'absolute', inset: 0 }}>
48
+ {[0, 1, 2, 3].map((rank) => (
49
+ <div key={rank} style={{ display: 'flex', position: 'absolute', inset: 0 }}>
50
+ <div style={{
51
+ display: 'flex',
52
+ position: 'absolute',
53
+ left: 22,
54
+ top: rankY(rank) - 16,
55
+ width: 122,
56
+ height: 32,
57
+ alignItems: 'center',
58
+ gap: 10,
59
+ paddingLeft: 12,
60
+ borderRadius: 9,
61
+ backgroundColor: c.bgCardAlt,
62
+ border: `1px solid ${c.borderSubtle}`,
63
+ color: c.textPrimary,
64
+ fontFamily: c.fontMono,
65
+ fontSize: 12,
66
+ fontWeight: 800,
67
+ }}>
68
+ <span style={{ width: 10, height: 10, borderRadius: 10, backgroundColor: c.neutralLight }} />
69
+ rank {rank}
70
+ </div>
71
+ <div style={{ display: 'flex', position: 'absolute', left: 170, top: rankY(rank) - 1, width: 780, height: 2, backgroundColor: c.borderSubtle }} />
72
+ </div>
73
+ ))}
74
+ </div>
75
+ )
76
+ }
77
+
78
+ function Frame({ theme, progress }: { theme: ThemeMode; progress: number }) {
79
+ const c = getThemeColors(theme)
80
+ const color = getToneColor('purple', c)
81
+ const semanticColor = getReadableToneColor('purple', c, c.bgCard)
82
+ const textColor = getReadableTextColor(color, c)
83
+ const p = clamp(progress)
84
+ const reduce = clamp(p / 0.5)
85
+ const broadcast = clamp((p - 0.46) / 0.54)
86
+ const inputOpacity = 1 - clamp((p - 0.46) / 0.12)
87
+ const centerX = 548
88
+ const centerY = 181
89
+ const sourceX = 226
90
+ const targetX = 850
91
+ const phase = p < 0.46 ? 'reduce matching values' : p < 0.92 ? 'broadcast completed sum' : 'same sum on every rank'
92
+
93
+ return (
94
+ <div style={{ display: 'flex', position: 'relative', width, height, backgroundColor: c.bg, fontFamily: c.fontSans }}>
95
+ <div style={{ display: 'flex', width, height, opacity: 0 }} />
96
+ <div style={{ display: 'flex', position: 'absolute', top: 18, width: '100%', justifyContent: 'center', color: c.textPrimary, fontSize: 36, fontWeight: 800 }}>NCCL · AllReduce</div>
97
+ <div style={{ display: 'flex', position: 'absolute', top: 62, width: '100%', justifyContent: 'center', color: c.textSecondary, fontFamily: c.fontMono, fontSize: 14 }}>Reduce rank-local values, then return completed sum to every GPU</div>
98
+
99
+ <div style={{ display: 'flex', position: 'absolute', left: 26, top: 100, width: 988, height: 374, overflow: 'hidden', borderRadius: 14, backgroundColor: c.bgCard, border: `1px solid ${c.borderSubtle}` }}>
100
+ <div style={{ display: 'flex', position: 'absolute', left: 22, top: 18, alignItems: 'center', gap: 10 }}>
101
+ <span style={{ width: 6, height: 28, borderRadius: 6, backgroundColor: color }} />
102
+ <span style={{ color: c.textPrimary, fontSize: 20, fontWeight: 800 }}>AllReduce</span>
103
+ <span style={{ color: c.textMuted, fontFamily: c.fontMono, fontSize: 11 }}>sum first; replicate second</span>
104
+ </div>
105
+ <div style={{ display: 'flex', position: 'absolute', right: 22, top: 24, color: semanticColor, fontFamily: c.fontMono, fontSize: 12, fontWeight: 900 }}>ALL → ALL</div>
106
+
107
+ <RankLanes c={c} />
108
+ <div style={{ display: 'flex', position: 'absolute', left: centerX - 27, top: centerY - 27, width: 54, height: 54, alignItems: 'center', justifyContent: 'center', borderRadius: 54, backgroundColor: c.bgCardAlt, border: `2px solid ${color}`, color, fontFamily: c.fontMono, fontSize: 20, fontWeight: 900 }}>Σ</div>
109
+ {inputOpacity > 0.01 && [0, 1, 2, 3].map((rank) => (
110
+ <Token
111
+ key={`input-${rank}`}
112
+ x={sourceX + (centerX - sourceX) * reduce}
113
+ y={rankY(rank) + (centerY - rankY(rank)) * reduce}
114
+ label={String(rank + 1)}
115
+ color={color}
116
+ textColor={textColor}
117
+ opacity={inputOpacity}
118
+ />
119
+ ))}
120
+ {[0, 1, 2, 3].map((rank) => (
121
+ <Token
122
+ key={`output-${rank}`}
123
+ x={centerX + (targetX - centerX) * broadcast}
124
+ y={centerY + (rankY(rank) - centerY) * broadcast}
125
+ label="10"
126
+ color={color}
127
+ textColor={textColor}
128
+ opacity={broadcast}
129
+ />
130
+ ))}
131
+ <div style={{ display: 'flex', position: 'absolute', left: centerX - 42, top: centerY + 34, color: c.textMuted, fontFamily: c.fontMono, fontSize: 11 }}>1 + 2 + 3 + 4</div>
132
+
133
+ <div style={{ display: 'flex', position: 'absolute', left: 22, top: 326, color: c.textMuted, fontFamily: c.fontMono, fontSize: 11 }}>{phase}</div>
134
+ <div style={{ display: 'flex', position: 'absolute', left: 170, top: 332, width: 780, height: 6, borderRadius: 6, backgroundColor: c.borderSubtle }}>
135
+ <div style={{ display: 'flex', width: `${Math.round(p * 100)}%`, height: 6, borderRadius: 6, backgroundColor: color }} />
136
+ </div>
137
+ </div>
138
+ </div>
139
+ )
140
+ }
5
141
 
6
142
  export function createAnimation(theme: ThemeMode) {
7
- return createNcclAnimation(theme, 'all-reduce')
143
+ return defineAnimation<State>({
144
+ initial: { progress: 0 },
145
+ timeline: [
146
+ hold(800, 'rank-local values'),
147
+ tween<Partial<State>>({ progress: 1 }, { duration: 3000, easing: 'ease-in-out', label: 'reduce and broadcast' }),
148
+ hold(1000, 'replicated sum'),
149
+ ],
150
+ fps: 20,
151
+ render: (state) => <Frame theme={theme} progress={state.progress} />,
152
+ })
8
153
  }
9
154
 
10
155
  export function create(theme: ThemeMode = 'dark') {
11
- return createNcclFrame(theme, 'all-reduce')
156
+ return <Frame theme={theme} progress={1} />
12
157
  }
13
158
 
14
159
  export default create('dark')
@@ -1,14 +1,146 @@
1
- import type { ThemeMode } from 'vizmatic'
2
- import { createNcclAnimation, createNcclFrame } from './_shared/nccl-collective'
1
+ import {
2
+ defineAnimation,
3
+ getReadableToneColor,
4
+ getReadableTextColor,
5
+ getThemeColors,
6
+ getToneColor,
7
+ hold,
8
+ tween,
9
+ type ThemeMode,
10
+ } from 'vizmatic'
3
11
 
4
- export { height, width } from './_shared/nccl-collective'
12
+ export const width = 1040
13
+ export const height = 500
14
+
15
+ type State = { progress: number }
16
+ type Colors = ReturnType<typeof getThemeColors>
17
+
18
+ const clamp = (value: number) => Math.max(0, Math.min(1, value))
19
+ const rankY = (rank: number) => 100 + rank * 54
20
+
21
+ function Token({ x, y, label, color, textColor }: { x: number; y: number; label: string; color: string; textColor: string }) {
22
+ return (
23
+ <div style={{
24
+ display: 'flex',
25
+ position: 'absolute',
26
+ left: x - 20,
27
+ top: y - 15,
28
+ width: 40,
29
+ height: 30,
30
+ alignItems: 'center',
31
+ justifyContent: 'center',
32
+ borderRadius: 8,
33
+ backgroundColor: color,
34
+ color: textColor,
35
+ fontFamily: 'JetBrains Mono',
36
+ fontSize: 11,
37
+ fontWeight: 900,
38
+ }}>
39
+ {label}
40
+ </div>
41
+ )
42
+ }
43
+
44
+ function RankLanes({ c }: { c: Colors }) {
45
+ return (
46
+ <div style={{ display: 'flex', position: 'absolute', inset: 0 }}>
47
+ {[0, 1, 2, 3].map((rank) => (
48
+ <div key={rank} style={{ display: 'flex', position: 'absolute', inset: 0 }}>
49
+ <div style={{
50
+ display: 'flex',
51
+ position: 'absolute',
52
+ left: 22,
53
+ top: rankY(rank) - 16,
54
+ width: 122,
55
+ height: 32,
56
+ alignItems: 'center',
57
+ gap: 10,
58
+ paddingLeft: 12,
59
+ borderRadius: 9,
60
+ backgroundColor: c.bgCardAlt,
61
+ border: `1px solid ${c.borderSubtle}`,
62
+ color: c.textPrimary,
63
+ fontFamily: c.fontMono,
64
+ fontSize: 12,
65
+ fontWeight: 800,
66
+ }}>
67
+ <span style={{ width: 10, height: 10, borderRadius: 10, backgroundColor: c.neutralLight }} />
68
+ rank {rank}
69
+ </div>
70
+ <div style={{ display: 'flex', position: 'absolute', left: 170, top: rankY(rank) - 1, width: 780, height: 2, backgroundColor: c.borderSubtle }} />
71
+ </div>
72
+ ))}
73
+ </div>
74
+ )
75
+ }
76
+
77
+ function Frame({ theme, progress }: { theme: ThemeMode; progress: number }) {
78
+ const c = getThemeColors(theme)
79
+ const color = getToneColor('warm', c)
80
+ const semanticColor = getReadableToneColor('warm', c, c.bgCard)
81
+ const p = clamp(progress)
82
+ const sourceX = 210
83
+ const outputX = 722
84
+ const gap = 44
85
+ const destinationColors = [c.info, c.primaryLight, c.secondaryLight, c.warningLight]
86
+ const phase = p < 0.08 ? 'grouped by source rank' : p < 0.92 ? 'exchange rank-addressed chunks' : 'grouped by destination rank'
87
+
88
+ return (
89
+ <div style={{ display: 'flex', position: 'relative', width, height, backgroundColor: c.bg, fontFamily: c.fontSans }}>
90
+ <div style={{ display: 'flex', width, height, opacity: 0 }} />
91
+ <div style={{ display: 'flex', position: 'absolute', top: 18, width: '100%', justifyContent: 'center', color: c.textPrimary, fontSize: 36, fontWeight: 800 }}>NCCL · AllToAll</div>
92
+ <div style={{ display: 'flex', position: 'absolute', top: 62, width: '100%', justifyContent: 'center', color: c.textSecondary, fontFamily: c.fontMono, fontSize: 14 }}>Every GPU sends one addressed chunk to every destination GPU</div>
93
+
94
+ <div style={{ display: 'flex', position: 'absolute', left: 26, top: 100, width: 988, height: 374, overflow: 'hidden', borderRadius: 14, backgroundColor: c.bgCard, border: `1px solid ${c.borderSubtle}` }}>
95
+ <div style={{ display: 'flex', position: 'absolute', left: 22, top: 18, alignItems: 'center', gap: 10 }}>
96
+ <span style={{ width: 6, height: 28, borderRadius: 6, backgroundColor: color }} />
97
+ <span style={{ color: c.textPrimary, fontSize: 20, fontWeight: 800 }}>AllToAll</span>
98
+ <span style={{ color: c.textMuted, fontFamily: c.fontMono, fontSize: 11 }}>label = source→destination; color = destination</span>
99
+ </div>
100
+ <div style={{ display: 'flex', position: 'absolute', right: 22, top: 24, color: semanticColor, fontFamily: c.fontMono, fontSize: 12, fontWeight: 900 }}>ALL ↔ ALL</div>
101
+
102
+ <RankLanes c={c} />
103
+ <div style={{ display: 'flex', position: 'absolute', left: 488, top: 128, width: 116, height: 106, alignItems: 'center', justifyContent: 'center', borderRadius: 12, backgroundColor: c.bgCardAlt, border: `2px dashed ${color}`, color: c.textMuted, fontFamily: c.fontMono, fontSize: 11, fontWeight: 900 }}>EXCHANGE</div>
104
+ {[0, 1, 2, 3].flatMap((source) => [0, 1, 2, 3].map((destination) => {
105
+ const tokenColor = destinationColors[destination]
106
+ const startX = sourceX + destination * gap
107
+ const endX = outputX + source * gap
108
+ return (
109
+ <Token
110
+ key={`${source}-${destination}`}
111
+ x={startX + (endX - startX) * p}
112
+ y={rankY(source) + (rankY(destination) - rankY(source)) * p}
113
+ label={`${source}→${destination}`}
114
+ color={tokenColor}
115
+ textColor={getReadableTextColor(tokenColor, c)}
116
+ />
117
+ )
118
+ }))}
119
+
120
+ <div style={{ display: 'flex', position: 'absolute', left: 22, top: 326, color: c.textMuted, fontFamily: c.fontMono, fontSize: 11 }}>{phase}</div>
121
+ <div style={{ display: 'flex', position: 'absolute', left: 170, top: 332, width: 780, height: 6, borderRadius: 6, backgroundColor: c.borderSubtle }}>
122
+ <div style={{ display: 'flex', width: `${Math.round(p * 100)}%`, height: 6, borderRadius: 6, backgroundColor: color }} />
123
+ </div>
124
+ </div>
125
+ </div>
126
+ )
127
+ }
5
128
 
6
129
  export function createAnimation(theme: ThemeMode) {
7
- return createNcclAnimation(theme, 'all-to-all')
130
+ return defineAnimation<State>({
131
+ initial: { progress: 0 },
132
+ timeline: [
133
+ hold(800, 'source-grouped chunks'),
134
+ tween<Partial<State>>({ progress: 1 }, { duration: 3000, easing: 'ease-in-out', label: 'all-to-all exchange' }),
135
+ hold(1000, 'destination-grouped chunks'),
136
+ ],
137
+ fps: 20,
138
+ render: (state) => <Frame theme={theme} progress={state.progress} />,
139
+ })
8
140
  }
9
141
 
10
142
  export function create(theme: ThemeMode = 'dark') {
11
- return createNcclFrame(theme, 'all-to-all')
143
+ return <Frame theme={theme} progress={1} />
12
144
  }
13
145
 
14
146
  export default create('dark')
@@ -1,14 +1,140 @@
1
- import type { ThemeMode } from 'vizmatic'
2
- import { createNcclAnimation, createNcclFrame } from './_shared/nccl-collective'
1
+ import {
2
+ defineAnimation,
3
+ getReadableToneColor,
4
+ getReadableTextColor,
5
+ getThemeColors,
6
+ getToneColor,
7
+ hold,
8
+ tween,
9
+ type ThemeMode,
10
+ } from 'vizmatic'
3
11
 
4
- export { height, width } from './_shared/nccl-collective'
12
+ export const width = 1040
13
+ export const height = 500
14
+
15
+ type State = { progress: number }
16
+ type Colors = ReturnType<typeof getThemeColors>
17
+
18
+ const clamp = (value: number) => Math.max(0, Math.min(1, value))
19
+ const rankY = (rank: number) => 100 + rank * 54
20
+
21
+ function Token({ x, y, color, textColor }: { x: number; y: number; color: string; textColor: string }) {
22
+ return (
23
+ <div style={{
24
+ display: 'flex',
25
+ position: 'absolute',
26
+ left: x - 17,
27
+ top: y - 17,
28
+ width: 34,
29
+ height: 34,
30
+ alignItems: 'center',
31
+ justifyContent: 'center',
32
+ borderRadius: 34,
33
+ backgroundColor: color,
34
+ color: textColor,
35
+ fontFamily: 'JetBrains Mono',
36
+ fontSize: 12,
37
+ fontWeight: 900,
38
+ }}>
39
+ X
40
+ </div>
41
+ )
42
+ }
43
+
44
+ function RankLanes({ c }: { c: Colors }) {
45
+ return (
46
+ <div style={{ display: 'flex', position: 'absolute', inset: 0 }}>
47
+ {[0, 1, 2, 3].map((rank) => (
48
+ <div key={rank} style={{ display: 'flex', position: 'absolute', inset: 0 }}>
49
+ <div style={{
50
+ display: 'flex',
51
+ position: 'absolute',
52
+ left: 22,
53
+ top: rankY(rank) - 16,
54
+ width: 122,
55
+ height: 32,
56
+ alignItems: 'center',
57
+ gap: 10,
58
+ paddingLeft: 12,
59
+ borderRadius: 9,
60
+ backgroundColor: c.bgCardAlt,
61
+ border: `1px solid ${c.borderSubtle}`,
62
+ color: c.textPrimary,
63
+ fontFamily: c.fontMono,
64
+ fontSize: 12,
65
+ fontWeight: 800,
66
+ }}>
67
+ <span style={{ width: 10, height: 10, borderRadius: 10, backgroundColor: rank === 0 ? c.info : c.neutralLight }} />
68
+ rank {rank}
69
+ </div>
70
+ <div style={{ display: 'flex', position: 'absolute', left: 170, top: rankY(rank) - 1, width: 780, height: 2, backgroundColor: c.borderSubtle }} />
71
+ </div>
72
+ ))}
73
+ </div>
74
+ )
75
+ }
76
+
77
+ function Frame({ theme, progress }: { theme: ThemeMode; progress: number }) {
78
+ const c = getThemeColors(theme)
79
+ const color = getToneColor('cyan', c)
80
+ const semanticColor = getReadableToneColor('cyan', c, c.bgCard)
81
+ const textColor = getReadableTextColor(color, c)
82
+ const p = clamp(progress)
83
+ const sourceX = 226
84
+ const targetX = 850
85
+ const phase = p < 0.08 ? 'root buffer' : p < 0.92 ? 'fan-out copies' : 'replicated on every rank'
86
+
87
+ return (
88
+ <div style={{ display: 'flex', position: 'relative', width, height, backgroundColor: c.bg, fontFamily: c.fontSans }}>
89
+ <div style={{ display: 'flex', width, height, opacity: 0 }} />
90
+ <div style={{ display: 'flex', position: 'absolute', top: 18, width: '100%', justifyContent: 'center', color: c.textPrimary, fontSize: 36, fontWeight: 800 }}>NCCL · Broadcast</div>
91
+ <div style={{ display: 'flex', position: 'absolute', top: 62, width: '100%', justifyContent: 'center', color: c.textSecondary, fontFamily: c.fontMono, fontSize: 14 }}>One root-owned buffer becomes available on every GPU</div>
92
+
93
+ <div style={{ display: 'flex', position: 'absolute', left: 26, top: 100, width: 988, height: 374, overflow: 'hidden', borderRadius: 14, backgroundColor: c.bgCard, border: `1px solid ${c.borderSubtle}` }}>
94
+ <div style={{ display: 'flex', position: 'absolute', left: 22, top: 18, alignItems: 'center', gap: 10 }}>
95
+ <span style={{ width: 6, height: 28, borderRadius: 6, backgroundColor: color }} />
96
+ <span style={{ color: c.textPrimary, fontSize: 20, fontWeight: 800 }}>Broadcast</span>
97
+ <span style={{ color: c.textMuted, fontFamily: c.fontMono, fontSize: 11 }}>root sends; peers do not contribute</span>
98
+ </div>
99
+ <div style={{ display: 'flex', position: 'absolute', right: 22, top: 24, color: semanticColor, fontFamily: c.fontMono, fontSize: 12, fontWeight: 900 }}>ONE → ALL</div>
100
+
101
+ <RankLanes c={c} />
102
+ {[1, 2, 3].map((rank) => (
103
+ <Token
104
+ key={rank}
105
+ x={sourceX + (targetX - sourceX) * p}
106
+ y={rankY(0) + (rankY(rank) - rankY(0)) * p}
107
+ color={color}
108
+ textColor={textColor}
109
+ />
110
+ ))}
111
+ <Token x={sourceX} y={rankY(0)} color={color} textColor={textColor} />
112
+ <div style={{ display: 'flex', position: 'absolute', left: sourceX - 20, top: rankY(0) - 40, color: c.textPrimary, fontFamily: c.fontMono, fontSize: 11, fontWeight: 900 }}>ROOT</div>
113
+
114
+ <div style={{ display: 'flex', position: 'absolute', left: 22, top: 326, color: c.textMuted, fontFamily: c.fontMono, fontSize: 11 }}>{phase}</div>
115
+ <div style={{ display: 'flex', position: 'absolute', left: 170, top: 332, width: 780, height: 6, borderRadius: 6, backgroundColor: c.borderSubtle }}>
116
+ <div style={{ display: 'flex', width: `${Math.round(p * 100)}%`, height: 6, borderRadius: 6, backgroundColor: color }} />
117
+ </div>
118
+ </div>
119
+ </div>
120
+ )
121
+ }
5
122
 
6
123
  export function createAnimation(theme: ThemeMode) {
7
- return createNcclAnimation(theme, 'broadcast')
124
+ return defineAnimation<State>({
125
+ initial: { progress: 0 },
126
+ timeline: [
127
+ hold(800, 'root buffer'),
128
+ tween<Partial<State>>({ progress: 1 }, { duration: 2600, easing: 'ease-in-out', label: 'fan out copies' }),
129
+ hold(1000, 'replicated result'),
130
+ ],
131
+ fps: 20,
132
+ render: (state) => <Frame theme={theme} progress={state.progress} />,
133
+ })
8
134
  }
9
135
 
10
136
  export function create(theme: ThemeMode = 'dark') {
11
- return createNcclFrame(theme, 'broadcast')
137
+ return <Frame theme={theme} progress={1} />
12
138
  }
13
139
 
14
140
  export default create('dark')
@@ -1,14 +1,170 @@
1
- import type { ThemeMode } from 'vizmatic'
2
- import { createNcclAnimation, createNcclFrame } from './_shared/nccl-collective'
1
+ import {
2
+ defineAnimation,
3
+ getReadableToneColor,
4
+ getReadableTextColor,
5
+ getThemeColors,
6
+ getToneColor,
7
+ hold,
8
+ tween,
9
+ type ThemeMode,
10
+ } from 'vizmatic'
3
11
 
4
- export { height, width } from './_shared/nccl-collective'
12
+ export const width = 1040
13
+ export const height = 500
14
+
15
+ type State = { progress: number }
16
+ type Colors = ReturnType<typeof getThemeColors>
17
+
18
+ const clamp = (value: number) => Math.max(0, Math.min(1, value))
19
+ const rankY = (rank: number) => 100 + rank * 54
20
+
21
+ function Token({ x, y, label, color, textColor, opacity = 1, size = 34 }: { x: number; y: number; label: string; color: string; textColor: string; opacity?: number; size?: number }) {
22
+ return (
23
+ <div style={{
24
+ display: 'flex',
25
+ position: 'absolute',
26
+ left: x - size / 2,
27
+ top: y - size / 2,
28
+ width: size,
29
+ height: size,
30
+ alignItems: 'center',
31
+ justifyContent: 'center',
32
+ borderRadius: size > 32 ? 10 : 7,
33
+ backgroundColor: color,
34
+ color: textColor,
35
+ fontFamily: 'JetBrains Mono',
36
+ fontSize: 11,
37
+ fontWeight: 900,
38
+ opacity,
39
+ }}>
40
+ {label}
41
+ </div>
42
+ )
43
+ }
44
+
45
+ function RankLanes({ c }: { c: Colors }) {
46
+ return (
47
+ <div style={{ display: 'flex', position: 'absolute', inset: 0 }}>
48
+ {[0, 1, 2, 3].map((rank) => (
49
+ <div key={rank} style={{ display: 'flex', position: 'absolute', inset: 0 }}>
50
+ <div style={{
51
+ display: 'flex',
52
+ position: 'absolute',
53
+ left: 22,
54
+ top: rankY(rank) - 16,
55
+ width: 122,
56
+ height: 32,
57
+ alignItems: 'center',
58
+ gap: 10,
59
+ paddingLeft: 12,
60
+ borderRadius: 9,
61
+ backgroundColor: c.bgCardAlt,
62
+ border: `1px solid ${c.borderSubtle}`,
63
+ color: c.textPrimary,
64
+ fontFamily: c.fontMono,
65
+ fontSize: 12,
66
+ fontWeight: 800,
67
+ }}>
68
+ <span style={{ width: 10, height: 10, borderRadius: 10, backgroundColor: c.neutralLight }} />
69
+ rank {rank}
70
+ </div>
71
+ <div style={{ display: 'flex', position: 'absolute', left: 170, top: rankY(rank) - 1, width: 780, height: 2, backgroundColor: c.borderSubtle }} />
72
+ </div>
73
+ ))}
74
+ </div>
75
+ )
76
+ }
77
+
78
+ function Frame({ theme, progress }: { theme: ThemeMode; progress: number }) {
79
+ const c = getThemeColors(theme)
80
+ const color = getToneColor('green', c)
81
+ const semanticColor = getReadableToneColor('green', c, c.bgCard)
82
+ const p = clamp(progress)
83
+ const reduce = clamp(p / 0.5)
84
+ const scatter = clamp((p - 0.5) / 0.5)
85
+ const inputOpacity = 1 - clamp((p - 0.46) / 0.12)
86
+ const resultOpacity = clamp((p - 0.42) / 0.12)
87
+ const centerX = 548
88
+ const centerY = 181
89
+ const outputX = 850
90
+ const chunkColors = [c.info, c.primaryLight, c.secondaryLight, c.positiveLight]
91
+ const phase = p < 0.46 ? 'reduce matching chunk indices' : p < 0.92 ? 'scatter one completed chunk per rank' : 'partitioned reduced result'
92
+
93
+ return (
94
+ <div style={{ display: 'flex', position: 'relative', width, height, backgroundColor: c.bg, fontFamily: c.fontSans }}>
95
+ <div style={{ display: 'flex', width, height, opacity: 0 }} />
96
+ <div style={{ display: 'flex', position: 'absolute', top: 18, width: '100%', justifyContent: 'center', color: c.textPrimary, fontSize: 36, fontWeight: 800 }}>NCCL · ReduceScatter</div>
97
+ <div style={{ display: 'flex', position: 'absolute', top: 62, width: '100%', justifyContent: 'center', color: c.textSecondary, fontFamily: c.fontMono, fontSize: 14 }}>Reduce corresponding chunks, then assign one completed shard to each GPU</div>
98
+
99
+ <div style={{ display: 'flex', position: 'absolute', left: 26, top: 100, width: 988, height: 374, overflow: 'hidden', borderRadius: 14, backgroundColor: c.bgCard, border: `1px solid ${c.borderSubtle}` }}>
100
+ <div style={{ display: 'flex', position: 'absolute', left: 22, top: 18, alignItems: 'center', gap: 10 }}>
101
+ <span style={{ width: 6, height: 28, borderRadius: 6, backgroundColor: color }} />
102
+ <span style={{ color: c.textPrimary, fontSize: 20, fontWeight: 800 }}>ReduceScatter</span>
103
+ <span style={{ color: c.textMuted, fontFamily: c.fontMono, fontSize: 11 }}>color identifies final owner</span>
104
+ </div>
105
+ <div style={{ display: 'flex', position: 'absolute', right: 22, top: 24, color: semanticColor, fontFamily: c.fontMono, fontSize: 12, fontWeight: 900 }}>ALL → ONE SHARD / RANK</div>
106
+
107
+ <RankLanes c={c} />
108
+ <div style={{ display: 'flex', position: 'absolute', left: centerX - 60, top: centerY - 49, width: 120, height: 98, alignItems: 'center', justifyContent: 'center', borderRadius: 12, backgroundColor: c.bgCardAlt, border: `2px dashed ${color}`, opacity: 0.82 }} />
109
+ <div style={{ display: 'flex', position: 'absolute', left: centerX - 48, top: centerY - 66, color: c.textMuted, fontFamily: c.fontMono, fontSize: 11, fontWeight: 900 }}>REDUCE BY INDEX</div>
110
+
111
+ {inputOpacity > 0.01 && [0, 1, 2, 3].flatMap((source) => [0, 1, 2, 3].map((destination) => {
112
+ const startX = 208 + destination * 36
113
+ const slotX = centerX - 36 + destination * 24
114
+ const chunkColor = chunkColors[destination]
115
+ return (
116
+ <Token
117
+ key={`input-${source}-${destination}`}
118
+ x={startX + (slotX - startX) * reduce}
119
+ y={rankY(source) + (centerY - rankY(source)) * reduce}
120
+ label={`${source}:${destination}`}
121
+ color={chunkColor}
122
+ textColor={getReadableTextColor(chunkColor, c)}
123
+ opacity={inputOpacity}
124
+ />
125
+ )
126
+ }))}
127
+ {[0, 1, 2, 3].map((destination) => {
128
+ const slotX = centerX - 36 + destination * 24
129
+ const chunkColor = chunkColors[destination]
130
+ return (
131
+ <Token
132
+ key={`output-${destination}`}
133
+ x={slotX + (outputX - slotX) * scatter}
134
+ y={centerY + (rankY(destination) - centerY) * scatter}
135
+ label={`R${destination}`}
136
+ color={chunkColor}
137
+ textColor={getReadableTextColor(chunkColor, c)}
138
+ opacity={resultOpacity}
139
+ size={38}
140
+ />
141
+ )
142
+ })}
143
+
144
+ <div style={{ display: 'flex', position: 'absolute', left: 22, top: 326, color: c.textMuted, fontFamily: c.fontMono, fontSize: 11 }}>{phase}</div>
145
+ <div style={{ display: 'flex', position: 'absolute', left: 170, top: 332, width: 780, height: 6, borderRadius: 6, backgroundColor: c.borderSubtle }}>
146
+ <div style={{ display: 'flex', width: `${Math.round(p * 100)}%`, height: 6, borderRadius: 6, backgroundColor: color }} />
147
+ </div>
148
+ </div>
149
+ </div>
150
+ )
151
+ }
5
152
 
6
153
  export function createAnimation(theme: ThemeMode) {
7
- return createNcclAnimation(theme, 'reduce-scatter')
154
+ return defineAnimation<State>({
155
+ initial: { progress: 0 },
156
+ timeline: [
157
+ hold(800, 'rank-local chunks'),
158
+ tween<Partial<State>>({ progress: 1 }, { duration: 3000, easing: 'ease-in-out', label: 'reduce and scatter' }),
159
+ hold(1000, 'one shard per rank'),
160
+ ],
161
+ fps: 20,
162
+ render: (state) => <Frame theme={theme} progress={state.progress} />,
163
+ })
8
164
  }
9
165
 
10
166
  export function create(theme: ThemeMode = 'dark') {
11
- return createNcclFrame(theme, 'reduce-scatter')
167
+ return <Frame theme={theme} progress={1} />
12
168
  }
13
169
 
14
170
  export default create('dark')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vizmatic",
3
- "version": "0.1.37",
3
+ "version": "0.1.38",
4
4
  "description": "Theme-aware visual primitives and a headless renderer for diagrams, figures, and presentation frames.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,420 +0,0 @@
1
- import {
2
- defineAnimation,
3
- getThemeColors,
4
- getReadableToneColor,
5
- getReadableTextColor,
6
- getToneColor,
7
- hold,
8
- tween,
9
- type ThemeMode,
10
- type ToneName,
11
- } from 'vizmatic'
12
-
13
- export const width = 1040
14
- export const height = 600
15
-
16
- type State = {
17
- progress: number
18
- }
19
-
20
- export type NcclCollective = 'broadcast' | 'all-reduce' | 'all-gather' | 'reduce-scatter' | 'all-to-all'
21
-
22
- type Operation = {
23
- name: string
24
- description: string
25
- semantic: string
26
- tone: ToneName
27
- }
28
-
29
- // Collective directions follow NVIDIA NCCL's operation definitions:
30
- // https://docs.nvidia.com/deeplearning/nccl/user-guide/docs/usage/collectives.html
31
- const operations: Record<NcclCollective, Operation> = {
32
- broadcast: {
33
- name: 'Broadcast',
34
- description: 'Copy root rank buffer to every rank.',
35
- semantic: 'one → all',
36
- tone: 'cyan',
37
- },
38
- 'all-reduce': {
39
- name: 'AllReduce',
40
- description: 'Reduce values, then return result to every rank.',
41
- semantic: 'all → all',
42
- tone: 'purple',
43
- },
44
- 'all-gather': {
45
- name: 'AllGather',
46
- description: 'Gather every rank tensor on every rank.',
47
- semantic: 'all → all · concat',
48
- tone: 'blue',
49
- },
50
- 'reduce-scatter': {
51
- name: 'ReduceScatter',
52
- description: 'Reduce by chunk, then scatter one result per rank.',
53
- semantic: 'all → one chunk',
54
- tone: 'green',
55
- },
56
- 'all-to-all': {
57
- name: 'AlltoAll',
58
- description: 'Exchange rank-addressed chunks among every rank.',
59
- semantic: 'all ↔ all',
60
- tone: 'warm',
61
- },
62
- }
63
-
64
- const rankY = (rank: number) => 68 + rank * 43
65
- const clamp = (value: number) => Math.max(0, Math.min(1, value))
66
- const absoluteFill = {
67
- display: 'flex',
68
- position: 'absolute' as const,
69
- left: 0,
70
- top: 0,
71
- width: '100%',
72
- height: '100%',
73
- }
74
-
75
- function phaseLabel(operation: NcclCollective, progress: number): string {
76
- const p = clamp(progress)
77
- if (operation === 'broadcast') return p < 0.12 ? 'root buffer' : p < 0.86 ? 'fan-out' : 'replicated'
78
- if (operation === 'all-reduce') return p < 0.48 ? 'reduce' : p < 0.88 ? 'broadcast sum' : 'complete'
79
- if (operation === 'all-gather') return p < 0.48 ? 'gather' : p < 0.88 ? 'replicate list' : 'complete'
80
- if (operation === 'reduce-scatter') return p < 0.48 ? 'reduce by index' : p < 0.88 ? 'scatter outputs' : 'complete'
81
- return p < 0.12 ? 'rank-addressed chunks' : p < 0.88 ? 'exchange' : 'rank-ordered output'
82
- }
83
-
84
- interface DataTokenProps {
85
- x: number
86
- y: number
87
- label: string
88
- color: string
89
- textColor: string
90
- opacity?: number
91
- width?: number
92
- }
93
-
94
- function DataToken({
95
- x,
96
- y,
97
- label,
98
- color,
99
- textColor,
100
- opacity = 1,
101
- width: tokenWidth = 34,
102
- }: DataTokenProps) {
103
- const tokenHeight = 24
104
- return (
105
- <div style={{
106
- display: 'flex',
107
- position: 'absolute',
108
- left: x - tokenWidth / 2,
109
- top: y - tokenHeight / 2,
110
- width: tokenWidth,
111
- height: tokenHeight,
112
- alignItems: 'center',
113
- justifyContent: 'center',
114
- borderRadius: 7,
115
- backgroundColor: color,
116
- color: textColor,
117
- fontSize: 11,
118
- fontWeight: 800,
119
- fontFamily: 'JetBrains Mono',
120
- opacity,
121
- }}>
122
- {label}
123
- </div>
124
- )
125
- }
126
-
127
- function RankLanes({ c }: { c: ReturnType<typeof getThemeColors> }) {
128
- return (
129
- <div style={absoluteFill}>
130
- <div style={{ display: 'flex', position: 'absolute', left: 24, top: 14, color: c.textMuted, fontSize: 11, fontWeight: 800, fontFamily: c.fontMono, letterSpacing: 1.2 }}>RANKS</div>
131
- <div style={{ display: 'flex', position: 'absolute', left: 222, top: 14, color: c.textMuted, fontSize: 11, fontWeight: 800, fontFamily: c.fontMono, letterSpacing: 1.2 }}>COLLECTIVE PATH</div>
132
- {[0, 1, 2, 3].map((rank) => {
133
- const y = rankY(rank)
134
- return (
135
- <div key={`rank-${rank}`} style={absoluteFill}>
136
- <div style={{ display: 'flex', position: 'absolute', left: 22, top: y - 15, width: 128, height: 30, alignItems: 'center', gap: 9, paddingLeft: 12, borderRadius: 9, backgroundColor: c.bgCardAlt, border: `1px solid ${c.borderSubtle}` }}>
137
- <span style={{ width: 10, height: 10, borderRadius: 10, backgroundColor: rank === 0 ? c.info : c.neutralLight }} />
138
- <span style={{ color: c.textPrimary, fontSize: 12, fontWeight: 700, fontFamily: c.fontMono }}>rank {rank}</span>
139
- </div>
140
- <div style={{ display: 'flex', position: 'absolute', left: 178, top: y - 1, width: 757, height: 2, backgroundColor: c.borderSubtle }} />
141
- <span style={{ position: 'absolute', left: 175, top: y - 3, width: 6, height: 6, borderRadius: 6, backgroundColor: c.borderLight }} />
142
- <span style={{ position: 'absolute', left: 932, top: y - 3, width: 6, height: 6, borderRadius: 6, backgroundColor: c.borderLight }} />
143
- </div>
144
- )
145
- })}
146
- </div>
147
- )
148
- }
149
-
150
- function BroadcastView({ c, progress, color }: { c: ReturnType<typeof getThemeColors>; progress: number; color: string }) {
151
- const p = clamp(progress)
152
- const sourceX = 248
153
- const targetX = 858
154
- const tokenText = getReadableTextColor(color, c)
155
- return (
156
- <div style={absoluteFill}>
157
- {[1, 2, 3].map((rank) => {
158
- const y = rankY(rank)
159
- return (
160
- <div key={`broadcast-path-${rank}`} style={absoluteFill}>
161
- {DataToken({ x: targetX, y, label: 'X', color, textColor: tokenText, opacity: 0.15 + p * 0.2 })}
162
- {DataToken({
163
- x: sourceX + (targetX - sourceX) * p,
164
- y: rankY(0) + (y - rankY(0)) * p,
165
- label: 'X',
166
- color,
167
- textColor: tokenText,
168
- opacity: 0.98,
169
- })}
170
- </div>
171
- )
172
- })}
173
- {DataToken({ x: sourceX, y: rankY(0), label: 'X', color, textColor: tokenText })}
174
- <div style={{ display: 'flex', position: 'absolute', left: sourceX - 18, top: rankY(0) - 34, color: c.textPrimary, fontSize: 11, fontWeight: 800, fontFamily: c.fontMono }}>ROOT</div>
175
- <div style={{ display: 'flex', position: 'absolute', left: targetX + 26, top: rankY(3) - 8, color: c.textMuted, fontSize: 11, fontFamily: c.fontMono }}>same buffer</div>
176
- </div>
177
- )
178
- }
179
-
180
- function AllReduceView({ c, progress, color }: { c: ReturnType<typeof getThemeColors>; progress: number; color: string }) {
181
- const p = clamp(progress)
182
- const centerX = 550
183
- const centerY = 143
184
- const outputX = 858
185
- const reduceP = Math.min(1, p * 2)
186
- const scatterP = clamp((p - 0.42) / 0.58)
187
- const tokenText = getReadableTextColor(color, c)
188
- return (
189
- <div style={absoluteFill}>
190
- <div style={{ display: 'flex', position: 'absolute', left: centerX - 26, top: centerY - 26, width: 52, height: 52, alignItems: 'center', justifyContent: 'center', borderRadius: 52, backgroundColor: c.bgCardAlt, border: `2px solid ${color}`, color, fontSize: 20, fontWeight: 800, fontFamily: c.fontMono }}>Σ</div>
191
- {[0, 1, 2, 3].map((rank) => {
192
- const y = rankY(rank)
193
- const sourceX = 248 + (centerX - 248) * reduceP
194
- return (
195
- <div key={`allreduce-${rank}`} style={absoluteFill}>
196
- {p < 0.75 && DataToken({ x: sourceX, y: y + (centerY - y) * reduceP, label: String(rank + 1), color, textColor: tokenText, opacity: 1 - Math.min(1, p * 1.35) })}
197
- {DataToken({ x: centerX + (outputX - centerX) * scatterP, y: centerY + (y - centerY) * scatterP, label: '10', color, textColor: tokenText, opacity: scatterP })}
198
- </div>
199
- )
200
- })}
201
- <div style={{ display: 'flex', position: 'absolute', left: centerX - 42, top: centerY + 31, color: c.textMuted, fontSize: 11, fontFamily: c.fontMono }}>1 + 2 + 3 + 4</div>
202
- </div>
203
- )
204
- }
205
-
206
- function AllGatherView({ c, progress, color }: { c: ReturnType<typeof getThemeColors>; progress: number; color: string }) {
207
- const p = clamp(progress)
208
- const gatherP = Math.min(1, p * 2)
209
- const replicateP = clamp((p - 0.43) / 0.57)
210
- const centerX = 548
211
- const centerY = 143
212
- const sourceX = 248
213
- const outputX = 736
214
- const labels = ['A', 'B', 'C', 'D']
215
- const tokenText = getReadableTextColor(color, c)
216
-
217
- return (
218
- <div style={absoluteFill}>
219
- <div style={{ display: 'flex', position: 'absolute', left: centerX - 52, top: centerY - 45, width: 104, height: 90, alignItems: 'center', justifyContent: 'center', borderRadius: 12, backgroundColor: c.bgCardAlt, border: `2px dashed ${color}`, opacity: 0.8 }} />
220
- <div style={{ display: 'flex', position: 'absolute', left: centerX - 26, top: centerY - 64, color: c.textMuted, fontSize: 11, fontWeight: 800, fontFamily: c.fontMono }}>CONCAT</div>
221
- {[0, 1, 2, 3].map((rank) => {
222
- const y = rankY(rank)
223
- const centerSlotX = centerX - 30 + rank * 20
224
- return (
225
- <div key={`allgather-${rank}`} style={absoluteFill}>
226
- {DataToken({
227
- x: sourceX + (centerSlotX - sourceX) * gatherP,
228
- y: y + (centerY + (rank - 1.5) * 2 - y) * gatherP,
229
- label: labels[rank],
230
- color,
231
- textColor: tokenText,
232
- opacity: 1 - Math.min(1, p * 1.4),
233
- width: 28,
234
- })}
235
- </div>
236
- )
237
- })}
238
- {[0, 1, 2, 3].flatMap((target) => labels.map((label, source) => {
239
- const centerSlotX = centerX - 30 + source * 20
240
- return DataToken({
241
- x: centerSlotX + (outputX + source * 34 - centerSlotX) * replicateP,
242
- y: centerY + (rankY(target) - centerY) * replicateP,
243
- label,
244
- color,
245
- textColor: tokenText,
246
- opacity: replicateP,
247
- width: 28,
248
- })
249
- }))}
250
- <div style={{ display: 'flex', position: 'absolute', left: 884, top: rankY(3) - 14, width: 102, height: 28, alignItems: 'center', justifyContent: 'center', borderRadius: 6, backgroundColor: c.bgCard, color: c.textMuted, fontSize: 11, fontFamily: c.fontMono, opacity: 0.94 }}>A · B · C · D</div>
251
- </div>
252
- )
253
- }
254
-
255
- function ReduceScatterView({ c, progress, color }: { c: ReturnType<typeof getThemeColors>; progress: number; color: string }) {
256
- const p = clamp(progress)
257
- const reduceP = Math.min(1, p * 2)
258
- const scatterP = clamp((p - 0.42) / 0.58)
259
- const centerX = 548
260
- const centerY = 143
261
- const outputX = 858
262
- const chunkColors = [c.info, c.primaryLight, c.secondaryLight, c.positiveLight]
263
- return (
264
- <div style={absoluteFill}>
265
- <div style={{ display: 'flex', position: 'absolute', left: centerX - 56, top: centerY - 47, width: 112, height: 94, borderRadius: 12, backgroundColor: c.bgCardAlt, border: `2px dashed ${color}`, opacity: 0.7 }} />
266
- <div style={{ display: 'flex', position: 'absolute', left: centerX - 48, top: centerY - 65, color: c.textMuted, fontSize: 11, fontWeight: 800, fontFamily: c.fontMono }}>REDUCE CHUNKS</div>
267
- {[0, 1, 2, 3].map((destination) => {
268
- const y = rankY(destination)
269
- const centerSlotX = centerX - 30 + destination * 20
270
- return (
271
- <div key={`reducescatter-destination-${destination}`} style={absoluteFill}>
272
- <div style={{ display: 'flex', position: 'absolute', left: centerSlotX - 13, top: centerY - 13, width: 26, height: 26, alignItems: 'center', justifyContent: 'center', borderRadius: 26, backgroundColor: c.bgCardAlt, border: `2px solid ${chunkColors[destination]}`, color: c.textPrimary, fontSize: 11, fontWeight: 800, fontFamily: c.fontMono }}>R{destination}</div>
273
- {DataToken({
274
- x: centerSlotX + (outputX - centerSlotX) * scatterP,
275
- y: centerY + (y - centerY) * scatterP,
276
- label: `R${destination}`,
277
- color: chunkColors[destination],
278
- textColor: getReadableTextColor(chunkColors[destination], c),
279
- opacity: scatterP,
280
- width: 38,
281
- })}
282
- </div>
283
- )
284
- })}
285
- {p < 0.75 && [0, 1, 2, 3].flatMap((source) => [0, 1, 2, 3].map((destination) => {
286
- const sourceX = 236 + destination * 26
287
- const sourceY = rankY(source)
288
- const centerSlotX = centerX - 30 + destination * 20
289
- return (
290
- <div key={`reducescatter-${source}-${destination}`} style={absoluteFill}>
291
- {DataToken({
292
- x: sourceX + (centerSlotX - sourceX) * reduceP,
293
- y: sourceY + (centerY - sourceY) * reduceP,
294
- label: `${source},${destination}`,
295
- color: chunkColors[destination],
296
- textColor: getReadableTextColor(chunkColors[destination], c),
297
- opacity: 1 - Math.min(1, p * 1.4),
298
- width: 24,
299
- })}
300
- </div>
301
- )
302
- }))}
303
- <div style={{ display: 'flex', position: 'absolute', left: 884, top: rankY(3) - 14, width: 102, height: 28, alignItems: 'center', justifyContent: 'center', borderRadius: 6, backgroundColor: c.bgCard, color: c.textMuted, fontSize: 11, fontFamily: c.fontMono, opacity: 0.94 }}>one chunk / rank</div>
304
- </div>
305
- )
306
- }
307
-
308
- function AllToAllView({ c, progress, color }: { c: ReturnType<typeof getThemeColors>; progress: number; color: string }) {
309
- const p = clamp(progress)
310
- const destinationColors = [c.info, c.primaryLight, c.secondaryLight, c.warningLight]
311
- const sourceStartX = 240
312
- const outputStartX = 730
313
- const tokenGap = 44
314
-
315
- return (
316
- <div style={absoluteFill}>
317
- <div style={{ display: 'flex', position: 'absolute', left: 492, top: 96, width: 112, height: 94, alignItems: 'center', justifyContent: 'center', borderRadius: 12, backgroundColor: c.bgCardAlt, border: `2px dashed ${color}`, color: c.textMuted, fontSize: 11, fontWeight: 800, fontFamily: c.fontMono }}>EXCHANGE</div>
318
- {[0, 1, 2, 3].flatMap((source) => [0, 1, 2, 3].map((destination) => {
319
- const tokenColor = destinationColors[destination]
320
- const startX = sourceStartX + destination * tokenGap
321
- const endX = outputStartX + source * tokenGap
322
- const startY = rankY(source)
323
- const endY = rankY(destination)
324
- return (
325
- <div key={`alltoall-${source}-${destination}`} style={absoluteFill}>
326
- {DataToken({
327
- x: startX + (endX - startX) * p,
328
- y: startY + (endY - startY) * p,
329
- label: `${source}→${destination}`,
330
- color: tokenColor,
331
- textColor: getReadableTextColor(tokenColor, c),
332
- width: 40,
333
- })}
334
- </div>
335
- )
336
- }))}
337
- <div style={{ display: 'flex', position: 'absolute', left: 224, top: 240, color: c.textMuted, fontSize: 11, fontFamily: c.fontMono }}>color = destination</div>
338
- <div style={{ display: 'flex', position: 'absolute', left: 882, top: 240, color: c.textMuted, fontSize: 11, fontFamily: c.fontMono }}>source order</div>
339
- </div>
340
- )
341
- }
342
-
343
- function renderFrame(theme: ThemeMode, collective: NcclCollective, state: Readonly<State>) {
344
- const c = getThemeColors(theme)
345
- const operation = operations[collective]
346
- const color = getToneColor(operation.tone, c)
347
- const semanticColor = getReadableToneColor(operation.tone, c, c.bgCardAlt)
348
- const p = clamp(state.progress)
349
-
350
- return (
351
- <div style={{
352
- display: 'flex',
353
- position: 'relative',
354
- flexGrow: 0,
355
- flexShrink: 0,
356
- width,
357
- minWidth: width,
358
- maxWidth: width,
359
- height,
360
- minHeight: height,
361
- maxHeight: height,
362
- backgroundColor: c.bg,
363
- fontFamily: c.fontSans,
364
- }}>
365
- <div style={{ display: 'flex', flexGrow: 0, flexShrink: 0, width, height, opacity: 0 }} />
366
- <div style={{ display: 'flex', position: 'absolute', left: 0, top: 20, width: '100%', justifyContent: 'center', color: c.textPrimary, fontFamily: c.fontSans, fontSize: 40, fontWeight: 700 }}>NCCL · {operation.name}</div>
367
- <div style={{ display: 'flex', position: 'absolute', left: 0, top: 72, width: '100%', justifyContent: 'center', color: c.textSecondary, fontFamily: c.fontMono, fontSize: 16 }}>Rank-local chunks, collective paths, and final ownership across four GPUs</div>
368
-
369
- <div style={{ display: 'flex', position: 'absolute', left: 26, top: 110, width: 988, height: 70, alignItems: 'stretch', justifyContent: 'space-between', gap: 14 }}>
370
- <div style={{ display: 'flex', flex: 1, alignItems: 'center', gap: 12, padding: '12px 16px', border: `1px solid ${c.borderSubtle}`, borderRadius: 12, backgroundColor: c.bgCard }}>
371
- <div style={{ display: 'flex', width: 6, height: 42, borderRadius: 6, backgroundColor: color }} />
372
- <div style={{ display: 'flex', flexDirection: 'column', gap: 3 }}>
373
- <div style={{ display: 'flex', color: c.textPrimary, fontFamily: c.fontSans, fontSize: 22, fontWeight: 800 }}>{operation.name}</div>
374
- <div style={{ display: 'flex', color: c.textSecondary, fontFamily: c.fontMono, fontSize: 11 }}>{operation.description}</div>
375
- </div>
376
- </div>
377
- <div style={{ display: 'flex', width: 236, flexDirection: 'column', justifyContent: 'center', gap: 7, padding: '11px 15px', border: `1px solid ${c.borderSubtle}`, borderRadius: 12, backgroundColor: c.bgCardAlt }}>
378
- <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
379
- <span style={{ color: c.textMuted, fontFamily: c.fontMono, fontSize: 11, fontWeight: 800 }}>COLLECTIVE</span>
380
- <span style={{ color: semanticColor, fontFamily: c.fontMono, fontSize: 11, fontWeight: 800 }}>{operation.semantic}</span>
381
- </div>
382
- <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
383
- <div style={{ display: 'flex', flex: 1, height: 5, borderRadius: 8, backgroundColor: c.borderSubtle }}>
384
- <div style={{ display: 'flex', width: `${Math.round(p * 100)}%`, height: 5, borderRadius: 8, backgroundColor: color }} />
385
- </div>
386
- <span style={{ color: c.textSecondary, fontFamily: c.fontMono, fontSize: 11 }}>{phaseLabel(collective, p)}</span>
387
- </div>
388
- </div>
389
- </div>
390
-
391
- <div style={{ display: 'flex', position: 'absolute', left: 26, top: 194, width: 988, height: 286, overflow: 'hidden', borderRadius: 14, backgroundColor: c.bgCard, border: `1px solid ${c.borderSubtle}` }}>
392
- {RankLanes({ c })}
393
- {collective === 'broadcast' && BroadcastView({ c, progress: p, color })}
394
- {collective === 'all-reduce' && AllReduceView({ c, progress: p, color })}
395
- {collective === 'all-gather' && AllGatherView({ c, progress: p, color })}
396
- {collective === 'reduce-scatter' && ReduceScatterView({ c, progress: p, color })}
397
- {collective === 'all-to-all' && AllToAllView({ c, progress: p, color })}
398
- </div>
399
-
400
- </div>
401
- )
402
- }
403
-
404
- export function createNcclAnimation(theme: ThemeMode, collective: NcclCollective) {
405
- const operation = operations[collective]
406
- return defineAnimation<State>({
407
- initial: { progress: 0 },
408
- timeline: [
409
- hold(700, `${operation.name} · input`),
410
- tween<Partial<State>>({ progress: 1 }, { duration: 2200, easing: 'ease-in-out', label: `${operation.name} · transfer` }),
411
- hold(700, `${operation.name} · output`),
412
- ],
413
- fps: 15,
414
- render: (state) => renderFrame(theme, collective, state),
415
- })
416
- }
417
-
418
- export function createNcclFrame(theme: ThemeMode, collective: NcclCollective, progress = 1) {
419
- return renderFrame(theme, collective, { progress })
420
- }