Skip to content

Changes to compile with 3.13 #126033

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 5 commits into from
Closed

Changes to compile with 3.13 #126033

wants to merge 5 commits into from

Conversation

albanD
Copy link
Collaborator

@albanD albanD commented May 12, 2024

This is mainly:

  • Fix refcount access macro
  • Hide all the Dynamo code that needs update as usual
  • Add _PyWeakref_ClearRef as an extern provided by CPython. Including the pycore header that defines it would require raw c include shenanigans that I don't think are worth it.
    This allows to build both with regular and nogil version of cpython. Both

Note that this requires the 3.13 branch at least past d3094744d40de2deefbda9b1996d5029c9ebf0b0 which we need for mimalloc include and weakref function being exposed.

debug-only issues in pybind11 with PyMem_MALLOC vs PyObject_MALLOC being should be synced either by updating pybind or cpython. @colesbury I can send a PR to ifdef the proper use in pybind if you think that this is the best solution here?

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang

@albanD albanD requested a review from colesbury May 12, 2024 17:07
Copy link

pytorch-bot bot commented May 12, 2024

🔗 Helpful Links

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

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

✅ No Failures

As of commit 2b2820e with merge base 037615b (image):
💚 Looks good so far! There are no failures yet. 💚

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

static Py_tss_t eval_frame_callback_key = Py_tss_NEEDS_INIT;

inline static PyObject* eval_frame_callback_get(void) {
void* result = PyThread_tss_get(&eval_frame_callback_key);
Copy link
Member

Choose a reason for hiding this comment

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

Does this work? Don't you need to call PyThread_tss_create before any get/set with this API?

I think this will probably be simpler if you just use C11 or platform thread-local definitions:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the current dynamo code that was just moved to be in the right ifdef section. So I guess it works because dynamo is doing that today already? :p

This file is pure C, not C11 because calling cpython code like this from c++ is tricky and simpler to keep this being pure C.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, that's fine. But, fwiw, C11 is C not C++.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

:o
Sorry misread that.
cc @jansel or @williamwen42 if you have any more context on migrating this to C11 ?

Copy link
Member

Choose a reason for hiding this comment

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

PyThread_tss_create is called in torch_c_dynamo_eval_frame_init below. I'm not aware of any plans to migrate to C11.

Copy link
Member

@colesbury colesbury left a comment

Choose a reason for hiding this comment

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

LGTM

@albanD albanD added the topic: not user facing topic category label May 13, 2024
@albanD
Copy link
Collaborator Author

albanD commented May 13, 2024

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label May 13, 2024
@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

tinglvv pushed a commit to tinglvv/pytorch that referenced this pull request May 14, 2024
This is mainly:
- Fix refcount access macro
- Hide all the Dynamo code that needs update as usual
- Add _PyWeakref_ClearRef as an extern provided by CPython. Including the pycore header that defines it would require raw c include shenanigans that I don't think are worth it.
This allows to build both with regular and nogil version of cpython. Both

Note that this requires the 3.13 branch at least past [d3094744d40de2deefbda9b1996d5029c9ebf0b0](python/cpython@d309474) which we need for mimalloc include and weakref function being exposed.

debug-only issues in pybind11 with PyMem_MALLOC vs PyObject_MALLOC being should be synced either by updating pybind or cpython. @colesbury I can send a PR to ifdef the proper use in pybind if you think that this is the best solution here?

Pull Request resolved: pytorch#126033
Approved by: https://github.com/colesbury
@albanD albanD mentioned this pull request Jul 8, 2024
37 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants