Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
Foresight swap: STRATA_FS_VERIFY test mode (read every landed slot back, compare with its source)
Andy44f650f972fd
diff --git a/include/strata/core/foresight_swap.hpp b/include/strata/core/foresight_swap.hppindex 92bb631b7..a689f8fc5 100644--- a/include/strata/core/foresight_swap.hpp+++ b/include/strata/core/foresight_swap.hpp@@ -14,7 +14,8 @@// plan resident layers without the host).//// Switches: STRATA_FS_SLOTS (per layer and card), STRATA_FS_BUDGET (copies per card per finished window, default 32),-// STRATA_FS_ADMIT (misses within the last 4 windows before an expert is copied, default 1), STRATA_FS_DEPTH.+// STRATA_FS_ADMIT (misses within the last 4 windows before an expert is copied, default 1), STRATA_FS_DEPTH,+// STRATA_FS_VERIFY=1 (test mode: every slot is read back and compared with its source the first time it is used).#include <atomic>#include <condition_variable>#include <cstdint>@@ -58,6 +59,8 @@ struct ForesightSwap {std::atomic<bool> failed{false};// counters (dispatch thread)uint64_t hits = 0, copies = 0, busy = 0, over_budget = 0, pending = 0;+ bool verify = false; ///< STRATA_FS_VERIFY=1: read every landed slot back and compare (slow, tests)+ uint64_t verify_ok = 0, verify_bad = 0;/// Allocates the slots on each card and starts the filler. `card_of_layer[l]` indexes `devices` (CUDA ids).bool init(int slots_per_layer, int64_t layers, int64_t experts, const std::vector<int>& card_of_layer,diff --git a/src/core/expert_source.cpp b/src/core/expert_source.cppindex 8dc53de56..1f7f66512 100644--- a/src/core/expert_source.cpp+++ b/src/core/expert_source.cpp@@ -4138,6 +4138,21 @@ bool ForesightSwap::take(int64_t layer, int32_t expert, unsigned long long& ptr)}sl.ready = true;sl.loading = false;+ if (verify) { // test mode: the bytes the GPU will read must be the expert's own+ std::vector<uint8_t> back((size_t) sl.bytes);+ const OnDevice on(layer_dev[(size_t) layer]);+ const bool same = cudaMemcpy(back.data(), (const void*) sl.dptr, (size_t) sl.bytes, cudaMemcpyDeviceToHost) ==+ cudaSuccess && std::memcmp(back.data(), sl.src, (size_t) sl.bytes) == 0;+ if (same) ++verify_ok;+ else {+ cudaGetLastError();+ ++verify_bad;+ sl.ready = false; // never serve it+ where[(size_t) (layer * n_expert + expert)] = -1;+ sl.expert = -1;+ return false;+ }+ }}sl.last_ref = completed.load(std::memory_order_acquire);ptr = sl.dptr;@@ -4191,12 +4206,14 @@ void ForesightSwap::note_miss(ExpertSource* src, int64_t layer, int32_t expert)}std::string ForesightSwap::report() const {- char buf[256];+ char buf[320];std::snprintf(buf, sizeof buf, "foresight swap: %llu experts served from the swap space, %llu copies, %llu not landed "- "yet, %llu no free slot, %llu over budget",+ "yet, %llu no free slot, %llu over budget%s",(unsigned long long) hits, (unsigned long long) copies, (unsigned long long) pending,- (unsigned long long) busy, (unsigned long long) over_budget);- return buf;+ (unsigned long long) busy, (unsigned long long) over_budget, verify ? "" : "");+ std::string r = buf;+ if (verify) r += ", verified " + std::to_string(verify_ok) + " ok / " + std::to_string(verify_bad) + " BAD";+ return r;}ForesightSwap* foresight_swap_from_env(int64_t layers, int64_t experts, const std::vector<int>& card_of_layer,@@ -4214,6 +4231,7 @@ ForesightSwap* foresight_swap_from_env(int64_t layers, int64_t experts, const stf->budget = env_int("STRATA_FS_BUDGET", 32, 1);f->admit = env_int("STRATA_FS_ADMIT", 1, 1);f->depth = env_int("STRATA_FS_DEPTH", 4, 2);+ f->verify = env_int("STRATA_FS_VERIFY", 0, 0) != 0;std::string err;if (!f->init(std::min(slots, 64), layers, experts, card_of_layer, devices, err)) {std::fprintf(stderr, "strata serve: foresight swap: %s - swap space off\n", err.c_str());