diff --git a/py/torch_tensorrt/dynamo/conversion/aten_ops_converters.py b/py/torch_tensorrt/dynamo/conversion/aten_ops_converters.py index 9ee84643c9..2acebea673 100644 --- a/py/torch_tensorrt/dynamo/conversion/aten_ops_converters.py +++ b/py/torch_tensorrt/dynamo/conversion/aten_ops_converters.py @@ -429,7 +429,7 @@ def index_nonbool_validator( node: Node, settings: Optional[CompilationSettings] = None ) -> bool: # for thor and tensorrt_rtx, we don't support boolean indices, due to nonzero op not supported - if is_thor() or ENABLED_FEATURES.tensorrt_rtx: + if ENABLED_FEATURES.tensorrt_rtx: index = node.args[1] for ind in index: if ind is not None: diff --git a/tests/py/dynamo/conversion/test_arange_aten.py b/tests/py/dynamo/conversion/test_arange_aten.py index 968611a4ec..d7b5298be5 100644 --- a/tests/py/dynamo/conversion/test_arange_aten.py +++ b/tests/py/dynamo/conversion/test_arange_aten.py @@ -5,14 +5,14 @@ import torch_tensorrt from parameterized import parameterized from torch.testing._internal.common_utils import run_tests -from torch_tensorrt._utils import is_tegra_platform, is_thor +from torch_tensorrt._utils import is_tegra_platform from .harness import DispatchTestCase @unittest.skipIf( - is_thor() or is_tegra_platform(), - "Skipped on Thor and Tegra platforms", + is_tegra_platform(), + "Skipped on Tegra platforms", ) class TestArangeConverter(DispatchTestCase): @parameterized.expand( diff --git a/tests/py/dynamo/conversion/test_cumsum_aten.py b/tests/py/dynamo/conversion/test_cumsum_aten.py index a677212cb1..e5e0d7df29 100644 --- a/tests/py/dynamo/conversion/test_cumsum_aten.py +++ b/tests/py/dynamo/conversion/test_cumsum_aten.py @@ -5,14 +5,14 @@ import torch_tensorrt from parameterized import parameterized from torch.testing._internal.common_utils import run_tests -from torch_tensorrt._utils import is_tegra_platform, is_thor +from torch_tensorrt._utils import is_tegra_platform from .harness import DispatchTestCase @unittest.skipIf( - is_thor() or is_tegra_platform(), - "Skipped on Thor and Tegra platforms", + is_tegra_platform(), + "Skipped on Tegra platforms", ) class TestCumsumConverter(DispatchTestCase): @parameterized.expand( diff --git a/tests/py/dynamo/conversion/test_index_aten.py b/tests/py/dynamo/conversion/test_index_aten.py index e34dc48dd5..fd8c35de53 100644 --- a/tests/py/dynamo/conversion/test_index_aten.py +++ b/tests/py/dynamo/conversion/test_index_aten.py @@ -6,7 +6,7 @@ from parameterized import parameterized from torch.testing._internal.common_utils import run_tests from torch_tensorrt import ENABLED_FEATURES, Input -from torch_tensorrt._utils import is_tegra_platform, is_thor +from torch_tensorrt._utils import is_tegra_platform from .harness import DispatchTestCase @@ -114,8 +114,8 @@ def forward(self, input): ] ) @unittest.skipIf( - is_thor() or ENABLED_FEATURES.tensorrt_rtx, - "Skipped on Thor or tensorrt_rtx due to nonzero not supported", + ENABLED_FEATURES.tensorrt_rtx, + "Skipped on tensorrt_rtx due to nonzero not supported", ) def test_index_constant_bool_mask(self, _, index, input): class TestModule(torch.nn.Module): @@ -149,8 +149,8 @@ def forward(self, x, index0): ) @unittest.skipIf( - is_thor() or ENABLED_FEATURES.tensorrt_rtx, - "Skipped on Thor or tensorrt_rtx due to nonzero not supported", + ENABLED_FEATURES.tensorrt_rtx, + "Skipped on tensorrt_rtx due to nonzero not supported", ) def test_index_zero_two_dim_ITensor_mask(self): class TestModule(nn.Module): @@ -163,10 +163,6 @@ def forward(self, x, index0): index0 = torch.tensor([True, False]) self.run_test(TestModule(), [input, index0], enable_passes=True) - @unittest.skipIf( - is_thor(), - "Skipped on Thor due to nonzero not supported", - ) def test_index_zero_index_three_dim_ITensor(self): class TestModule(nn.Module): def forward(self, x, index0): @@ -180,8 +176,8 @@ def forward(self, x, index0): self.run_test(TestModule(), [input, index0]) @unittest.skipIf( - is_thor() or ENABLED_FEATURES.tensorrt_rtx, - "Skipped on Thor or tensorrt_rtx due to nonzero not supported", + ENABLED_FEATURES.tensorrt_rtx, + "Skipped on tensorrt_rtx due to nonzero not supported", ) def test_index_zero_index_three_dim_mask_ITensor(self): class TestModule(nn.Module): @@ -252,8 +248,8 @@ def forward(self, input): @unittest.skipIf( - torch_tensorrt.ENABLED_FEATURES.tensorrt_rtx or is_thor() or is_tegra_platform(), - "nonzero is not supported for tensorrt_rtx", + torch_tensorrt.ENABLED_FEATURES.tensorrt_rtx or is_tegra_platform(), + "nonzero is not supported for tensorrt_rtx or Tegra platforms", ) class TestIndexDynamicInputNonDynamicIndexConverter(DispatchTestCase): def test_index_input_non_dynamic_index_dynamic(self): diff --git a/tests/py/dynamo/conversion/test_nonzero_aten.py b/tests/py/dynamo/conversion/test_nonzero_aten.py index 641cc7c098..646f000a8d 100644 --- a/tests/py/dynamo/conversion/test_nonzero_aten.py +++ b/tests/py/dynamo/conversion/test_nonzero_aten.py @@ -6,14 +6,14 @@ from parameterized import parameterized from torch.testing._internal.common_utils import run_tests from torch_tensorrt import Input -from torch_tensorrt._utils import is_tegra_platform, is_thor +from torch_tensorrt._utils import is_tegra_platform from .harness import DispatchTestCase @unittest.skipIf( - torch_tensorrt.ENABLED_FEATURES.tensorrt_rtx or is_thor() or is_tegra_platform(), - "nonzero is not supported for tensorrt_rtx", + torch_tensorrt.ENABLED_FEATURES.tensorrt_rtx or is_tegra_platform(), + "nonzero is not supported for tensorrt_rtx or Tegra platforms", ) class TestNonZeroConverter(DispatchTestCase): @parameterized.expand( diff --git a/tests/py/dynamo/conversion/test_sym_size.py b/tests/py/dynamo/conversion/test_sym_size.py index 770dd75504..968ecd322b 100644 --- a/tests/py/dynamo/conversion/test_sym_size.py +++ b/tests/py/dynamo/conversion/test_sym_size.py @@ -4,15 +4,10 @@ import torch.nn as nn from parameterized import parameterized from torch.testing._internal.common_utils import run_tests -from torch_tensorrt._utils import is_thor from .harness import DispatchTestCase -@unittest.skipIf( - is_thor(), - "Skipped on Thor", -) class TestSymSizeConverter(DispatchTestCase): @parameterized.expand( [ diff --git a/tests/py/dynamo/models/test_export_kwargs_serde.py b/tests/py/dynamo/models/test_export_kwargs_serde.py index dabbad3cc8..81121cbccd 100644 --- a/tests/py/dynamo/models/test_export_kwargs_serde.py +++ b/tests/py/dynamo/models/test_export_kwargs_serde.py @@ -75,7 +75,8 @@ def forward(self, x, b=5, c=None, d=None): ) # Save the module - trt_ep_path = os.path.join(tempfile.gettempdir(), "compiled.ep") + tmp_dir = tempfile.mkdtemp(prefix="test_custom_model") + trt_ep_path = os.path.join(tmp_dir, "compiled.ep") torchtrt.save(trt_gm, trt_ep_path, retrace=False) # Clean up model env torch._dynamo.reset() @@ -137,7 +138,8 @@ def forward(self, x, b=5, c=None, d=None): ) # Save the module - trt_ep_path = os.path.join(tempfile.gettempdir(), "compiled.ep") + tmp_dir = tempfile.mkdtemp(prefix="test_custom_model_with_dynamo_trace") + trt_ep_path = os.path.join(tmp_dir, "compiled.ep") torchtrt.save(trt_gm, trt_ep_path, retrace=False) # Clean up model env torch._dynamo.reset() @@ -208,7 +210,8 @@ def forward(self, x, b=5, c=None, d=None): ) # Save the module - trt_ep_path = os.path.join(tempfile.gettempdir(), "compiled.ep") + tmp_dir = tempfile.mkdtemp(prefix="test_custom_model_with_dynamo_trace_dynamic") + trt_ep_path = os.path.join(tmp_dir, "compiled.ep") torchtrt.save(trt_gm, trt_ep_path, retrace=False) # Clean up model env torch._dynamo.reset() @@ -298,7 +301,10 @@ def forward(self, x, b=None, c=None, d=None, e=[]): msg=f"CustomKwargs Module TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}", ) # Save the module - trt_ep_path = os.path.join(tempfile.gettempdir(), "compiled.ep") + tmp_dir = tempfile.mkdtemp( + prefix="test_custom_model_with_dynamo_trace_kwarg_dynamic" + ) + trt_ep_path = os.path.join(tmp_dir, "compiled.ep") torchtrt.save(trt_gm, trt_ep_path, retrace=False) # Clean up model env torch._dynamo.reset() @@ -388,7 +394,10 @@ def forward(self, x, b=None, c=None, d=None, e=[]): msg=f"CustomKwargs Module TRT outputs don't match with the original model. Cosine sim score: {cos_sim} Threshold: {COSINE_THRESHOLD}", ) # Save the module - trt_ep_path = os.path.join(tempfile.gettempdir(), "compiled.ep") + tmp_dir = tempfile.mkdtemp( + prefix="test_custom_model_with_dynamo_trace_kwarg_dynamic" + ) + trt_ep_path = os.path.join(tmp_dir, "compiled.ep") torchtrt.save(trt_gm, trt_ep_path, retrace=False) # Clean up model env torch._dynamo.reset() diff --git a/tests/py/dynamo/models/test_export_serde.py b/tests/py/dynamo/models/test_export_serde.py index c5b007e34b..8c00d1ec3d 100644 --- a/tests/py/dynamo/models/test_export_serde.py +++ b/tests/py/dynamo/models/test_export_serde.py @@ -17,8 +17,6 @@ if importlib.util.find_spec("torchvision"): import torchvision.models as models -trt_ep_path = os.path.join(tempfile.gettempdir(), "trt.ep") - @pytest.mark.unit @pytest.mark.critical @@ -27,6 +25,8 @@ def test_base_full_compile(ir): This tests export serde functionality on a base model which is fully TRT convertible """ + tmp_dir = tempfile.mkdtemp(prefix="test_base_full_compile") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") class MyModule(torch.nn.Module): def __init__(self): @@ -82,6 +82,9 @@ def test_base_full_compile_multiple_outputs(ir): with multiple outputs which is fully TRT convertible """ + tmp_dir = tempfile.mkdtemp(prefix="test_base_full_compile_multiple_outputs") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") + class MyModule(torch.nn.Module): def __init__(self): super().__init__() @@ -141,6 +144,8 @@ def test_no_compile(ir): This tests export serde functionality on a model which won't convert to TRT because of min_block_size=5 constraint """ + tmp_dir = tempfile.mkdtemp(prefix="test_no_compile") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") class MyModule(torch.nn.Module): def __init__(self): @@ -202,6 +207,9 @@ def test_hybrid_relu_fallback(ir): fallback """ + tmp_dir = tempfile.mkdtemp(prefix="test_hybrid_relu_fallback") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") + class MyModule(torch.nn.Module): def __init__(self): super().__init__() @@ -262,6 +270,9 @@ def test_resnet18(ir): """ This tests export save and load functionality on Resnet18 model """ + tmp_dir = tempfile.mkdtemp(prefix="test_resnet18") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") + model = models.resnet18().eval().cuda() input = torch.randn((1, 3, 224, 224)).to("cuda") @@ -307,6 +318,9 @@ def test_resnet18_cpu_offload(ir): """ This tests export save and load functionality on Resnet18 model """ + tmp_dir = tempfile.mkdtemp(prefix="test_resnet18_cpu_offload") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") + model = models.resnet18().eval().cuda() input = torch.randn((1, 3, 224, 224)).to("cuda") @@ -359,6 +373,9 @@ def test_resnet18_dynamic(ir): """ This tests export save and load functionality on Resnet18 model """ + tmp_dir = tempfile.mkdtemp(prefix="test_resnet18_dynamic") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") + model = models.resnet18().eval().cuda() input = torch.randn((1, 3, 224, 224)).to("cuda") @@ -399,6 +416,9 @@ def test_resnet18_torch_exec_ops_serde(ir): """ This tests export save and load functionality on Resnet18 model """ + tmp_dir = tempfile.mkdtemp(prefix="test_resnet18_torch_exec_ops_serde") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") + model = models.resnet18().eval().cuda() input = torch.randn((1, 3, 224, 224)).to("cuda") @@ -432,6 +452,9 @@ def test_hybrid_conv_fallback(ir): model where a conv (a weighted layer) has been forced to fallback to Pytorch. """ + tmp_dir = tempfile.mkdtemp(prefix="test_hybrid_conv_fallback") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") + class MyModule(torch.nn.Module): def __init__(self): super().__init__() @@ -493,6 +516,9 @@ def test_hybrid_conv_fallback_cpu_offload(ir): model where a conv (a weighted layer) has been forced to fallback to Pytorch. """ + tmp_dir = tempfile.mkdtemp(prefix="test_hybrid_conv_fallback_cpu_offload") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") + class MyModule(torch.nn.Module): def __init__(self): super().__init__() @@ -555,6 +581,8 @@ def test_arange_export(ir): Here the arange output is a static constant (which is registered as input to the graph) in the exporter. """ + tmp_dir = tempfile.mkdtemp(prefix="test_arange_export") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") class MyModule(torch.nn.Module): def __init__(self): diff --git a/tests/py/dynamo/models/test_model_refit.py b/tests/py/dynamo/models/test_model_refit.py index e6b7f6e2a4..c9d4595d43 100644 --- a/tests/py/dynamo/models/test_model_refit.py +++ b/tests/py/dynamo/models/test_model_refit.py @@ -532,7 +532,10 @@ def test_refit_one_engine_bert_with_weightmap(): ) @pytest.mark.unit def test_refit_one_engine_inline_runtime_with_weightmap(): - trt_ep_path = os.path.join(tempfile.gettempdir(), "compiled.ep") + tmp_dir = tempfile.mkdtemp( + prefix="test_refit_one_engine_inline_runtime_with_weightmap" + ) + trt_ep_path = os.path.join(tmp_dir, "compiled.ep") model = models.resnet18(pretrained=False).eval().to("cuda") model2 = models.resnet18(pretrained=True).eval().to("cuda") inputs = [torch.randn((1, 3, 224, 224)).to("cuda")] @@ -889,7 +892,10 @@ def test_refit_one_engine_bert_without_weightmap(): ) @pytest.mark.unit def test_refit_one_engine_inline_runtime_without_weightmap(): - trt_ep_path = os.path.join(tempfile.gettempdir(), "compiled.ep") + tmp_dir = tempfile.mkdtemp( + prefix="test_refit_one_engine_inline_runtime_without_weightmap" + ) + trt_ep_path = os.path.join(tmp_dir, "compiled.ep") model = models.resnet18(pretrained=True).eval().to("cuda") model2 = models.resnet18(pretrained=False).eval().to("cuda") inputs = [torch.randn((1, 3, 224, 224)).to("cuda")] diff --git a/tests/py/dynamo/models/test_reexport.py b/tests/py/dynamo/models/test_reexport.py index 7c414def52..0ede5a9226 100644 --- a/tests/py/dynamo/models/test_reexport.py +++ b/tests/py/dynamo/models/test_reexport.py @@ -14,8 +14,6 @@ if importlib.util.find_spec("torchvision"): import torchvision.models as models -trt_ep_path = os.path.join(tempfile.gettempdir(), "trt.ep") - @pytest.mark.unit @pytest.mark.critical @@ -56,6 +54,9 @@ def forward(self, x): # Reexport trt_exp_program = torch.export.export(trt_module, (input,), strict=False) + tmp_dir = tempfile.mkdtemp(prefix="test_base_full_compile") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") + torch.export.save(trt_exp_program, trt_ep_path) deser_trt_module = torchtrt.load(trt_ep_path).module() @@ -82,6 +83,9 @@ def test_base_full_compile_multiple_outputs(ir): with multiple outputs which is fully TRT convertible """ + tmp_dir = tempfile.mkdtemp(prefix="test_base_full_compile_multiple_outputs") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") + class MyModule(torch.nn.Module): def __init__(self): super().__init__() @@ -157,6 +161,8 @@ def forward(self, x): relu = self.relu(conv) return conv, relu + tmp_dir = tempfile.mkdtemp(prefix="test_no_compile") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") model = MyModule().eval().cuda() input = torch.randn((1, 3, 224, 224)).to("cuda") @@ -207,6 +213,9 @@ def test_hybrid_relu_fallback(ir): fallback """ + tmp_dir = tempfile.mkdtemp(prefix="test_hybrid_relu_fallback") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") + class MyModule(torch.nn.Module): def __init__(self): super().__init__() @@ -270,6 +279,9 @@ def test_resnet18(ir): """ This tests export save and load functionality on Resnet18 model """ + tmp_dir = tempfile.mkdtemp(prefix="test_resnet18") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") + model = models.resnet18().eval().cuda() input = torch.randn((1, 3, 224, 224)).to("cuda") @@ -315,6 +327,8 @@ def test_hybrid_conv_fallback(ir): This tests export save and load functionality on a hybrid model where a conv (a weighted layer) has been forced to fallback to Pytorch. """ + tmp_dir = tempfile.mkdtemp(prefix="test_hybrid_conv_fallback") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") class MyModule(torch.nn.Module): def __init__(self): @@ -378,6 +392,8 @@ def test_arange_export(ir): Here the arange output is a static constant (which is registered as input to the graph) in the exporter. """ + tmp_dir = tempfile.mkdtemp(prefix="test_arange_export") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") class MyModule(torch.nn.Module): def __init__(self): @@ -440,6 +456,8 @@ def test_resnet18_dynamic(ir): """ This tests export save and load functionality on Resnet18 model with dynamic shapes """ + tmp_dir = tempfile.mkdtemp(prefix="test_resnet18_dynamic") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") model = models.resnet18().eval().cuda() input_bs2 = torch.randn((2, 3, 224, 224)).to("cuda") @@ -514,6 +532,8 @@ def test_resnet18_dynamic_fallback(ir): """ This tests export save and load functionality on Resnet18 model with dynamic shapes and fallback """ + tmp_dir = tempfile.mkdtemp(prefix="test_resnet18_dynamic_fallback") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") model = models.resnet18().eval().cuda() input_bs2 = torch.randn((2, 3, 224, 224)).to("cuda") @@ -588,6 +608,8 @@ def test_bitwise_and_dynamic_fallback(ir): """ This tests export save and load functionality on a bitwise_and model with dynamic shapes and fallback """ + tmp_dir = tempfile.mkdtemp(prefix="test_bitwise_and_dynamic_fallback") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") class bitwise_and(torch.nn.Module): def forward(self, lhs_val, rhs_val): @@ -668,6 +690,8 @@ def test_random_dynamic_fallback(ir): """ This tests export save and load functionality on a random model with dynamic shapes and fallback """ + tmp_dir = tempfile.mkdtemp(prefix="test_random_dynamic_fallback") + trt_ep_path = os.path.join(tmp_dir, "trt.ep") class NeuralNetwork(nn.Module): def __init__(self): diff --git a/tests/py/dynamo/runtime/test_output_allocator.py b/tests/py/dynamo/runtime/test_output_allocator.py index ce00135c99..28d8ad3e94 100644 --- a/tests/py/dynamo/runtime/test_output_allocator.py +++ b/tests/py/dynamo/runtime/test_output_allocator.py @@ -5,7 +5,7 @@ import torch_tensorrt from parameterized import parameterized from torch.testing._internal.common_utils import TestCase, run_tests -from torch_tensorrt._utils import is_tegra_platform, is_thor +from torch_tensorrt._utils import is_tegra_platform from ..testing_utilities import DECIMALS_OF_AGREEMENT @@ -45,7 +45,7 @@ def forward(self, input): @unittest.skipIf( - torch_tensorrt.ENABLED_FEATURES.tensorrt_rtx or is_thor() or is_tegra_platform(), + torch_tensorrt.ENABLED_FEATURES.tensorrt_rtx or is_tegra_platform(), "TensorRT RTX does not support nonzero which are required for this test", ) class TestOutputAllocatorStaticModel(TestCase): @@ -158,7 +158,7 @@ def test_combination_of_cg_and_oa(self, _, use_python_runtime): @unittest.skipIf( - torch_tensorrt.ENABLED_FEATURES.tensorrt_rtx or is_thor() or is_tegra_platform(), + torch_tensorrt.ENABLED_FEATURES.tensorrt_rtx or s_tegra_platform(), "TensorRT RTX does not support nonzero which are required for this test", ) class TestOutputAllocatorDDSModel(TestCase): @@ -268,7 +268,7 @@ def test_combination_of_cg_and_oa(self, _, use_python_runtime): @unittest.skipIf( - torch_tensorrt.ENABLED_FEATURES.tensorrt_rtx or is_thor() or is_tegra_platform(), + torch_tensorrt.ENABLED_FEATURES.tensorrt_rtx or is_tegra_platform(), "TensorRT RTX does not support nonzero which are required for this test", ) class TestOutputAllocatorDDSOpWithReductionOpModel(TestCase): @@ -382,7 +382,7 @@ def test_combination_of_cg_and_oa(self, _, use_python_runtime): @unittest.skipIf( - torch_tensorrt.ENABLED_FEATURES.tensorrt_rtx or is_thor() or is_tegra_platform(), + torch_tensorrt.ENABLED_FEATURES.tensorrt_rtx or is_tegra_platform(), "TensorRT RTX does not support nonzero which are required for this test", ) class TestOutputAllocatorDDSModelWithGraphBreak(TestCase):