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

Improve generate docstring #18198

Merged
merged 3 commits into from
Aug 2, 2022

Conversation

JoaoLages
Copy link
Contributor

@JoaoLages JoaoLages commented Jul 19, 2022

What does this PR do?

The generate docstring is not correct, because it has a lot of defaults that read from model.config and that is not clearly stated in the method description.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).

Who can review?

@sgugger @patrickvonplaten I believe this one is for one of you two?

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jul 19, 2022

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

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

I think it's best to leave the default as they were (since they are ultimately the defaults for the model config) and put a big warning at the top of the arg section of the docstring stating that all of them will be overridden by the model config. What do you think @patrickvonplaten ?

@JoaoLages
Copy link
Contributor Author

I think it's best to leave the default as they were (since they are ultimately the defaults for the model config) and put a big warning at the top of the arg section of the docstring stating that all of them will be overridden by the model config. What do you think @patrickvonplaten ?

Things like model.config.num_beams change frequently from model to model. Looking at the 'defaults to 1' was very misleading for me.

@JoaoLages JoaoLages requested a review from sgugger July 20, 2022 09:39
@patrickvonplaten
Copy link
Contributor

Thanks for the feedback here @JoaoLages! I understand the reason behind your PR and am inclined to merge it as is - would like to get some input from @gante here as well though before merging

@gante
Copy link
Member

gante commented Aug 2, 2022

This is a tough one. The change (as it is) is possibly good for generate-savvy users but will make it more confusing for most use cases -- all those config values have their own defaults which are in fact almost always used. We would lose that very useful part of the documentation to make this caveat more visible.

In general, we can all agree that defaulting to the config specification is confusing (and a giant source of issues) -- @JoaoLages we are working on a plan to remove them, which is actually the root problem here. This means that documentation changes as a result of this PR will be temporary :)

Personally, because of the two paragraphs above, I am more inclined toward @sgugger's suggestion -- the most common situation stays clearly documented, and a temporary warning gets added. @JoaoLages WDYT?

@JoaoLages
Copy link
Contributor Author

JoaoLages commented Aug 2, 2022

In general, we can all agree that defaulting to the config specification is confusing (and a giant source of issues)

Totally agree with this statement!

Personally, because of the two paragraphs above, I am more inclined toward @sgugger's suggestion -- the most common situation stays clearly documented, and a temporary warning gets added. @JoaoLages WDYT?

The warning would help 👍

@gante
Copy link
Member

gante commented Aug 2, 2022

Awesome, I think we can move forward with it then :)

One detail -- this warning should go in FLAX's and TF's docstring as well. If it is not asking too much @JoaoLages, can you copy it to the other frameworks as well? 🙏

@JoaoLages
Copy link
Contributor Author

Awesome, I think we can move forward with it then :)

One detail -- this warning should go in FLAX's and TF's docstring as well. If it is not asking too much @JoaoLages, can you copy it to the other frameworks as well? 🙏

Actually, the warning is already in the docstring, right? I guess it is not that visible 😅

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

What about putting this text at each default?

@@ -927,43 +927,43 @@ def generate(
max_new_tokens (`int`, *optional*, defaults to None):
The maximum numbers of tokens to generate, ignore the current number of tokens. Use either
`max_new_tokens` or `max_length` but not both, they serve the same purpose.
min_length (`int`, *optional*, defaults to 10):
min_length (`int`, *optional*, defaults to `model.config.min_length`):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
min_length (`int`, *optional*, defaults to `model.config.min_length`):
min_length (`int`, *optional*, defaults to `model.config.min_length` or 10 if the config does not set any value):

Copy link
Member

@gante gante Aug 2, 2022

Choose a reason for hiding this comment

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

This is verbose... but possibly the best solution until it gets fixed.

As @JoaoLages mentioned, the warning is already there (PT only). However, because our documentation shows the parameters first and generate has 39 parameters (😅), the warning is not visible at first (see the docs).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, that's why I'm suggesting this compromise :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll make the changes then. Thanks for your great work HuggingFacers! 💪

Copy link
Collaborator

@sgugger sgugger 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 with us!

@sgugger sgugger merged commit dbd9641 into huggingface:main Aug 2, 2022
@JoaoLages
Copy link
Contributor Author

Thanks for iterating with us!

You were too fast 😂
I also added the changes for TF and FLAX. Opened another PR #18432

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