MCPcopy Create free account
hub / github.com/pytorch/tutorials / profile_graph

Function profile_graph

advanced_source/cuda_graph_annotations_tutorial.py:248–269  ·  view source on GitHub ↗

Profile graph replays and save the trace.

(graph, output_dir)

Source from the content-addressed store, hash-verified

246# we'll later merge with our annotations.
247
248def profile_graph(graph, output_dir):
249 """Profile graph replays and save the trace."""
250 output_dir = Path(output_dir)
251 output_dir.mkdir(exist_ok=True, parents=True)
252
253 # Warm up replays
254 for _ in range(3):
255 graph.replay()
256 torch.cuda.synchronize()
257
258 # Profile several replays
259 with profile(activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA]) as prof:
260 for _ in range(5):
261 graph.replay()
262 torch.cuda.synchronize()
263
264 # Export the raw trace
265 trace_path = output_dir / "trace_raw.json.gz"
266 prof.export_chrome_trace(str(trace_path))
267 print(f"Saved raw trace to {trace_path}")
268
269 return trace_path
270
271###############################################################################
272# Saving Annotation Metadata

Callers 2

mainFunction · 0.85
_comm_workerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected