M02.02·Profiling·Core·75 minutes·2 min read

Named ranges and the five-line report

Design profiler ranges for a prefill+decode request, then write the five-line report from a table that only makes sense with those names.

Module
See inside the box
Objective
Put semantic names on a trace before you collect it, and write a five-line report that a teammate could act on.

A trace without names is a map with the cities scraped off. This drill is the naming habit, then the report habit.

Part A — Name the program

You will profile one chat request: tokenize, 2K prefill, 64 decode tokens, detokenize, JSON response.

Write the exact record_function / NVTX strings you will wrap, nested. At least:

request
  tokenize
  prefill
  decode
    decode_step   (loop)
  detokenize

Add two more ranges that would save you an hour next week. Name them.

Then write the PyTorch profile(...) call: activities, record_shapes, profile_memory, and what you sort the table by first.

Part B — Report from a named table

range / opCUDA totalCPU totalcalls
prefill140 ms8 ms1
decode96 ms88 ms1
decode_step1.4 ms avg1.3 ms avg64
aten::mm110 ms6 ms48
aten::copy_22 ms24 ms64
tokenize0 ms31 ms1

Workload: 7B bf16, batch 1, L4, 2K→64.

Write:

Workload:
Hardware:
Top CUDA time:
Top CPU / orchestration cost:
Next experiment:

Then: one sentence on whether decode is kernel-bound or host-bound, using the decode vs decode_step rows.

Part C — Without looking

Write the five field names from memory. Fill them for a run where tokenize is 400 ms and GPU decode is 40 ms. Next experiment must not mention FlashAttention.

Acceptance

  1. Ranges nest prefill vs decode. copy_ inside decode_step is visible as a hypothesis (dtype/device).
  2. Prefill owns CUDA; decode's CPU ≈ CUDA suggests host/sync per token.
  3. 400 ms tokenize is a TTFT bug on the host.

Check

Sort CUDA first. Prefill mm is expected. 64 copies in 64 steps is a smell. decode CPU 88 ms vs GPU 96 ms: the loop is not "free." Tokenize is TTFT, not a kernel.

Debrief

The first profiler pass is triage with names. If you cannot write the five lines, you are not done collecting — you are decorating a JSON file.