8000 Fix profiler on cpython-3.13 by malfet · Pull Request #153848 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

Fix profiler on cpython-3.13 #153848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Conversation

malfet
Copy link
Contributor
@malfet malfet commented May 19, 2025

Stack from ghstack (oldest at bottom):

Per PEP 667 PyFrame_GetLocals no longer returns dict, but rather instance of PyFrameLocalsProxy_Type, so calling PyDict_GetItemString is no longer valid(it will always return None) and must be replaced with PyMapping_GetItemString

Tested by partially reverting #141674 full revert will be done in the followup PR

Fixes #148273

[ghstack-poisoned]
@malfet malfet requested a review from sraikund16 as a code owner May 19, 2025 18:47
Copy link
pytorch-bot bot commented May 19, 2025

🔗 Helpful Links

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

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

⏳ No Failures, 48 Pending

As of commit 507e70e with merge base ae0e8f0 (image):
💚 Looks good so far! There are no failures yet. 💚

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

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

@malfet malfet requested review from Skylion007 and albanD May 19, 2025 18:48
@malfet malfet added release notes: profiler release notes category topic: bug fixes topic category labels May 19, 2025
[ghstack-poisoned]
malfet added a commit that referenced this pull request May 19, 2025
Per [PEP 667](https://peps.python.org/pep-0667/) `PyFrame_GetLocals` no
longer returns dict, but rather instance of `PyFrameLocalsProxy_Type`,
so calling `PyDict_GetItemString` is no longer valid and must be
replaced with `PyMapping_GetItemString`

Fixes #148273

ghstack-source-id: a6f5b55
Pull Request resolved: #153848
@malfet
Copy link
Contributor Author
malfet commented May 19, 2025

@pytorchbot merge -f "It was green in the previous iteration, this just fixes the linter"

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

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

malfet added a commit that referenced this pull request May 20, 2025
As underlying issue were fixed by #153848

Fixes #142166

ghstack-source-id: c97acbe
Pull Request resolved: #153857
pytorchmergebot pushed a commit that referenced this pull request May 20, 2025
As underlying issue were fixed by #153848

Fixes #142166
Pull Request resolved: #153857
Approved by: https://github.com/williamwen42
ghstack dependencies: #153848
@@ -882,15 +882,26 @@ void PythonTracer::recordPyCall(
// `PyFrame_FastToLocals` which forces the interpreter to materialize
// the full dict of locals.
auto locals = THPObjectPtr(PyFrame_GetLocals(frame));

#if PY_MAJOR_VERSION < 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 13)
Copy link
Collaborator

Choose a reason for hiding this comment

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

we have #if IS_PYTHON_3_13_PLUS and opposite as a shorthand for these !

#else
// In Python-3.13+ `PyFrame_GetLocals()` returns instance of
// PyFrameLocalsProxy_Type See PEP 667 for more info
auto self = THPObjectPtr(PyMapping_GetItemString(locals, "self"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a mapping for all versions of cpython (since dict are mapping), should we not just use the mapping API for all versions to keep this simpler?

@malfet
Copy link
Contributor Author
malfet commented May 21, 2025

@pytorchbot cherry-pick --onto release/2.7 --category regression

Copy link
pytorch-bot bot commented May 21, 2025

❌ 🤖 pytorchbot command failed:

@pytorchbot cherry-pick: error: the following arguments are required: -c/--classification

usage: @pytorchbot cherry-pick --onto ONTO [--fixes FIXES] -c
                               {regression,critical,fixnewfeature,docs,release}

Try @pytorchbot --help for more info.

@malfet
Copy link
Contributor Author
malfet commented May 21, 2025

@pytorchbot cherry-pick --onto release/2.7 -c regression

pytorchbot pushed a commit that referenced this pull request May 21, 2025
Per [PEP 667](https://peps.python.org/pep-0667/) `PyFrame_GetLocals` no longer returns dict, but rather instance of `PyFrameLocalsProxy_Type`, so calling `PyDict_GetItemString` is no longer valid(it will always return None) and must be replaced with `PyMapping_GetItemString`

Tested by partially reverting #141674 full revert will be done in the followup PR

Fixes #148273
Pull Request resolved: #153848
Approved by: https://github.com/Skylion007

(cherry picked from commit c0343b1)
@pytorchbot
Copy link
Collaborator

Cherry picking #153848

The cherry pick PR is at #154037 and it is recommended to link a regression cherry pick PR with an issue. The following tracker issues are updated:

Details for Dev Infra team Raised by workflow job

atalman pushed a commit that referenced this pull request May 21, 2025
Fix profiler on cpython-3.13 (#153848)

Per [PEP 667](https://peps.python.org/pep-0667/) `PyFrame_GetLocals` no longer returns dict, but rather instance of `PyFrameLocalsProxy_Type`, so calling `PyDict_GetItemString` is no longer valid(it will always return None) and must be replaced with `PyMapping_GetItemString`

Tested by partially reverting #141674 full revert will be done in the followup PR

Fixes #148273
Pull Request resolved: #153848
Approved by: https://github.com/Skylion007

(cherry picked from commit c0343b1)

Co-authored-by: Nikita Shulga <nshulga@meta.com>
@github-actions github-actions bot deleted the gh/malfet/342/head branch June 21, 2025 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Merged release notes: profiler release notes category topic: bug fixes topic category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0