Cannot load a model that saved locally
Author: rcontesti
Pull request: no

### System Info

```
- `transformers` version: 4.24.0
- Platform: Linux-5.15.0-53-generic-x86_64-with-glibc2.35
- Python version: 3.9.15
- Huggingface_hub version: 0.10.1
- PyTorch version (GPU?): 1.13.0+cu117 (False)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>
```

### 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, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

```
from transformers import AutoTokenizer, AutoModelForQuestionAnswering
import torch

model_name = "twmkn9/albert-base-v2-squad2"


model = AutoModelForQuestionAnswering.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

model_dir="./models/"+model_name
_ = model.save_pretrained(model_dir)
_ = tokenizer.save_pretrained(model_dir)


model = AutoModelForQuestionAnswering.from_pretrained("model_dir")
tokenizer = AutoTokenizer.from_pretrained("model_dir")
```

### Expected behavior

I would expect that after successfully saving the model locally I'm able to load it. Unfortunately, I'm getting the following error:

```
Output exceeds the [size limit](command:workbench.action.openSettings?[). Open the full output data [in a text editor](command:workbench.action.openLargeOutput?17b3235e-945e-4cb8-b7e0-e53f106f5fad)
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
File ~/anaconda3/envs/nlp4diag/lib/python3.9/site-packages/huggingface_hub/utils/_errors.py:213, in hf_raise_for_status(response, endpoint_name)
    212 try:
--> 213     response.raise_for_status()
    214 except HTTPError as e:

File ~/anaconda3/envs/nlp4diag/lib/python3.9/site-packages/requests/models.py:1021, in Response.raise_for_status(self)
   1020 if http_error_msg:
-> 1021     raise HTTPError(http_error_msg, response=self)

HTTPError: 401 Client Error: Unauthorized for url: https://huggingface.co/model_dir/resolve/main/config.json

The above exception was the direct cause of the following exception:

RepositoryNotFoundError                   Traceback (most recent call last)
File ~/anaconda3/envs/nlp4diag/lib/python3.9/site-packages/transformers/utils/hub.py:409, in cached_file(path_or_repo_id, filename, cache_dir, force_download, resume_download, proxies, use_auth_token, revision, local_files_only, subfolder, user_agent, _raise_exceptions_for_missing_entries, _raise_exceptions_for_connection_errors, _commit_hash)
    407 try:
    408     # Load from URL or cache if already cached
--> 409     resolved_file = hf_hub_download(
    410         path_or_repo_id,
    411         filename,
    412         subfolder=None if len(subfolder) == 0 else subfolder,
    413         revision=revision,
    414         cache_dir=cache_dir,
...
    434         f"'https://huggingface.co/{path_or_repo_id}' for available revisions."
    435     )

OSError: model_dir is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models'
If this is a private repository, make sure to pass a token having permission to this repo with `use_auth_token` or log in with `huggingface-cli login` and pass `use_auth_token=True`.

```

Comments:
You need to remove the quotes around model_dir:
```
model = AutoModelForQuestionAnswering.from_pretrained(model_dir)
tokenizer = AutoTokenizer.from_pretrained(model_dir)
```

Thanks. Really embarrassing!

i push the model in github using lfs but when i deploy it show me the same error

Hi @NimishNatani, could you share the steps you took, your running environment (run `transformers-cli env` in the terminal and copy-paste the output) and the full error traceback?

In your message, you say you pushed the model to github. When loading models, it is expected that the path passed in is either to a local folder or a repo on the hugging face hub (i.e. not github)

Steps that I follow are 
1) take the model using TFAutomodelforsequenceclassification and autotokenizer then I get the model by passing their results in pipeline I get the model so I save in my local machine using save_pretrained and I after that I call the model from the local machine so that again again model will not download and my web app run perfectly.
But the problem arises when I push the model in GitHub using lFs 
My streamlit app did not recognise the model 
If I save the model using Ifs Is I have to call the model in a different way or not 
And can you suggest some other way to save the model els where and the web app run perfectly 

Hi @NimishNatani, 

* Regarding the steps, could you share a minimal code example? From text descriptions it's hard to know what's happening or might be wrong.
* Re my comment above - when we load from AutoModelXX.from_pretrained, it's expected the model is on the hugging face hub or local, not a github repository.
* Could you share the full error traceback from the steamlit app? 

Here's a guide on pushing models to the hugging face hub: https://huggingface.co/docs/transformers/en/model_sharing