Chaoqun commited on
Commit
7163150
·
unverified ·
1 Parent(s): 983e4bd

docker : Dockerize whisper.cpp (#1674)

Browse files

* build: add dockerfile for ci

* ci: add action to build/push docker image

* fix: lowercase repository to fix ci

* ci: update cuBLAS flag

* build: install curl and ffmped in image

* docs: add docker section

* fix: improve args check when download model

.devops/main-cuda.Dockerfile ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ARG UBUNTU_VERSION=22.04
2
+ # This needs to generally match the container host's environment.
3
+ ARG CUDA_VERSION=12.3.1
4
+ # Target the CUDA build image
5
+ ARG BASE_CUDA_DEV_CONTAINER=nvidia/cuda:${CUDA_VERSION}-devel-ubuntu${UBUNTU_VERSION}
6
+ # Target the CUDA runtime image
7
+ ARG BASE_CUDA_RUN_CONTAINER=nvidia/cuda:${CUDA_VERSION}-runtime-ubuntu${UBUNTU_VERSION}
8
+
9
+ FROM ${BASE_CUDA_DEV_CONTAINER} AS build
10
+ WORKDIR /app
11
+
12
+ # Unless otherwise specified, we make a fat build.
13
+ ARG CUDA_DOCKER_ARCH=all
14
+ # Set nvcc architecture
15
+ ENV CUDA_DOCKER_ARCH=${CUDA_DOCKER_ARCH}
16
+ # Enable cuBLAS
17
+ ENV WHISPER_CUBLAS=1
18
+
19
+ RUN apt-get update && \
20
+ apt-get install -y build-essential \
21
+ && rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
22
+
23
+ COPY .. .
24
+ RUN make
25
+
26
+ FROM ${BASE_CUDA_RUN_CONTAINER} AS runtime
27
+ WORKDIR /app
28
+
29
+ RUN apt-get update && \
30
+ apt-get install -y curl ffmpeg \
31
+ && rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
32
+
33
+ COPY --from=build /app /app
34
+ ENTRYPOINT [ "bash", "-c" ]
.devops/main.Dockerfile ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:22.04 AS build
2
+ WORKDIR /app
3
+
4
+ RUN apt-get update && \
5
+ apt-get install -y build-essential \
6
+ && rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
7
+
8
+ COPY .. .
9
+ RUN make
10
+
11
+ FROM ubuntu:22.04 AS runtime
12
+ WORKDIR /app
13
+
14
+ RUN apt-get update && \
15
+ apt-get install -y curl ffmpeg \
16
+ && rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
17
+
18
+ COPY --from=build /app /app
19
+ ENTRYPOINT [ "bash", "-c" ]
.github/workflows/docker.yml ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Publish Docker image
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - master
8
+
9
+ jobs:
10
+ push_to_registry:
11
+ name: Push Docker image to Docker Hub
12
+ if: github.event.pull_request.draft == false
13
+
14
+ runs-on: ubuntu-latest
15
+ env:
16
+ COMMIT_SHA: ${{ github.sha }}
17
+ strategy:
18
+ matrix:
19
+ config:
20
+ - { tag: "main", dockerfile: ".devops/main.Dockerfile", platform: "linux/amd64,linux/arm64" }
21
+ - { tag: "main-cuda", dockerfile: ".devops/main-cuda.Dockerfile", platform: "linux/amd64" }
22
+
23
+ steps:
24
+ - name: Check out the repo
25
+ uses: actions/checkout@v3
26
+
27
+ - name: Set up QEMU
28
+ uses: docker/setup-qemu-action@v3
29
+
30
+ - name: Set up Docker Buildx
31
+ uses: docker/setup-buildx-action@v3
32
+
33
+ - name: Log in to Docker Hub
34
+ uses: docker/login-action@v3
35
+ with:
36
+ registry: ghcr.io
37
+ username: ${{ github.repository_owner }}
38
+ password: ${{ secrets.GITHUB_TOKEN }}
39
+
40
+ - name: Build and push Docker image (versioned)
41
+ if: github.event_name == 'push'
42
+ uses: docker/build-push-action@v5
43
+ with:
44
+ context: .
45
+ push: true
46
+ platforms: ${{ matrix.config.platforms }}
47
+ tags: "ghcr.io/${{ github.repository }}:${{ matrix.config.tag }}-${{ env.COMMIT_SHA }}"
48
+ file: ${{ matrix.config.dockerfile }}
49
+
50
+ - name: Build and push Docker image (tagged)
51
+ uses: docker/build-push-action@v4
52
+ with:
53
+ context: .
54
+ push: ${{ github.event_name == 'push' }}
55
+ platforms: ${{ matrix.config.platforms }}
56
+ tags: "ghcr.io/${{ github.repository }}:${{ matrix.config.tag }}"
57
+ file: ${{ matrix.config.dockerfile }}
README.md CHANGED
@@ -33,6 +33,7 @@ Supported platforms:
33
  - [x] [WebAssembly](examples/whisper.wasm)
34
  - [x] Windows ([MSVC](https://github.com/ggerganov/whisper.cpp/blob/master/.github/workflows/build.yml#L117-L144) and [MinGW](https://github.com/ggerganov/whisper.cpp/issues/168)]
35
  - [x] [Raspberry Pi](https://github.com/ggerganov/whisper.cpp/discussions/166)
 
36
 
37
  The entire high-level implementation of the model is contained in [whisper.h](whisper.h) and [whisper.cpp](whisper.cpp).
38
  The rest of the code is part of the [ggml](https://github.com/ggerganov/ggml) machine learning library.
@@ -448,6 +449,36 @@ make clean
448
  WHISPER_OPENBLAS=1 make -j
449
  ```
450
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
451
  ## Limitations
452
 
453
  - Inference only
 
33
  - [x] [WebAssembly](examples/whisper.wasm)
34
  - [x] Windows ([MSVC](https://github.com/ggerganov/whisper.cpp/blob/master/.github/workflows/build.yml#L117-L144) and [MinGW](https://github.com/ggerganov/whisper.cpp/issues/168)]
35
  - [x] [Raspberry Pi](https://github.com/ggerganov/whisper.cpp/discussions/166)
36
+ - [x] [docker](https://github.com/ggerganov/whisper.cpp/pkgs/container/whisper.cpp)
37
 
38
  The entire high-level implementation of the model is contained in [whisper.h](whisper.h) and [whisper.cpp](whisper.cpp).
39
  The rest of the code is part of the [ggml](https://github.com/ggerganov/ggml) machine learning library.
 
449
  WHISPER_OPENBLAS=1 make -j
450
  ```
451
 
452
+ ## Docker
453
+
454
+ ### Prerequisites
455
+ * Docker must be installed and running on your system.
456
+ * Create a folder to store big models & intermediate files (ex. /whisper/models)
457
+
458
+ ### Images
459
+ We have two Docker images available for this project:
460
+
461
+ 1. `ghcr.io/ggerganov/whisper.cpp:main`: This image includes the main executable file as well as `curl` and `ffmpeg`. (platforms: `linux/amd64`, `linux/arm64`)
462
+ 2. `ghcr.io/ggerganov/whisper.cpp:main-cuda`: Same as `main` but compiled with CUDA support. (platforms: `linux/amd64`)
463
+
464
+ ### Usage
465
+
466
+ ```shell
467
+ # download model and persist it in a local folder
468
+ docker run -it --rm \
469
+ -v path/to/models:/models \
470
+ whisper.cpp:main "./models/download-ggml-model.sh base /models"
471
+ # transcribe an audio file
472
+ docker run -it --rm \
473
+ -v path/to/models:/models \
474
+ -v path/to/audios:/audios \
475
+ whisper.cpp:main "./main -m /models/ggml-base.bin -f /audios/jfk.wav"
476
+ # transcribe an audio file in samples folder
477
+ docker run -it --rm \
478
+ -v path/to/models:/models \
479
+ whisper.cpp:main "./main -m /models/ggml-base.bin -f ./samples/jfk.wav"
480
+ ```
481
+
482
  ## Limitations
483
 
484
  - Inference only
models/download-ggml-model.sh CHANGED
@@ -19,7 +19,7 @@ function get_script_path() {
19
  fi
20
  }
21
 
22
- models_path="$(get_script_path)"
23
 
24
  # Whisper models
25
  models=(
@@ -56,8 +56,8 @@ function list_models {
56
  printf "\n\n"
57
  }
58
 
59
- if [ "$#" -ne 1 ]; then
60
- printf "Usage: $0 <model>\n"
61
  list_models
62
 
63
  exit 1
@@ -105,7 +105,7 @@ if [ $? -ne 0 ]; then
105
  exit 1
106
  fi
107
 
108
- printf "Done! Model '$model' saved in 'models/ggml-$model.bin'\n"
109
  printf "You can now use it like this:\n\n"
110
- printf " $ ./main -m models/ggml-$model.bin -f samples/jfk.wav\n"
111
  printf "\n"
 
19
  fi
20
  }
21
 
22
+ models_path="${2:-$(get_script_path)}"
23
 
24
  # Whisper models
25
  models=(
 
56
  printf "\n\n"
57
  }
58
 
59
+ if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
60
+ printf "Usage: $0 <model> [models_path]\n"
61
  list_models
62
 
63
  exit 1
 
105
  exit 1
106
  fi
107
 
108
+ printf "Done! Model '$model' saved in '$models_path/ggml-$model.bin'\n"
109
  printf "You can now use it like this:\n\n"
110
+ printf " $ ./main -m $models_path/ggml-$model.bin -f samples/jfk.wav\n"
111
  printf "\n"