1
1
#include " llama.h"
2
- #include < assert.h>
3
- #include < math.h>
2
+ #include " ggml.h"
3
+ #include < cassert>
4
+ #include < cmath>
4
5
#include < numeric>
5
6
#include < cassert>
6
7
#include < iostream>
7
8
#include < vector>
8
9
#include < algorithm>
9
10
10
- #undef assert
11
- #define assert (__expr ) do { if (!(__expr)) { printf (" %s:%d (%s) %s\n " , __FILE__, __LINE__, __func__, #__expr); exit (1 ); } } while (0 )
12
11
13
12
void dump (const llama_token_data_array * candidates) {
14
13
for (size_t i = 0 ; i < candidates->size ; i++) {
@@ -32,9 +31,9 @@ void test_top_k(const std::vector<float> & probs,
32
31
33
32
llama_token_data_array candidates_p = { candidates.data (), candidates.size (), false };
34
33
llama_sample_softmax (nullptr , &candidates_p);
35
- // DUMP(&candidates_p);
34
+ DUMP (&candidates_p);
36
35
llama_sample_top_k (nullptr , &candidates_p, k);
37
- // DUMP(&candidates_p);
36
+ DUMP (&candidates_p);
38
37
39
38
assert (candidates_p.size == expected_probs.size ());
40
39
for (size_t i = 0 ; i < candidates_p.size ; i++) {
@@ -57,9 +56,9 @@ void test_top_p(const std::vector<float> & probs,
57
56
58
57
llama_token_data_array candidates_p = { candidates.data (), candidates.size (), false };
59
58
llama_sample_softmax (nullptr , &candidates_p);
60
- // DUMP(&candidates_p);
59
+ DUMP (&candidates_p);
61
60
llama_sample_top_p (nullptr , &candidates_p, p);
62
- // DUMP(&candidates_p);
61
+ DUMP (&candidates_p);
63
62
64
63
assert (candidates_p.size == expected_probs.size ());
65
64
for (size_t i = 0 ; i < candidates_p.size ; i++) {
@@ -80,9 +79,9 @@ void test_tfs(const std::vector<float> & probs,
80
79
}
81
80
82
81
llama_token_data_array candidates_p = { candidates.data (), candidates.size (), false };
83
- // DUMP(&candidates_p);
82
+ DUMP (&candidates_p);
84
83
llama_sample_tail_free (nullptr , &candidates_p, z);
85
- // DUMP(&candidates_p);
84
+ DUMP (&candidates_p);
86
85
87
86
assert (candidates_p.size == expected_probs.size ());
88
87
for (size_t i = 0 ; i < candidates_p.size ; i++) {
@@ -103,9 +102,9 @@ void test_typical(const std::vector<float> & probs,
103
102
}
104
103
105
104
llama_token_data_array candidates_p = { candidates.data (), candidates.size (), false };
106
- // DUMP(&candidates_p);
105
+ DUMP (&candidates_p);
107
106
llama_sample_typical (nullptr , &candidates_p, p);
108
- // DUMP(&candidates_p);
107
+ DUMP (&candidates_p);
109
108
110
109
assert (candidates_p.size == expected_probs.size ());
111
110
for (size_t i = 0 ; i < candidates_p.size ; i++) {
@@ -172,6 +171,8 @@ void test_frequency_presence_penalty(
172
171
}
173
172
174
173
int main (void ) {
174
+ ggml_time_init ();
175
+
175
176
test_top_k ({0.1 , 0.2 , 0.3 , 0.4 }, {0.4 }, 1 );
176
177
test_top_k ({0.1 , 0.2 , 0.3 , 0.4 }, {0.4 , 0.3 , 0.2 }, 3 );
177
178
0 commit comments