-
Notifications
You must be signed in to change notification settings - Fork 50
/
test-fine-encoder.cpp
88 lines (72 loc) · 2.68 KB
/
test-fine-encoder.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "bark.h"
#include <cstdio>
#include <string>
#include <map>
#include <random>
#include <vector>
static const std::map<bark_codes, bark_codes> & k_tests()
{
static const bark_codes seq1 = {};
static const bark_codes seq2 = {};
static const bark_codes seq3 = {};
static const bark_codes ans1 = { {}, {} };
static const bark_codes ans2 = { {}, {} };
static const bark_codes ans3 = { {}, {} };
static std::map<bark_codes, bark_codes> _k_tests = {
// { seq1, ans1 }, // hello world
// { seq2, ans2 }, // this is an audio
{ seq3, ans3 }, // You cannot, sir, take from me anything
};
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];
gpt_model model;
std::mt19937 rng(0);
const int n_threads = 4;
const float temp = 0.0f; // deterministic sampling
printf("%s: reading bark coarse model\n", __func__);
if(!gpt_model_load(fname, model)) {
fprintf(stderr, "%s: invalid model file '%s'\n", __func__, fname.c_str());
return 1;
}
for (const auto & test_kv : k_tests()) {
bark_codes res = bark_forward_fine_encoder(
test_kv.first, model, rng, n_threads, temp);
bool correct = res.size() == test_kv.second.size();
for (int i = 0; i < (int) res.size() && correct; ++i) {
correct = res[i].size() == test_kv.second[i].size();
for (int j = 0; j < (int) res[i].size() && correct; j++) {
if (res[i][j] != test_kv.second[i][j]) {
correct = false;
}
}
}
if (!correct) {
fprintf(stderr, "%s : failed test \n", __func__);
fprintf(stderr, "%s : expected tokens (n=%zu): ", __func__, test_kv.second.size());
for (int i = 0; i < (int) test_kv.second.size(); i++) {
for (int j = 0; j < (int) test_kv.second[i].size(); j++) {
fprintf(stderr, "%d ", test_kv.second[i][j]);
}
fprintf(stderr, "\n");
}
fprintf(stderr, "\n");
fprintf(stderr, "%s : got tokens (n=%zu): ", __func__, res.size());
for (int i = 0; i < (int) res.size(); i++) {
for (int j = 0; j < (int) res[i].size(); j++) {
fprintf(stderr, "%d ", res[i][j]);
}
fprintf(stderr, "\n");
}
fprintf(stderr, "\n");
return 3;
}
}
fprintf(stderr, "%s : tests passed successfully.\n", __func__);
return 0;
}