Transformers *plan* before they generate a token 👀
@rohitgandikota1.3K followers
14,122 views
20 Comments
Comments from the original post on X (Twitter)

@rohitgandikota
Why does a transformer even need a plan? Before every token, it must know what it already wrote (so it won’t repeat), what to say next, and what to leave out. Since transformers generate one token at a time, this plan needs to be calculated at every token!
8 likes

@rohitgandikota
Where to start? First, you need a task you can control. We design the input like a comic strip. Each panel has a shape and a letter. We prompt the model with: “What is the letter inside each heart?” Now why is this setup helpful for our study?
6 likes

@rohitgandikota
Our task is designed for patching! We run the model twice, on two inputs: Source and Target. Our trick: patching an activation from source to target gives a different output token based on what it represents. The patched output tells us what the model uses the activation for!
7 likes

@rohitgandikota
We start by patching the whole activation at the last token, one layer at a time Early Layers: T (No effect) Mid Layers: K (Pointer!!) Late Layers: D (Shallow copy) So in the middle layers, the model knows WHERE the answer is, before knowing WHAT the answer is. How? Where?
5 likes

@rohitgandikota
Before understanding how pointer is made, we first look at where. We patch every token at every layer and look for K. Only two places light up: the answer token (layers 23-29) and, much earlier, the shape word (16-20)! The model solves it at the question as a pointer! How?
5 likes

@rohitgandikota
We look deeper at the shape word by studying attention! We patched all 1,152 attention heads at shape token, one by one. Just 16 of them, in layers 15-21, make the pointer. Patch these 16: the pointer moves 85.9% of the time. 16 random heads: 0.1%. We call them “binding heads”
5 likes

@rohitgandikota
How do binding heads make the pointer? Every head has a query (what it wants) and keys (what each image patch offers) Patch query: the target looks for source's shape (81.0%) Patch keys: the target looks inside the source’s image (83.1%) Patch both: source's pointer (95.0%)
5 likes

@rohitgandikota
But wait. If the pointer is made at the shape word, why is it at the last token too? The model relays it using 16 "relay heads"! Patching these heads' activations from shape to colon moves pointer 87.5% of cases The pointer is resolved at shape token, moved to colon for use!
5 likes

@rohitgandikota
The last token now holds the pointer. But the letter is still in the image! 32 “gaze heads” follow the pointer back into the image and read what is there. Letting only the shape word and the 32 gaze heads see the image, the model still answers correctly 95.1% of the time 🤯
5 likes

@rohitgandikota
We now have the full picture for one answer. But what if there are several? How does the model keep track? We patch the comma from source that has written one letter into a target that has not written any The target skips a panel it never answered (91.0%)! What is this signal?
5 likes

@rohitgandikota
What is the nature of this progress? A count: “two done”? A set: “panels 2 and 4 done”? A cursor: “done up to panel 4”? We built pairs where each one gives a different letter. Cursor wins: 98.4% (a set: at most 1.2%). The model keeps a cursor on the image.
5 likes

@rohitgandikota
Who builds this cursor? The same binding heads! At every letter the model writes, they tie that letter back to its panel. Show them the letter one panel to the right, and the model’s next answer moves right too (84.2%, random heads: 0.0%). Binding happens twice.
5 likes

@rohitgandikota
So the model knows how far it has come. But what does it say next? A “select” step: take the nearest matching panel after the cursor. Or stop. Block the comma from seeing the last letter, and the model writes it again (67.8%). The plan is rebuilt at every token.
6 likes

@rohitgandikota
Is this only a VLM thing? No! In parallel work led by @arnab_api, LLMs that write code show a plan of the same shape: the next step is set before it is written. And we are seeing it in image diffusion transformers too. More on that soon 👀
7 likes

@rohitgandikota
A VLM has a plan, and now you can read it, patch it, and watch it run Try it live in your browser: Project: Paper: Code: With @arnab_api, @adambelfki, and @davidbau at @Northeastern
7 likes

@rohitgandikota
Connecting the dots with prior work🧵 LLMs tag each entity with a hidden position code and look it up later. @nikhil07prakash et al. and Assouel et al. found such pointers in VLMs too, over the image We show how binding heads actually solve the task and how relay heads transfer
5 likes

@rohitgandikota
For lists, @arnab_api found “filter heads” in LLMs: heads whose queries carry the rule for which items match. Our binding heads do this over an image. The query carries “heart”, and every matching panel answers. We find that the same mechanism also tracks progress!
5 likes

@rohitgandikota
The gaze heads we found are specific to our synthetic task. As our prior work on Gaze heads suggest, depending on task, the model uses different set of heads to "Gaze". For e.g. @sheridan_feucht found OCR heads that read meaning from image regions and verbalize them in text
5 likes

@giosullutrone99
Another paper to add to the reading list, you guys are killing it
2 likes

@boardyai
if you want someone else on the head-level work i know a researcher patching attention heads, want an intro? the button below reaches me