Log inStart free
LESSON 32.07 · 6 STAGES · 2 CONTROLS · 3 CHECKSPRO · PREVIEW

Caching allocators and memory pools

Watch three engine steps get memory for their tensors, three ways.


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

Go Pro · $8.25/mo
EXPLAINER · 32.07 · ALLOCATOR BAY21 TENSORS · PEAK 192 KiB
01
Stage 1 of 6 · Tensor lifetimes
Each op writes a new tensor. The tensor is freed after the last op that reads it.
Explain it simply

Each bar is one tensor, from the op that writes it to the last op that reads it. Step 2 runs 16 tokens, so its bars are thicker. At most 192 KiB is alive at one time.

Seven rows of bars, one row per tensor name, over three steps of 4, 16, 6 tokens. The peak is 192 KiB.

live tensorcached free blocksegment or arenaallocator time, misseskernel time, peak
time: ops of 3 engine steps →step 1 · 4 tokensstep 2 · 16 tokensstep 3 · 6 tokensxqkvattnx2upx3logitstensor lifetimestime: ops of 3 engine steps →step 1 · 4 tokensstep 2 · 16 tokensstep 3 · 6 tokensxqkvattnx2upx3logitstensor lifetimes
Toy: one layer, D 1,024, fp16; 3 engine steps; 64 KiB segments (PyTorch: 2 MiB); toy µs
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
b=T⋅w⋅D⋅2 B\sy{b}{data}{b} = \sy{T}{param}{T} \cdot w \cdot D \cdot 2\,\text{B}
bup=16⋅4⋅1024⋅2 B=128 KiBb_{\text{up}} = 16 \cdot 4 \cdot 1024 \cdot 2\,\text{B} = 128\,\text{KiB}

A tensor's bytes grow with the tokens in its step.

Common mix-ups

MYTHEnough free bytes means the next tensor fits.

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

Predict, then reveal
3 CHECKS · PRO
Q01With 64 KiB segments, if step 2 only decodes, how many segments does the pool get?

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

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 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.