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

Fix bucketing bug #554

Merged
merged 1 commit into from
Jun 3, 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 src/fairseq2/data/data_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,14 +531,16 @@ def create_bucket_sizes(

bucket_size = max_num_elements

while seq_len <= max_seq_len:
while seq_len < max_seq_len:
if seq_len >= min_seq_len:
bucket_sizes.append((bucket_size, seq_len))

bucket_size = max_num_elements // (seq_len + 1)

seq_len = max_num_elements // bucket_size

bucket_sizes.append((bucket_size, max_seq_len))

if num_seqs_multiple_of == 1:
return bucket_sizes

Expand Down
8 changes: 8 additions & 0 deletions tests/unit/data/data_pipeline/test_bucket_by_length.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ def test_create_bucket_sizes_with_num_seqs_multiple_of() -> None:
)

assert bucket_sizes == [(8, 2), (4, 3), (4, 4), (2, 5), (2, 8)]


def test_create_bucket_sizes_with_max_seq_len_equals_max_num_elements() -> None:
bucket_sizes = create_bucket_sizes(
max_num_elements=16, max_seq_len=16, min_seq_len=2
)

assert bucket_sizes == [(8, 2), (5, 3), (4, 4), (3, 5), (2, 8), (1, 16)]
Loading