PermissionError when writing to HF_HOME directory on startup
When starting my Hugging Face Space with Docker (during setup will dochmod -R 777 /app/REDACTED_TOKEN, thenexport HF_HOME=/app/REDACTED_TOKEN launch) I get this error:The cache for model files in Transformers v4.22.0 has been updated. Migrating your old cache. This is a one-time only operation. You can interrupt this and resume the migration later on by calling `transformers.utils.move_cache()`.
0it [00:00, ?it/s]
0it [00:00, ?it/s]
There was a problem when trying to write in your cache folder (/app/REDACTED_TOKEN/hub). You should set the environment variable TRANSFORMERS_CACHE to a writable directory.
Traceback (most recent call last):
  File "/app/index.py", line 22, in <module>
    snapshot_download(repo_id=model, revision="main", token=HF_AUTH_TOKEN)
Downloading AI model (mistralai/Mistral-7B-Instruct-v0.2)...
  File "/usr/local/lib/python3.11/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/huggingface_hub/_snapshot_download.py", line 261, in snapshot_download
    with open(ref_path, "w") as f:
         ^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/app/REDACTED_TOKEN/hub/models--mistralai--Mistral-7B-Instruct-v0.2/refs/main'
2024-05-22T00:24:10Z
hi@LunarN0v4, could you please share your Dockerfile? you could use this examplehuggingface.coDocker SpacesWe’re on a journey to advance and democratize artificial intelligence through open source and open science.and add an user and give the folder permission to write.FROM python:3.9

WORKDIR /code

COPY ./requirements.txt /code/requirements.txt

RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

RUN useradd -m -u 1000 user

USER user

ENV HOME=/home/user \
	PATH=/home/user/.local/bin:$PATH

WORKDIR $HOME/app

COPY --chown=user . $HOME/app

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
2024-05-22T09:14:19Z
Hi radames, here is my Dockerfile:FROM python:3.11.9-bookworm
WORKDIR /app
COPY ./* /app/
RUN python -m pip install --upgrade pip
RUN pip install requests huggingface_hub fastapi transformers[torch] uvicorn
RUN mkdir -p ./REDACTED_TOKEN/
RUN chmod -R 777 ./REDACTED_TOKEN/
RUN sh -c "export HF_HOME=/app/REDACTED_TOKEN/ && python setup.py"
CMD ["sh", "-c", "export HF_HOME=/app/REDACTED_TOKEN/ && python index.py"]I am pretty solid on trying to get it to run as root, since that works very well on my main system, however, I can certainly try it with an individual user instead.