From ddb8079e80e76d610f4958e1b6409b2d8f89bbd7 Mon Sep 17 00:00:00 2001 From: rishikanthc Date: Sat, 19 Oct 2024 21:35:32 -0700 Subject: [PATCH] fix(docker): fix minor bugs in dockerfiles for concurrency and nvidia gpus --- Dockerfile | 4 ++ Dockerfile.gpu | 100 ++++++++++++++++------------------------- src/lib/queue.ts | 2 +- src/lib/wizardQueue.ts | 8 +++- 4 files changed, 50 insertions(+), 64 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6d3f636..aed2376 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,6 +38,8 @@ ARG OPENAI_MODEL="gpt-4" ARG OPENAI_ROLE="system" ARG POCKETBASE_VERSION=0.22.21 ARG DEV_MODE +ARG NVIDIA +ARG CONCURRENCY ENV POCKETBASE_ADMIN_EMAIL=$POCKETBASE_ADMIN_EMAIL ENV POCKETBASE_ADMIN_PASSWORD=$POCKETBASE_ADMIN_PASSWORD @@ -51,6 +53,8 @@ ENV OPENAI_ROLE=$OPENAI_ROLE ENV BODY_SIZE_LIMIT=512M ENV DEV_MODE=$DEV_MODE ENV POCKETBASE_URL=$POCKETBASE_URL +ENV NVIDIA=$NVIDIA +ENV CONCURRENCY=$CONCURRENCY # ENV LD_PRELOAD=/usr/local/lib/python3.8/dist-packages/sklearn/__check_build/../../scikit_learn.libs/libgomp-d22c30c5.so.1.0.0 RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && apt-get install -y nodejs diff --git a/Dockerfile.gpu b/Dockerfile.gpu index ff81c0a..82b6fd2 100644 --- a/Dockerfile.gpu +++ b/Dockerfile.gpu @@ -1,44 +1,44 @@ -# Start from NVIDIA CUDA Ubuntu image for GPU support -FROM nvidia/cuda:12.2.0-devel-ubuntu22.04 AS build_whisper - -# Install necessary build tools and dependencies for Whisper -RUN apt-get update && \ - apt-get install -y build-essential \ - ca-certificates \ - git && \ - rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/* - -# Clone and build Whisper.cpp -WORKDIR /app -RUN git clone https://github.com/ggerganov/whisper.cpp.git - -WORKDIR /app/whisper.cpp -# Compile Whisper.cpp with make -RUN GGML_CUDA=1 make -j - # Use the NVIDIA CUDA base image with Ubuntu FROM nvidia/cuda:12.2.0-runtime-ubuntu22.04 AS base -# Add AudioWaveform via PPA and install necessary tools -RUN apt-get update && \ - apt-get install -y software-properties-common && \ - add-apt-repository ppa:chris-needham/ppa && \ - apt-get update && \ - apt-get install -y audiowaveform ffmpeg libgd3 libmad0 libid3tag0 libsndfile1 zlib1g wget python3-pip \ - && rm -rf /var/lib/apt/lists/* +# Set environment variables to make the installation non-interactive +ENV DEBIAN_FRONTEND=noninteractive +ENV TZ="Etc/UTC" + +RUN apt-get update && apt-get install -y \ + python3 \ + python3-dev \ + python3-pip \ + software-properties-common \ + tzdata \ + ffmpeg \ + curl \ + unzip \ + git + +# Add the required PPA for audiowaveform +RUN add-apt-repository ppa:chris-needham/ppa \ + && apt-get update \ + && apt-get install -y audiowaveform + +# Clean up the apt cache to reduce image size +RUN apt-get clean && rm -rf /var/lib/apt/lists/* -# Environment variables for PocketBase, Redis, OpenAI, and others ARG POCKETBASE_ADMIN_EMAIL ARG POCKETBASE_ADMIN_PASSWORD +ARG POCKETBASE_URL ARG SCRIBO_FILES ARG REDIS_HOST ARG REDIS_PORT ARG OPENAI_API_KEY -ARG OPENAI_ENDPOINT="https://api.openai.com/v1" +ARG OPENAI_ENDPOINT=https://api.openai.com/v1 ARG OPENAI_MODEL="gpt-4" ARG OPENAI_ROLE="system" - -# Set environment variables to be overridden at runtime +ARG POCKETBASE_VERSION=0.22.21 +ARG DEV_MODE +ARG NVIDIA +ARG CONCURRENCY + ENV POCKETBASE_ADMIN_EMAIL=$POCKETBASE_ADMIN_EMAIL ENV POCKETBASE_ADMIN_PASSWORD=$POCKETBASE_ADMIN_PASSWORD ENV SCRIBO_FILES=$SCRIBO_FILES @@ -49,49 +49,25 @@ ENV OPENAI_ENDPOINT=$OPENAI_ENDPOINT ENV OPENAI_MODEL=$OPENAI_MODEL ENV OPENAI_ROLE=$OPENAI_ROLE ENV BODY_SIZE_LIMIT=512M +ENV DEV_MODE=$DEV_MODE +ENV POCKETBASE_URL=$POCKETBASE_URL +ENV NVIDIA=$NVIDIA +ENV CONCURRENCY=$CONCURRENCY +# ENV LD_PRELOAD=/usr/local/lib/python3.8/dist-packages/sklearn/__check_build/../../scikit_learn.libs/libgomp-d22c30c5.so.1.0.0 + +RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && apt-get install -y nodejs + -# Install additional packages and dependencies -RUN apt-get update && apt-get install -y curl unzip wget - -# Download and unzip PocketBase dynamically based on architecture -ENV POCKETBASE_VERSION=0.22.21 -RUN if [ "$(uname -m)" = "aarch64" ]; then \ - ARCH="arm64"; \ - else \ - ARCH="amd64"; \ - fi && \ - curl -L "https://github.com/pocketbase/pocketbase/releases/download/v${POCKETBASE_VERSION}/pocketbase_${POCKETBASE_VERSION}_linux_${ARCH}.zip" -o /tmp/pb.zip - -RUN unzip /tmp/pb.zip pocketbase -d /usr/local/bin/ && rm /tmp/pb.zip - -# Install pyannote -RUN python3 -m pip install pyannote.audio - -# Copy the whisper.cpp binary from the build stage -COPY --from=build_whisper /app/whisper.cpp/main /usr/local/bin/whisper -COPY --from=build_whisper /app/whisper.cpp/models/download-ggml-model.sh /usr/local/bin/download-ggml-model.sh - -# Download Whisper models -WORKDIR /models -RUN download-ggml-model.sh base.en /models && \ - download-ggml-model.sh tiny.en /models && \ - download-ggml-model.sh small.en /models - -# Set the working directory for the application WORKDIR /app -# Copy application files COPY . . -# Install Node.js and dependencies -RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && apt-get install -y nodejs +RUN git clone https://github.com/ggerganov/whisper.cpp.git -# RUN apt install nodejs && apt install npm RUN npm ci # Expose necessary ports EXPOSE 3000 8080 9243 -# Start the services CMD ["/bin/sh", "/app/start_services.sh"] diff --git a/src/lib/queue.ts b/src/lib/queue.ts index 73b7330..a00edec 100644 --- a/src/lib/queue.ts +++ b/src/lib/queue.ts @@ -281,7 +281,7 @@ const worker = new Worker( }, { connection: { host: env.REDIS_HOST, port: env.REDIS_PORT }, // Redis connection - concurrency: 5 // Allows multiple jobs to run concurrently + concurrency: env.CONCURRENCY // Allows multiple jobs to run concurrently } ); diff --git a/src/lib/wizardQueue.ts b/src/lib/wizardQueue.ts index c8fefbb..67547ff 100644 --- a/src/lib/wizardQueue.ts +++ b/src/lib/wizardQueue.ts @@ -144,7 +144,13 @@ const worker = new Worker( cmd = `make clean -C ${modelPath}` await execCommandWithLogging(cmd, job); - cmd = `make -C ${modelPath}`; + const isNvidia= env.NVIDIA === 'true' || env.NVIDIA === true; + + if (isNvidia) { + cmd = `GGML_CUDA=1 make -j -C ${modelPath}`; + } else { + cmd = `make -C ${modelPath}`; + } await execCommandWithLogging(cmd, job); await job.log('finished making whisper') job.updateProgress(50)