Skip to content

Remove unnecessary py::object copy in PyRRef ctor#38402

Closed
mrshenli wants to merge 5 commits intogh/mrshenli/177/basefrom
gh/mrshenli/177/head
Closed

Remove unnecessary py::object copy in PyRRef ctor#38402
mrshenli wants to merge 5 commits intogh/mrshenli/177/basefrom
gh/mrshenli/177/head

Conversation

@mrshenli
Copy link
Copy Markdown
Contributor

@mrshenli mrshenli commented May 13, 2020

Stack from ghstack:

Differential Revision: D21554724

@dr-ci
Copy link
Copy Markdown

dr-ci Bot commented May 13, 2020

💊 CI failures summary and remediations

As of commit a7eb6d6 (more details on the Dr. CI page):


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-CircleCI failure(s)

ci.pytorch.org: 1 failed


This 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.

See how this bot performed.

This comment has been revised 12 times.

// 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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

comments added

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@mrshenli merged this pull request in f99a693.

@facebook-github-bot facebook-github-bot deleted the gh/mrshenli/177/head branch May 17, 2020 14:18
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
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