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

Async whisper #2

Merged
merged 11 commits into from
Oct 30, 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
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