Skip to content

Update the profiler_recipe tutorial #3386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions recipes_source/recipes/profiler_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
# 5. Using tracing functionality
# 6. Examining stack traces
# 7. Using profiler to analyze long-running jobs
# 8. Memory Timeline Visualization
#
# 1. Import all necessary libraries
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -453,6 +454,16 @@ def trace_handler(p):
model(inputs)
p.step()

######################################################################
# Memory Timeline Visualization
with profile(activities=[ProfilerActivity.CPU],
profile_memory=True, record_shapes=True, with_stack=True) as prof:
model(inputs)

# Add the memory timeline export right after:
prof.export_memory_timeline("memory_timeline.html")


######################################################################
# Learn More
# ----------
Expand All @@ -461,4 +472,5 @@ def trace_handler(p):
#
# - `PyTorch Benchmark <https://pytorch.org/tutorials/recipes/recipes/benchmark.html>`_
# - `Visualizing models, data, and training with TensorBoard <https://pytorch.org/tutorials/intermediate/tensorboard_tutorial.html>`_ tutorial
# - `Understanding GPU Memory 1: Visualizing All Allocations over Time <https://pytorch.org/blog/understanding-gpu-memory-1/>`
#