LESSON 6.09 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW
torch.compile: from eager to graph
Watch torch.compile trace a function into a graph and fuse its kernels.
Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 3 controls and 3 checks, in this lesson and every other.
Go Pro · $8.25/moEXPLAINER · 6.09 · COMPILE BAYEAGER · 4 KERNELS · GPU BUSY 24%
01
Stage 1 of 6 · Eager mode
In eager mode, each line runs at once as its own GPU kernel. The GPU idles 76% of the time, waiting for Python.
Explain it simply
Python reads f one line at a time, like a cook who follows a recipe step by step. Each op starts one kernel, and each red band is a result written to GPU memory and read back. Python spends 8 microseconds on each op, but the tiny kernel takes only 2. So the GPU mostly waits.
Eager run of f: 4 ops, 4 kernels, 320 B moved, 34 µs in total.
tensorsweights, guardsmemory traffic, breakskernels, output
Toy: f on x with 8 columns · times from a cost model
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
Each op costs its Python time or its kernel time, whichever is longer.
PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
- 5 more stages and 3 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.