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 [Generation] Fix some issues when running the MaxLength criteria on CPU #29317

Merged
merged 2 commits into from
Mar 5, 2024

Conversation

younesbelkada
Copy link
Contributor

@younesbelkada younesbelkada commented Feb 27, 2024

What does this PR do?

Hey @zucchini-nlp @gante

In TRL we do have a class that call generate with MaxLengthCriteria and running the CI on main seems to cause some issues after #29116 😱
Not sure how to repro apart from running the failing CI and I did not flagged anything alarming outside my CI but to be on the safe zone I propose to init the torch.full tensor in bool directly, I assume it's fine according to the type hint

Here is the traceback:

self = [<transformers.generation.stopping_criteria.MaxLengthCriteria object at 0x7f652ccf8810>]
input_ids = tensor([[31373,   995, 19277],
        [31373,   995, 27455],
        [31373,   995,  4562],
        [31373,   995, 26964]])
scores = None, kwargs = {}, is_done = tensor([False, False, False, False])
criteria = <transformers.generation.stopping_criteria.MaxLengthCriteria object at 0x7f652ccf8810>

    @add_start_docstrings(STOPPING_CRITERIA_INPUTS_DOCSTRING)
    def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> torch.BoolTensor:
        is_done = torch.full((input_ids.shape[0],), False, device=input_ids.device)
        for criteria in self:
>           is_done = is_done | criteria(input_ids, scores, **kwargs)
E           RuntimeError: "bitwise_or_cpu" not implemented for 'Float'

https://github.com/huggingface/trl/actions/runs/8058401333/job/22011132917

@younesbelkada
Copy link
Contributor Author

younesbelkada commented Feb 27, 2024

cc @zucchini-nlp @gante what do you think about these changes ? 🙏 I can also spend some time on trying to repro with a minial snippet but if these changes look good to you perhaps we can move forward with it

PS: and for some reason I can't request review @zucchini-nlp 🤯

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@zucchini-nlp
Copy link
Member

Okay for me, but it's weird that max_length criteria was returning a float tensor

@younesbelkada
Copy link
Contributor Author

@zucchini-nlp torch.full(xxx) returns a float tensor by default unless you don't explicitly cast it or init the tensor with the desired dtype. The thing I am not sure about is that why it didn't get flagged on other tests

Copy link
Member

@gante gante left a comment

Choose a reason for hiding this comment

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

Perfect, thank you for having a look at the issue 🤗

@gante gante requested review from ArthurZucker and removed request for ArthurZucker March 4, 2024 09:56
@younesbelkada younesbelkada merged commit 81c8191 into huggingface:main Mar 5, 2024
21 checks passed
@younesbelkada younesbelkada deleted the fix-dtype-bool branch March 5, 2024 01:29
damithsenanayake pushed a commit to damithsenanayake/transformers that referenced this pull request Mar 7, 2024
itazap pushed a commit that referenced this pull request May 14, 2024
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.

5 participants