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 Kosmos2Processor batch mode #27323

Merged
merged 3 commits into from
Nov 6, 2023
Merged

Fix Kosmos2Processor batch mode #27323

merged 3 commits into from
Nov 6, 2023

Conversation

ydshieh
Copy link
Collaborator

@ydshieh ydshieh commented Nov 6, 2023

What does this PR do?

Fix Kosmos2Processor batch mode as there is a bug, see comment in the code change.

Fix one issue about batch mode opened in #27301

@@ -211,7 +211,9 @@ def __call__(
image_embeds_position_mask.append(mask)

if isinstance(text, list):
sorted_length = sorted([(idx, len(x)) for idx, x in enumerate(text_encoding.input_ids)])
sorted_length = sorted(
[(idx, len(x)) for idx, x in enumerate(text_encoding.input_ids)], key=lambda x: x[-1]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here my intention was to sort with the length, not the index. However, I forgot to specify the key so it did not do what I expected.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we do have tests regarding the batch mode - but the examples I used have the longest sequence as the last example in a batch, so it didn't detect this issue 😭

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update the test so that it would have been caught?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK!

@ydshieh
Copy link
Collaborator Author

ydshieh commented Nov 6, 2023

All tests (even slow) pass!

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Nov 6, 2023

The documentation is not available anymore as the PR was closed or merged.

@ydshieh ydshieh merged commit 1b20e2b into main Nov 6, 2023
18 checks passed
@ydshieh ydshieh deleted the fix_kosmos2_batch_process branch November 6, 2023 18:05
EduardoPach pushed a commit to EduardoPach/transformers that referenced this pull request Nov 19, 2023
* fix

* fix

* fix

---------

Co-authored-by: ydshieh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants