Skip to content

[Profiler] Add priority key to EventsMetadata - #180100

Closed
ryanzhang22 wants to merge 1 commit into
pytorch:mainfrom
ryanzhang22:profiler-add-priority
Closed

ryanzhang22 wants to merge 1 commit into
pytorch:mainfrom
ryanzhang22:profiler-add-priority

Conversation

@ryanzhang22

@ryanzhang22 ryanzhang22 commented Apr 11, 2026 •

Copy link
Copy Markdown
Contributor

As titled

Demo, on top of pytorch/kineto#1361

with torch.profiler.profile(
    activities=[torch.profiler.ProfilerActivity.CUDA],
    experimental_config=torch._C._profiler._ExperimentalConfig(expose_kineto_event_metadata=True)
) as prof:
    x = torch.randn(500, 500, device='cuda')
    y = torch.randn(500, 500, device='cuda')
    result = torch.matmul(x, y)
EventMetadata(registers_per_thread=84, shared_memory=12672, grid=[7, 7, 1], block=[64, 1, 1], priority=4, blocks_per_sm=0.331081, warps_per_sm=0.662162, occupancy=1.0, queued=0, graph_id=0, graph_node_id=0, stream=7, context=1, bytes=None, bandwidth_gb_s=None, collective_name=None, dtype=None, in_msg_nelems=None, out_msg_nelems=None, in_split_size=None, out_split_size=None, global_rank_start=None, global_rank_stride=None, group_size=None, process_group_name=None, process_group_desc=None, group_ranks=None, rank=None, src_rank=None, dst_rank=None, seq=None, is_async=None)

@pytorch-bot

pytorch-bot Bot commented Apr 11, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/180100

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit 563bb25 with merge base d15b805 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot

pytorch-bot Bot commented Apr 11, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@ryanzhang22 ryanzhang22 added the release notes: profiler release notes category label Apr 11, 2026
@ryanzhang22

Copy link
Copy Markdown
Contributor Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased profiler-add-priority onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout profiler-add-priority && git pull --rebase)

@ryanzhang22

Copy link
Copy Markdown
Contributor Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased profiler-add-priority onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout profiler-add-priority && git pull --rebase)

@scotts

scotts commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

@ryanzhang22, do we need to wait until we do another Kineto release that has pytorch/kineto#1361 before merging this one? I don't see any logic that connects the C++ layer to what's in the Python, which I was expecting to see.

@ryanzhang22

Copy link
Copy Markdown
Contributor Author

@ryanzhang22, do we need to wait until we do another Kineto release that has pytorch/kineto#1361 before merging this one? I don't see any logic that connects the C++ layer to what's in the Python, which I was expecting to see.

Shouldn't need to -- this just shows up as None if it can't be parsed from the JSON

@ryanzhang22
ryanzhang22 marked this pull request as ready for review April 13, 2026 18:57
@meta-codesync

meta-codesync Bot commented Apr 13, 2026

Copy link
Copy Markdown

@ryanzhang22 has imported this pull request. If you are a Meta employee, you can view this in D100688145.

@ryanzhang22

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Apr 13, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 8 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@ryanzhang22

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

BoyuanFeng pushed a commit that referenced this pull request Apr 15, 2026
As titled

Demo, on top of pytorch/kineto#1361

```
with torch.profiler.profile(
    activities=[torch.profiler.ProfilerActivity.CUDA],
    experimental_config=torch._C._profiler._ExperimentalConfig(expose_kineto_event_metadata=True)
) as prof:
    x = torch.randn(500, 500, device='cuda')
    y = torch.randn(500, 500, device='cuda')
    result = torch.matmul(x, y)
```

```
EventMetadata(registers_per_thread=84, shared_memory=12672, grid=[7, 7, 1], block=[64, 1, 1], priority=4, blocks_per_sm=0.331081, warps_per_sm=0.662162, occupancy=1.0, queued=0, graph_id=0, graph_node_id=0, stream=7, context=1, bytes=None, bandwidth_gb_s=None, collective_name=None, dtype=None, in_msg_nelems=None, out_msg_nelems=None, in_split_size=None, out_split_size=None, global_rank_start=None, global_rank_stride=None, group_size=None, process_group_name=None, process_group_desc=None, group_ranks=None, rank=None, src_rank=None, dst_rank=None, seq=None, is_async=None)
```
Pull Request resolved: #180100
Approved by: https://github.com/scotts
pytorchmergebot pushed a commit that referenced this pull request Apr 15, 2026
This was failing on ROCm and recently exposed by removing the early exit hack. Taking this as an opportunity to beef it up some more.

Basically this will loop through events() and json outputs, fetch all the events, match them, and compare to make sure that every key in json is present in events and that the two match.

Sample failure that I artificially induced:

```
AssertionError:
====================================================================================
IMPORTANT: Are you making a Kineto change or bumping the third_party/kineto
submodule hash and seeing this message?

New metadata keys (see below) were found in the Chrome trace JSON that are not
yet exposed through the profiler's events() API (i.e. EventMetadata in
torch/autograd/profiler_util.py).

To fix this properly, you need to make sure the new Kineto data makes its way
to the events() property. The steps are:

1. Add the new key(s) to _EVENT_METADATA_KEYS in torch/autograd/profiler_util.py
   with the appropriate field name and type converter.
2. Add corresponding field(s) to the EventMetadata dataclass in the same file.
3. If the key should NOT be mapped (e.g. it duplicates an existing FunctionEvent
   attribute), add it to allowed_non_structured_trace_keys in this test instead.

For a model PR to follow, see: #180100
====================================================================================

Unmapped keys:
  Memcpy DtoH (Device -> Pageable) (gpu_memcpy): 'device'
  ampere_sgemm_32x128_nn (kernel): 'device'
  cudaDeviceGetAttribute (cuda_runtime): 'cbid'
  cudaDeviceGetStreamPriorityRange (cuda_runtime): 'cbid'
  cudaFree (cuda_runtime): 'cbid'
  cudaGetDriverEntryPoint (cuda_runtime): 'cbid'
  cudaGetSymbolAddress (cuda_runtime): 'cbid'
  cudaLaunchKernel (cuda_runtime): 'cbid'
  cudaMalloc (cuda_runtime): 'cbid'
  cudaMemcpyAsync (cuda_runtime): 'cbid'
  cudaOccupancyMaxActiveBlocksPerMultiprocessor (cuda_runtime): 'cbid'
  cudaStreamGetCaptureInfo_v2 (cuda_runtime): 'cbid'
  cudaStreamIsCapturing (cuda_runtime): 'cbid'
  cudaStreamSynchronize (cuda_runtime): 'cbid'
  void at::native::(anonymous namespace)::distribution_elementwise_grid_stride_kernel<float, 4, at::na (kernel): 'device'
  void at::native::vectorized_elementwise_kernel<4, at::native::CUDAFunctor_add<float>, std::array<cha (kernel): 'device'
```
Pull Request resolved: #180085
Approved by: https://github.com/scotts
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
As titled

Demo, on top of pytorch/kineto#1361

```
with torch.profiler.profile(
    activities=[torch.profiler.ProfilerActivity.CUDA],
    experimental_config=torch._C._profiler._ExperimentalConfig(expose_kineto_event_metadata=True)
) as prof:
    x = torch.randn(500, 500, device='cuda')
    y = torch.randn(500, 500, device='cuda')
    result = torch.matmul(x, y)
```

```
EventMetadata(registers_per_thread=84, shared_memory=12672, grid=[7, 7, 1], block=[64, 1, 1], priority=4, blocks_per_sm=0.331081, warps_per_sm=0.662162, occupancy=1.0, queued=0, graph_id=0, graph_node_id=0, stream=7, context=1, bytes=None, bandwidth_gb_s=None, collective_name=None, dtype=None, in_msg_nelems=None, out_msg_nelems=None, in_split_size=None, out_split_size=None, global_rank_start=None, global_rank_stride=None, group_size=None, process_group_name=None, process_group_desc=None, group_ranks=None, rank=None, src_rank=None, dst_rank=None, seq=None, is_async=None)
```
Pull Request resolved: pytorch#180100
Approved by: https://github.com/scotts
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
This was failing on ROCm and recently exposed by removing the early exit hack. Taking this as an opportunity to beef it up some more.

Basically this will loop through events() and json outputs, fetch all the events, match them, and compare to make sure that every key in json is present in events and that the two match.

Sample failure that I artificially induced:

```
AssertionError:
====================================================================================
IMPORTANT: Are you making a Kineto change or bumping the third_party/kineto
submodule hash and seeing this message?

New metadata keys (see below) were found in the Chrome trace JSON that are not
yet exposed through the profiler's events() API (i.e. EventMetadata in
torch/autograd/profiler_util.py).

To fix this properly, you need to make sure the new Kineto data makes its way
to the events() property. The steps are:

1. Add the new key(s) to _EVENT_METADATA_KEYS in torch/autograd/profiler_util.py
   with the appropriate field name and type converter.
2. Add corresponding field(s) to the EventMetadata dataclass in the same file.
3. If the key should NOT be mapped (e.g. it duplicates an existing FunctionEvent
   attribute), add it to allowed_non_structured_trace_keys in this test instead.

For a model PR to follow, see: pytorch#180100
====================================================================================

Unmapped keys:
  Memcpy DtoH (Device -> Pageable) (gpu_memcpy): 'device'
  ampere_sgemm_32x128_nn (kernel): 'device'
  cudaDeviceGetAttribute (cuda_runtime): 'cbid'
  cudaDeviceGetStreamPriorityRange (cuda_runtime): 'cbid'
  cudaFree (cuda_runtime): 'cbid'
  cudaGetDriverEntryPoint (cuda_runtime): 'cbid'
  cudaGetSymbolAddress (cuda_runtime): 'cbid'
  cudaLaunchKernel (cuda_runtime): 'cbid'
  cudaMalloc (cuda_runtime): 'cbid'
  cudaMemcpyAsync (cuda_runtime): 'cbid'
  cudaOccupancyMaxActiveBlocksPerMultiprocessor (cuda_runtime): 'cbid'
  cudaStreamGetCaptureInfo_v2 (cuda_runtime): 'cbid'
  cudaStreamIsCapturing (cuda_runtime): 'cbid'
  cudaStreamSynchronize (cuda_runtime): 'cbid'
  void at::native::(anonymous namespace)::distribution_elementwise_grid_stride_kernel<float, 4, at::na (kernel): 'device'
  void at::native::vectorized_elementwise_kernel<4, at::native::CUDAFunctor_add<float>, std::array<cha (kernel): 'device'
```
Pull Request resolved: pytorch#180085
Approved by: https://github.com/scotts
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
As titled

Demo, on top of pytorch/kineto#1361

```
with torch.profiler.profile(
    activities=[torch.profiler.ProfilerActivity.CUDA],
    experimental_config=torch._C._profiler._ExperimentalConfig(expose_kineto_event_metadata=True)
) as prof:
    x = torch.randn(500, 500, device='cuda')
    y = torch.randn(500, 500, device='cuda')
    result = torch.matmul(x, y)
```

```
EventMetadata(registers_per_thread=84, shared_memory=12672, grid=[7, 7, 1], block=[64, 1, 1], priority=4, blocks_per_sm=0.331081, warps_per_sm=0.662162, occupancy=1.0, queued=0, graph_id=0, graph_node_id=0, stream=7, context=1, bytes=None, bandwidth_gb_s=None, collective_name=None, dtype=None, in_msg_nelems=None, out_msg_nelems=None, in_split_size=None, out_split_size=None, global_rank_start=None, global_rank_stride=None, group_size=None, process_group_name=None, process_group_desc=None, group_ranks=None, rank=None, src_rank=None, dst_rank=None, seq=None, is_async=None)
```
Pull Request resolved: pytorch#180100
Approved by: https://github.com/scotts
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
This was failing on ROCm and recently exposed by removing the early exit hack. Taking this as an opportunity to beef it up some more.

Basically this will loop through events() and json outputs, fetch all the events, match them, and compare to make sure that every key in json is present in events and that the two match.

Sample failure that I artificially induced:

```
AssertionError:
====================================================================================
IMPORTANT: Are you making a Kineto change or bumping the third_party/kineto
submodule hash and seeing this message?

New metadata keys (see below) were found in the Chrome trace JSON that are not
yet exposed through the profiler's events() API (i.e. EventMetadata in
torch/autograd/profiler_util.py).

To fix this properly, you need to make sure the new Kineto data makes its way
to the events() property. The steps are:

1. Add the new key(s) to _EVENT_METADATA_KEYS in torch/autograd/profiler_util.py
   with the appropriate field name and type converter.
2. Add corresponding field(s) to the EventMetadata dataclass in the same file.
3. If the key should NOT be mapped (e.g. it duplicates an existing FunctionEvent
   attribute), add it to allowed_non_structured_trace_keys in this test instead.

For a model PR to follow, see: pytorch#180100
====================================================================================

Unmapped keys:
  Memcpy DtoH (Device -> Pageable) (gpu_memcpy): 'device'
  ampere_sgemm_32x128_nn (kernel): 'device'
  cudaDeviceGetAttribute (cuda_runtime): 'cbid'
  cudaDeviceGetStreamPriorityRange (cuda_runtime): 'cbid'
  cudaFree (cuda_runtime): 'cbid'
  cudaGetDriverEntryPoint (cuda_runtime): 'cbid'
  cudaGetSymbolAddress (cuda_runtime): 'cbid'
  cudaLaunchKernel (cuda_runtime): 'cbid'
  cudaMalloc (cuda_runtime): 'cbid'
  cudaMemcpyAsync (cuda_runtime): 'cbid'
  cudaOccupancyMaxActiveBlocksPerMultiprocessor (cuda_runtime): 'cbid'
  cudaStreamGetCaptureInfo_v2 (cuda_runtime): 'cbid'
  cudaStreamIsCapturing (cuda_runtime): 'cbid'
  cudaStreamSynchronize (cuda_runtime): 'cbid'
  void at::native::(anonymous namespace)::distribution_elementwise_grid_stride_kernel<float, 4, at::na (kernel): 'device'
  void at::native::vectorized_elementwise_kernel<4, at::native::CUDAFunctor_add<float>, std::array<cha (kernel): 'device'
```
Pull Request resolved: pytorch#180085
Approved by: https://github.com/scotts
pytorchmergebot pushed a commit that referenced this pull request Sep 10, 2026
)

TestProfilerEventsParity::test_structured_metadata_matches_chrome_trace fails on ROCm because kernel and copy events carry kineto's `hsa_queue` metadata field (libkineto MetadataFieldCatalog kHsaQueue, the HSA queue the activity was dispatched to), which `_EVENT_METADATA_KEYS` never mapped, so the parity check reports it as an unmapped key on four kernels. Following the test's own fix recipe (and the model in #180100): add the key to `_EVENT_METADATA_KEYS`, add the corresponding field to `EventMetadata` (None on CUDA; `EventMetadata` has a single keyword-only construction site, so the added field is backward-safe), and remove the test's ROCm skip.

Test plan, on gfx950 (ROCm 10.0, HIP 7.15): the parity test passes (previously failed with unmapped 'hsa_queue'), 25 consecutive runs clean, and the 12 surrounding metadata/events tests pass.

```
PYTORCH_TEST_WITH_ROCM=1 python test/profiler/test_profiler.py -k test_structured_metadata_matches_chrome_trace
```

gfx942/gfx90a validation via the ciflow labels below; the auto-disabler remains as the safety net.

This PR was authored with the assistance of an AI agent (Claude). The analysis and test results were verified by hand.

Pull Request resolved: #196487
Approved by: https://github.com/jeffdaily

Co-authored-by: Jeff Daily <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: profiler release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants