MCPcopy Create free account
hub / github.com/cactus-compute/cactus / test_reset_functionality

Function test_reset_functionality

tests/test_kv_cache.cpp:182–218  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

180}
181
182bool test_reset_functionality() {
183 KVCache cache;
184 cache.init(2, 1024, std::vector<size_t>(2, 64), std::vector<size_t>(2, 8), Precision::FP16);
185 cache.set_window_size(16, 4);
186
187 CactusGraph graph;
188 graph.input({1}, Precision::FP32);
189 vector<size_t> k_nodes, v_nodes;
190
191 for (size_t layer = 0; layer < 2; layer++) {
192 size_t k_node = graph.input({10, 8, 64}, Precision::FP16);
193 size_t v_node = graph.input({10, 8, 64}, Precision::FP16);
194
195 vector<uint8_t> data;
196 fill_fp16(data, 10 * 8 * 64, 1.0f);
197 graph.set_input(k_node, data.data(), Precision::FP16);
198 graph.set_input(v_node, data.data(), Precision::FP16);
199
200 k_nodes.push_back(k_node);
201 v_nodes.push_back(v_node);
202 }
203
204 graph.execute();
205 cache.update_from_graph(&graph, k_nodes, v_nodes, 10, 2);
206
207 assert(cache.get_effective_seq_len() == 10);
208 assert(cache.get_total_seq_len() == 10);
209
210 cache.reset();
211
212 assert(cache.get_effective_seq_len() == 0);
213 assert(cache.get_total_seq_len() == 0);
214 assert(cache.get_keys_int8(0) == nullptr);
215 assert(cache.get_values_int8(0) == nullptr);
216
217 return true;
218}
219
220bool test_large_window() {
221 const size_t num_layers = 4;

Callers 1

mainFunction · 0.85

Calls 13

fill_fp16Function · 0.85
set_window_sizeMethod · 0.80
dataMethod · 0.80
update_from_graphMethod · 0.80
get_effective_seq_lenMethod · 0.80
get_total_seq_lenMethod · 0.80
get_keys_int8Method · 0.80
get_values_int8Method · 0.80
initMethod · 0.45
inputMethod · 0.45
set_inputMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected