Search code examples
pythonhuggingface-transformers

Where does AutoModelForSeq2SeqLM.from_pretrained() store the model to disk?


I attempted the following on a Windows device:

from transformers import AutoModelForSeq2SeqLM, AutoTokenizer

model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-small")
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-small")

It worked, but when I tried to download a larger version of the model:

model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-XL")

I ran out of disk space: OSError: [Errno 28] No space left on device

However, it did not appear to delete what it had downloaded, and I can't seem to locate the model files on the disk. Where does it store?


Solution

  • In most cases the loaded models are saved in the transformers cache directory.

    On Windows, the default directory is given by C:\Users\username. cache\huggingface\transformers.

    You can specify the cache directory every time you load a model by setting the parameter cache_dir

    For python

    import os
    os.environ['TRANSFORMERS_CACHE'] = '/path/cache/'