Skip to content

Commit

Permalink
Add explicit error if empty batch received (#2115)
Browse files Browse the repository at this point in the history
* Add explicit error if empty batch received

* Move error check to cover all empty iterables
  • Loading branch information
YuryYakhno committed Nov 3, 2023
1 parent fa6f430 commit 4f10031
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/accelerate/utils/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ def find_batch_size(data):
Returns:
`int`: The batch size.
"""
if isinstance(data, (tuple, list, Mapping)) and (len(data) == 0):
raise ValueError(f"Cannot find the batch size from empty {type(data)}.")

if isinstance(data, (tuple, list)):
return find_batch_size(data[0])
elif isinstance(data, Mapping):
Expand Down

0 comments on commit 4f10031

Please sign in to comment.