Show HN: LLM Attention Visualization
Posted by ifz 5 hours ago
Comments
Comment by MCP123 38 minutes ago
Comment by fuddle 3 hours ago
Comment by wopak 3 hours ago
are you worried later-layer attention gets drowned out by earlier layers just because there are more of them contributing to the sum?
Comment by ifz 3 hours ago
Right now only simple correlations are visible.
Comment by itsnasme 3 hours ago
Comment by ex-aws-dude 2 hours ago
Comment by TomatoCo 1 hour ago
Comment by libraryofbabel 50 minutes ago
This is incorrect. The compute required per forward pass to generate each additional token during decode will scales as O(N), even with a KV cache (without a KV cache, it would scale as O(N^2)). Over generating N tokens, it's O(N^2) with the cache (and O(N^3) without).
It's O(N) for a forward pass because that new token still has to "attend to" to each previous token. That requires N dot products: between the cached key vectors and the new query vector for the new position. You also have N reads from memory (K and V) which is probably gonna be your actual bottleneck. (Decode is memory-bound.)
This is why you should avoid long contexts, if you can, even with a warm cache. You will get charged more, in "cache read" tokens.
Comment by ex-aws-dude 1 hour ago
Or does it accumulate the relations like A relates to B, so also add in B's relations
Comment by acedTrex 2 hours ago
Comment by sva_ 4 hours ago
Comment by smallmancontrov 4 hours ago
Comment by ifz 4 hours ago
To me, it's more of a neat visualization, not something that can be used to interpret LLM behavior. Even with a lot of simplification, it can show some interesting patterns.
Comment by apnabhidu47 3 hours ago
Comment by stared 3 hours ago
I mean, there so many headers and layers, it is tricky to make a choice that will resonate with our intuition . Is it some weighted average? Or maybe ablation test?
Comment by ifz 3 hours ago
When I started, I expected I'd have to experiment a lot to find something comprehensible. But this simple computation can already show some patterns.
Comment by stared 2 hours ago
Comment by visarga 2 hours ago
Comment by colophontio 4 hours ago
Comment by Yyylov 55 minutes ago