Search code examples
pythonnlphuggingface

Changing the Default Cache Path for All HuggingFace Data


The default cache path of huggingface is in ~/.cache/huggingface, and in that folder, there are multiple cache files like models, and hub.

The huggingface documents indicates that the default dataset cache location can be modified by setting the shell environment variable, HF_DATASETS_CACHE to a different directory as shown below:

$ export HF_DATASETS_CACHE="/path/to/another/directory"

However, my objective is to alter the default cache directory for all HuggingFace data and not solely the dataset. I am facing difficulties in finding the respective shell environment variable in the HuggingFace documentation to accomplish this. Any help would be appreciated.


Solution

  • It seems that the variable is HF_HOME as this document indicates. So probably this terminal code should be the solution:

    export HF_HOME="/path/.cache/huggingface"
    export HF_DATASETS_CACHE="/path/.cache/huggingface/datasets"
    export TRANSFORMERS_CACHE="/path/.cache/huggingface/models"
    

    p.s. If you want to make your change permanent, you should write these lines in your .bashrc(Can do with .bash_profile too) file using nano ~/.bashrc