Measure TTFT and ITL for GPT-2 small on your CPU
CPU · your Macexperiment90 minrequiredGoal · Produce a table of prefill time, per-token decode time and achieved GFLOP/s for prompt lengths from 16 to 1024 tokens.
- 1Load gpt2 in fp32, model.eval(), torch.set_num_threads to your physical core count, and fix torch.manual_seed.
- 2For T_prompt in [16, 64, 256, 1024] build a random token tensor of that length and warm up once.
- 3Time a single forward with use_cache=True on the full prompt (prefill) with time.perf_counter; repeat 5 times and take the median.
- 4Using the returned past_key_values, time 32 single-token forward steps (decode) and record the median per-step time.
- 5Compute prefill GFLOP/s as 2 * 124e6 * T_prompt / prefill_seconds and decode GFLOP/s as 2 * 124e6 / step_seconds.
- 6Compute the bytes of weights read per decode step (124e6 * 4) and the implied GB/s; compare with your laptop's memory bandwidth spec.
- 7Tabulate T_prompt, prefill_ms, decode_ms_per_token, prefill_GFLOPs, decode_GFLOPs and write three sentences on the pattern.
- Deliverable
- A CSV and a markdown table with the measured numbers plus a short interpretation.
- Check
- Prefill GFLOP/s at T=1024 is at least 5x higher than decode GFLOP/s, and decode ms per token is roughly flat across prompt lengths (within 2x).