Skip to content

Conversation

@colesbury
Copy link
Member

Ensure that each THPVariable -> THPFunction reference contributes one
ref count to the THPFunction by creating a new shared_ptr for each ref.

Because multiple shared_ptrs can again manage a single THPFunction, it's
not safe to use std::weak_ptr where it may point to a PyFunction. It's
still safe to use weak_ptr for grad_accumulator since these are never
PyFunctions.

Fixes #1626

Ensure that each THPVariable -> THPFunction reference contributes one
ref count to the THPFunction by creating a new shared_ptr for each ref.

Because multiple shared_ptrs can again manage a single THPFunction, it's
not safe to use std::weak_ptr where it may point to a PyFunction. It's
still safe to use weak_ptr for grad_accumulator since these are never
PyFunctions.

Fixes pytorch#1626
// The C++ wrapper for this Python function.
// See a comment in THPFunction_asFunction for details about this field.
// You can use cdata directly if you don't actually need a shared_ptr.
std::weak_ptr<torch::autograd::PyFunction> cdata_ptr;

This comment was marked as off-topic.

int expected_version;

std::shared_ptr<Variable> unpack();
std::shared_ptr<Variable> unpack(std::shared_ptr<Function> saved_for=nullptr);

This comment was marked as off-topic.

This comment was marked as off-topic.

@soumith soumith merged commit eba3dc8 into pytorch:master Jun 3, 2017
@colesbury colesbury deleted the gc_refs branch June 5, 2017 18:02
jjsjann123 pushed a commit to jjsjann123/pytorch that referenced this pull request May 17, 2022
* Fix un-welford transformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants