Lab 02 — Profiling Context & Trace Analysis

Phase: 07 — Profiling & Performance Engineering | Difficulty: ⭐⭐⭐⭐☆ | Time: 2–3 hours

Read PyTorch Profiler traces and Chrome timeline JSON to identify performance hotspots.

What you build

  • Parse torch.profiler output JSON (Chrome trace format)
  • Compute per-op total time, call count, avg time
  • Identify top-N bottleneck ops
  • Detect GPU idle gaps (kernel launch overhead)
  • Build a summary report with actionable recommendations

Key concepts

ConceptWhat to understand
Chrome trace format{"name", "ph", "ts", "dur", "pid", "tid"} events
torch.profiler.profileContext manager for PyTorch profiling
Kernel launch overheadCPU→GPU launch latency — batch ops to amortize
record_functionCustom trace annotations for user-defined regions

Files

FilePurpose
lab.pyStubs with TODO markers
solution.pyComplete working implementation
test_lab.pypytest suite
requirements.txtDependencies

Run

pip install -r requirements.txt
python lab.py
pytest test_lab.py -v