Log inStart free
LESSON 32.02 · 5 STAGES · 2 CONTROLS · 3 CHECKSPRO · PREVIEW

Shape specialization, JIT and AOT

Watch a compile cache meet new input shapes, during serving or before it.


Pro lesson. Stage 1 is free to watch. Pro opens all 5 stages, 2 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 32.02 · COMPILE BAYCALL 1 · COMPILED 85 µs · EAGER 294 µs
01
Stage 1 of 5 · Shape baked in
Shape specialization builds 3 kernels for one shape key. Call 1 runs in 85 µs, against 294 µs in eager mode.
Explain it simply

Eager mode runs 13 small kernels on every call. A compiler traces the ops once and writes 3 fused kernels. With the shape known, it can pick loop sizes and record one CUDA graph, one launch for all 3. The compile takes 1.9 seconds and saves 209 microseconds on a 16-row call, so it pays off after 9091 calls.

Call 1 has 16 rows. Its compiled bar shows 85 microseconds; the dashed eager bar shows 294.

rows per callshape key, cachecompile wait, padding, extra launchesrun timeeager mode
serving: calls 1 to 10 in orderbefore servingcompile cacheno compilesN = 16call 1116key 16miss85294compiledeagercompile1.9 sserving: calls 1 to 10 in orderbefore servingcompile cacheno compilesN = 16call 1116key 16miss85294compiledeagercompile1.9 s
Toy: one MLP block, 10 calls of 16 to 1024 rows, toy GPU
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
t=nlaunch⋅4 μs+∑kmax⁡ ⁣(FkP, BkW)\sy{t}{out}{t} = n_{\text{launch}} \cdot 4\,\mu s + \sum_k \max\!\left(\tfrac{F_k}{P},\ \tfrac{B_k}{W}\right)
t(16)=85 μs,teager(16)=294 μst(16) = 85\,\mu s,\quad t_{\text{eager}}(16) = 294\,\mu s

Each kernel takes the slower of its math and its memory traffic.

Common mix-ups

MYTHA compiled model runs any input shape as it is.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01With the power-of-2 key, how many compiles does the JIT session need?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 5
Unlock the full explainer
  • 4 more stages and 2 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.