File size: 5,265 Bytes
ce35403
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { Arrow, FigBox, FILL, LoopFigure, type LoopStop } from "./LoopFigure";

const STOPS: LoopStop[] = [
  {
    x: 160,
    y: 110,
    ids: ["vision"],
    inspect: "vision",
    title: "Image patches",
    note: "The image is cut into patches. This is the new front-end; the language model still has not seen pixels.",
  },
  {
    x: 160,
    y: 170,
    ids: ["vision"],
    inspect: "vision",
    title: "ViT encoder",
    note: "A vision Transformer (often CLIP-ViT) turns patches into a sequence of embeddings.",
  },
  {
    x: 160,
    y: 270,
    ids: ["projector"],
    inspect: "projector",
    title: "Projector W",
    note: "A linear layer or small MLP maps vision width onto the LLM hidden size.",
  },
  {
    x: 500,
    y: 170,
    ids: ["decoder"],
    inspect: "decoder",
    title: "Text tokens",
    note: "The prompt is embedded as usual. Vision tokens will sit in the same residual stream.",
  },
  {
    x: 330,
    y: 360,
    ids: ["decoder", "projector"],
    inspect: "decoder",
    title: "Concat [vision ; text]",
    note: "z = LLM([W · ViT(image); text]). Cross-attention variants keep the ViT as a separate memory.",
  },
  {
    x: 330,
    y: 450,
    ids: ["decoder"],
    inspect: "decoder",
    title: "LLM decoder → logits",
    note: "The top layer is still next-token prediction. Once vision tokens are in context, the same stack can caption or follow instructions.",
  },
];

export function VlmLoop({ onSelect }: { onSelect: (id: string) => void }) {
  return (
    <LoopFigure
      stops={STOPS}
      loopMs={15000}
      viewBox="0 0 680 520"
      ariaLabel="Vision-language model architecture"
      onSelect={onSelect}
    >
      {({ on, markerId }) => (
        <g>
          <rect width="680" height="520" fill="#f7f4ec" />
          <text x="340" y="28" textAnchor="middle" fontSize="16" fontWeight="700" fill="#222">
            Vision-Language Model
          </text>
          <text x="340" y="48" textAnchor="middle" fontSize="12" fill="#555">
            z = LLM([W · ViT(image); text])
          </text>

          <text x="160" y="78" textAnchor="middle" fontSize="12" fill="#555">
            Vision
          </text>
          <g>
            {[0, 1, 2].map((r) =>
              [0, 1, 2].map((c) => (
                <rect
                  key={`${r}-${c}`}
                  x={118 + c * 28}
                  y={86 + r * 16}
                  width="24"
                  height="13"
                  rx="2"
                  fill={on("vision") ? FILL.green : "#cfe8d4"}
                  stroke="#3a7a4a"
                />
              )),
            )}
          </g>
          <Arrow x1={160} y1={140} x2={160} y2={148} active={on("vision")} markerId={markerId} />
          <FigBox
            x={70}
            y={148}
            w={180}
            h={48}
            fill={FILL.cyan}
            lit={on("vision")}
            label="ViT encoder"
            onClick={() => onSelect("vision")}
          />
          <Arrow x1={160} y1={196} x2={160} y2={242} active={on("vision") || on("projector")} markerId={markerId} />
          <FigBox
            x={70}
            y={248}
            w={180}
            h={44}
            fill={FILL.yellow}
            lit={on("projector")}
            label="Projector W"
            onClick={() => onSelect("projector")}
          />

          <text x="500" y="88" textAnchor="middle" fontSize="12" fill="#555">
            Language
          </text>
          <FigBox
            x={410}
            y={148}
            w={180}
            h={48}
            fill={FILL.pink}
            lit={on("decoder")}
            label="Text tokens"
            onClick={() => onSelect("decoder")}
          />
          <Arrow x1={500} y1={196} x2={500} y2={248} active={on("decoder")} markerId={markerId} />
          <FigBox
            x={410}
            y={248}
            w={180}
            h={44}
            fill={FILL.orange}
            lit={on("decoder")}
            label="Text embed"
            onClick={() => onSelect("decoder")}
          />

          <path
            d="M160 292 V 330 H 330"
            fill="none"
            stroke={on("projector") || on("decoder") ? "#111" : "#888"}
            strokeWidth={on("projector") ? 2.2 : 1.2}
            markerEnd={`url(#${markerId})`}
          />
          <path
            d="M500 292 V 330 H 330"
            fill="none"
            stroke={on("decoder") ? "#111" : "#888"}
            strokeWidth={on("decoder") ? 2.2 : 1.2}
            markerEnd={`url(#${markerId})`}
          />

          <FigBox
            x={220}
            y={336}
            w={220}
            h={48}
            fill={FILL.purple}
            lit={on("decoder")}
            label="[vision tokens ; text]"
            onClick={() => onSelect("decoder")}
          />
          <Arrow x1={330} y1={384} x2={330} y2={418} active={on("decoder")} markerId={markerId} />
          <FigBox
            x={200}
            y={426}
            w={260}
            h={52}
            fill={FILL.orange}
            lit={on("decoder")}
            label="LLM decoder → logits"
            onClick={() => onSelect("decoder")}
          />
        </g>
      )}
    </LoopFigure>
  );
}