mirrash7 commited on
Commit
3d11649
·
verified ·
1 Parent(s): 495255b

Redirect HOME/torch.hub/caches to writable /app (fix torch.hub PermissionError)

Browse files
Files changed (1) hide show
  1. Dockerfile +13 -2
Dockerfile CHANGED
@@ -31,12 +31,23 @@ RUN pip install --no-cache-dir -r /app/requirements.txt \
31
  "git+https://github.com/facebookresearch/detectron2.git@a1ce2f9" --no-build-isolation --no-deps \
32
  && pip install --no-cache-dir "git+https://github.com/microsoft/MoGe.git"
33
 
 
 
 
 
 
 
 
 
 
34
  # App (UI + the pipeline package; GPU code is isolated in pipeline/gpu.py)
35
  COPY app.py /app/app.py
36
  COPY pipeline /app/pipeline
37
 
38
- # Writable cache (HF Spaces runs as a non-root user)
39
- RUN mkdir -p /app/.cache/huggingface && chmod -R 777 /app/.cache
 
 
40
 
41
  EXPOSE 7860
42
  CMD ["python", "app.py"]
 
31
  "git+https://github.com/facebookresearch/detectron2.git@a1ce2f9" --no-build-isolation --no-deps \
32
  && pip install --no-cache-dir "git+https://github.com/microsoft/MoGe.git"
33
 
34
+ # Runtime cache redirection. HF Spaces runs as a non-root user with HOME=/, so
35
+ # anything writing to ~/.cache (torch.hub clones DINOv3 here at model load,
36
+ # matplotlib, fontconfig, ...) hits a read-only /.cache. These are only needed at
37
+ # runtime, so they sit BELOW the pip layer to keep that expensive layer cached.
38
+ ENV HOME=/app \
39
+ XDG_CACHE_HOME=/app/.cache \
40
+ TORCH_HOME=/app/.cache/torch \
41
+ MPLCONFIGDIR=/app/.cache/matplotlib
42
+
43
  # App (UI + the pipeline package; GPU code is isolated in pipeline/gpu.py)
44
  COPY app.py /app/app.py
45
  COPY pipeline /app/pipeline
46
 
47
+ # Writable cache + home (HF Spaces runs as a non-root user). torch.hub needs to
48
+ # clone into TORCH_HOME at runtime, so the whole /app tree must be writable.
49
+ RUN mkdir -p /app/.cache/huggingface /app/.cache/torch /app/.cache/matplotlib \
50
+ && chmod -R 777 /app
51
 
52
  EXPOSE 7860
53
  CMD ["python", "app.py"]