Skip to content

Commit

Permalink
dbg: fix the forward pass (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
PABannier committed Apr 10, 2024
1 parent 3c4411d commit 68cbd71
Show file tree
Hide file tree
Showing 31 changed files with 1,378 additions and 121,735 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- main
- encodec-submodule-fix-ci
paths:
[
".github/workflows/**",
Expand Down Expand Up @@ -56,7 +55,6 @@ jobs:
- name: Build
id: cmake_build
run: |
cd bark
mkdir build
cd build
cmake ..
Expand All @@ -82,7 +80,6 @@ jobs:
id: cmake_build
run: |
sysctl -a
cd bark
mkdir build
cd build
cmake ..
Expand Down
21 changes: 2 additions & 19 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*.wav
*.bin
.build/
build/
.cache/
*.dSYM/
.direnv/
Expand All @@ -18,21 +17,5 @@ build/
.vs/
.vscode/

ggml_weights/*
ggml_weights_*/*
models/

build-info.h

!ggml_weights/ggml_vocab.bin
!ggml_weights/vocab.txt

tests/test-gpt-eval
tests/test-fine-gpt-eval

tests/test-forward-coarse
tests/test-forward-semantic
tests/test-forward-fine
tests/test-forward-encodec

tests/test-tokenizer
bark_weights/
build/
31 changes: 12 additions & 19 deletions bark/CMakeLists.txt → CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.12)
project("bark" C CXX)

set(BARK_BUILD_EXAMPLES ON)

if (NOT XCODE AND NOT MSVC AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
Expand All @@ -9,33 +11,24 @@ endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_FLAGS_RELEASE "-O3")

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(BARK_STANDALONE ON)
else()
set(BARK_STANDALONE OFF)
endif()

option(BARK_BUILD_TESTS "bark: build tests" ${BARK_STANDALONE})
option(BARK_BUILD_EXAMPLES "bark: build examples" ${BARK_STANDALONE})

# Build libraries

set(BARK_LIB bark)

# add_subdirectory(../ggml ${CMAKE_BINARY_DIR}/ggml)
add_subdirectory(../encodec.cpp ${CMAKE_BINARY_DIR}/encodec.cpp)
add_subdirectory(encodec.cpp)

add_library(${BARK_LIB} bark.cpp bark.h)
add_library(${BARK_LIB} STATIC bark.cpp bark.h)

if (BARK_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

if (BARK_BUILD_TESTS)
include(CTest)
add_subdirectory(tests)
endif ()

target_link_libraries(${BARK_LIB} PUBLIC ggml encodec)
target_include_directories(${BARK_LIB} PUBLIC .)
target_compile_features(${BARK_LIB} PUBLIC cxx_std_11)

if (GGML_CUBLAS)
add_compile_definitions(GGML_USE_CUBLAS)
endif()

if (GGML_METAL)
add_compile_definitions(GGML_USE_METAL)
endif()
21 changes: 7 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Inference of [SunoAI's bark model](https://github.com/suno-ai/bark) in pure C/C+

## Description

With `bark.cpp`, my goal is to bring **real-time realistic multilingual** text-to-speech generation to the community. Currently, I am focused on porting the [Bark](https://github.com/suno-ai/bark) model in C++.
With `bark.cpp`, our goal is to bring **real-time realistic multilingual** text-to-speech generation to the community. Currently, I am focused on porting the [Bark](https://github.com/suno-ai/bark) model in C++.

- [x] Plain C/C++ implementation without dependencies
- [x] AVX, AVX2 and AVX512 for x86 architectures
Expand Down Expand Up @@ -93,8 +93,8 @@ git submodule update --init --recursive
In order to build bark.cpp you must use `CMake`:

```bash
mkdir bark/build
cd bark/build
mkdir build
cd build
cmake ..
cmake --build . --config Release
```
Expand All @@ -106,16 +106,13 @@ cmake --build . --config Release
python3 -m pip install -r bark/requirements.txt

# obtain the original bark and encodec weights and place them in ./models
python3 bark/download_weights.py --download-dir ./models
python3 download_weights.py --download-dir ./models

# convert the model to ggml format
python3 bark/convert.py \
--dir-model ./models \
--vocab-path ./ggml_weights/ \
--out-dir ./ggml_weights/
python3 convert.py --dir-model ./models --out-dir ./ggml_weights/

# run the inference
./bark/build/examples/main/main -m ./ggml_weights/ -p "this is an audio"
./build/examples/main/main -m ./ggml_weights/ -p "this is an audio"
```

### (Optional) Quantize weights
Expand All @@ -125,11 +122,7 @@ Weights can be quantized using the following strategy: `q4_0`, `q4_1`, `q5_0`, `
Note that to preserve audio quality, we do not quantize the codec model. The bulk of the computation is in the forward pass of the GPT models.

```bash
mkdir ggml_weights_q4
cp ggml_weights/*vocab* ggml_weights_q4
./bark/build/examples/quantize/quantize ./ggml_weights/ggml_weights_text.bin ./ggml_weights_q4/ggml_weights_text.bin q4_0
./bark/build/examples/quantize/quantize ./ggml_weights/ggml_weights_coarse.bin ./ggml_weights_q4/ggml_weights_coarse.bin q4_0
./bark/build/examples/quantize/quantize ./ggml_weights/ggml_weights_fine.bin ./ggml_weights_q4/ggml_weights_fine.bin q4_0
./build/examples/quantize/quantize ./ggml_weights.bin ./ggml_weights_q4.bin q4_0
```

### Seminal papers
Expand Down

0 comments on commit 68cbd71

Please sign in to comment.