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.profileroutput 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
| Concept | What to understand |
|---|---|
| Chrome trace format | {"name", "ph", "ts", "dur", "pid", "tid"} events |
torch.profiler.profile | Context manager for PyTorch profiling |
| Kernel launch overhead | CPU→GPU launch latency — batch ops to amortize |
record_function | Custom trace annotations for user-defined regions |
Files
| File | Purpose |
|---|---|
lab.py | Stubs with TODO markers |
solution.py | Complete working implementation |
test_lab.py | pytest suite |
requirements.txt | Dependencies |
Run
pip install -r requirements.txt
python lab.py
pytest test_lab.py -v