Skip to content

Expose Kineto event metadata in PyTorch Profiler events#161624

Closed
mihaipgc wants to merge 9 commits intopytorch:mainfrom
graphcore:mihaip/event-metadata
Closed

Expose Kineto event metadata in PyTorch Profiler events#161624
mihaipgc wants to merge 9 commits intopytorch:mainfrom
graphcore:mihaip/event-metadata

Conversation

@mihaipgc
Copy link
Contributor

Overview

This PR allows the profiler users to access Kineto and TorchOp metadata in JSON string format through a new metadata_json attribute in FunctionEvent objects, which is triggered through a new expose_kineto_event_metadata flag in ExperimentalConfig.

Testing

A unit test was added to validate functionality.

Documentation

Added/updated function doc strings where appropriate.

Example output

import torch
from torch.profiler import profile

with profile(experimental_config=torch._C._profiler._ExperimentalConfig(expose_kineto_event_metadata=True)) as prof:
    res = torch.mm(torch.rand(1024, 1024), torch.rand(1024, 1024))

for event in prof.events():
    print(f'name: {event.key}, metadata: {event.metadata_json}')
name: aten::rand, metadata: "Ev Idx": 0
name: aten::empty, metadata: "Ev Idx": 1
name: aten::uniform_, metadata: "Ev Idx": 2
name: aten::rand, metadata: "Ev Idx": 3
name: aten::empty, metadata: "Ev Idx": 4
name: aten::uniform_, metadata: "Ev Idx": 5
name: aten::mm, metadata: "Ev Idx": 6
name: aten::resolve_conj, metadata: "Ev Idx": 7
name: aten::resolve_conj, metadata: "Ev Idx": 8
name: aten::resolve_conj, metadata: "Ev Idx": 9

@pytorch-bot
Copy link

pytorch-bot bot commented Aug 27, 2025

🔗 Helpful Links

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

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

✅ No Failures

As of commit 4bf01ac with merge base a213848 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 27, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@mihaipgc
Copy link
Contributor Author

@pytorchbot label "release notes: profiler"

@pytorch-bot pytorch-bot bot added the release notes: profiler release notes category label Aug 27, 2025
@albanD albanD removed their request for review September 4, 2025 14:10
@soulitzer soulitzer removed their request for review September 11, 2025 21:08
@soulitzer soulitzer added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Sep 11, 2025
if (e) {
e->visit(c10::overloaded(
[&](ExtraFields<EventType::TorchOp>& i) {
if (config_.experimental_config.expose_kineto_event_metadata) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit but we could just have the expose_kineto_event_metadata on the outside of the e->visit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you so much for the review, I pushed a change to move the check out of e->visit

Copy link
Contributor

@sraikund16 sraikund16 left a comment

Choose a reason for hiding this comment

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

Overall LGTM!

@sraikund16 sraikund16 added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 18, 2025
@pytorch-bot pytorch-bot bot removed the ciflow/trunk Trigger trunk jobs on your pull request label Sep 19, 2025
@mihaipgc
Copy link
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 19, 2025
@pytorchmergebot
Copy link
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
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: trunk / linux-jammy-rocm-py3.10 / test (default, 1, 2, linux.rocm.gpu.gfx942.1)

Details for Dev Infra team Raised by workflow job

@mihaipgc
Copy link
Contributor Author

@pytorchbot rebase -b viable/strict

@pytorch-bot
Copy link

pytorch-bot bot commented Sep 24, 2025

You don't have permissions to rebase this PR since you are a first time contributor. If you think this is a mistake, please contact PyTorch Dev Infra.

@sraikund16
Copy link
Contributor

@pytorchbot rebase -b viable/strict

@pytorchmergebot
Copy link
Collaborator

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

@pytorchmergebot
Copy link
Collaborator

Rebase failed due to Command git -C /home/runner/work/pytorch/pytorch push -f https://github.com/graphcore/pytorch-fork.git pull/161624/head:mihaip/event-metadata returned non-zero exit code 128

remote: {"auth_status":"access_denied_to_user","body":"Permission to graphcore/pytorch-fork.git denied to pytorchmergebot."}
fatal: unable to access 'https://github.com/graphcore/pytorch-fork.git/': The requested URL returned error: 403

Raised by https://github.com/pytorch/pytorch/actions/runs/17992488499

@mihaipgc mihaipgc force-pushed the mihaip/event-metadata branch from e16d56a to 4bf01ac Compare September 25, 2025 09:43
@pytorch-bot pytorch-bot bot removed the ciflow/trunk Trigger trunk jobs on your pull request label Sep 25, 2025
@mihaipgc
Copy link
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 25, 2025
@pytorchmergebot
Copy link
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

jainapurva pushed a commit that referenced this pull request Sep 29, 2025
## Overview
This PR allows the profiler users to access `Kineto` and `TorchOp` metadata in JSON string format through a new `metadata_json` attribute in `FunctionEvent` objects, which is triggered through a new `expose_kineto_event_metadata` flag in `ExperimentalConfig`.

## Testing
A unit test was added to validate functionality.

## Documentation
Added/updated function doc strings where appropriate.

## Example output
```python
import torch
from torch.profiler import profile

with profile(experimental_config=torch._C._profiler._ExperimentalConfig(expose_kineto_event_metadata=True)) as prof:
    res = torch.mm(torch.rand(1024, 1024), torch.rand(1024, 1024))

for event in prof.events():
    print(f'name: {event.key}, metadata: {event.metadata_json}')
```

```
name: aten::rand, metadata: "Ev Idx": 0
name: aten::empty, metadata: "Ev Idx": 1
name: aten::uniform_, metadata: "Ev Idx": 2
name: aten::rand, metadata: "Ev Idx": 3
name: aten::empty, metadata: "Ev Idx": 4
name: aten::uniform_, metadata: "Ev Idx": 5
name: aten::mm, metadata: "Ev Idx": 6
name: aten::resolve_conj, metadata: "Ev Idx": 7
name: aten::resolve_conj, metadata: "Ev Idx": 8
name: aten::resolve_conj, metadata: "Ev Idx": 9
```

Pull Request resolved: #161624
Approved by: https://github.com/sraikund16
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 open source release notes: profiler release notes category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants