Verify restored draft KV and fail incomplete state fingerprints

Move core diagnostics from the dependent NVMe work (4d73bb3) into the shared-core review branch. Read back authoritative bytes and resident ring pages without rewriting state; remove a redundant GPU fixture refill that could mask restore failures. Bound hash workspace and check synchronization/copy errors. Opt-in diagnostics record batched versus token draft prefill.

Validation: current core translation units pass C++ syntax checks; 1188 host transfer checks pass with ASan/UBSan. Real GPU and full-model validation remain pending the benchmark window.
This commit is contained in:
Jeremiah Ritchey authored and Niko1221 committed 2026-09-30 16:31:45 +02:00
1 parent f3072a95e6
commit 13fd32a227
5 files changed
+90 -8

No files matched your search

+35 -4
View File
@@ -3360,6 +3360,9 @@ int main(int argc, char** argv) {
// E-9: batched through the prompt path when it can (one GPU: a layer split's drafter is on the last stage)
const bool batched = !multi_gpu && sp.draft_kv(mtp, R_rows, nxt.data(), T, p0, e);
if (!e.empty() || (!batched && !mtp.prefill(R_rows, nxt.data(), T, p0, e))) return false;
if (std::getenv("STRATA_SNAPSHOT_VERIFY") != nullptr)
std::fprintf(stderr, "strata serve: DRAFT_PREFILL path=%s mode=%d cells=%lld\n",
batched ? "batched" : "token", mtp.kv_state().kv_mode, (long long) T);
// progress for the server window: PP <position reached> <prompt tokens> <ms> <fresh tokens/s>
const int64_t done = p0 + T;
const double ms = std::chrono::duration<double, std::milli>(Clock::now() - pp_t0).count();
@@ -3864,6 +3867,17 @@ int main(int argc, char** argv) {
std::printf("ERR restoring parked conversation: %s\n", err.c_str());
return 1;
}
if (std::getenv("STRATA_SNAPSHOT_VERIFY") != nullptr) {
uint64_t draft_hash = 0;
if (!strata::core::conversation_kv_verify(incoming->kv.back(), mtp.kv_state(), g,
int64_t(incoming->live.ids.size()), false, draft_hash, err)) {
std::printf("ERR verifying restored draft KV: %s\n", err.c_str());
return 1;
}
std::fprintf(stderr, "strata serve: SNAPSHOT_VERIFY draft=%016llx cells=%lld mode=%d source=%s\n",
(unsigned long long) draft_hash, (long long) incoming->kv.back().cells,
mtp.kv_state().kv_mode, "ram");
}
live = std::move(incoming->live.ids);
live_imgs = std::move(incoming->live.imgs);
checks = std::move(incoming->checkpoints);
@@ -4309,17 +4323,30 @@ int main(int argc, char** argv) {
if (state_hash && live_ok) {
// DEBUG: a fingerprint of every part of the session over the positions it holds ([0, L)), and
// separately of what lies past them in the last KV page (stale cells, fine unless something reads them)
cudaDeviceSynchronize();
if (cudaDeviceSynchronize() != cudaSuccess) {
std::printf("ERR synchronizing state fingerprint\n");
return 1;
}
const int64_t L = (int64_t) live.size();
const strata::kernels::QsaShapes qs = [&] {
strata::kernels::QsaShapes s = strata::kernels::qsa_real_shapes();
s.n_head_kv = g.n_head_kv; s.head_dim = g.head_dim; s.idx_dim = g.idx_key_dim;
return s;
}();
bool hash_ok = true;
std::array<uint8_t, 65536> hash_buffer;
auto hash_dev = [&](const void* p, size_t bytes, uint64_t h) {
std::vector<uint8_t> b(bytes);
if (bytes) cudaMemcpy(b.data(), p, bytes, cudaMemcpyDefault); // VRAM or a streamed host copy
return fnv1a(b.data(), b.size(), h);
for (size_t offset = 0; hash_ok && offset < bytes;) {
const size_t n = std::min(hash_buffer.size(), bytes - offset);
// VRAM or a streamed host copy, with fixed diagnostic workspace.
if (cudaMemcpy(hash_buffer.data(), static_cast<const uint8_t*>(p) + offset, n, cudaMemcpyDefault) != cudaSuccess) {
hash_ok = false;
break;
}
h = fnv1a(hash_buffer.data(), n, h);
offset += n;
}
return h;
};
// the cells [c0, c1) of one int8 K or V pool ([page][kv_head][page_size][head_dim]), bytes per value `w`
auto hash_cells = [&](const void* pool, int64_t per_cell, int64_t c0, int64_t c1, uint64_t h) {
@@ -4386,6 +4413,10 @@ int main(int argc, char** argv) {
const int64_t mL = std::min<int64_t>(L, ms.max_cells);
for (const auto& [pool, w] : kv_arrays(ms))
if (pool != nullptr) h_mtp = hash_cells(pool, w, 0, mL, h_mtp);
if (!hash_ok) {
std::printf("ERR reading state fingerprint\n");
return 1;
}
std::fprintf(stderr, "strata serve: STATE_HASH L=%lld gdn=%016llx ple=%016llx tail=%016llx pooled=%016llx "
"kv=%016llx mtp=%016llx stale=%016llx dead=%016llx ple_prev=%d,%d\n", (long long) L,
(unsigned long long) h_gdn, (unsigned long long) h_ple, (unsigned long long) h_tail,