Skip to content

Bake CUDA graph annotations into the profiler export - #4447

Merged
tianyu-l merged 1 commit into
pytorch:mainfrom
ngimel:ngimel/inline-cudagraph-annotations
Sep 3, 2026
Merged

tianyu-l merged 1 commit into
pytorch:mainfrom
ngimel:ngimel/inline-cudagraph-annotations

Conversation

@ngimel

@ngimel ngimel commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

torch is removing torch/cuda/_annotate_cuda_graph_trace.py, the offline joiner that merged CUDA-graph kernel annotations into an already-written trace. Its replacement is a cuda_graph_annotations argument on export_chrome_trace, which splices the annotations in during the export pass, so the trace is never read back and re-written -- for the gzipped traces the profiler has produced since
#3483 that was paying the compression cost twice.

The trace handler now passes get_cudagraph_annotations() straight to export_chrome_trace, and cudagraph_annotate_trace_post_processor goes away with its import. Passing an empty mapping is defined to mean the same as passing none, so the handler no longer needs the early return the post-processor had.

The two post-processor tests are replaced by one that checks the handler hands the captured annotations to the export of the .json.gz path. The gzip round-trip case they covered is now torch's exporter picking compression off the file suffix, tested there rather than here.

Depends on the torch-side change; until it lands in a nightly, export_chrome_trace does not accept cuda_graph_annotations.

Authored with assistance from Claude Code.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 3, 2026
@ngimel
ngimel force-pushed the ngimel/inline-cudagraph-annotations branch from a4eb8b5 to bc16838 Compare September 3, 2026 20:25
torch is removing torch/cuda/_annotate_cuda_graph_trace.py, the offline joiner
that merged CUDA-graph kernel annotations into an already-written trace. Its
replacement is a cuda_graph_annotations argument on export_chrome_trace, which
splices the annotations in during the export pass, so the trace is never read
back and re-written -- for the gzipped traces the profiler has produced since
 pytorch#3483 that was paying the compression cost twice.

The trace handler now passes get_cudagraph_annotations() straight to
export_chrome_trace, and cudagraph_annotate_trace_post_processor goes away with
its import. Passing an empty mapping is defined to mean the same as passing
none, so the handler no longer needs the early return the post-processor had.

The two post-processor tests are replaced by one that checks the handler hands
the captured annotations to the export of the .json.gz path. The gzip
round-trip case they covered is now torch's exporter picking compression off
the file suffix, tested there rather than here.

The argument is passed only when the installed torch accepts it, checked once
against the export_chrome_trace signature. On an older torch the trace is still
written, without the annotations, and a warning says so -- so this does not have
to wait for the torch-side change to reach a nightly.

Authored with assistance from Claude Code.
@ngimel
ngimel force-pushed the ngimel/inline-cudagraph-annotations branch from bc16838 to 8a66af8 Compare September 3, 2026 20:28

@tianyu-l tianyu-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@tianyu-l
tianyu-l merged commit d2e8d9f into pytorch:main Sep 3, 2026
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants