Getting error AttributeError: 'BertOnlyMLMHead' object has no attribute 'bias' when giving TF path
Author: kennysmith12
Pull request: no
Labels: name: wontfix

# 🐛 Bug

## Information

Model I am using BERT:

Language I am using the model on English:

The problem arises when using:
the official example scripts: 





The tasks I am working on is:
my own task or dataset: (give details below)

## To reproduce

Steps to reproduce the behavior:
I have this line in config class:

`    self.model_type = "bert"`

the config.model_name_or_path is the path where the checkpint file, index, meta config and vocab files are located
This is the problem with my code:
```
MODEL_CLASSES = {
  "bert": (BertConfig, BertForMaskedLM, BertTokenizer),
}
 config_class, model_class, tokenizer_class = MODEL_CLASSES[config.model_type]
  tokenizer = tokenizer_class.from_pretrained(config.model_name_or_path, cache_dir=None)
  gradients = []
  model_config = config_class.from_pretrained(config.model_name_or_path, cache_dir=None)

  model = model_class.from_pretrained(
    config.model_name_or_path,
    from_tf=True,
    config=model_config,
    cache_dir=None,
  )
```
I am getting this error :
```
  File "\transformers\src\transformers\modeling_utils.py", line 481, in from_pretrained
    model = cls.load_tf_weights(model, config, resolved_archive_file[:-6])  # Remove the '.index'
  File "\transformers\src\transformers\modeling_bert.py", line 105, in load_tf_weights_in_bert
    pointer = getattr(pointer, "bias")
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\torch\nn\modules\module.py", line 576, in __getattr__
    type(self).__name__, name))
AttributeError: 'BertOnlyMLMHead' object has no attribute 'bias'

Process finished with exit code 1

I tried to convert the TF model to Pytorch model, but I am always getting the same error (from each script on different attribute).

```

<!-- If you have code snippets, error messages, stack traces please provide them here as well.
     Important! Use code tags to correctly format your code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting
     Do not use screenshots, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code.-->

## Expected behavior
I expect the "from_pretrained" to load the TF model
<!-- A clear and concise description of what you would expect to happen. -->

## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->
     
- `transformers` version:
- Platform: windows
- Python version: 3.7
- PyTorch version no
- Tensorflow version 2.1.0:
- Using GPU in script: no
- Using distributed or parallel set-up in script: no


Comments:
To load TF models you should use the TF class `TFBertForMaskedLM` and not `BertForMaskedLM` which is the PyTorch class.

Thanks for the response
I found that  BertForPreTraining also allows to loads when the TF model

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.