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

Function test_large_window

tests/test_kv_cache.cpp:220–258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

218}
219
220bool test_large_window() {
221 const size_t num_layers = 4;
222 const size_t num_kv_heads = 8;
223 const size_t head_dim = 64;
224 const size_t window_size = 512;
225
226 KVCache cache;
227 cache.init(num_layers, 2048, std::vector<size_t>(num_layers, head_dim), std::vector<size_t>(num_layers, num_kv_heads), Precision::FP16);
228 cache.set_window_size(window_size, 4);
229
230 CactusGraph graph;
231 graph.input({1}, Precision::FP32);
232
233 size_t seq_len = 600;
234 vector<size_t> k_nodes, v_nodes;
235
236 for (size_t layer = 0; layer < num_layers; layer++) {
237 size_t k_node = graph.input({seq_len, num_kv_heads, head_dim}, Precision::FP16);
238 size_t v_node = graph.input({seq_len, num_kv_heads, head_dim}, Precision::FP16);
239
240 vector<uint8_t> k_data, v_data;
241 fill_fp16(k_data, seq_len * num_kv_heads * head_dim, float(layer + 1));
242 fill_fp16(v_data, seq_len * num_kv_heads * head_dim, float(layer + 101));
243
244 graph.set_input(k_node, k_data.data(), Precision::FP16);
245 graph.set_input(v_node, v_data.data(), Precision::FP16);
246
247 k_nodes.push_back(k_node);
248 v_nodes.push_back(v_node);
249 }
250
251 graph.execute();
252 cache.update_from_graph(&graph, k_nodes, v_nodes, seq_len, num_layers);
253
254 assert(cache.get_effective_seq_len() == window_size);
255 assert(cache.get_total_seq_len() == seq_len);
256
257 return true;
258}
259
260int main() {
261 TestUtils::TestRunner runner("KV Cache Sliding Window Tests");

Callers 1

mainFunction · 0.85

Calls 10

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
initMethod · 0.45
inputMethod · 0.45
set_inputMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected