Repository navigation
[profiler] capture CUDA graphs with CUPTI annotations under Cuspy - #5136
Conversation
[ghstack-poisoned]
When Cuspy profiling is enabled, capture the forward-backward and optimizer CUDA graphs with an annotation config (backend="cupti") so kernels replayed from graphs keep their mark_kernels metadata in the Cuspy trace. The CUDA graph wrappers take an annotation_config that is passed through to torch.cuda.graph; it stays None, preserving current behavior, unless profiler.cuspy is set. key_by="auto" keys annotations to the capture graph, which Cuspy resolves through CUPTI's sourceGraphNodeId. Cuspy resolves graph event-record nodes only by exec-graph id, so enable_event_node_ids keys by the exec graph instead. This starts Cuspy's CUPTI subscription at the first capture and holds it for the rest of the run, so other CUPTI tools (Nsight Systems, dynolog) can't attach to that process. ghstack-source-id: 454e540 Pull Request resolved: #5136
| ] | ||
|
|
||
|
|
||
| def _get_cuda_graph_annotation_config( |
There was a problem hiding this comment.
can be a method of profiler.cuspy config or a "maybe" method from profiler config
[ghstack-poisoned]
|
@claude review |
|
Claude finished @tianyu-l's task in 1m 7s —— View job Review: [profiler] capture CUDA graphs with CUPTI annotations under Cuspy
The change is small and the default behavior stays the same: when Cuspy isn't enabled, Issues worth addressing
Nits
Correctness checks that passed
I didn't run tests or lint; this was a read-only review. |
When Cuspy profiling is enabled, capture the forward-backward and optimizer
CUDA graphs with an annotation config (backend="cupti") so kernels replayed
from graphs keep their mark_kernels metadata in the Cuspy trace. The CUDA graph
wrappers take an annotation_config that is passed through to torch.cuda.graph;
it stays None, preserving current behavior, unless profiler.cuspy is set.
key_by="auto" keys annotations to the capture graph, which Cuspy resolves
through CUPTI's sourceGraphNodeId. Cuspy resolves graph event-record nodes only
by exec-graph id, so enable_event_node_ids keys by the exec graph instead.
This starts Cuspy's CUPTI subscription at the first capture and holds it for
the rest of the run, so other CUPTI tools (Nsight Systems, dynolog) can't
attach to that process.
CuspyProfilerConfig.record_py_stacks also records each graph node's Python
launch stack (annotation_config["record_py_stacks"], which needs the CUPTI
backend) and writes them beside each trace as
rank{rank}_cuda_graph_py_stacks.json.gz, keyed by (graph id << 32) | graph
node id of the trace's kernel events. On a 1-GPU llama3 debugmodel run with
CUDA graphs, all 545 graphed kernel events in the Cuspy trace have a stack,
e.g. the embedding gather resolves to torchtitan/models/common/embedding.py:41.
ghstack-source-id: 54dbd0a
Pull Request resolved: pytorch/torchtitan#5136
[ghstack-poisoned]
When Cuspy profiling is enabled, capture the forward-backward, optimizer, and
validation CUDA graphs with an annotation config (backend="cupti") so kernels
replayed from graphs keep their mark_kernels metadata in the Cuspy trace. The
CUDA graph wrappers take an annotation_config that is passed through to
torch.cuda.graph; it stays None, preserving current behavior, unless
profiler.cuspy is set.
key_by="auto" keys annotations to the capture graph, which Cuspy resolves
through CUPTI's sourceGraphNodeId. Cuspy resolves graph event-record nodes only
by exec-graph id, so enable_event_node_ids keys by the exec graph instead.
This starts Cuspy's CUPTI subscription at the first capture and holds it for
the rest of the run, so other CUPTI tools (Nsight Systems, dynolog) can't
attach to that process.
CuspyProfilerConfig.record_py_stacks also records each graph node's Python
launch stack (annotation_config["record_py_stacks"], which needs the CUPTI
backend) and writes them beside each trace as
rank{rank}_cuda_graph_py_stacks.json.gz, keyed by (graph id << 32) | graph
node id of the trace's kernel events. On a 1-GPU llama3 debugmodel run with
CUDA graphs, all 545 graphed kernel events in the Cuspy trace have a stack,
e.g. the embedding gather resolves to torchtitan/models/common/embedding.py:41.
ghstack-source-id: 21cdfca
Pull Request resolved: pytorch/torchtitan#5136
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0) (oldest at bottom): * #5527 * #5526 * #5136 * __->__ #5525 Profiler.Config.cuspy switches CUDA activity collection from Kineto to Cuspy (PM sampling, environment counters, sync events, graph dependencies, event-node ids, and optional Perfetto protobuf output). Profiler startup raises a ValueError if torch or libcupti lacks Cuspy support. With CUDA graphs on, kernels replayed from graphs do not carry annotations in the Cuspy trace yet; the next PR in the stack captures graphs with a CUPTI annotation config to fix that.
When Cuspy profiling is enabled, capture the forward-backward, optimizer, and
validation CUDA graphs with an annotation config (backend="cupti") so kernels
replayed from graphs keep their mark_kernels metadata in the Cuspy trace. The
CUDA graph wrappers take an annotation_config that is passed through to
torch.cuda.graph; it stays None, preserving current behavior, unless
profiler.cuspy is set.
key_by="auto" keys annotations to the capture graph, which Cuspy resolves
through CUPTI's sourceGraphNodeId. Cuspy resolves graph event-record nodes only
by exec-graph id, so enable_event_node_ids keys by the exec graph instead.
This starts Cuspy's CUPTI subscription at the first capture and holds it for
the rest of the run, so other CUPTI tools (Nsight Systems, dynolog) can't
attach to that process.
CuspyProfilerConfig.record_py_stacks also records each graph node's Python
launch stack (annotation_config["record_py_stacks"], which needs the CUPTI
backend) and writes them beside each trace as
rank{rank}_cuda_graph_py_stacks.json.gz, keyed by (graph id << 32) | graph
node id of the trace's kernel events. On a 1-GPU llama3 debugmodel run with
CUDA graphs, all 545 graphed kernel events in the Cuspy trace have a stack,
e.g. the embedding gather resolves to torchtitan/models/common/embedding.py:41.
ghstack-source-id: 0f33ac5
Pull Request resolved: pytorch/torchtitan#5136
Stack from ghstack (oldest at bottom):
When Cuspy profiling is enabled, capture the forward-backward and optimizer
CUDA graphs with an annotation config (backend="cupti") so kernels replayed
from graphs keep their mark_kernels metadata in the Cuspy trace. The CUDA graph
wrappers take an annotation_config that is passed through to torch.cuda.graph;
it stays None, preserving current behavior, unless profiler.cuspy is set.
key_by="auto" keys annotations to the capture graph, which Cuspy resolves
through CUPTI's sourceGraphNodeId. Cuspy resolves graph event-record nodes only
by exec-graph id, so enable_event_node_ids keys by the exec graph instead.
This starts Cuspy's CUPTI subscription at the first capture and holds it for
the rest of the run, so other CUPTI tools (Nsight Systems, dynolog) can't
attach to that process.