How to globally change the PYTORCH_PRETRAINED_BERT_CACHE path
Author: jzhoubu
Pull request: no
Labels: name: wontfix

Hi, all. I don't have enough disk space under `~/` to download the pre-trained model. When I run others' experiments, I always need to change their code from
```
model = BertForQuestionAnswering.from_pretrained(args.bert_model, \
                            cache_dir=PYTORCH_PRETRAINED_BERT_CACHE'distributed_{}'.format(-1))
```
to something like
```
PYTORCH_PRETRAINED_BERT_CACHE = ELSE_WHERE
model = BertForQuestionAnswering.from_pretrained(args.bert_model, \
                            cache_dir=PYTORCH_PRETRAINED_BERT_CACHE'distributed_{}'.format(-1))
```
or
```
model = BertForQuestionAnswering.from_pretrained(args.bert_model, \
                            cache_dir=ELSE_WHERE)
```

For the convenience of those who don't have enough disk under home dir `~/`, I wonder if there is any way to globally change this `PYTORCH_PRETRAINED_BERT_CACHE` value once and for all.





Comments:
Hello! You can set the environment variable `TRANSFORMERS_CACHE` to define which location should be used to store weights.

@LysandreJik Thanks. 
Just to make sure I understand your point correctly. If I run `TRANSFORMERS_CACHE=ELSE_WHERE train.sh` in cmd, are all the downloaded pretrained cache files stored under `ELSE_WHERE` rather than `~/.pytorch_pretrained_bert`?

It doesn't work for me. Specifically, I run `TRANSFORMERS_CACHE=./cache_dir bash train.sh` instead of `bash train.sh` and the cache files are still download to my HOME dir `/homes/jzhoubu/.pytorch_pretrained_bert`. Below is the log.
```
11/30/2020 23:12:36 - INFO - pytorch_pretrained_bert.tokenization -   loading vocabulary file https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-uncased-vocab.txt from cache at /homes/jzhoubu/.pytorch_pretrained_bert/26bc1ad6c0ac742e9b52263248f6d0f00068293b33709fae12320c0e35ccfbbb.542ce4285a40d23a559526243235df47c5f75c197f04f37d1a0c124c32c9a084
11/30/2020 23:12:42 - INFO - pytorch_pretrained_bert.modeling -   loading archive file https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-uncased.tar.gz from cache at /homes/jzhoubu/.pytorch_pretrained_bert/9c41111e2de84547a463fd39217199738d1e3deb72d4fec4399e6e241983c6f0.ae3cef932725ca7a30cdcb93fc6e09150a55e2a130ec7af63975a16c153ae2ba
11/30/2020 23:12:42 - INFO - pytorch_pretrained_bert.modeling -   extracting archive file /homes/jzhoubu/.pytorch_pretrained_bert/9c41111e2de84547a463fd39217199738d1e3deb72d4fec4399e6e241983c6f0.ae3cef932725ca7a30cdcb93fc6e09150a55e2a130ec7af63975a16c153ae2ba to temp dir /tmp/tmpwf4pab4l
```




Ah, given your logs, it seems you're running on a very very old version (`pytorch_pretrained_bert`, which is 1+ years old). While we recommend updating to more recent versions, you should be able to obtain the same behavior by setting the `PYTORCH_PRETRAINED_BERT_CACHE` environment variable instead.

For future issues, please always complete the issue template, the information related to your environment is especially important for us to help you correctly.

This issue has been automatically marked as stale and been closed because it has not had recent activity. Thank you for your contributions.

If you think this still needs to be addressed please comment on this thread.