nsys timeline of GPT-2 prefill and decode on a T4
Colab T4 · freecli120 minrequiredGoal · Record an annotated nsys profile of a 64-token GPT-2 generation, measure the fraction of GPU idle time during decode, and show it shrinks with CUDA Graphs.
- 1Install Nsight Systems on Colab (apt or the .deb from the NVIDIA repo) and confirm nsys --version works.
- 2Write gen.py that loads gpt2 in float16 and generates 64 tokens, wrapping prefill and each decode step in torch.cuda.nvtx.range annotations.
- 3Run nsys profile -t cuda,nvtx -o eager python gen.py; then nsys stats --report cuda_gpu_kern_sum and --report nvtx_sum eager.nsys-rep.
- 4From the stats compute total kernel time inside the decode NVTX ranges versus the total range duration; the difference is GPU idle time.
- 5Count the kernels per decode step and the average kernel duration.
- 6Repeat with the decode step captured in a CUDA Graph (from the p4-cuda-graphs lesson) and compare the idle fraction.
- 7Download the two .nsys-rep files and open them in the Nsight Systems GUI on your Mac; take a screenshot of one decode step from each.
- Deliverable
- Two .nsys-rep files, the stats CSVs, the idle-fraction numbers and the two screenshots.
- Check
- Eager decode shows a GPU idle fraction above 30 percent with hundreds of sub-20-microsecond kernels per step; the CUDA Graph run shows the idle fraction cut sharply.
- Fallback
- Use torch.profiler with record_shapes on CPU and view the Chrome trace in chrome://tracing to measure Python overhead between ops; the structure of the analysis is the same.