M1 MacOS: "OSError: Can't load config for 'bert-base-uncased'"
Author: ugm2
Pull request: no
Labels: name: bug

### System Info

```shell
WARNING:tensorflow:From /Users/unaigaraymaestre/miniforge3/envs/test/lib/python3.9/site-packages/transformers/commands/env.py:52: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
Metal device set to: Apple M1 Pro

systemMemory: 16.00 GB
maxCacheSize: 5.33 GB

2022-05-18 09:30:52.149441: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:305] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support.
2022-05-18 09:30:52.149855: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:271] Created TensorFlow device (/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: METAL, pci bus id: <undefined>)

- `transformers` version: 4.19.2
- Platform: macOS-12.3-arm64-arm-64bit
- Python version: 3.9.12
- Huggingface_hub version: 0.6.0
- PyTorch version (GPU?): not installed (NA)
- Tensorflow version (GPU?): 2.8.0 (True)
- 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

- [X] The official example scripts
- [ ] My own modified scripts

### Tasks

- [X] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

## Setup steps

* Following MacOS installation of tensorflow for M1 chips:

https://developer.apple.com/metal/tensorflow-plugin/

* Create python=3.9 environment: `conda create -n test python=3.9`

* Install `tensorflow-deps` using conda: `conda install -c apple tensorflow-deps`

* Install `tensorflow-macos` using pip: `python -m pip install tensorflow-macos`

* Output from installing `tensorflow-macos`:

```
Successfully installed absl-py-1.0.0 astunparse-1.6.3 cachetools-5.1.0 certifi-2021.10.8 charset-normalizer-2.0.12 flatbuffers-2.0 gast-0.5.3 google-auth-2.6.6 google-auth-oauthlib-0.4.6 google-pasta-0.2.0 idna-3.3 importlib-metadata-4.11.3 keras-2.8.0 keras-preprocessing-1.1.2 libclang-14.0.1 markdown-3.3.7 oauthlib-3.2.0 opt-einsum-3.3.0 protobuf-3.20.1 pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.27.1 requests-oauthlib-1.3.1 rsa-4.8 tensorboard-2.8.0 tensorboard-data-server-0.6.1 tensorboard-plugin-wit-1.8.1 tensorflow-macos-2.8.0 termcolor-1.1.0 tf-estimator-nightly-2.8.0.dev2021122109 typing-extensions-4.2.0 urllib3-1.26.9 werkzeug-2.1.2 wrapt-1.14.1 zipp-3.8.0
```

* Install `tensorflow-metal` using pip: `python -m pip install tensorflow-metal`

* Output from installing tensorflow-metal: `Successfully installed six-1.15.0 tensorflow-metal-0.4.0`

And then: `pip install transformers`

Output:

`Successfully installed filelock-3.7.0 huggingface-hub-0.6.0 packaging-21.3 pyparsing-3.0.9 pyyaml-6.0 regex-2022.4.24 tokenizers-0.12.1 tqdm-4.64.0 transformers-4.19.2`

## Script to reproduce

I used the most basic example in Huggingface (mentioned [here](https://huggingface.co/bert-base-uncased)):

```python
from transformers import pipeline
unmasker = pipeline('fill-mask', model='bert-base-uncased')
```

That throws the following error:

```
Traceback (most recent call last):
  File "/Users/unaigaraymaestre/miniforge3/envs/test/lib/python3.9/site-packages/transformers/configuration_utils.py", line 601, in _get_config_dict
    resolved_config_file = cached_path(
  File "/Users/unaigaraymaestre/miniforge3/envs/test/lib/python3.9/site-packages/transformers/utils/hub.py", line 282, in cached_path
    output_path = get_from_cache(
  File "/Users/unaigaraymaestre/miniforge3/envs/test/lib/python3.9/site-packages/transformers/utils/hub.py", line 470, in get_from_cache
    os.makedirs(cache_dir, exist_ok=True)
  File "/Users/unaigaraymaestre/miniforge3/envs/test/lib/python3.9/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/Users/unaigaraymaestre/miniforge3/envs/test/lib/python3.9/os.py", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/Users/unaigaraymaestre/.cache/huggingface'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/unaigaraymaestre/miniforge3/envs/test/lib/python3.9/site-packages/transformers/pipelines/__init__.py", line 541, in pipeline
    config = AutoConfig.from_pretrained(model, revision=revision, _from_pipeline=task, **model_kwargs)
  File "/Users/unaigaraymaestre/miniforge3/envs/test/lib/python3.9/site-packages/transformers/models/auto/configuration_auto.py", line 680, in from_pretrained
    config_dict, _ = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
  File "/Users/unaigaraymaestre/miniforge3/envs/test/lib/python3.9/site-packages/transformers/configuration_utils.py", line 553, in get_config_dict
    config_dict, kwargs = cls._get_config_dict(pretrained_model_name_or_path, **kwargs)
  File "/Users/unaigaraymaestre/miniforge3/envs/test/lib/python3.9/site-packages/transformers/configuration_utils.py", line 641, in _get_config_dict
    raise EnvironmentError(
OSError: Can't load config for 'bert-base-uncased'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'bert-base-uncased' is the correct path to a directory containing a config.json file
```

**Note that I also tried installing Pytorch with CPU setup and the same happened, it's not related to Tensorflow for M1 chips.**

### Expected behavior

```shell
Model (pipeline) should load properly by automatically downloading the `bert-base-uncased`.

I've tried with many models, none work

Thank you in advance!
```


Comments:
I got this error because of the way I installed python in MacOS. **It seems that if you don't execute the script with sudo powers then the script is not able to write to disk and thus it fails at downloading the model.**

I couldn't find a better way than using sudo, since giving full access to disk to Python in the Security & Privacy settings didn't work