Skip to content

Commit

Permalink
Prevent in_memory_cache from yielding from source_dp when it's fu…
Browse files Browse the repository at this point in the history
…lly cached (#1160)

Summary:
Fixes #1159.

Pull Request resolved: #1160

Reviewed By: NivekT

Differential Revision: D45883150

Pulled By: ejguan

fbshipit-source-id: 8aa15294bf32559334817a1b8ec8b88b2807fd5a
  • Loading branch information
hirayaku authored and facebook-github-bot committed May 16, 2023
1 parent 0b39117 commit ba31745
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions torchdata/datapipes/iter/util/cacheholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ def __init__(self, source_dp: IterDataPipe[T_co], size: Optional[int] = None) ->

def __iter__(self) -> Iterator[T_co]:
if self.cache:
for idx, data in enumerate(self.source_dp):
if idx < self.idx:
yield data
else:
break
if self.idx > 0:
for idx, data in enumerate(self.source_dp):
if idx < self.idx:
yield data
else:
break
yield from self.cache
else:
# Local cache
Expand Down

0 comments on commit ba31745

Please sign in to comment.