From dfd616e658527d809b7d1d351a6b9c6f3c498096 Mon Sep 17 00:00:00 2001 From: Yih-Dar <2521628+ydshieh@users.noreply.github.com> Date: Tue, 29 Jul 2025 15:35:44 +0200 Subject: [PATCH] Avoid OOM when other tests are failing (#39758) fix Co-authored-by: ydshieh --- .../musicgen_melody/test_modeling_musicgen_melody.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/models/musicgen_melody/test_modeling_musicgen_melody.py b/tests/models/musicgen_melody/test_modeling_musicgen_melody.py index a09f37d115..73af767e04 100644 --- a/tests/models/musicgen_melody/test_modeling_musicgen_melody.py +++ b/tests/models/musicgen_melody/test_modeling_musicgen_melody.py @@ -31,6 +31,7 @@ from transformers import ( ) from transformers.testing_utils import ( Expectations, + cleanup, get_device_properties, is_torch_available, is_torchaudio_available, @@ -1256,6 +1257,12 @@ class MusicgenMelodyIntegrationTests(unittest.TestCase): def model(self): return MusicgenMelodyForConditionalGeneration.from_pretrained("ylacombe/musicgen-melody").to(torch_device) + def setUp(self): + cleanup(torch_device, gc_collect=True) + + def tearDown(self): + cleanup(torch_device, gc_collect=True) + @cached_property def processor(self): return MusicgenMelodyProcessor.from_pretrained("ylacombe/musicgen-melody")