sivakorn-su
fix code quere
0e1a412
FROM nvidia/cuda:12.3.2-cudnn9-runtime-ubuntu22.04
WORKDIR /app
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
# system deps
RUN apt-get update && apt-get install -y \
python3.10 python3.10-venv python3-pip \
ffmpeg git libsndfile1 curl tzdata wget build-essential \
&& ln -sf /usr/bin/python3.10 /usr/bin/python \
&& ln -sf /usr/bin/pip3 /usr/bin/pip \
&& rm -rf /var/lib/apt/lists/*
# timezone
RUN ln -fs /usr/share/zoneinfo/Asia/Bangkok /etc/localtime && \
dpkg-reconfigure -f noninteractive tzdata
# caches
RUN mkdir -p /tmp/hf_cache /tmp/torch_cache /tmp/matplotlib /tmp/xdg_cache /tmp/home /tmp/uploads /tmp/pythainlp_data \
&& chmod -R 777 /tmp/hf_cache /tmp/torch_cache /tmp/matplotlib /tmp/xdg_cache /tmp/home /tmp/uploads /tmp/pythainlp_data
# --------- IMPORTANT: limit threads to avoid libgomp spawn fail ---------
ENV OMP_NUM_THREADS=1 \
OPENBLAS_NUM_THREADS=1 \
MKL_NUM_THREADS=1 \
NUMEXPR_NUM_THREADS=1 \
VECLIB_MAXIMUM_THREADS=1 \
BLIS_NUM_THREADS=1 \
TOKENIZERS_PARALLELISM=false \
PL_DISABLE_VERSION_CHECK=1 \
HUGGINGFACE_HUB_CACHE=/tmp/hf_cache \
HF_HOME=/tmp/hf_cache \
HF_CACHE=/tmp/hf_cache \
TRANSFORMERS_CACHE=/tmp/hf_cache \
TORCH_HOME=/tmp/torch_cache \
MPLCONFIGDIR=/tmp/matplotlib \
XDG_CACHE_HOME=/tmp/xdg_cache \
HOME=/tmp/home \
TMPDIR=/tmp \
TEMP=/tmp \
TMP=/tmp \
LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH \
PYTHAINLP_DATA_DIR=/tmp/pythainlp_data
# python deps
COPY requirements.txt .
RUN pip install --upgrade pip
# torch cuda12.1
RUN pip install --no-cache-dir \
torch==2.3.0+cu121 torchvision==0.18.0+cu121 torchaudio==2.3.0 \
--extra-index-url https://download.pytorch.org/whl/cu121
# others
RUN pip install --no-cache-dir -r requirements.txt
# app
COPY . /app
EXPOSE 7860
# run: limit workers & concurrency; set ulimit before start
CMD ["uvicorn","app:app","--host","0.0.0.0","--port","7860","--workers","1","--limit-concurrency","8","--timeout-keep-alive","120","--timeout-graceful-shutdown","120"]