NVIDIA Nsight Python Tutorial Shows GPU Kernel Profiling in Colab
Tutorial shows NVIDIA Nsight Python profiling GPU kernels in Colab, returning hardware metrics as pandas DataFrames.
The tutorial says the approach replaces running a script under the Nsight Compute command line and digging through a report afterward. Users mark the code regions they care about with nsight.annotate, decorate a benchmark function with nsight.analyze.kernel and get back a DataFrame of hardware metrics per annotated region, per configuration and per run. Since version 1.0, the library attaches Nsight Compute to the running Python process, making it usable in Jupyter and Colab; the upcoming 1.1 release adds an experimental CUPTI backend, explicit tool management and custom information collectors, the tutorial says.
The walkthrough runs on a free Colab T4. It installs a current Nsight Compute next to the older ncu that Colab ships because nsight-python needs Nsight Compute 2026.2.1 or newer. The tutorial tries 2026.3.1 first, falls back to 2026.2.1, installs from NVIDIA's apt repository and puts the new ncu launcher at the front of PATH so nsight-python can find it. It leaves the preinstalled version untouched.
The tutorial pins nsight-python to a GitHub commit because version 1.1.0 is tagged but not yet on PyPI. For the CUPTI backend, it installs cupti-python 13.4 and related packages into a separate directory because Colab's PyTorch is pinned to an older libcupti, according to the tutorial. It imports nsight before anything initializes CUDA to activate the injection library.
The profiling sequence covers a first kernel, the number of runs a measurement needs, and the effect of cache and clock control on the same kernel. It sweeps matrix sizes in fp32 and fp16 with a derived TFLOP/s metric, uses hardware counters to tell compute-bound from memory-bound work, measures kernel fusion in bytes moved, records clocks and temperature per run, compares the CUPTI backend with Nsight Compute and keeps the raw report for deeper analysis.