avoid calling gc.collect and cuda.empty_cache (#34514)

* update

* update

* update

* update

* update

---------

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
This commit is contained in:
Yih-Dar
2024-10-31 16:36:13 +01:00
committed by GitHub
parent dca93ca076
commit ab98f0b0a1
24 changed files with 77 additions and 94 deletions

View File

@@ -14,7 +14,6 @@
# limitations under the License.
"""Testing suite for the PyTorch Clvp model."""
import gc
import tempfile
import unittest
@@ -23,6 +22,7 @@ import numpy as np
from transformers import ClvpConfig, ClvpDecoderConfig, ClvpEncoderConfig
from transformers.testing_utils import (
cleanup,
require_torch,
slow,
torch_device,
@@ -174,8 +174,7 @@ class ClvpEncoderTest(ModelTesterMixin, unittest.TestCase):
def tearDown(self):
super().tearDown()
# clean-up as much as possible GPU memory occupied by PyTorch
gc.collect()
torch.cuda.empty_cache()
cleanup(torch_device)
def test_config(self):
self.encoder_config_tester.run_common_tests()
@@ -294,8 +293,7 @@ class ClvpDecoderTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMix
def tearDown(self):
super().tearDown()
# clean-up as much as possible GPU memory occupied by PyTorch
gc.collect()
torch.cuda.empty_cache()
cleanup(torch_device)
def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
@@ -421,8 +419,7 @@ class ClvpModelForConditionalGenerationTest(ModelTesterMixin, unittest.TestCase)
def tearDown(self):
super().tearDown()
# clean-up as much as possible GPU memory occupied by PyTorch
gc.collect()
torch.cuda.empty_cache()
cleanup(torch_device)
def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
@@ -571,8 +568,7 @@ class ClvpIntegrationTest(unittest.TestCase):
def tearDown(self):
super().tearDown()
# clean-up as much as possible GPU memory occupied by PyTorch
gc.collect()
torch.cuda.empty_cache()
cleanup(torch_device, gc_collect=True)
def test_conditional_encoder(self):
with torch.no_grad():