Update Dockerfile
Browse files- Dockerfile +26 -26
Dockerfile
CHANGED
|
@@ -1,24 +1,33 @@
|
|
| 1 |
# 1. Base Image
|
| 2 |
FROM python:3.9-slim
|
| 3 |
|
| 4 |
-
# 2.
|
| 5 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 6 |
openjdk-21-jre-headless \
|
| 7 |
libxrender1 \
|
| 8 |
libxext6 \
|
|
|
|
|
|
|
| 9 |
gcc \
|
| 10 |
python3-dev \
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
ENV JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64 \
|
| 17 |
PATH=$JAVA_HOME/bin:$PATH \
|
| 18 |
TF_ENABLE_ONEDNN_OPTS=1 \
|
| 19 |
TF_CPP_MIN_LOG_LEVEL=2 \
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
HOME=/home/user
|
| 23 |
|
| 24 |
# 4. Hugging Face User Setup
|
|
@@ -27,8 +36,7 @@ USER user
|
|
| 27 |
WORKDIR /home/user/app
|
| 28 |
ENV PATH=/home/user/.local/bin:$PATH
|
| 29 |
|
| 30 |
-
# 5. Install
|
| 31 |
-
# 'intel-tensorflow' replaces standard tensorflow for AVX512/VNNI support
|
| 32 |
RUN pip install --no-cache-dir wheel && \
|
| 33 |
pip install --no-cache-dir \
|
| 34 |
intel-tensorflow \
|
|
@@ -37,16 +45,15 @@ RUN pip install --no-cache-dir wheel && \
|
|
| 37 |
# 6. Create app.py
|
| 38 |
RUN cat <<EOF > app.py
|
| 39 |
import os
|
| 40 |
-
|
| 41 |
-
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
| 42 |
-
|
| 43 |
from fastapi import FastAPI, HTTPException, Body
|
| 44 |
from STOUT import translate_forward, translate_reverse
|
| 45 |
from rdkit import Chem
|
| 46 |
from typing import List
|
| 47 |
|
| 48 |
-
app = FastAPI(title="STOUT V2
|
| 49 |
|
|
|
|
| 50 |
def clean_smi(s):
|
| 51 |
try:
|
| 52 |
m = Chem.MolFromSmiles(s)
|
|
@@ -54,8 +61,7 @@ def clean_smi(s):
|
|
| 54 |
except: return None
|
| 55 |
|
| 56 |
@app.get("/")
|
| 57 |
-
def root():
|
| 58 |
-
return {"message": "STOUT V2 - Optimized for Intel Sapphire Rapids"}
|
| 59 |
|
| 60 |
@app.api_route("/smiles_to_iupac", methods=["GET", "POST"])
|
| 61 |
def s2i(smiles: str):
|
|
@@ -63,25 +69,19 @@ def s2i(smiles: str):
|
|
| 63 |
if not s: raise HTTPException(400, "Invalid SMILES")
|
| 64 |
return {"iupac": translate_forward(s)}
|
| 65 |
|
| 66 |
-
@app.api_route("/iupac_to_smiles", methods=["GET", "POST"])
|
| 67 |
-
def i2s(iupac: str):
|
| 68 |
-
try: return {"smiles": translate_reverse(iupac)}
|
| 69 |
-
except: raise HTTPException(400, "Invalid IUPAC")
|
| 70 |
-
|
| 71 |
-
@app.post("/batch/smiles_to_iupac")
|
| 72 |
-
def batch_s2i(smiles_list: List[str] = Body(...)):
|
| 73 |
-
return [{"smiles": s, "iupac": translate_forward(clean_smi(s))} for s in smiles_list if clean_smi(s)]
|
| 74 |
-
|
| 75 |
@app.get("/health")
|
| 76 |
def health(): return {"status": "healthy"}
|
|
|
|
|
|
|
|
|
|
| 77 |
EOF
|
| 78 |
|
| 79 |
-
# 7.
|
| 80 |
EXPOSE 7860
|
| 81 |
|
| 82 |
-
#
|
| 83 |
CMD ["gunicorn", "app:app", \
|
| 84 |
-
"--workers", "
|
| 85 |
"--worker-class", "uvicorn.workers.UvicornWorker", \
|
| 86 |
"--bind", "0.0.0.0:7860", \
|
| 87 |
"--timeout", "300"]
|
|
|
|
| 1 |
# 1. Base Image
|
| 2 |
FROM python:3.9-slim
|
| 3 |
|
| 4 |
+
# 2. System dependencies (Added locales and libstdc++6)
|
| 5 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 6 |
openjdk-21-jre-headless \
|
| 7 |
libxrender1 \
|
| 8 |
libxext6 \
|
| 9 |
+
libstdc++6 \
|
| 10 |
+
locales \
|
| 11 |
gcc \
|
| 12 |
python3-dev \
|
| 13 |
&& rm -rf /var/lib/apt/lists/*
|
| 14 |
|
| 15 |
+
# Generate locales to prevent character conversion crashes
|
| 16 |
+
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
|
| 17 |
+
locale-gen
|
| 18 |
+
ENV LANG=en_US.UTF-8 \
|
| 19 |
+
LANGUAGE=en_US:en \
|
| 20 |
+
LC_ALL=en_US.UTF-8
|
| 21 |
+
|
| 22 |
+
# 3. Environment Variables (Critical Fixes for SIGSEGV)
|
| 23 |
ENV JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64 \
|
| 24 |
PATH=$JAVA_HOME/bin:$PATH \
|
| 25 |
TF_ENABLE_ONEDNN_OPTS=1 \
|
| 26 |
TF_CPP_MIN_LOG_LEVEL=2 \
|
| 27 |
+
# Forces C++ libs to resolve early and avoid conflicts
|
| 28 |
+
LD_BIND_NOW=1 \
|
| 29 |
+
# Force the standard C++ lib to be pre-loaded
|
| 30 |
+
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6 \
|
| 31 |
HOME=/home/user
|
| 32 |
|
| 33 |
# 4. Hugging Face User Setup
|
|
|
|
| 36 |
WORKDIR /home/user/app
|
| 37 |
ENV PATH=/home/user/.local/bin:$PATH
|
| 38 |
|
| 39 |
+
# 5. Install Python Stack
|
|
|
|
| 40 |
RUN pip install --no-cache-dir wheel && \
|
| 41 |
pip install --no-cache-dir \
|
| 42 |
intel-tensorflow \
|
|
|
|
| 45 |
# 6. Create app.py
|
| 46 |
RUN cat <<EOF > app.py
|
| 47 |
import os
|
| 48 |
+
import uvicorn
|
|
|
|
|
|
|
| 49 |
from fastapi import FastAPI, HTTPException, Body
|
| 50 |
from STOUT import translate_forward, translate_reverse
|
| 51 |
from rdkit import Chem
|
| 52 |
from typing import List
|
| 53 |
|
| 54 |
+
app = FastAPI(title="STOUT V2 SIGSEGV-Fixed API")
|
| 55 |
|
| 56 |
+
# Helper to ensure RDKit doesn't break
|
| 57 |
def clean_smi(s):
|
| 58 |
try:
|
| 59 |
m = Chem.MolFromSmiles(s)
|
|
|
|
| 61 |
except: return None
|
| 62 |
|
| 63 |
@app.get("/")
|
| 64 |
+
def root(): return {"message": "STOUT V2 - Stable Build"}
|
|
|
|
| 65 |
|
| 66 |
@app.api_route("/smiles_to_iupac", methods=["GET", "POST"])
|
| 67 |
def s2i(smiles: str):
|
|
|
|
| 69 |
if not s: raise HTTPException(400, "Invalid SMILES")
|
| 70 |
return {"iupac": translate_forward(s)}
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
@app.get("/health")
|
| 73 |
def health(): return {"status": "healthy"}
|
| 74 |
+
|
| 75 |
+
if __name__ == "__main__":
|
| 76 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
| 77 |
EOF
|
| 78 |
|
| 79 |
+
# 7. Expose Port and Start
|
| 80 |
EXPOSE 7860
|
| 81 |
|
| 82 |
+
# Reduce workers to 2 or 3 if memory crashes persist; 4 is the limit for 32GB
|
| 83 |
CMD ["gunicorn", "app:app", \
|
| 84 |
+
"--workers", "3", \
|
| 85 |
"--worker-class", "uvicorn.workers.UvicornWorker", \
|
| 86 |
"--bind", "0.0.0.0:7860", \
|
| 87 |
"--timeout", "300"]
|