digifreely commited on
Commit
33e772c
Β·
verified Β·
1 Parent(s): 4dad6a8

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +7 -23
Dockerfile CHANGED
@@ -1,8 +1,4 @@
1
  # ── Base image ────────────────────────────────────────────────────────────────
2
- # Use python:3.11-slim for CPU Spaces (free tier).
3
- # For GPU Spaces swap to:
4
- # FROM nvidia/cuda:12.1.0-cudnn8-runtime-ubuntu22.04
5
- # and add Python install steps below.
6
  FROM python:3.11-slim
7
 
8
  # ── Environment ───────────────────────────────────────────────────────────────
@@ -14,8 +10,6 @@ ENV PYTHONUNBUFFERED=1 \
14
  PIP_DISABLE_PIP_VERSION_CHECK=1
15
 
16
  # ── System deps ───────────────────────────────────────────────────────────────
17
- # espeak-ng β†’ required by piper-phonemize (used inside piper-tts)
18
- # libsndfile1 β†’ audio I/O
19
  RUN apt-get update && apt-get install -y --no-install-recommends \
20
  gcc g++ git wget curl \
21
  espeak-ng espeak-ng-data \
@@ -28,26 +22,16 @@ RUN useradd -m -u 1000 appuser
28
 
29
  # ── Python dependencies ───────────────────────────────────────────────────────
30
  COPY requirements.txt .
31
- # Install CPU-only torch first to keep image size reasonable
32
  RUN pip install torch==2.5.1 --index-url https://download.pytorch.org/whl/cpu \
33
  && pip install -r requirements.txt
34
 
35
- # ── Pre-build optimum-quanto C++ extension (must run as root) ────────────────
36
- # quanto lazily compiles a C++ kernel on first use and writes into the package
37
- # directory. Pre-building here (as root) avoids a PermissionError when the
38
- # container later runs as the unprivileged appuser.
39
- # freeze() is required after quantize() β€” without it, weights are NoneType
40
- # and the forward pass crashes with a TypeError.
41
- RUN python -c "\
42
- import torch; \
43
- import torch.nn as nn; \
44
- from optimum.quanto import quantize, freeze, qint4; \
45
- m = nn.Linear(8, 8); \
46
- quantize(m, weights=qint4); \
47
- freeze(m); \
48
- _ = m(torch.randn(1, 8)); \
49
- print('optimum-quanto C++ extension built successfully') \
50
- "
51
 
52
  # ── Piper TTS voice model ─────────────────────────────────────────────────────
53
  RUN mkdir -p /app/models \
 
1
  # ── Base image ────────────────────────────────────────────────────────────────
 
 
 
 
2
  FROM python:3.11-slim
3
 
4
  # ── Environment ───────────────────────────────────────────────────────────────
 
10
  PIP_DISABLE_PIP_VERSION_CHECK=1
11
 
12
  # ── System deps ───────────────────────────────────────────────────────────────
 
 
13
  RUN apt-get update && apt-get install -y --no-install-recommends \
14
  gcc g++ git wget curl \
15
  espeak-ng espeak-ng-data \
 
22
 
23
  # ── Python dependencies ───────────────────────────────────────────────────────
24
  COPY requirements.txt .
 
25
  RUN pip install torch==2.5.1 --index-url https://download.pytorch.org/whl/cpu \
26
  && pip install -r requirements.txt
27
 
28
+ # ── Fix optimum-quanto C++ extension permissions ──────────────────────────────
29
+ # quanto JIT-compiles a C++ kernel on first use and writes to a `build/`
30
+ # directory inside the package. Since the container runs as non-root appuser,
31
+ # we pre-create that directory as root and make it world-writable so the
32
+ # runtime compilation succeeds without a PermissionError.
33
+ RUN mkdir -p /usr/local/lib/python3.11/site-packages/optimum/quanto/library/extensions/cpp/build \
34
+ && chmod 777 /usr/local/lib/python3.11/site-packages/optimum/quanto/library/extensions/cpp/build
 
 
 
 
 
 
 
 
 
35
 
36
  # ── Piper TTS voice model ─────────────────────────────────────────────────────
37
  RUN mkdir -p /app/models \