ImportError: cannot import name 'TFGenerationMixin' from 'transformers.generation'
Author: Furknn
Pull request: no

### System Info

# Info

- `transformers` version: 4.25.1
- Platform: Linux-6.0.8-1-MANJARO-x86_64-with-glibc2.36
- Python version: 3.10.8
- Huggingface_hub version: 0.11.1
- PyTorch version (GPU?): 1.13.0+cu117 (True)
- Tensorflow version (GPU?): 2.11.0 (False)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: False
- Using distributed or parallel set-up in script?: False

# Problem

`ImportError: cannot import name 'TFGenerationMixin' from 'transformers.generation'`

I am getting this error while loading a pretrained TensorFlow model as shown below.

```python
import tensorflow,torch
from transformers import AutoTokenizer, AutoModel
model = AutoModel.from_pretrained("model-name", from_tf=True)
```

Model is located in a local folder
```
model-name\
	config.json
	tf-model.h5
```

# Stacktrace
```
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[20], line 5
      2 from transformers import AutoTokenizer, AutoModel
      4 # load the model
----> 5 model = AutoModel.from_pretrained("model-name", from_tf=True)

File ~/project/venv/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py:463, in _BaseAutoModelClass.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
    461 elif type(config) in cls._model_mapping.keys():
    462     model_class = _get_model_class(config, cls._model_mapping)
--> 463     return model_class.from_pretrained(
    464         pretrained_model_name_or_path, *model_args, config=config, **hub_kwargs, **kwargs
    465     )
    466 raise ValueError(
    467     f"Unrecognized configuration class {config.__class__} for this kind of AutoModel: {cls.__name__}.\n"
    468     f"Model type should be one of {', '.join(c.__name__ for c in cls._model_mapping.keys())}."
    469 )

File ~/project/venv/lib/python3.10/site-packages/transformers/modeling_utils.py:2344, in PreTrainedModel.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
   2341 try:
   2342     from .modeling_tf_pytorch_utils import load_tf2_checkpoint_in_pytorch_model
-> 2344     model, loading_info = load_tf2_checkpoint_in_pytorch_model(
   2345         model, resolved_archive_file, allow_missing_keys=True, output_loading_info=True
   2346     )
   2347 except ImportError:
   2348     logger.error(
   2349         "Loading a TensorFlow model in PyTorch, requires both PyTorch and TensorFlow to be installed."
   2350         " Please see https://pytorch.org/ and https://www.tensorflow.org/install/ for installation"
   2351         " instructions."
   2352     )

File ~/project/venv/lib/python3.10/site-packages/transformers/modeling_tf_pytorch_utils.py:359, in load_tf2_checkpoint_in_pytorch_model(pt_model, tf_checkpoint_path, tf_inputs, allow_missing_keys, output_loading_info)
    355     raise
    357 import transformers
--> 359 from .modeling_tf_utils import load_tf_weights
    361 logger.info(f"Loading TensorFlow weights from {tf_checkpoint_path}")
    363 # Instantiate and load the associated TF 2.0 model

File ~/project/venv/lib/python3.10/site-packages/transformers/modeling_tf_utils.py:42
     40 from .configuration_utils import PretrainedConfig
     41 from .dynamic_module_utils import custom_object_save
---> 42 from .generation import TFGenerationMixin
     43 from .tf_utils import shape_list
     44 from .utils import (
     45     DUMMY_INPUTS,
     46     SAFE_WEIGHTS_INDEX_NAME,
   (...)
     63     working_or_temp_dir,
     64 )

ImportError: cannot import name 'TFGenerationMixin' from 'transformers.generation' 
```



### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [x] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [x] My own task or dataset (give details below)

### Reproduction

Can be reproduced by loading a tensorflow model in local storage using 

```
 AutoModel.from_pretrained()
```


### Expected behavior

I have trained a TFBertForMaskedLM model with a custom dataset on google colab. I saved weights of this model by calling 

```python
model.save_pretrained()
```

Now I want to load it in my local machine and use it.

Comments:
cc @gante if you have any idea.

Hi @Furknn 👋 

I have tried to reproduce this in my local machine (current `main` branch) in a local notebook (with `transformers==4.25.1`), using the following script:

```python
import tensorflow,torch
from transformers import AutoTokenizer, AutoModel
model = AutoModel.from_pretrained("gpt2", from_tf=True)
```

In both cases, no exception was thrown. Can I ask you to reinstall `transformers` and, if the issue persists, to share a script I can call on my end where I can reproduce the issue? :)

I have reinstalled transformers version 4.25.1 and tried. It works correctly now.

Thanks