PermissionError: [Errno 13] Permission denied: '/.cache' - Error occurred while building a docker image

Viewed 4057
C:\Users\Jinu Augustine\Documents\Solidaridad FAQ Bot>docker run 4145b1589e68
2020-08-21 15:46:25 INFO     rasa_sdk.endpoint  - Starting action endpoint server...
2020-08-21 15:46:25 INFO     transformers.file_utils  - PyTorch version 1.6.0 available.
2020-08-21 15:46:26 INFO     root  - Load pretrained SentenceTransformer: bert-base-nli-mean-tokens
2020-08-21 15:46:26 INFO     root  - Did not find a '/' or '\' in the name. Assume to download model from server.
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/app/rasa_sdk/__main__.py", line 34, in <module>
    main()
  File "/app/rasa_sdk/__main__.py", line 30, in main
    main_from_args(cmdline_args)
  File "/app/rasa_sdk/__main__.py", line 21, in main_from_args
    args.auto_reload,
  File "/app/rasa_sdk/endpoint.py", line 137, in run
    action_package_name, cors_origins=cors_origins, auto_reload=auto_reload
  File "/app/rasa_sdk/endpoint.py", line 80, in create_app
    executor.register_package(action_package_name)
  File "/app/rasa_sdk/executor.py", line 249, in register_package
    self._import_submodules(package)
  File "/app/rasa_sdk/executor.py", line 205, in _import_submodules
    package = self._import_module(package)
  File "/app/rasa_sdk/executor.py", line 226, in _import_module
    module = importlib.import_module(name)
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/app/actions.py", line 151, in <module>
    encode_standard_question(sentence_transformer_select,pretrained_model)
  File "/app/actions.py", line 135, in encode_standard_question
    bc = SentenceTransformer(pretrained_model)
  File "/opt/venv/lib/python3.7/site-packages/sentence_transformers/SentenceTransformer.py", line 48, in __init__
    os.makedirs(model_path, exist_ok=True)
  File "/usr/local/lib/python3.7/os.py", line 213, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/local/lib/python3.7/os.py", line 213, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/local/lib/python3.7/os.py", line 213, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/local/lib/python3.7/os.py", line 223, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/.cache'

I'm getting the following error while was trying to build a docker image for a rasa chatbot. I was able to build the docker image, but when i try to run the image, the following error occurs. Im using a sentence transformer for NLP and using bert-base-nli-mean-tokens as the nli model. Don't know what is wrong.

1 Answers

The problem is having a writable directory path to download pretrained models.

SentenceTransformers Lib reads this cache directory path(directory where pretrained models gets downloaded) using 2 ways:-

  1. In file SentenceTransformer.py#L55, it checks if environment variable SENTENCE_TRANSFORMERS_HOME is set properly. So you can set this env. var to the directory where you have the write access.

  2. If env. var. SENTENCE_TRANSFORMERS_HOME is not set, it uses pytorch to get its cache directory. Pytorch by default gives <HOME>./cache (see here) as cache directory, but you can override this choice by setting environment variable TORCH_HOME.

Now, in your case, it is writing to /.cache directory, is probably because the user set/notset for docker. When you ssh to docker container, if there is no /home/username directory, pytorch gives /.cache directory by default(See here). You can use above 2 ways to override this path.

As an example, you can pass env value as: SENTENCE_TRANSFORMERS_HOME=./.config python train.py

Related