Skip to content

Fixed resize_token_embedding issue #21053#21065

Merged
sgugger merged 1 commit intohuggingface:mainfrom
susnato:tfgpt2_resize_token_embedding
Jan 16, 2023
Merged

Fixed resize_token_embedding issue #21053#21065
sgugger merged 1 commit intohuggingface:mainfrom
susnato:tfgpt2_resize_token_embedding

Conversation

@susnato
Copy link
Copy Markdown
Contributor

@susnato susnato commented Jan 9, 2023

What does this PR do?

There was a typo in Line 449 in huggingface/transformers/blob/main/src/transformers/models/gpt2/modeling_tf_gpt2.py where the code was doing a check between input_ids and self.vocab_size but resize_token_embeddings change self.config.vocab_size so we were getting the error described in the issue, to overcome this I replaced it with self.config.vocab_size and it worked.

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

@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

HuggingFaceDocBuilderDev commented Jan 9, 2023

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

@sgugger
Copy link
Copy Markdown
Collaborator

sgugger commented Jan 9, 2023

cc @gante and @Rocketknight1

Copy link
Copy Markdown
Contributor

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

This is absolutely correct. self.vocab_size can easily get stale when the vocabulary gets updated, and the check should be done against the config.

(there are other models with this issue, where the fix needs to be slightly different, so I'll have a look very soon)

@gante
Copy link
Copy Markdown
Contributor

gante commented Jan 16, 2023

@sgugger feel free to merge if you approve. As I wrote above, other models have a similar problem (which require a more elaborate fix)

@gante
Copy link
Copy Markdown
Contributor

gante commented Jan 16, 2023

@susnato can you remove the Fixes https://github.com/huggingface/transformers/issues/21053 at the top? That way, the issue stays open and I'll likely won't forget to fix the other models :)

@susnato
Copy link
Copy Markdown
Contributor Author

susnato commented Jan 16, 2023

@susnato can you remove the Fixes https://github.com/huggingface/transformers/issues/21053 at the top? That way, the issue stays open and I'll likely won't forget to fix the other models :)

Hi, @gante I removed the line...is it ok now?

Copy link
Copy Markdown
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 the fix!

@sgugger sgugger merged commit a5327c6 into huggingface:main Jan 16, 2023
@susnato
Copy link
Copy Markdown
Contributor Author

susnato commented Jan 16, 2023

This is absolutely correct. self.vocab_size can easily get stale when the vocabulary gets updated, and the check should be done against the config.

(there are other models with this issue, where the fix needs to be slightly different, so I'll have a look very soon)

Hi, @gante if you want, I would be happy to look into this and fix if I can.

@gante
Copy link
Copy Markdown
Contributor

gante commented Jan 17, 2023

@susnato sounds good!

My plan consists in removing all references to self.vocab_size, deleting the variable whenever it is a variable that is set at __init__ time from the config (if needed, store the config in self.config instead, since it will hold the mutable vocabulary size).

If you search for "tf.cast(self.vocab_size", you will find all matches that will likely have to be touched.

@susnato susnato deleted the tfgpt2_resize_token_embedding branch January 17, 2023 15:19
@susnato
Copy link
Copy Markdown
Contributor Author

susnato commented Jan 17, 2023

@susnato sounds good!

My plan consists in removing all references to self.vocab_size, deleting the variable whenever it is a variable that is set at __init__ time from the config (if needed, store the config in self.config instead, since it will hold the mutable vocabulary size).

If you search for "tf.cast(self.vocab_size", you will find all matches that will likely have to be touched.

Hi @gante I am going to check for all models in src/transformers/models/modeling_tf_<model>.py to remove references of self.vocab_size and also I found some references of self.vocab_size in some of the <model>MLMHead, I need to change them too right?

@gante
Copy link
Copy Markdown
Contributor

gante commented Jan 18, 2023

@susnato yes. If we look at the corresponding PT implementation e.g. for Albert, the layer classes store self.config = config for future use, as opposed to individual attributes of config. Making the switch here protects us from errors like the one that originated this PR :)

@susnato susnato changed the title Fixed issue #21053 Fixed resize_token_embedding issue #21053 Jan 27, 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.

4 participants