Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more efficient batch generation #4

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion batched/aio/batch_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ async def optimal_batches(self) -> Generator[list[AsyncBatchItem[T, U]], None, N
if queue_size == 0:
continue

batch_items = [self._queue._get() for _ in range(queue_size)] # noqa: SLF001
n_batches = max(1, queue_size // self._batch_size)
size_batches = min(self._batch_size * n_batches, queue_size)
batch_items = [self._queue._get() for _ in range(size_batches)] # noqa: SLF001
for batch in batch_iter(batch_items, self._batch_size):
yield batch
4 changes: 3 additions & 1 deletion batched/batch_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ def optimal_batches(self) -> Generator[list[BatchItem[T, U]], None, None]:
if queue_size == 0:
continue

batch_items = [self._queue._get() for _ in range(queue_size)] # noqa: SLF001
n_batches = max(1, queue_size // self._batch_size)
size_batches = min(self._batch_size * n_batches, queue_size)
batch_items = [self._queue._get() for _ in range(size_batches)] # noqa: SLF001
for batch in batch_iter(batch_items, self._batch_size):
if self._stop_requested:
break
Expand Down
11 changes: 8 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[project]
name = "batched"
version = "0.1.0"
description = "Batched is a flexible and efficient dynamic batching library implemented in Python. It supports asynchronous batch processing with dynamic batching and prioritization."
authors = [{ name = "Mixedbread", email = "support@mixedbread.ai" }, { name = "Julius Lipp", email = "julius@mixedbread.ai" }, { name = "Rui Huang", email = "rui@mixedbread.ai" }]
version = "0.1.1"
description = "Batched is a flexible and efficient batch processing library implemented in Python. It supports asynchronous batch processing with dynamic batching and prioritization."
authors = [
{ name = "Mixedbread", email = "support@mixedbread.ai" },
{ name = "Julius Lipp", email = "julius@mixedbread.ai" },
{ name = "Rui Huang", email = "rui@mixedbread.ai" },
]
dependencies = []
requires-python = ">=3.9"
readme = "README.md"
Expand All @@ -16,6 +20,7 @@ build-backend = "setuptools.build_meta"
dev = [
"pytest>=8.0.0",
"pytest-cov>=4.1.0",
"pytest-asyncio>=0.24.0",
"ruff>=0.2.0",
"pre-commit>=3.6.0",
"torch>=2.0.0",
Expand Down