MCPcopy Create free account
hub / github.com/Niko1221/Strata / fixture

Function fixture

engine/src/core/conversation_validation_test.cpp:83–284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81};
82
83void fixture(int format, int experts, bool zero_qsa, bool ple) {
84 ModelGeometry g;
85 g.n_layers = zero_qsa ? 3 : 8; g.n_expert = experts;
86 g.ssm_state_size = 2; g.ssm_v_heads = 2; g.ssm_conv_channels = 8;
87 g.n_head_kv = 1; g.head_dim = 64; g.idx_key_dim = 8;
88 std::string error;
89 ConversationStateSizes z;
90 check(conversation_state_sizes(g, z, error), "checked canonical/pruned/zero-QSA sizing");
91 Pools first(g, format), last(g, format), draft(g, format);
92 std::array<QsaState, 2> layers{first.st, last.st};
93 std::vector<uint8_t> gdn(z.gdn, 0xa5), history(ple ? z.ple : 0, 0xa5);
94 SessionState ss;
95 ss.max_cells = 96; ss.gdn_state = (float*) gdn.data();
96 // the whole-model carve, as session_init leaves a one-GPU session
97 ss.layer_hi = g.n_layers; ss.gdn_alloc = g.n_gdn_layers(); ss.qsa_alloc = g.n_qsa_layers();
98 ss.ple_hist = ple ? (float*) history.data() : nullptr;
99 ss.qsa_states = zero_qsa ? nullptr : layers.data();
100 SavedConversation image;
101 image.geometry = {g.n_embd,g.n_layers,g.qsa_interval,g.ssm_state_size,g.ssm_k_heads,g.ssm_v_heads,
102 g.ssm_d_conv,g.ssm_conv_channels,g.ssm_value_dim,g.n_head,g.n_head_kv,g.head_dim,
103 g.idx_q_heads,g.idx_key_dim,g.hc,g.hc_lr,g.n_expert,g.n_ff};
104 image.layer_hi = g.n_layers;
105 auto checkpoint = [&](size_t tokens) {
106 ConversationCheckpoint c;
107 c.ids.resize(tokens);
108 for (size_t i = 0; i < tokens; ++i) c.ids[i] = (int32_t) i + 1;
109 c.imgs = {{1, 44}};
110 c.gdn.resize(z.gdn, 13); c.ple.resize(ple ? z.ple : 0, 13);
111 c.tails.resize(g.n_qsa_layers() * z.tail, 13); c.dead.resize(g.n_qsa_layers() * z.dead, 13);
112 c.block_pos.resize(g.n_qsa_layers() * z.block_pos, 13);
113 return c;
114 };
115 image.live = checkpoint(9); image.checkpoints.push_back(checkpoint(5));
116 image.kv.reserve((size_t) g.n_qsa_layers() + 1);
117 if (!zero_qsa) { image.kv.push_back(first.image(g, true)); image.kv.push_back(last.image(g, true)); }
118 image.kv.push_back(draft.image(g, false));
119 check(conversation_snapshot_validate(image, ss, g, draft.st, error), "complete image validates without CUDA");
120 size_t estimate = 0;
121 check(conversation_snapshot_bytes({image.live.ids,image.live.imgs,image.checkpoints,true},ss,g,draft.st,estimate,error),
122 "capture estimate works without CUDA");
123 check(estimate == image.bytes(), "estimate covers checkpoint/indexer/spare payloads");
124 auto unchanged = [&] {
125 auto pristine = [](const auto& bytes) { return std::all_of(bytes.begin(),bytes.end(),[](uint8_t b){return b==0xa5;}); };
126 if (!pristine(gdn) || !pristine(history) || ss.ple_prev[0] != -1 || ss.ple_prev[1] != -1) return false;
127 for (const auto* p : {&first,&last,&draft}) for (const auto& bytes : p->data) if (!pristine(bytes)) return false;
128 return true;
129 };
130 auto reject = [&](const std::function<void(SavedConversation&)>& mutate, const char* label) {
131 auto bad = image; mutate(bad);
132 check(conversation_snapshot_restore(bad,ss,g,draft.st,error) == ConversationRestore::invalid,label);
133 check(unchanged(), "invalid restore did not touch any layer or running-state buffer");
134 };
135 reject([](auto& s){s.kv.back().k.pop_back();}, "late draft corruption rejected before first layer write");
136 reject([](auto& s){s.geometry[16] = 128;}, "different expert geometry rejected");
137 reject([](auto& s){s.live.stage_parts.emplace_back();}, "layer-split live state rejected before writes");
138 reject([](auto& s){s.checkpoints[0].stage_parts.emplace_back();}, "layer-split checkpoint rejected before writes");
139 reject([](auto& s){s.kv.pop_back();}, "missing KV layer rejected");
140 reject([](auto& s){s.live.gdn.pop_back();}, "bad live recurrence rejected");

Callers 1

mainFunction · 0.70

Calls 15

unchangedFunction · 0.85
moveFunction · 0.85
n_qsa_layersMethod · 0.80
push_backMethod · 0.80
checkFunction · 0.70
conversation_state_sizesFunction · 0.70
checkpointFunction · 0.70

Tested by

no test coverage detected