Skip to content

Conversation

lucasb-eyer
Copy link
Contributor

Via google search I got to torch.autograd.profiler and implemented my code with it. Only to be taken by surprise finding torch.profile.profiler, which has a note saying the autograd one is legacy.

This just adds such note to autograd.profiler to avoid this confusion and waste of time to future people in my situation.

@lucasb-eyer lucasb-eyer requested a review from sraikund16 as a code owner July 2, 2025 15:14
Copy link

pytorch-bot bot commented Jul 2, 2025

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit 989980b with merge base 510c398 (image):

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

@lucasb-eyer
Copy link
Contributor Author

@pytorchbot label "topic: not user facing"

@pytorch-bot pytorch-bot bot added the topic: not user facing topic category label Jul 2, 2025
@sraikund16
Copy link
Contributor

This note is not quite correct. The autograd profiler is the backend that the profiler.profiler uses.

@lucasb-eyer
Copy link
Contributor Author

I was careful to use the exact wording of the note I found in torch.profiler here, which calls this "legacy".

Also, the torch.profile profiler uses KinetoStepTracker, but not the class profile. I only annotate the doc-comment from the class profile (which is what I mistakenly used), not the whole module.

So, I do think it's actually correct. If you still disagree, any edit you suggest?

@lucasb-eyer
Copy link
Contributor Author

ping

@sraikund16
Copy link
Contributor

sraikund16 commented Jul 7, 2025

@lucasb-eyer sorry for delay, was out on holiday.

So profiler.profile uses autograd.profile here: https://github.com/pytorch/pytorch/blob/main/torch/profiler/profiler.py#L190
and it is imported here: https://github.com/pytorch/pytorch/blob/main/torch/profiler/profiler.py#L16

The current mechanism is that profiler.profile mostly handles scheduling and some callback registering but autograd.profile is what is actually responsible for calling the pybind functions that will start the profiling. Essentially, the profiler.profile is a wrapper around the autograd implementation.

Sorry if this has caused confusion! We should be more clear in the note to explain this implementation and suggest users to use the profiler.profile as the frontend.

@soulitzer soulitzer added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jul 7, 2025
@lucasb-eyer
Copy link
Contributor Author

No worries. You are right, thanks for pointing to the exact code! I changed the wording to now (hopefully) be correct:

This is the backend, most people should use :mod:torch.profiler instead.

The important part is just to redirect most users there.

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.

LGTM!

@lucasb-eyer
Copy link
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jul 7, 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: linux-binary-manywheel / manywheel-py3_9-rocm6_4-test

Details for Dev Infra team Raised by workflow job

@lucasb-eyer
Copy link
Contributor Author

@pytorchbot merge

@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

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 topic: not user facing topic 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