Fixed issue #21053
# 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](https://github.com/huggingface/transformers/blob/48d4e147d824efab97637947709d5aa67c809b3d/src/transformers/models/gpt2/modeling_tf_gpt2.py#L449) 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. 
<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->


## Before submitting
- [x] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? 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](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] 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

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- text models: @ArthurZucker and @younesbelkada
- vision models: @amyeroberts and @NielsRogge
- speech models: @sanchit-gandhi

Library:

- flax: @sanchit-gandhi
- generate: @gante
- pipelines: @Narsil
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @sgugger

Integrations:

- deepspeed: @stas00
- ray/raytune: @richardliaw, @amogkam

Documentation: @sgugger, @stevhliu and @MKhalusova

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @sanchit-gandhi
- PyTorch: @sgugger
- TensorFlow: @Rocketknight1

 -->

_The documentation is not available anymore as the PR was closed or merged._<|||||>cc @gante and @Rocketknight1 <|||||>@sgugger feel free to merge if you approve. As I wrote above, other models have a similar problem (which require a more elaborate fix)<|||||>@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 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?<|||||>> 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.<|||||>@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 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? <|||||>@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 :)