Skip to content

Commit

Permalink
Patchfix infinite loop (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
muellerzr authored and sgugger committed Apr 29, 2022
1 parent c665779 commit b3691db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/accelerate/memory_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,7 @@ def decorator(*args, **kwargs):
gc.collect()
torch.cuda.empty_cache()
batch_size //= 2
else:
raise

return decorator
9 changes: 9 additions & 0 deletions tests/test_memory_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,12 @@ def mock_training_loop_function(batch_size, arg1, arg2):
mock_training_loop_function(128, "hello", "world")
self.assertIn("Batch size was passed into `f`", cm.exception.args[0])
self.assertIn("`f(arg1='hello', arg2='world')", cm.exception.args[0])

def test_any_other_error(self):
@find_executable_batch_size(starting_batch_size=16)
def mock_training_loop_function(batch_size):
raise ValueError("Oops, we had an error!")

with self.assertRaises(ValueError) as cm:
mock_training_loop_function()
self.assertIn("Oops, we had an error!", cm.exception.args[0])

0 comments on commit b3691db

Please sign in to comment.