Skip to content

Commit

Permalink
fix: deliver the last batch from the sharded sampler (#1993)
Browse files Browse the repository at this point in the history
  • Loading branch information
westonpace authored Feb 24, 2024
1 parent e37685d commit eef90e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/python/lance/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ def _shard_scan(
rows_accumulated = big_batch.num_rows
if big_batch.num_rows > 0:
accumulated_batches.append(big_batch)
# deliver any batches left over, they will be <= batch
# size but that is ok because we are done
last_batch = (
pa.Table.from_batches(accumulated_batches).combine_chunks().to_batches()[0]
)
yield last_batch

def _sample_filtered(
self,
Expand Down
3 changes: 3 additions & 0 deletions python/python/tests/torch_tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ def test_sample_batches_with_filter(tmp_path: Path):
# - - - 26 -
# ...
all_ids = list(chain.from_iterable([batch.cpu().numpy() for batch in ds]))
# Half of the data is filtered out, divided amongst 5 workers s
# each should see 1/10th of the data
assert len(all_ids) == 1000
assert all_ids == [6 + (10 * i) for i in range(len(all_ids))]

# Now test with random order
Expand Down

0 comments on commit eef90e0

Please sign in to comment.