-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
182 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ build/ | |
|
||
bark | ||
encodec | ||
main | ||
tests/test-tokenizer | ||
|
||
*.o | ||
*.plist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "ggml.h" | ||
#include "bark.h" | ||
|
||
int main() { | ||
const int64_t t_main_start_us = ggml_time_us(); | ||
|
||
int64_t t_load_us = 0; | ||
int64_t t_eval_us = 0; | ||
|
||
bark_model model; | ||
std::string fname = "./ggml_weights"; | ||
|
||
// load the model | ||
{ | ||
const int64_t t_start_us = ggml_time_us(); | ||
|
||
if(!bark_model_load(fname, model)) { | ||
fprintf(stderr, "%s: failed to load model from '%s'\n", __func__, fname.c_str()); | ||
return 1; | ||
} | ||
|
||
t_load_us = ggml_time_us() - t_start_us; | ||
} | ||
|
||
printf("\n"); | ||
|
||
// forward pass | ||
const std::string prompt = "This is an audio"; | ||
{ | ||
const int64_t t_eval_us_start = ggml_time_us(); | ||
|
||
// call to generate audio | ||
bark_generate_audio(model, model.vocab, prompt.data(), 4); | ||
|
||
t_eval_us = ggml_time_us() - t_eval_us_start; | ||
} | ||
|
||
// report timing | ||
{ | ||
const int64_t t_main_end_us = ggml_time_us(); | ||
|
||
printf("\n\n"); | ||
printf("%s: load time = %8.2f ms\n", __func__, t_load_us/1000.0f); | ||
printf("%s: eval time = %8.2f ms\n", __func__, t_eval_us/1000.0f); | ||
printf("%s: total time = %8.2f ms\n", __func__, (t_main_end_us - t_main_start_us)/1000.0f); | ||
} | ||
|
||
// TODO: write wrapper | ||
ggml_free(model.coarse_model.ctx); | ||
ggml_free(model.fine_model.ctx); | ||
ggml_free(model.text_model.ctx); | ||
ggml_free(model.codec_model.ctx); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function(bark_add_test source) | ||
get_filename_component(TEST_TARGET ${source} NAME_WE) | ||
add_executable(${TEST_TARGET} ${source}) | ||
install(TARGETS ${TEST_TARGET} RUNTIME) | ||
target_link_libraries(${TEST_TARGET} PRIVATE bark) | ||
add_test(NAME ${TEST_TARGET} COMMAND $<TARGET_FILE:${TEST_TARGET}> ${ARGN}) | ||
endfunction() | ||
|
||
llama_add_test(test-tokenizer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../ggml_weights/ggml_weights_text.bin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include "bark.h" | ||
|
||
#include <cstdio> | ||
#include <string> | ||
#include <map> | ||
#include <vector> | ||
|
||
static const std::map<std::string, std::vector<bark_vocab::id>> & k_tests() | ||
{ | ||
static std::map<std::string, std::vector<bark_vocab::id>> _k_tests = { | ||
{ "Hello world!", { 31178, 11356, 106, }, }, | ||
{ "Hello world", { 31178, 11356, }, }, | ||
{ " Hello world!", { 31178, 11356, 106, }, }, | ||
// { "this is an audio generated by bark", { 10531, 10124, 10151, 23685, 48918, 10155, 18121, 10174, }, }, | ||
}; | ||
return _k_tests; | ||
}; | ||
|
||
int main(int argc, char **argv) { | ||
if (argc < 2) { | ||
fprintf(stderr, "Usage: %s <model-file>\n", argv[0]); | ||
return 1; | ||
} | ||
|
||
const std::string fname = argv[1]; | ||
|
||
fprintf(stderr, "%s : reading vocab from: '%s'\n", __func__, fname.c_str()); | ||
|
||
bark_model model; | ||
int max_ctx_size = 256; | ||
|
||
// load text model and vocab | ||
{ | ||
if(!gpt_model_load(fname, model.text_model, model.vocab, true)) { | ||
fprintf(stderr, "%s: invalid model file '%s' (bad text)\n", __func__, fname.c_str()); | ||
return 1; | ||
} | ||
model.memsize += model.text_model.memsize; | ||
} | ||
|
||
for (const auto & test_kv : k_tests()) { | ||
std::vector<bark_vocab::id> res(test_kv.first.size()); | ||
int n_tokens; | ||
bert_tokenize(model.vocab, test_kv.first.c_str(), res.data(), &n_tokens, max_ctx_size); | ||
res.resize(n_tokens); | ||
|
||
bool correct = res.size() == test_kv.second.size(); | ||
|
||
for (int i = 0; i < (int) res.size() && correct; ++i) { | ||
if (res[i] != test_kv.second[i]) { | ||
correct = false; | ||
} | ||
} | ||
|
||
if (!correct) { | ||
fprintf(stderr, "%s : failed test: '%s'\n", __func__, test_kv.first.c_str()); | ||
fprintf(stderr, "%s : expected tokens: ", __func__); | ||
for (const auto & t : test_kv.second) { | ||
fprintf(stderr, "%6d, ", t); | ||
} | ||
fprintf(stderr, "\n"); | ||
fprintf(stderr, "%s : got tokens: ", __func__); | ||
for (const auto & t : res) { | ||
fprintf(stderr, "%6d, ", t); | ||
} | ||
fprintf(stderr, "\n"); | ||
|
||
return 3; | ||
} | ||
} | ||
|
||
ggml_free(model.coarse_model.ctx); | ||
ggml_free(model.fine_model.ctx); | ||
ggml_free(model.text_model.ctx); | ||
ggml_free(model.codec_model.ctx); | ||
|
||
return 0; | ||
} |