Skip to content

⚡️ Speed up method Batch.broadcast by 12% #1116

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

Merged
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
17 changes: 10 additions & 7 deletions inference/core/workflows/execution_engine/entities/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,18 @@ def iter_with_indices(self) -> Iterator[Tuple[Tuple[int, ...], B]]:
def broadcast(self, n: int) -> "Batch":
if n <= 0:
raise ValueError(
f"Broadcast to size {n} requested which is invalid operation."
f"Broadcast to size {n} requested which is an invalid operation."
)
if len(self._content) == n:

num_content = len(self._content)

if num_content == n:
return self
if len(self._content) == 1:
return Batch(content=[self._content[0]] * n, indices=[self._indices[0]] * n)
raise ValueError(
f"Could not broadcast batch of size {len(self._content)} to size {n}"
)

if num_content == 1:
return Batch(content=self._content * n, indices=self._indices * n)

raise ValueError(f"Could not broadcast batch of size {num_content} to size {n}")


class VideoMetadata(BaseModel):
Expand Down