From a1bd2bd19da11e7ab552ff6d35a33b7069a2abfd Mon Sep 17 00:00:00 2001 From: PyTorch MergeBot Date: Sun, 3 Nov 2024 02:40:45 +0000 Subject: [PATCH] Revert "Expose Storage _use_count API in Python (#139426)" This reverts commit e31136d07bbfb10735df101df953c73d22dde24b. Reverted https://github.com/pytorch/pytorch/pull/139426 on behalf of https://github.com/huydhn due to Sorry for reverting your change, but it is failing some inductor job in trunk ([comment](https://github.com/pytorch/pytorch/pull/139426#issuecomment-2453269063)) --- test/test_torch.py | 13 ------------- torch/csrc/StorageMethods.cpp | 8 -------- 2 files changed, 21 deletions(-) diff --git a/test/test_torch.py b/test/test_torch.py index 03929f1ee7e6d..2b80384100b98 100644 --- a/test/test_torch.py +++ b/test/test_torch.py @@ -10057,19 +10057,6 @@ def __del__(self): self.assertEqual(MyStorage.finalized_count, 1) self.assertTrue(m[0]) - @unittest.skipIf(not torch.cuda.is_available(), "_storage_Use_Count only registered when CUDA is available") - def test_storage__use_count_APIs_align(self): - a = torch.rand(2, 3) - s = a.untyped_storage() - init_use_count = s._use_count() - self.assertEqual(init_use_count, torch._C._storage_Use_Count(s._cdata)) - b = a.t() - self.assertEqual(s._use_count(), init_use_count + 1) - self.assertEqual(s._use_count(), torch._C._storage_Use_Count(s._cdata)) - del b - self.assertEqual(s._use_count(), init_use_count) - self.assertEqual(s._use_count(), torch._C._storage_Use_Count(s._cdata)) - def test_tensor_ressurecting_clear(self): # Regression test for https://github.com/pytorch/pytorch/issues/136358 # A Tensor with custom __dict__ diff --git a/torch/csrc/StorageMethods.cpp b/torch/csrc/StorageMethods.cpp index f74dd8348554b..7200688dd475b 100644 --- a/torch/csrc/StorageMethods.cpp +++ b/torch/csrc/StorageMethods.cpp @@ -47,13 +47,6 @@ static PyObject* THPStorage_nbytes(PyObject* self, PyObject* noargs) { END_HANDLE_TH_ERRORS } -static PyObject* THPStorage__useCount(PyObject* self, PyObject* noargs) { - HANDLE_TH_ERRORS - THPStorage_assertNotNull(self); - return py::cast(THPStorage_Unpack(self).use_count()).release().ptr(); - END_HANDLE_TH_ERRORS -} - static PyObject* THPStorage_dataPtr(PyObject* self, PyObject* noargs) { HANDLE_TH_ERRORS // PyLong_FromVoidPtr should not need to mutate the pointer in order @@ -627,7 +620,6 @@ static PyMethodDef THPStorage_methods[] = { METH_VARARGS | METH_STATIC, nullptr}, {"_set_from_file", THPStorage_setFromFile, METH_VARARGS, nullptr}, - {"_use_count", THPStorage__useCount, METH_NOARGS, nullptr}, {"from_buffer", castPyCFunctionWithKeywords(THPStorage_fromBuffer), METH_VARARGS | METH_KEYWORDS | METH_STATIC,