Skip to content

Commit c89d79f

Browse files
authored
ai-runner: Allow running without MODEL_DIR env (#878)
Will default to ./.lpData/models and always set it for child processes (usefull when running locally)
1 parent 80206b9 commit c89d79f

6 files changed

Lines changed: 19 additions & 19 deletions

File tree

live/comfyui/Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ RUN git clone --branch n7.1 --depth 1 https://github.com/FFmpeg/FFmpeg.git ffmpe
6363
cd .. \
6464
rm -rf ffmpeg
6565

66+
# Common environment variables for AI runner pipelines
67+
ENV MAX_WORKERS=1 \
68+
HUGGINGFACE_HUB_CACHE=/models \
69+
DIFFUSERS_CACHE=/models \
70+
MODEL_DIR=/models
71+
6672
# -----------------------------------------------------------------------------
6773
# live-base: End of section
6874
# -----------------------------------------------------------------------------
@@ -113,12 +119,6 @@ COPY live/comfyui/main.py ./main.py
113119
# Final sync to install the project
114120
RUN uv sync --active --locked --inexact
115121

116-
# Set environment variables
117-
ENV MAX_WORKERS=1 \
118-
HUGGINGFACE_HUB_CACHE=/models \
119-
DIFFUSERS_CACHE=/models \
120-
MODEL_DIR=/models
121-
122122
# Keep these args/envs last to maximize cache reuse when only runtime envs change
123123
ARG GIT_SHA
124124
ARG VERSION="undefined"

live/scope/Dockerfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ RUN uv sync --locked --inexact
2929
# Configure Scope models directory
3030
ENV DAYDREAM_SCOPE_MODELS_DIR="/models/Scope--models"
3131

32-
ENV HF_HUB_OFFLINE=1 \
33-
MAX_WORKERS=1 \
34-
HUGGINGFACE_HUB_CACHE=/models \
35-
DIFFUSERS_CACHE=/models \
36-
MODEL_DIR=/models
32+
ENV HF_HUB_OFFLINE=1
3733

3834
ARG GIT_SHA
3935
ARG VERSION="undefined"

live/streamdiffusion/Dockerfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ RUN ln -s /models/StreamDiffusion--engines ./engines \
3131
&& ln -s /models/StreamDiffusion--models ./models
3232

3333
ENV HF_HUB_ENABLE_HF_TRANSFER=1 \
34-
HF_HUB_OFFLINE=1 \
35-
MAX_WORKERS=1 \
36-
HUGGINGFACE_HUB_CACHE=/models \
37-
DIFFUSERS_CACHE=/models \
38-
MODEL_DIR=/models
34+
HF_HUB_OFFLINE=1
3935

4036
ARG GIT_SHA
4137
ARG VERSION="undefined"

runner/docker/Dockerfile.live-base

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,9 @@ RUN git clone --branch n7.1 --depth 1 https://github.com/FFmpeg/FFmpeg.git ffmpe
6565
cp -R /compiled/* /usr/local/ && \
6666
cd .. \
6767
rm -rf ffmpeg
68+
69+
# Common environment variables for AI runner pipelines
70+
ENV MAX_WORKERS=1 \
71+
HUGGINGFACE_HUB_CACHE=/models \
72+
DIFFUSERS_CACHE=/models \
73+
MODEL_DIR=/models

runner/src/runner/pipelines/live_video_to_video.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ def start_process(self):
113113
# TODO: set torch device from self.torch_device
114114

115115
env = os.environ.copy()
116-
env["HUGGINGFACE_HUB_CACHE"] = str(self.model_dir)
116+
env.setdefault("HUGGINGFACE_HUB_CACHE", str(self.model_dir))
117+
env.setdefault("DIFFUSERS_CACHE", str(self.model_dir))
118+
env.setdefault("MODEL_DIR", str(self.model_dir))
117119

118120
try:
119121
self.process = subprocess.Popen(

runner/src/runner/pipelines/utils/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
def get_model_dir() -> Path:
26-
return Path(os.environ["MODEL_DIR"])
26+
return Path(os.environ.get("MODEL_DIR", os.path.expanduser("~/.lpData/models")))
2727

2828

2929
def get_model_path(model_id: str) -> Path:
@@ -154,7 +154,7 @@ def __init__(
154154

155155
self.device = device
156156
self._dtype = dtype
157-
157+
158158
from diffusers.pipelines.stable_diffusion import StableDiffusionSafetyChecker
159159
self._safety_checker = StableDiffusionSafetyChecker.from_pretrained(
160160
"CompVis/stable-diffusion-safety-checker"

0 commit comments

Comments
 (0)