pytorch
9f91e940 - Workaround for NumPy builds that ship with a broken Dlpack deleter (#89759)

Commit
1 year ago
Workaround for NumPy builds that ship with a broken Dlpack deleter (#89759) NumPy versions 1.22 and 1.23 (and their respective bugfix releases included) have a buggy implementation of the Dlpack deleter that doesn't account for no-GIL contexts. Since we now release the GIL when deallocating tensors in `THPVariable_clear`, this leads to a failure of internal consistency checks when freeing a Dlpack-backed tensor from NumPy. This PR adds a check for the buggy NumPy versions and overrides the `DlManagedTensor` deleter to reacquire the GIL before deallocation. ### Rationale for this implementation The version check was added to `tensor_numpy.h/cpp` as it seemed like a more logical location for it than creating a new translation unit. The overriding of the deleter was originally attempted by directly modifying `at::fromDlpack`, but the lack of a build dependency on the Python C API in A10 prevented that. So, I extended the A10 Dlpack API instead to additionally accept a custom deleter functor. Fixes #88082 Pull Request resolved: https://github.com/pytorch/pytorch/pull/89759 Approved by: https://github.com/albanD
Author
Committer
Parents
Loading