File size: 18,587 Bytes
15ad46e 4bf0bc7 15ad46e 4bf0bc7 15ad46e 4bf0bc7 15ad46e 4bf0bc7 15ad46e 4bf0bc7 15ad46e 4bf0bc7 15ad46e 4bf0bc7 15ad46e 4bf0bc7 15ad46e 4bf0bc7 15ad46e 4bf0bc7 15ad46e 4bf0bc7 15ad46e 4bf0bc7 15ad46e 4bf0bc7 15ad46e 4bf0bc7 15ad46e 4bf0bc7 15ad46e 4bf0bc7 15ad46e 4bf0bc7 15ad46e 4bf0bc7 15ad46e 38a56bc 4bf0bc7 |
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 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FlashInfer: Attention States & Recursive Merge</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Inter', sans-serif;
overflow-x: hidden;
}
.math {
font-family: 'Times New Roman', serif;
font-style: italic;
}
.node {
transition: all 0.5s ease-in-out;
}
.arrow {
stroke-dasharray: 10;
animation: dash 1s linear infinite;
}
@keyframes dash {
to {
stroke-dashoffset: -20;
}
}
.highlight {
animation: pulse 2s infinite;
}
@keyframes pulse {
0% { transform: scale(1); opacity: 1; }
50% { transform: scale(1.05); opacity: 0.9; }
100% { transform: scale(1); opacity: 1; }
}
.fade-in {
opacity: 0;
animation: fadeIn 1s forwards;
}
@keyframes fadeIn {
to { opacity: 1; }
}
.equation {
transition: all 0.5s ease;
}
.panel {
transition: transform 0.5s ease-out;
}
</style>
</head>
<body class="bg-gray-100 text-gray-900">
<div class="container mx-auto p-4 max-w-6xl">
<header class="text-center my-8">
<h1 class="text-4xl font-bold text-blue-800 mb-2">FlashInfer: Attention States & Recursive Merge</h1>
<p class="text-xl text-gray-600">Visualizing how FlashInfer accelerates LLM inference</p>
</header>
<div class="bg-white rounded-xl shadow-lg p-6 mb-8">
<h2 class="text-2xl font-semibold mb-4 text-blue-700">Key Innovation: Attention States</h2>
<p class="mb-4">FlashInfer introduces the concept of <strong>attention states</strong>, which fully characterize the attention between a query and a set of key/value pairs. Each attention state consists of two components:</p>
<div class="flex flex-col md:flex-row gap-4 mb-6">
<div class="flex-1 bg-blue-50 p-4 rounded-lg">
<h3 class="font-medium text-blue-800 mb-2">Generalized Score (s)</h3>
<div class="flex justify-center">
<div class="math text-xl">
s(I) = log(β<sub>iβI</sub> exp(s<sub>i</sub>))
</div>
</div>
<p class="mt-2 text-sm text-gray-600">The log-sum-exp (LSE) of pre-softmax attention scores</p>
</div>
<div class="flex-1 bg-blue-50 p-4 rounded-lg">
<h3 class="font-medium text-blue-800 mb-2">Generalized Value (v)</h3>
<div class="flex justify-center">
<div class="math text-xl">
v(I) = β<sub>iβI</sub> softmax(s<sub>i</sub>)v<sub>i</sub>
</div>
</div>
<p class="mt-2 text-sm text-gray-600">The weighted sum of value vectors using the softmax of scores</p>
</div>
</div>
</div>
<div class="bg-white rounded-xl shadow-lg p-6 mb-8">
<h2 class="text-2xl font-semibold mb-4 text-blue-700">Recursive Merge Operator</h2>
<p class="mb-4">The key insight of FlashInfer is that attention states can be <strong>merged</strong> efficiently. Given two attention states corresponding to different subsets of KV pairs, we can compute the attention state for their union:</p>
<div class="bg-blue-50 p-4 rounded-lg mb-6">
<div class="flex justify-center">
<div class="math text-xl">
[v(IβͺJ), s(IβͺJ)] = [v(I), s(I)] β [v(J), s(J)]
</div>
</div>
</div>
<p class="mb-6">This merge operator (β) is <strong>commutative</strong> and <strong>associative</strong>, allowing flexible computation strategies.</p>
</div>
<!-- Interactive Visualization -->
<div class="bg-white rounded-xl shadow-lg p-6 mb-8">
<h2 class="text-2xl font-semibold mb-4 text-blue-700">Interactive Visualization</h2>
<p class="mb-6">This animation shows how FlashInfer computes attention for a query over 4 KV pairs by partitioning the work and merging results.</p>
<div class="flex justify-center">
<div class="relative" style="width: 700px; height: 650px;" id="visualization">
<!-- SVG will be inserted here -->
</div>
</div>
<div class="flex justify-center mt-4">
<button id="resetBtn" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg mr-4">
Reset Animation
</button>
<button id="playBtn" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg">
Play Animation
</button>
</div>
</div>
<div class="bg-white rounded-xl shadow-lg p-6 mb-8">
<h2 class="text-2xl font-semibold mb-4 text-blue-700">Applications</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div class="bg-blue-50 p-4 rounded-lg">
<h3 class="font-medium text-blue-800 mb-2">Shared-Prefix Batch Decoding</h3>
<p>When multiple sequences share a common prefix (e.g., same prompt), compute the attention state for the shared part once, then merge with each sequence's unique suffix.</p>
<p class="mt-2 text-sm font-medium text-green-600">Up to 30x speedup in long-context scenarios</p>
</div>
<div class="bg-blue-50 p-4 rounded-lg">
<h3 class="font-medium text-blue-800 mb-2">KV Sequence Parallelism</h3>
<p>Partition long KV sequences across multiple processing units, compute partial attention states in parallel, then merge the results.</p>
<p class="mt-2 text-sm font-medium text-green-600">Improves GPU utilization for memory-constrained scenarios</p>
</div>
</div>
</div>
</div>
<script>
</script>
</body>
</html> |