Skip to content

Commit

Permalink
Merge pull request #2 from pharmbio/feature/scilife_serve_bundle
Browse files Browse the repository at this point in the history
Scilifelab serve version in single container..
  • Loading branch information
morganekmefjord authored Nov 28, 2024
2 parents ec96000 + cbec14d commit 873b579
Show file tree
Hide file tree
Showing 10 changed files with 540 additions and 17 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,34 @@ To use this project, follow these steps:
docker-compose up --build
```

### Scilifelab Deployment

1. Build container
```sh
docker build -t ptp .
```
2. Push container to registry


3. Deploy

4. Configuration
- Set environment variables
Use `DOWNLOAD=true` to download models prior to startup.
- preferebly mount `/app/inference/models` directory to outside storage to avoid ram bloat.

- Use `MAX_MODELS` to limit the number of active models (for debug purposes) .otherwise it iterates all models present (currently 800+).

- If desired use `MODEL_DIR` to change path where model are found (default /app/inference/models/models)


## References
Model repository on Hugging Face: [pharmbio/ptp](https://huggingface.co/pharmbio/ptp)

## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.


## Authors
- **Jonathan Alvarsson** - *Research, scipipe version and models* - [jonathanalvarsson](https://github.com/jonalv)
- **Morgan Ekmefjord** - *Web service, deployment and service packaging* - [morganekmefjord](https://github.com/morganekmefjord)
3 changes: 2 additions & 1 deletion ptp/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*/conformal_models/*
*/vennABERS_models/*
inference/models/*
*.jar
*.jar
tmp/*
28 changes: 24 additions & 4 deletions ptp/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
FROM python:3.11 AS djangobase

# Set working directory
ENV USER=ptp

RUN mkdir /app

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y gcc python3-dev libpq-dev
RUN apt-get update && apt-get install -y gcc git-lfs python3-dev redis-server supervisor \
&& apt-get clean

# Install Java (OpenJDK)
RUN apt-get update && apt-get install -y openjdk-17-jre-headless \
Expand All @@ -20,6 +22,8 @@ ENV PATH=$JAVA_HOME/bin:$PATH
COPY requirements.txt /app/
RUN pip install -r requirements.txt

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Copy the application code
FROM djangobase AS djangoapp

Expand All @@ -32,5 +36,21 @@ WORKDIR /app
# Expose the port the Django app runs on
EXPOSE 8000

# Default command
CMD ["gunicorn", "p2p.wsgi:application", "--bind", "0.0.0.0:8000"]
RUN useradd -u 1000 $USER

RUN chown -R $USER:$USER /etc/supervisor/conf.d/supervisord.conf
RUN chown -R $USER:$USER /app/
RUN chown -R $USER:$USER /var/log/supervisor/
RUN chmod +x /app/start-single.sh
RUN chmod +x /app/start-django.sh
RUN chmod +x /app/download.sh

# Make sure the container is running as non-root
USER $USER

ENV CELERY_BROKER_URL="redis://localhost:6379/0"
ENV REDIS_URL="redis://localhost:6379/0"
ENV DOWNLOAD=false

# Start supervisord
CMD ["sh", "-c", "/app/start-single.sh"]
9 changes: 9 additions & 0 deletions ptp/download.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
if [ "$DOWNLOAD" = "true" ]; then
git clone https://huggingface.co/pharmbio/ptp /app/inference/models && \
cd /app/inference/models && \
git lfs pull
else
echo "noop"
fi
exit 0
7 changes: 6 additions & 1 deletion ptp/inference/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import pandas as pd
from datetime import timezone

model_dir = os.environ.get("MODEL_DIR", "/app/inference/models/models/")
max_models = os.environ.get("MAX_MODELS", False)

@shared_task
def run_inference(job_id):

Expand Down Expand Up @@ -37,7 +40,7 @@ def run_inference(job_id):
chembl_version = 'chembl_34'
else:
chembl_version = 'chembl_34'
base = '/app/inference/models/'
base = model_dir
try:
model_files = [os.path.join(base,chembl_version,path, f) for f in os.listdir(os.path.join(base, chembl_version,path)) if f.endswith('.jar')]
except Exception as e:
Expand All @@ -54,6 +57,8 @@ def run_inference(job_id):
if DEBUG:
print("RUNNING IN DEBUG MODE ONLY CALCULATING 3 MODELS", flush=True)
model_files = model_files#[:5]
if max_models:
model_files = model_files[:int(max_models)]

try:
for model in model_files:
Expand Down
Loading

0 comments on commit 873b579

Please sign in to comment.