Skip to content

Commit

Permalink
Merge pull request #2 from locaal-ai/roy.async_whisper
Browse files Browse the repository at this point in the history
Async whisper
  • Loading branch information
royshil authored Oct 30, 2024
2 parents b826054 + 4136426 commit 2bca184
Show file tree
Hide file tree
Showing 11 changed files with 802 additions and 305 deletions.
53 changes: 5 additions & 48 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,31 @@ jobs:
matrix:
os: ['windows-latest', 'macos-latest', 'ubuntu-latest']
python-version: ['3.11', '3.12']
platform: ['x86_64', 'arm64', 'win64']
acceleration: ['cpu', 'cuda', 'hipblas', 'vulkan']
platform: ['x86_64', 'win64']
acceleration: ['cpu', 'cuda']
exclude:
- os: windows-latest
platform: arm64
- os: windows-latest
platform: x86_64
- os: macos-latest
acceleration: cuda
- os: macos-latest
acceleration: hipblas
- os: macos-latest
acceleration: vulkan
- os: macos-latest
platform: win64
- os: ubuntu-latest
platform: win64
- os: ubuntu-latest
platform: arm64
- os: ubuntu-latest
acceleration: cuda
- os: ubuntu-latest
acceleration: hipblas
- os: ubuntu-latest
acceleration: vulkan

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4

- name: Set up Python Non-Mac
if: ${{ matrix.os != 'macos-latest' }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Set up Python Mac arm64
if: ${{ matrix.os == 'macos-latest' && matrix.platform == 'arm64' }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: 'arm64'

- name: Set up Python Mac x86_64
if: ${{ matrix.os == 'macos-latest' && matrix.platform == 'x86_64' }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: 'x64'

- name: Install dependencies
run: |
Expand Down Expand Up @@ -97,27 +72,9 @@ jobs:
pip install $wheelFile.FullName
- name: Test import
if: false
run: |
python -c "import simpler_whisper; print(simpler_whisper.__file__)"
- name: Rename wheel file
shell: python
run: |
import os
import glob
wheel_file = glob.glob('dist/*.whl')[0]
base_name = os.path.basename(wheel_file)
name_parts = base_name.split('-')
# Insert acceleration and platform after the first part of the name
underscore_parts = [name_parts[0], '${{ matrix.acceleration }}', '${{ matrix.platform }}']
new_name_parts = ['_'.join(underscore_parts)] + name_parts[1:]
new_name = '-'.join(new_name_parts)
new_path = os.path.join('dist', new_name)
os.rename(wheel_file, new_path)
print(f"Renamed {base_name} to {new_name}")
python -c "import sys; sys.path.pop(0); import simpler_whisper; print(simpler_whisper.__file__)"
- name: Set wheel name
shell: pwsh
Expand Down
89 changes: 46 additions & 43 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
cmake_minimum_required(VERSION 3.15)
project(whisper_cpp_wrapper)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Find Python
find_package(Python ${PYTHON_VERSION} EXACT COMPONENTS Interpreter Development NumPy REQUIRED)

# Fetch pybind11
include(FetchContent)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v2.13.6 # Specify a version/tag here
)
FetchContent_MakeAvailable(pybind11)

include(cmake/BuildWhispercpp.cmake)

# Include directories
include_directories(${Python_INCLUDE_DIRS})
include_directories(${Python_NumPy_INCLUDE_DIRS})

# Create the extension module
pybind11_add_module(_whisper_cpp src/whisper_wrapper.cpp)
target_link_libraries(_whisper_cpp PRIVATE Whispercpp)

# Set the output directory for the built module
set_target_properties(_whisper_cpp PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/simpler_whisper
)

# Copy the DLL to the output directory on Windows
if(WIN32 OR APPLE)
foreach(WHISPER_ADDITIONAL_FILE ${WHISPER_ADDITIONAL_FILES})
add_custom_command(TARGET _whisper_cpp POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${WHISPER_ADDITIONAL_FILE}"
$<TARGET_FILE_DIR:_whisper_cpp>
)
endforeach()
endif()
cmake_minimum_required(VERSION 3.15)
project(whisper_cpp_wrapper)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Find Python
find_package(
Python ${PYTHON_VERSION} EXACT
COMPONENTS Interpreter Development
REQUIRED)

# Fetch pybind11
include(FetchContent)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v2.13.6 # Specify a version/tag here
)
FetchContent_MakeAvailable(pybind11)

include(cmake/BuildWhispercpp.cmake)

# Include directories
include_directories(${Python_INCLUDE_DIRS})
include_directories(${Python_NumPy_INCLUDE_DIRS})

# Create the extension module
pybind11_add_module(_whisper_cpp src/whisper_wrapper.cpp)
target_link_libraries(_whisper_cpp PRIVATE Whispercpp)

# Set the output directory for the built module
set_target_properties(
_whisper_cpp PROPERTIES LIBRARY_OUTPUT_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/simpler_whisper)

# Copy the DLL to the output directory on Windows
if(WIN32 OR APPLE)
foreach(WHISPER_ADDITIONAL_FILE ${WHISPER_ADDITIONAL_FILES})
add_custom_command(
TARGET _whisper_cpp
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${WHISPER_ADDITIONAL_FILE}" $<TARGET_FILE_DIR:_whisper_cpp>)
endforeach()
endif()
Loading

0 comments on commit 2bca184

Please sign in to comment.