Reduce number of CEX when passing Tensors to Python (#60546)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/60546
Before, we assume conservatively that any Tensor passed to
THPVariable_Wrap could be aliased in another thread and therefore race.
However, THPVariable_Wrap takes in Variable by value; and so if
use_count() <= 1, it is impossible for another thread to have a
reference to it. So we can conclude that it is definitely uninitialized
if the quick test fails!
Thanks bdhirsh for pointing out the optimization opportunity here.
Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Test Plan: Imported from OSS
Reviewed By: albanD
Differential Revision: D29331718
Pulled By: ezyang
fbshipit-source-id: e100796fbc55a0af2c6565c6fbc9ddc8ae7ceb42