Skip to content

Commit

Permalink
Avoid GPT-2 daily CI job OOM (in TF tests) (#24106)
Browse files Browse the repository at this point in the history
* fix

* fix

---------

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
  • Loading branch information
ydshieh and ydshieh authored Jun 8, 2023
1 parent 9322c24 commit 2e2088f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/models/gpt2/test_modeling_gpt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


import datetime
import gc
import math
import unittest

Expand Down Expand Up @@ -500,6 +501,12 @@ def setUp(self):
self.model_tester = GPT2ModelTester(self)
self.config_tester = ConfigTester(self, config_class=GPT2Config, n_embd=37)

def tearDown(self):
super().tearDown()
# clean-up as much as possible GPU memory occupied by PyTorch
gc.collect()
torch.cuda.empty_cache()

def test_config(self):
self.config_tester.run_common_tests()

Expand Down Expand Up @@ -683,6 +690,12 @@ def test_model_from_pretrained(self):

@require_torch
class GPT2ModelLanguageGenerationTest(unittest.TestCase):
def tearDown(self):
super().tearDown()
# clean-up as much as possible GPU memory occupied by PyTorch
gc.collect()
torch.cuda.empty_cache()

def _test_lm_generate_gpt2_helper(
self,
gradient_checkpointing=False,
Expand Down

0 comments on commit 2e2088f

Please sign in to comment.