Remove unnecessary py::object copy in PyRRef ctor#38402
Closed
mrshenli wants to merge 5 commits intogh/mrshenli/177/basefrom
Closed
Remove unnecessary py::object copy in PyRRef ctor#38402mrshenli wants to merge 5 commits intogh/mrshenli/177/basefrom
mrshenli wants to merge 5 commits intogh/mrshenli/177/basefrom
Conversation
[ghstack-poisoned]
This was referenced May 13, 2020
💊 CI failures summary and remediationsAs of commit a7eb6d6 (more details on the Dr. CI page):
ci.pytorch.org: 1 failedThis comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker. This comment has been revised 12 times. |
xush6528
reviewed
May 13, 2020
| // jit::toIValue takes a py::handle as the first argument, and it calls | ||
| // py::handle.cast<py::object>() to incref of provided value. The | ||
| // returned ivalue will keep the reference alive. | ||
| IValue ivalue = jit::toIValue(value, elem_type); |
Contributor
There was a problem hiding this comment.
I think this simplification makes sense.
There is one subtle change here.
If we have this py::object copy, the passed-in const py::object& must be kept alive until py::object copy(value); to make PyRRef::PyRRef work correctly.
If we remove this py::object copy, the passed-in const py::object& must be kept alive until the py::handle.cast<py::object>() in jit::toIValue(..).
So let's mention this lifetime assumption on the passed-in const py::object&, and why we need this the pybind11 binding for this constructor to be holding GIL.
[ghstack-poisoned]
added 3 commits
May 13, 2020 12:00
Differential Revision: [D21554724](https://our.internmc.facebook.com/intern/diff/D21554724) [ghstack-poisoned]
Differential Revision: [D21554724](https://our.internmc.facebook.com/intern/diff/D21554724) [ghstack-poisoned]
Differential Revision: [D21554724](https://our.internmc.facebook.com/intern/diff/D21554724) [ghstack-poisoned]
xush6528
approved these changes
May 13, 2020
Contributor
laurentdupin
pushed a commit
to laurentdupin/pytorch
that referenced
this pull request
Apr 24, 2026
Summary: Pull Request resolved: pytorch#38402 Test Plan: Imported from OSS Differential Revision: D21554724 Pulled By: mrshenli fbshipit-source-id: abab45010810ec53628ea2c7a9c76cdc50eb2f74
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack:
Differential Revision: D21554724