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

Cleanup return_text and return_full_text options in TextGenerationPipeline #33542

Merged
merged 6 commits into from
Sep 27, 2024

Conversation

Rocketknight1
Copy link
Member

@Rocketknight1 Rocketknight1 commented Sep 17, 2024

The extra options in TextGenerationPipeline right now are confusing and poorly documented. This PR refactors things so that the documentation is clearer. It also creates a proper hierarchy of options (return_full_text overrides and ignores return_text, and return_tensors is incompatible with both)

Before this PR, the documentation was incorrect, as it claimed that return_full_text required return_text, whereas actually these options were not compatible with each other!

Behaviour after the change should be mostly unchanged, with the exception that return_full_text overrides return_text if both are set, rather than raising an error. The test that checked for those two options being incompatible has been removed.

Fixes #33535

@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.

@Rocketknight1
Copy link
Member Author

cc @LysandreJik for review!

@Rocketknight1
Copy link
Member Author

Maybe cc @amyeroberts actually, since Lysandre is still away (also I know this is 6 on a Friday, don't worry about reviewing it until Monday!)

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 adding!

Two questions about the intended behaviour. It might be that I'm not familiar with the way the pipeline is normally used

Comment on lines 189 to 190
# Explicitly setting return_full_text = False is caught here, and results in ReturnType.NEW_TEXT
return_type = ReturnType.NEW_TEXT
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm confused why we would have ReturnType.NEW_TEXT if return_text=None and return_full_text=False

Comment on lines 438 to 439
with self.assertRaises(ValueError):
outputs = text_generator("test", return_full_text=True, return_text=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm also not sure why we remove a check that they're mutually exclusive -- I think it's far better to raise an exception if both are set rather than have one silently override the other

Copy link
Member Author

Choose a reason for hiding this comment

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

I was trying to reconcile the docs (which used to be very wrong) with the options, but you're right - I'll make them mutually exclusive like they were before, and update the docs instead.

Comment on lines 176 to 190
if return_type is not None and (
return_text is not None or return_full_text is not None or return_tensors is not None
):
raise ValueError(
"`return_type` is mutually exclusive with `return_text`, `return_full_text`, and `return_tensors`"
)
if return_tensors is not None:
if return_text or return_full_text:
raise ValueError("`return_text` and `return_full_text` are mutually exclusive with `return_tensors`")
return_type = ReturnType.TENSORS
elif return_full_text and return_type is None:
return_type = ReturnType.FULL_TEXT
elif (return_text or return_full_text is not None) and return_type is None:
# Explicitly setting return_full_text = False is caught here, and results in ReturnType.NEW_TEXT
return_type = ReturnType.NEW_TEXT
Copy link
Member

Choose a reason for hiding this comment

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

This whole block is really hard to parse, is it possible to add white space/comments?

@Rocketknight1 Rocketknight1 force-pushed the update_return_full_text branch from 5107db2 to 776e25c Compare September 26, 2024 13:55
@Rocketknight1
Copy link
Member Author

@amyeroberts @LysandreJik I reworked the PR in response to Amy's comment - I think she was right about the new behaviour not being any better. I restored the tests and behaviour to how they were before, and instead updated the docs so they correctly reflect that behaviour. As a result, this PR only touches docstrings now!

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

That's certainly easier to review 😄

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 iterating and fixing the docs!

@Rocketknight1 Rocketknight1 merged commit 75cd270 into main Sep 27, 2024
9 checks passed
@Rocketknight1 Rocketknight1 deleted the update_return_full_text branch September 27, 2024 14:01
BenjaminBossan pushed a commit to BenjaminBossan/transformers that referenced this pull request Sep 30, 2024
…eline (huggingface#33542)

* Cleanup return_text and return_full_text options in TextGenerationPipeline

* Cleanup return_text and return_full_text options in TextGenerationPipeline

* Cleanup return_text and return_full_text options in TextGenerationPipeline

* Cleanup return_text and return_full_text options in TextGenerationPipeline

* Revert pipeline code, but update docs instead

* Restore pipeline test
amyeroberts pushed a commit to amyeroberts/transformers that referenced this pull request Oct 2, 2024
…eline (huggingface#33542)

* Cleanup return_text and return_full_text options in TextGenerationPipeline

* Cleanup return_text and return_full_text options in TextGenerationPipeline

* Cleanup return_text and return_full_text options in TextGenerationPipeline

* Cleanup return_text and return_full_text options in TextGenerationPipeline

* Revert pipeline code, but update docs instead

* Restore pipeline test
BernardZach pushed a commit to BernardZach/transformers that referenced this pull request Dec 5, 2024
…eline (huggingface#33542)

* Cleanup return_text and return_full_text options in TextGenerationPipeline

* Cleanup return_text and return_full_text options in TextGenerationPipeline

* Cleanup return_text and return_full_text options in TextGenerationPipeline

* Cleanup return_text and return_full_text options in TextGenerationPipeline

* Revert pipeline code, but update docs instead

* Restore pipeline test
BernardZach pushed a commit to innovationcore/transformers that referenced this pull request Dec 6, 2024
…eline (huggingface#33542)

* Cleanup return_text and return_full_text options in TextGenerationPipeline

* Cleanup return_text and return_full_text options in TextGenerationPipeline

* Cleanup return_text and return_full_text options in TextGenerationPipeline

* Cleanup return_text and return_full_text options in TextGenerationPipeline

* Revert pipeline code, but update docs instead

* Restore pipeline test
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.

TextGenerationPipeline: ValueError: return_text is mutually exclusive with return_full_text
4 participants