Unify cpp_extension build directory removal (#136059)

Keeps existing default directory clearing logic, even though it fails when TORCH_EXTENSIONS_DIR is set. To properly clear, we'd need to track all the folders we compiled the extensions to.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/136059
Approved by: https://github.com/ezyang, https://github.com/albanD
This commit is contained in:
Simon Fan
2024-10-02 16:21:38 -07:00
committed by PyTorch MergeBot
parent 55c343fa3a
commit b86269fab5
8 changed files with 26 additions and 80 deletions

View File

@ -1,8 +1,6 @@
# Owner(s): ["module: mtia"]
import os
import shutil
import sys
import tempfile
import unittest
@ -26,15 +24,6 @@ TEST_ROCM = TEST_CUDA and torch.version.hip is not None and ROCM_HOME is not Non
TEST_CUDA = TEST_CUDA and CUDA_HOME is not None
def remove_build_path():
if sys.platform == "win32":
# Not wiping extensions build folder because Windows
return
default_build_root = torch.utils.cpp_extension.get_default_build_root()
if os.path.exists(default_build_root):
shutil.rmtree(default_build_root, ignore_errors=True)
# Since we use a fake MTIA device backend to test generic Stream/Event, device backends are mutual exclusive to each other.
# The test will be skipped if any of the following conditions are met:
@unittest.skipIf(
@ -67,11 +56,11 @@ class TestCppExtensionStreamAndEvent(common.TestCase):
@classmethod
def tearDownClass(cls):
remove_build_path()
torch.testing._internal.common_utils.remove_cpp_extensions_build_root()
@classmethod
def setUpClass(cls):
remove_build_path()
torch.testing._internal.common_utils.remove_cpp_extensions_build_root()
build_dir = tempfile.mkdtemp()
# Load the fake device guard impl.
src = f"{os.path.abspath(os.path.dirname(__file__))}/cpp_extensions/mtia_extension.cpp"