Skip to content

Commit

Permalink
Fix dataloader hang at the end of an epoch (#741)
Browse files Browse the repository at this point in the history
Co-authored-by: Saaketh Narayan <[email protected]>
  • Loading branch information
XiaohanZhangCMU and snarayan21 authored Aug 22, 2024
1 parent d0495c6 commit fac1852
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion streaming/base/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,11 @@ def _prepare_thread(self, it: _Iterator) -> None:
break

# If we're out of samples this epoch, exit this thread because we are done downloading.
if it.prepare_index == it.total:
# Or, if the ready_index has reached the end, exit this thread to unblock other threads.
# The second scenario is rare, where ready_thread has higher priority and progresses way
# faster than this thread, which means at the end of epoch all other threads need to wait.
if it.prepare_index == it.total or it.ready_index == it.total:
it.prepare_index = it.total
break

# Background thread or a main process crashed, terminate this thread.
Expand Down

0 comments on commit fac1852

Please sign in to comment.