Profile graph replays and save the trace.
(graph, output_dir)
| 246 | # we'll later merge with our annotations. |
| 247 | |
| 248 | def 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 |
no outgoing calls
no test coverage detected