---
title: "Profiling in PyTorch (Part 1): A Beginner's Guide to torch.profiler"
description: "torch.profiler produces two artifacts: a statistical table showing where time goes and a Chrome/Perfetto trace showing when CPU and GPU events happen."
url: "https://swe.quest/articles/profiling-in-pytorch-part-1-a-beginner-s-guide-to-torch-profiler-de0c791495fa22c4"
canonical: "https://huggingface.co/blog/torch-profiler"
source: "Hugging Face"
published: "2026-05-29"
difficulty: "medium"
kind: "How-to"
reading_minutes: 27
tags: ["performance","machine-learning","python","debugging"]
---

# Profiling in PyTorch (Part 1): A Beginner's Guide to torch.profiler

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2026-05-29, 27 min read, How-to. Original: [https://huggingface.co/blog/torch-profiler](https://huggingface.co/blog/torch-profiler)

## Summary

torch.profiler produces two artifacts: a statistical table showing where time goes and a Chrome/Perfetto trace showing when CPU and GPU events happen. A small 64x64 bf16 matmul+add is overhead-bound, with GPU time under 1% of CPU time, while 4096x4096 matrices shift the work to compute-bound GEMM kernels. The trace walkthrough explains a cold-start dead window of about 228 µs before aten::matmul dispatch, a CPU-GPU lane offset, gaps caused by profiler Activity Buffer Requests, and the dispatch chain from Python down to CUDA kernels. The practical advice is to warm up, use profiler schedules, and read Self versus total times carefully before turning to torch.compile.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)
- [Debugging](https://swe.quest/tags/debugging.md) (Engineering practices)

## Prerequisites

- basic PyTorch
- GPU kernel basics ([easy posts on Hardware](https://swe.quest/tags/hardware.md?difficulty=easy))

## Keywords

PyTorch, torch.profiler, Perfetto, CUDA, torch.compile, cuBLAS

## Related posts

- [Profiling TorchNeuron (Part 1): System-level profiling on AWS Trainium.](https://swe.quest/articles/profiling-torchneuron-part-1-system-level-profiling-on-aws-trainium-034696b775aee014.md): Hugging Face · 2026-10-21 · Medium · 9 min read · Performance engineering, Inference & serving, Hardware, Python
  A beginner-friendly walkthrough of system-level profiling for PyTorch on AWS Trainium using TorchNeuron.
- [Profiling in PyTorch (Part 2): From nn.Linear to a Fused MLP](https://swe.quest/articles/profiling-in-pytorch-part-2-from-nn-linear-to-a-fused-mlp-9b220b5d3b1f868e.md): Hugging Face · 2026-06-11 · Hard · 19 min read · Performance engineering, Python, Machine learning, Compilers
  Profiling an nn.Linear on an A100 shows a single cuBLAS/CUTLASS GEMM kernel with the bias folded in as an epilogue via aten::addmm, while aten::t only rewrites strides on the CPU and launches nothing.
- [Host overhead is killing your inference efficiency](https://swe.quest/articles/host-overhead-is-killing-your-inference-efficiency-42291cc0b68e5c36.md): Modal · 2025-11-18 · Medium · 7 min read · Inference & serving, Performance engineering, Hardware
  GPU idle time while the CPU prepares work (host overhead) shows up as low GPU kernel utilization and directly multiplies inference cost; 50% overhead means GPU spend is 2x what it could be.
- [Profiling in PyTorch (Part 3): Attention is all you profile](https://swe.quest/articles/profiling-in-pytorch-part-3-attention-is-all-you-profile-44c4f73b7586bec2.md): Hugging Face · 2026-07-10 · Medium · 21 min read · Performance engineering, Inference & serving, Python, Hardware, LLMs
  Profiling attention variants in PyTorch on an A100 shows how each implementation appears in profiler traces.
- [Visualize and understand GPU memory in PyTorch](https://swe.quest/articles/visualize-and-understand-gpu-memory-in-pytorch-69d1cac2293ba761.md): Hugging Face · 2024-12-24 · Medium · 10 min read · Model training, Python, Memory management, Hardware, LLMs
  PyTorch's memory snapshot recorder (torch.cuda.memory.\_record\_memory\_history plus the memory\_viz web tool) makes it possible to see exactly where GPU memory goes during training: persistent parameters, activations that grow in the forward pass and shrink in backward, gradients, optimizer state and transient optimizer intermediates.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
