1
+ /* ------------------------------------------------------------------------------
2
+ * Unit tests for llama-memory.h and derived memory implementations. It contains
3
+ * a number of tests which can be run all together or separately.
4
+ *
5
+ * USAGE: ./bin/test-memory <test_name1> <test_name2>
6
+ *
7
+ * When adding a new test, do the following:
8
+ *
9
+ * 1. Add the new test_<memory_type>_description function under the
10
+ * appropriate memory type section
11
+ *
12
+ * 2. Add `RUN_TEST(test_<memory_type>_description);` to main
13
+ *----------------------------------------------------------------------------*/
14
+
1
15
#include " ../src/llama-arch.h"
2
16
#include " ../src/llama-hparams.h"
3
17
#include " ../src/llama-impl.h"
@@ -61,13 +75,22 @@ struct log_scope {
61
75
}
62
76
};
63
77
64
- #define LOG_SCOPE () log_scope __log_scope (__func__)
78
+ #define RUN_TEST (test_name ) \
79
+ do { \
80
+ bool run_test = argc < 2 ; \
81
+ std::vector<std::string> args (argv + 1 , argv + argc); \
82
+ if (std::find (args.begin (), args.end (), #test_name) != args.end ()) \
83
+ run_test = true ; \
84
+ if (run_test) { \
85
+ log_scope __log_scope (#test_name); \
86
+ test_name (); \
87
+ } \
88
+ } while (0 )
65
89
66
90
/* - Unified Cache ------------------------------------------------------------*/
67
91
68
92
/* Test that the unified cache can be constructed and destructed safely */
69
93
static void test_llama_kv_cache_unified_constructor () {
70
- LOG_SCOPE ();
71
94
auto model = _make_model ();
72
95
llama_kv_cache_unified cache (
73
96
/* model */ *model,
@@ -84,7 +107,6 @@ static void test_llama_kv_cache_unified_constructor() {
84
107
85
108
/* Test that the recurrent cache can be constructed and destructed safely */
86
109
static void test_llama_kv_cache_recurrent_constructor () {
87
- LOG_SCOPE ();
88
110
auto model = _make_model (LLM_ARCH_MAMBA);
89
111
llama_kv_cache_recurrent cache (
90
112
/* model */ *model,
@@ -99,7 +121,6 @@ static void test_llama_kv_cache_recurrent_constructor() {
99
121
100
122
/* Test that the hybrid cache can be constructed and destructed safely */
101
123
static void test_llama_kv_cache_hybrid_constructor () {
102
- LOG_SCOPE ();
103
124
auto model = _make_model (
104
125
/* arch =*/ LLM_ARCH_LLAMA,
105
126
/* n_layer =*/ 4 ,
@@ -159,12 +180,13 @@ static void test_llama_kv_cache_hybrid_constructor() {
159
180
160
181
/* - Main ---------------------------------------------------------------------*/
161
182
162
- int main () {
183
+ int main (int argc, char * argv[] ) {
163
184
// Unified Cache Tests
164
- test_llama_kv_cache_unified_constructor ();
185
+ RUN_TEST (test_llama_kv_cache_unified_constructor);
186
+ RUN_TEST (test_llama_kv_cache_unified_single_seq);
165
187
// Recurrent Cache Tests
166
- test_llama_kv_cache_recurrent_constructor ( );
188
+ RUN_TEST (test_llama_kv_cache_recurrent_constructor );
167
189
// Hybrid Cache Tests
168
- test_llama_kv_cache_hybrid_constructor ( );
190
+ RUN_TEST (test_llama_kv_cache_hybrid_constructor );
169
191
return 0 ;
170
192
}
0 commit comments