From 5a6de703a729d89448bd8bb4e3e4d7426351e779 Mon Sep 17 00:00:00 2001 From: Yih-Dar <2521628+ydshieh@users.noreply.github.com> Date: Wed, 16 Apr 2025 19:48:30 +0200 Subject: [PATCH] Run `test_can_load_with_global_device_set` using a subprocess (#37553) * fix * fix * fix * Update tests/test_modeling_common.py Co-authored-by: Cyril Vallez * fix --------- Co-authored-by: ydshieh Co-authored-by: Cyril Vallez --- tests/test_modeling_common.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_modeling_common.py b/tests/test_modeling_common.py index 00fb2a77d8..3ec6ba30bf 100755 --- a/tests/test_modeling_common.py +++ b/tests/test_modeling_common.py @@ -89,6 +89,7 @@ from transformers.testing_utils import ( require_torch_multi_accelerator, require_torch_multi_gpu, require_torch_sdpa, + run_test_using_subprocess, set_config_for_less_flaky_test, set_model_for_less_flaky_test, set_model_tester_for_less_flaky_test, @@ -4550,6 +4551,9 @@ class ModelTesterMixin: unique_devices, {device}, f"All parameters should be on {device}, but found {unique_devices}." ) + # Here we need to run with a subprocess as otherwise setting back the default device to the default value ("cpu") + # may bring unwanted consequences on other tests. See PR #37553 + @run_test_using_subprocess @require_torch_accelerator def test_can_load_with_global_device_set(self): config, _ = self.model_tester.prepare_config_and_inputs_for_common()