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

[MM-59980] Upgrade to whisper.cpp v1.7.1 #33

Merged
merged 6 commits into from
Oct 29, 2024
Merged
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
24 changes: 4 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,33 @@ on: [push]
name: CI
jobs:
lint:
env:
GOPATH: ${{ github.workspace }}

defaults:
run:
working-directory: ${{ env.GOPATH }}/src/github.com/${{ github.repository }}
working-directory: ${{ github.workspace }}/src/github.com/${{ github.repository }}

runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
path: ${{ env.GOPATH }}/src/github.com/${{ github.repository }}
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: ${{ env.GOPATH }}/src/github.com/${{ github.repository }}/go.mod
cache-dependency-path: ${{ env.GOPATH }}/src/github.com/${{ github.repository }}/go.sum
path: ${{ github.workspace }}/src/github.com/${{ github.repository }}
- name: Lint code
run: |
make go-lint

test:
env:
GOPATH: ${{ github.workspace }}

defaults:
run:
working-directory: ${{ env.GOPATH }}/src/github.com/${{ github.repository }}
working-directory: ${{ github.workspace }}/src/github.com/${{ github.repository }}

runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
path: ${{ env.GOPATH }}/src/github.com/${{ github.repository }}
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: ${{ env.GOPATH }}/src/github.com/${{ github.repository }}/go.mod
cache-dependency-path: ${{ env.GOPATH }}/src/github.com/${{ github.repository }}/go.sum
path: ${{ github.workspace }}/src/github.com/${{ github.repository }}
- name: Execute Tests
run: |
go mod download
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ endif

## CGO dependencies
# Whisper.cpp
WHISPER_VERSION ?= "1.6.2"
WHISPER_SHA ?= "da7988072022acc3cfa61b370b3c51baad017f1900c3dc4e68cb276499f66894"
WHISPER_VERSION ?= "1.7.1"
WHISPER_SHA ?= "97f19a32212f2f215e538ee37a16ff547aaebc54817bd8072034e02466ce6d55"
WHISPER_MODELS ?= "tiny base small"
# Opus
OPUS_VERSION ?= "1.4"
OPUS_SHA ?= "c9b32b4253be5ae63d1ff16eea06b94b5f0f2951b7a02aceef58e3a3ce49c51f"
OPUS_VERSION ?= "1.5.2"
OPUS_SHA ?= "65c1d2f78b9f2fb20082c38cbe47c951ad5839345876e46941612ee87f9a7ce1"
# ONNX Runtime
ONNX_VERSION ?= "1.18.1"
# Azure Speech SDK
Expand Down
15 changes: 10 additions & 5 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@
# A multi stage build, with golang used as a builder
# and debian:sid-slim as runner
ARG GO_VERSION
FROM --platform=$TARGETPLATFORM debian:bookworm-20240612-slim as base
FROM --platform=$TARGETPLATFORM debian:bookworm-20240612-slim AS base

# Setup system dependencies
WORKDIR /workdir

# Install TLS certificates
# Install TLS certificates and libgomp
# hadolint ignore=DL3008
RUN apt-get update && \
apt-get install --no-install-recommends -y ca-certificates && \
apt-get install --no-install-recommends -y ca-certificates libgomp1 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Create unprivileged user to run the recorder process
RUN groupadd -r calls && useradd -mr -g calls calls

ARG GO_VERSION
FROM --platform=$TARGETPLATFORM golang:${GO_VERSION}-bookworm as builder
FROM --platform=$TARGETPLATFORM golang:${GO_VERSION}-bookworm AS builder
# Install patch
# hadolint ignore=DL3008
RUN apt-get update && \
apt-get install --no-install-recommends -y patch

ARG TARGETOS
ARG TARGETARCH
ARG GO_BUILD_PLATFORMS=${TARGETOS}-${TARGETARCH}
Expand All @@ -37,7 +42,7 @@ ARG AZURE_SDK_SHA
# We first copy just the build directory so that we can properly cache dependencies which can take a while to download.
COPY ./build /src/build
WORKDIR /src
RUN /bin/bash ./build/prepare_deps.sh ${OPUS_VERSION} ${OPUS_SHA} ${WHISPER_VERSION} ${WHISPER_SHA} "${WHISPER_MODELS}" ${ONNX_VERSION} ${TARGETARCH} ${AZURE_SDK_VERSION} ${AZURE_SDK_SHA}
RUN /bin/bash ./build/prepare_deps.sh ${OPUS_VERSION} ${OPUS_SHA} ${WHISPER_VERSION} ${WHISPER_SHA} "${WHISPER_MODELS}" ${ONNX_VERSION} ${TARGETARCH} ${AZURE_SDK_VERSION} ${AZURE_SDK_SHA} "true"

COPY . /src
RUN /bin/bash ./build/build.sh ${OPUS_VERSION} ${OPUS_SHA} ${WHISPER_VERSION} ${WHISPER_SHA} "${WHISPER_MODELS}" ${ONNX_VERSION} ${TARGETARCH} ${AZURE_SDK_VERSION} ${AZURE_SDK_SHA}
Expand Down
4 changes: 2 additions & 2 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ AZURE_SDK_VERSION=$8
AZURE_SDK_SHA=$9

OPUS_INCLUDE_PATH="/tmp/opus-${OPUS_VERSION}/include"
WHISPER_INCLUDE_PATH="/tmp/whisper.cpp-${WHISPER_VERSION}"
WHISPER_INCLUDE_PATH="/tmp/whisper.cpp-${WHISPER_VERSION}/include:/tmp/whisper.cpp-${WHISPER_VERSION}/ggml/include"
OPUS_LIBRARY_PATH="/tmp/opus-${OPUS_VERSION}/.libs"
WHISPER_LIBRARY_PATH=${WHISPER_INCLUDE_PATH}
WHISPER_LIBRARY_PATH="/tmp/whisper.cpp-${WHISPER_VERSION}"
ONNX_INCLUDE_PATH="/tmp/onnxruntime-linux-${ONNX_VERSION}/include"
ONNX_LIBRARY_PATH="/tmp/onnxruntime-linux-${ONNX_VERSION}/lib"
AZURE_SDK_INCLUDE_PATH="/tmp/SpeechSDK-Linux-${AZURE_SDK_VERSION}/include/c_api"
Expand Down
4 changes: 2 additions & 2 deletions build/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ AZURE_SDK_VERSION=$7
AZURE_SDK_SHA=$8

OPUS_INCLUDE_PATH="/tmp/opus-${OPUS_VERSION}/include"
WHISPER_INCLUDE_PATH="/tmp/whisper.cpp-${WHISPER_VERSION}"
WHISPER_INCLUDE_PATH="/tmp/whisper.cpp-${WHISPER_VERSION}/include:/tmp/whisper.cpp-${WHISPER_VERSION}/ggml/include"
OPUS_LIBRARY_PATH="/tmp/opus-${OPUS_VERSION}/.libs"
WHISPER_LIBRARY_PATH=${WHISPER_INCLUDE_PATH}
WHISPER_LIBRARY_PATH="/tmp/whisper.cpp-${WHISPER_VERSION}"
ONNX_INCLUDE_PATH="/tmp/onnxruntime-linux-${ONNX_VERSION}/include"
ONNX_LIBRARY_PATH="/tmp/onnxruntime-linux-${ONNX_VERSION}/lib"
AZURE_SDK_INCLUDE_PATH="/tmp/SpeechSDK-Linux-${AZURE_SDK_VERSION}/include/c_api"
Expand Down
2 changes: 2 additions & 0 deletions build/prepare_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ONNX_VERSION=$6
TARGET_ARCH=$7
AZURE_SDK_VERSION=$8
AZURE_SDK_SHA=$9
IS_BUILD=${10}
ONNX_ARCH=x64
ONNX_SHA=a0994512ec1e1debc00c18bfc7a5f16249f6ebd6a6128ff2034464cc380ea211
if [ "$TARGET_ARCH" == "arm64" ]; then
Expand All @@ -35,6 +36,7 @@ wget https://github.com/ggerganov/whisper.cpp/archive/refs/tags/v${WHISPER_VERSI
echo "${WHISPER_SHA} v${WHISPER_VERSION}.tar.gz" | sha256sum --check && \
tar xf v${WHISPER_VERSION}.tar.gz && \
cd whisper.cpp-${WHISPER_VERSION} && \
([[ "$TARGET_ARCH" == "amd64" ]] && [[ "$IS_BUILD" == "true" ]] && echo "Patching Whisper.CPP Makefile" && patch -p1 Makefile /src/build/whisper.patch) || true && \
for model in ${MODELS}; do ./models/download-ggml-model.sh "${model}"; done && \
make -j4 libwhisper.a UNAME_M=${UNAME_M} && \
cd /tmp && \
Expand Down
4 changes: 2 additions & 2 deletions build/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ AZURE_SDK_VERSION=$8
AZURE_SDK_SHA=$9

OPUS_INCLUDE_PATH="/tmp/opus-${OPUS_VERSION}/include"
WHISPER_INCLUDE_PATH="/tmp/whisper.cpp-${WHISPER_VERSION}"
WHISPER_INCLUDE_PATH="/tmp/whisper.cpp-${WHISPER_VERSION}/include:/tmp/whisper.cpp-${WHISPER_VERSION}/ggml/include"
OPUS_LIBRARY_PATH="/tmp/opus-${OPUS_VERSION}/.libs"
WHISPER_LIBRARY_PATH=${WHISPER_INCLUDE_PATH}
WHISPER_LIBRARY_PATH="/tmp/whisper.cpp-${WHISPER_VERSION}"
ONNX_INCLUDE_PATH="/tmp/onnxruntime-linux-${ONNX_VERSION}/include"
ONNX_LIBRARY_PATH="/tmp/onnxruntime-linux-${ONNX_VERSION}/lib"
AZURE_SDK_INCLUDE_PATH="/tmp/SpeechSDK-Linux-${AZURE_SDK_VERSION}/include/c_api"
Expand Down
21 changes: 21 additions & 0 deletions build/whisper.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/Makefile b/Makefile
index 32b7cbb..9ac28a4 100644
--- a/Makefile
+++ b/Makefile
@@ -361,12 +361,12 @@ ifndef RISCV

ifeq ($(UNAME_M),$(filter $(UNAME_M),x86_64 i686 amd64))
# Use all CPU extensions that are available:
- MK_CFLAGS += -march=native -mtune=native
- HOST_CXXFLAGS += -march=native -mtune=native
+ #MK_CFLAGS += -march=native -mtune=native
+ #HOST_CXXFLAGS += -march=native -mtune=native

# Usage AVX-only
- #MK_CFLAGS += -mfma -mf16c -mavx
- #MK_CXXFLAGS += -mfma -mf16c -mavx
+ MK_CFLAGS += -mfma -mf16c -mavx
+ MK_CXXFLAGS += -mfma -mf16c -mavx

# Usage SSSE3-only (Not is SSE3!)
#MK_CFLAGS += -mssse3
2 changes: 1 addition & 1 deletion cmd/transcriber/apis/whisper.cpp/context.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package whisper

// #cgo linux LDFLAGS: -l:libwhisper.a -lm -lstdc++
// #cgo linux LDFLAGS: -l:libwhisper.a -lm -lstdc++ -fopenmp
// #cgo darwin LDFLAGS: -lwhisper -lstdc++ -framework Accelerate
// #include <whisper.h>
// #include <stdlib.h>
Expand Down