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

Bug fix in ModularTokenizer.decode() when the input is torch.Tensor type #376

Merged
merged 2 commits into from
Oct 21, 2024

Conversation

SagiPolaczek
Copy link
Collaborator

@SagiPolaczek SagiPolaczek commented Oct 19, 2024

Another "solution" would be to validate that the input value is a list of integers.

The main problem in the current implementation, is that the user is not aware of the type mismatch - the token just appears as missing (!)

@@ -1148,6 +1149,9 @@ def decode(self, ids: Iterable, skip_special_tokens: Optional[bool] = False) ->
Returns:
str: _description_
"""
if isinstance(ids, Tensor):
# Tokens in 'self.decoder_dict' are integers, and not singletons
Copy link
Collaborator

Choose a reason for hiding this comment

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

singletons?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need also to move it to CPU before? in cases the tensor is on the GPU.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good question, so it's being done automatically:

Returns the tensor as a (nested) list. For scalars, a standard Python number is returned, just like with item(). Tensors are automatically moved to the CPU first if necessary.

https://pytorch.org/docs/stable/generated/torch.Tensor.tolist.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

singletons?

Meaning a tensor with a single item in it. Will make it clearer

Copy link
Collaborator

@mosheraboh mosheraboh left a comment

Choose a reason for hiding this comment

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

LGTM

@SagiPolaczek SagiPolaczek merged commit 7c59aff into master Oct 21, 2024
5 checks passed
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.

2 participants