> ## Documentation Index
> Fetch the complete documentation index at: https://docs.domino.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Unable to deploy Model - [Errno 13] Permission denied: '/.cache'

## Issue

When deploying a model as a Model API, the build completes successfully but the model fails to start, with the following error:

```
Jan 05 2023 14:21:05 -0500 There was a problem when trying to write in your cache folder (/.cache/huggingface/hub). You should set the environment variable TRANSFORMERS_CACHE to a writable directory.
Jan 05 2023 14:21:05 -0500 PermissionError: [Errno 13] Permission denied: '/.cache'
```

The model's Python code uses the Transformers package. By default, Transformers sets its cache directory to `/.cache`, which may not be writable in the Model API environment.

## Solution

Override the default cache path by setting `TRANSFORMERS_CACHE` to a writable directory.

**Python:**

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

**Bash:**

```
export TRANSFORMERS_CACHE=/path/to/writable/cache/
```

Replace `/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

The `TRANSFORMERS_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:

```
export HF_HOME=/path/to/writable/cache/
```

To also protect against cases where the environment variable isn't set, create a symlink from the default cache location to your writable directory:

```
ln -s /path/to/writable/cache/ ~/.cache/huggingface
```

### How the default cache directory is determined

The Transformers documentation describes [cache setup](https://huggingface.co/docs/transformers/installation?highlight=transformers_cache#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 variable `TRANSFORMERS_CACHE`. On Windows, the default directory is given by `C:\Users\username\.cache\huggingface\transformers`. You can change the shell environment variables shown below — in order of priority — to specify a different cache directory:
>
> 1. Shell environment variable (default): `TRANSFORMERS_CACHE`
> 2. Shell environment variable: `HF_HOME` + `transformers/`
> 3. 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`.


## Related topics

- [Troubleshooting](/knowledge-base/troubleshooting-overview.md)
- [ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied:](/knowledge-base/error-could-not-install-packages-due-to-an-environmenterror-errno-13-permission-denied.md)
- [How to prevent the permission denied error when running "pip install" in a workspace](/knowledge-base/how-to-prevent-the-permission-denied-error-when-running-pip-install-in-a-workspace.md)
- [Clearing Git Cache](/knowledge-base/clearing-git-cache.md)
