From f964753090cc72df6817e57104d777d77613c865 Mon Sep 17 00:00:00 2001 From: thomwolf Date: Tue, 18 Jun 2019 11:36:28 +0200 Subject: [PATCH] explanation on the current location of the caching folder --- README.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a596dc4c64..b4c0ab9f01 100644 --- a/README.md +++ b/README.md @@ -516,7 +516,9 @@ Here is a detailed documentation of the classes in the package and how to use th ### Loading Google AI or OpenAI pre-trained weights or PyTorch dump -To load one of Google AI's, OpenAI's pre-trained models or a PyTorch saved model (an instance of `BertForPreTraining` saved with `torch.save()`), the PyTorch model classes and the tokenizer can be instantiated as +### `from_pretrained()` method + +To load one of Google AI's, OpenAI's pre-trained models or a PyTorch saved model (an instance of `BertForPreTraining` saved with `torch.save()`), the PyTorch model classes and the tokenizer can be instantiated using the `from_pretrained()` method: ```python model = BERT_CLASS.from_pretrained(PRE_TRAINED_MODEL_NAME_OR_PATH, cache_dir=None, from_tf=False, state_dict=None, *input, **kwargs) @@ -581,6 +583,22 @@ model = GPT2Model.from_pretrained('gpt2') ``` +#### Cache directory + +`pytorch_pretrained_bert` save the pretrained weights in a cache directory which is located at (in this order of priority): + +- `cache_dir` optional arguments to the `from_pretrained()` method (see above), +- shell environment variable `PYTORCH_PRETRAINED_BERT_CACHE`, +- PyTorch cache home + `/pytorch_pretrained_bert/` + where PyTorch cache home is defined by (in this order): + - shell environment variable `ENV_TORCH_HOME` + - shell environment variable `ENV_XDG_CACHE_HOME` + `/torch/`) + - default: `~/.cache/torch/` + +Usually, if you don't set any specific environment variable, `pytorch_pretrained_bert` cache will be at `~/.cache/torch/pytorch_pretrained_bert/`. + +You can alsways safely delete `pytorch_pretrained_bert` cache but the pretrained model weights and vocabulary files wil have to be re-downloaded from our S3. + ### Serialization best-practices This section explain how you can save and re-load a fine-tuned model (BERT, GPT, GPT-2 and Transformer-XL). @@ -590,6 +608,13 @@ There are three types of files you need to save to be able to reload a fine-tune - the configuration file of the model which is saved as a JSON file, and - the vocabulary (and the merges for the BPE-based models GPT and GPT-2). +The defaults files names of these files are as follow: + +- the model weights file: `pytorch_model.bin`, +- the configuration file: `config.json`, +- the vocabulary file: `vocab.txt` for BERT and Transformer-XL, `vocab.json` for GPT/GPT-2 (BPE vocabulary), +- for GPT/GPT-2 (BPE vocabulary) the additional merges file: `merges.txt`. + Here is the recommended way of saving the model, configuration and vocabulary to an `output_dir` directory and reloading the model and tokenizer afterwards: ```python