Issue
When deploying a model as a Model API, the build completes successfully but the model fails to start, with the following error:/.cache, which may not be writable in the Model API environment.
Solution
Override the default cache path by settingTRANSFORMERS_CACHE to a writable directory.
Python:
/path/to/writable/cache/ with a directory your model environment can write to, such as a path under your project or home directory.
Set HF_HOME for broader cache coverage
TheTRANSFORMERS_CACHE variable controls only the Transformers cache. The Hugging Face (HF) HF_HOME variable controls a broader set of caches, including the datasets cache. Set HF_HOME to cover both:
How the default cache directory is determined
The Transformers documentation describes cache setup and the order of priority for environment variables:Pretrained models are downloaded and locally cached at:~/.cache/huggingface/transformers/. This is the default directory given by the shell environment variableTRANSFORMERS_CACHE. On Windows, the default directory is given byC:\Users\username\.cache\huggingface\transformers. You can change the shell environment variables shown below — in order of priority — to specify a different cache directory:
- Shell environment variable (default):
TRANSFORMERS_CACHE- Shell environment variable:
HF_HOME+transformers/- Shell environment variable:
XDG_CACHE_HOME+/huggingface/transformers
HF_HOME defaults to $XDG_CACHE_HOME/huggingface. If XDG_CACHE_HOME is not set, it defaults to $HOME/.cache, making the usual default $HOME/.cache/huggingface.