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

Concatenate last batches for batched inference #200

Open
wants to merge 2 commits into
base: batched-inference-and-padding
Choose a base branch
from
Open
Changes from 1 commit
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
14 changes: 13 additions & 1 deletion cebra/solver/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,19 @@ def __getitem__(self, idx):
index_dataloader = DataLoader(index_dataset, batch_size=batch_size)

output = []
for index_batch in index_dataloader:
for batch_idx, index_batch in enumerate(index_dataloader):
# NOTE(celia): This is to prevent that adding the offset to the
# penultimate batch for larger offset make the batch_end_idx larger
# than the input length, while we also don't want to drop the last
# samples that do not fit in a complete batch.
if batch_idx == (len(index_dataloader) - 2):
# penultimate batch, last complete batch
last_batch = index_batch
continue
if batch_idx == (len(index_dataloader) - 1):
# last batch, incomplete
index_batch = torch.cat((last_batch, index_batch), dim=0)

batch_start_idx, batch_end_idx = index_batch[0], index_batch[-1] + 1
batched_data = _get_batch(inputs=inputs,
offset=offset,
Expand Down