[go: nahoru, domu]

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

replaced assert with raise ValueError for t5, switch_transformers, pix2struct, mt5, longt5, gptsan_japanese. #23273

Merged
merged 3 commits into from
May 12, 2023

Conversation

susnato
Copy link
Contributor
@susnato susnato commented May 10, 2023

What does this PR do?

As said by @sanchit-gandhi, here this PR replaces assert with raise ValueError for models - t5, switch_transformers, pix2struct, mt5, longt5, gptsan_japanese.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@sanchit-gandhi

@HuggingFaceDocBuilderDev
Copy link
HuggingFaceDocBuilderDev commented May 10, 2023

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

Copy link
Contributor
@sanchit-gandhi sanchit-gandhi left a comment

Choose a reason for hiding this comment

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

Awesome - thanks for the quick fix @susnato! All the changes LGTM - would suggest maybe just putting one of the error messages onto one line then running:

make style

To automatically format as required, otherwise all good from my side!

Comment on lines 1354 to 1357
raise ValueError(
"self.model.config.decoder_start_token_id has to be defined. In LongT5 it is usually set to the pad_token_id."
" See LongT5 docs for more information"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

This has gone a bit weird with the formatting - shall we put everything onto one line and then let ruff fix it for us by calling make style?

Suggested change
raise ValueError(
"self.model.config.decoder_start_token_id has to be defined. In LongT5 it is usually set to the pad_token_id."
" See LongT5 docs for more information"
)
raise ValueError("self.model.config.decoder_start_token_id has to be defined. In LongT5 it is usually set to the pad_token_id. See LongT5 docs for more information")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, trying now.

raise ValueError(
f"reordered_layer_past_states[0] shape {reordered_layer_past_states[0].shape} and layer_past_states[0] shape {layer_past_states[0].shape} mismatched"
)
if len(reordered_layer_past_states) != len(layer_past_states):
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@susnato
Copy link
Contributor Author
susnato commented May 11, 2023

Hi @sanchit-gandhi just pushed the change that you requested.

@sanchit-gandhi
Copy link
Contributor

Awesome thanks - requesting a final 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 updating these!

There's just a few places where the error messages should be updated to be in line with line-width limits, and two which I think are wrong because of a copy-paste

)
if decoder_start_token_id is None:
raise ValueError(
"self.model.config.decoder_start_token_id has to be defined. In LongT5 it is usually set to the pad_token_id. See LongT5 docs for more information."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Otherwise line is longer than repo limit 165 > 120

Suggested change
"self.model.config.decoder_start_token_id has to be defined. In LongT5 it is usually set to the pad_token_id. See LongT5 docs for more information."
"self.model.config.decoder_start_token_id has to be defined. In LongT5 it is usually set to the pad_token_id."
" See LongT5 docs for more information."

)
if decoder_start_token_id is None:
raise ValueError(
"self.model.config.decoder_start_token_id has to be defined. In MT5 it is usually set to the pad_token_id. See MT5 docs for more information."
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here re line length

Suggested change
"self.model.config.decoder_start_token_id has to be defined. In MT5 it is usually set to the pad_token_id. See MT5 docs for more information."
"self.model.config.decoder_start_token_id has to be defined. In MT5 it is usually set to the pad_token_id."
" See MT5 docs for more information."

@@ -961,7 +964,8 @@ def forward(
mask_seq_length = past_key_values[0][0].shape[2] + seq_length if past_key_values is not None else seq_length

if use_cache is True:
assert self.is_decoder, f"`use_cache` can only be set to `True` if {self} is used as a decoder"
if not self.is_decoder:
raise ValueError("You have to initialize the model with valid token embeddings")
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
raise ValueError("You have to initialize the model with valid token embeddings")
raise ValueError(f"`use_cache` can only be set to `True` if {self} is used as a decoder")

)
if decoder_start_token_id is None:
raise ValueError(
"self.model.config.decoder_start_token_id has to be defined. In T5 it is usually set to the pad_token_id. See T5 docs for more information."
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
"self.model.config.decoder_start_token_id has to be defined. In T5 it is usually set to the pad_token_id. See T5 docs for more information."
"self.model.config.decoder_start_token_id has to be defined. In T5 it is usually set to the pad_token_id."
" See T5 docs for more information."

@@ -990,7 +992,8 @@ def forward(
mask_seq_length = past_key_values[0][0].shape[2] + seq_length if past_key_values is not None else seq_length

if use_cache is True:
assert self.is_decoder, f"`use_cache` can only be set to `True` if {self} is used as a decoder"
if not self.is_decoder:
raise ValueError("You have to initialize the model with valid token embeddings")
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
raise ValueError("You have to initialize the model with valid token embeddings")
raise ValueError(f"`use_cache` can only be set to `True` if {self} is used as a decoder")

@susnato
Copy link
Contributor Author
susnato commented May 11, 2023

Hi @amyeroberts, just pushed the changes you requested!
Let me know if any more changes are needed or not.

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!

@amyeroberts
Copy link
Collaborator

Merging as errors are unrelated to this PR and have been resolved on main

@amyeroberts amyeroberts merged commit 79743ce into huggingface:main May 12, 2023
sheonhan pushed a commit to sheonhan/transformers that referenced this pull request May 15, 2023
…x2struct, mt5, longt5, gptsan_japanese. (huggingface#23273)

* replaced assert with raise ValueError

* one liner

* reverse one liner and cache-decoder check
gojiteji pushed a commit to gojiteji/transformers that referenced this pull request Jun 5, 2023
…x2struct, mt5, longt5, gptsan_japanese. (huggingface#23273)

* replaced assert with raise ValueError

* one liner

* reverse one liner and cache-decoder check
novice03 pushed a commit to novice03/transformers that referenced this pull request Jun 23, 2023
…x2struct, mt5, longt5, gptsan_japanese. (huggingface#23273)

* replaced assert with raise ValueError

* one liner

* reverse one liner and cache-decoder check
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.

None yet

4 participants