Skip to content

Fixed resize_token_embedding issue #21053 - #21065

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

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

Conversation

@susnato

@susnato susnato commented Jan 9, 2023

Copy link
Copy Markdown
Contributor

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

HuggingFaceDocBuilderDev commented Jan 9, 2023

Copy link
Copy Markdown

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

@sgugger

sgugger commented Jan 9, 2023

Copy link
Copy Markdown
Collaborator

cc @gante and @Rocketknight1

@gante gante left a comment

Copy link
Copy Markdown
Contributor

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

gante commented Jan 16, 2023

Copy link
Copy Markdown
Contributor

@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

gante commented Jan 16, 2023

Copy link
Copy Markdown
Contributor

@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

susnato commented Jan 16, 2023

Copy link
Copy Markdown
Contributor Author

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

@sgugger sgugger left a comment

Copy link
Copy Markdown
Collaborator

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

susnato commented Jan 16, 2023

Copy link
Copy Markdown
Contributor Author

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

gante commented Jan 17, 2023

Copy link
Copy Markdown
Contributor

@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

susnato commented Jan 17, 2023

Copy link
Copy Markdown
Contributor Author

@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

gante commented Jan 18, 2023

Copy link
Copy Markdown
Contributor

@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