Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker build for salad and salad_app.py to setup environment #204

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions runner/docker/Dockerfile.salad
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ARG BASE_IMAGE=livepeer/ai-runner:base
FROM ${BASE_IMAGE}

RUN pip install --no-cache-dir huggingface_hub

COPY ./dl_checkpoints.sh /app
COPY ./salad_app.py /app

CMD ["python", "-u", "/app/salad_app.py"]
56 changes: 56 additions & 0 deletions runner/salad_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import logging
import os
import argparse
from huggingface_hub import snapshot_download
import re
import uvicorn
import json

logger = logging.getLogger(__name__)

MODELS_DIR = os.getenv("MODELS_DIR","/models")
PIPELINE = os.getenv("PIPELINE", "")
MODEL_ID = os.getenv("MODEL_ID", "")
HOST = os.getenv("HOST", "::")
PORT = os.getenv("PORT", "8000")

def get_download_cmd():
include = []
exclude = []
with open('/app/dl_checkpoints.sh', 'r') as file:
lines = file.readlines() # Reads all lines into a list
for line in lines:
if MODEL_ID in line:
line = line.strip()
include_re = re.findall("--include\s+([\*\.\s\w\"]+)(?!\s--\w+)", line)
exclude_re = re.findall("--exclude\s+([\*\.\s\w\"]+)(?!\s--\w+)", line)
if len(include_re) > 0:
include = ["**/"+s.replace('"', '') for s in include_re[0].split()]
if len(exclude_re) > 0:
exclude = ["**/"+s.replace('"', '') for s in exclude_re[0].split()]
return include, exclude, MODELS_DIR

#no automatic download found
return [], [], ""

if __name__ == "__main__":
allow, ignore, cache_folder = get_download_cmd()
if len(allow) == 0 and len(ignore) == 0:
logger.error("no include and exclude files found")

#download the model
print(f"Downloading model {MODEL_ID} from huggingface")
snapshot_download(repo_id=MODEL_ID, cache_dir=cache_folder)

print(f"Starting ai-runner")
with open("/app/app/cfg/uvicorn_logging_config.json", "r") as file:
log_config = json.load(file)

#run the api
uvicorn.run(
"app.main:app",
host=HOST,
port=int(PORT),
log_config=log_config
)