Skip to content
Closed
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 @@ -40,6 +40,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 @@ -472,6 +473,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 @@ -480,4 +491,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/>`
#