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++
expert profile: refuse a header version other than 1, naming both numbers and the file
Léon Avic Simmons536db01af965
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 46a2ae4dd..b147be05e 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -477,6 +477,14 @@ if(STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP)add_test(NAME expert_profile_save_test COMMAND expert_profile_save_test)set_tests_properties(expert_profile_save_test PROPERTIES TIMEOUT 60)endif()+ # the profile header's version is enforced: a version other than 1 is refused by its number (CPU only)+ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/core/expert_profile_version_test.cpp")+ enable_testing()+ add_executable(expert_profile_version_test tests/core/expert_profile_version_test.cpp)+ target_link_libraries(expert_profile_version_test PRIVATE strata_engine)+ add_test(NAME expert_profile_version_test COMMAND expert_profile_version_test)+ set_tests_properties(expert_profile_version_test PROPERTIES TIMEOUT 60)+ endif()if(STRATA_BUILD_TESTS AND STRATA_NATIVE_EXPERTS)# native_experts.txt v2-v4 (the real packs' copies and the per-role shard column) and the arena filled from# synthetic GGUF shards at the real expert dimensionsdiff --git a/src/core/expert_cache.cpp b/src/core/expert_cache.cppindex f266f613e..9fe45205f 100644--- a/src/core/expert_cache.cpp+++ b/src/core/expert_cache.cpp@@ -89,6 +89,18 @@ bool read_expert_profile(const std::string& path, int64_t n_layers, int64_t n_exreturn false;}const uint32_t version = hdr[0], nl = hdr[1], ne = hdr[2], want = hdr[3], n_ranked = hdr[4];+ // the version comes first: the fields after it are only known to be these in a version 1 file, so a later+ // format is refused by its number rather than read as if it were this one+ if (version != 1) {+ std::fclose(f);+ char buf[256];+ std::snprintf(buf, sizeof buf,+ "read_expert_profile: %s is a version %u profile but this engine reads version 1 - it was "+ "written by a different release's tools/make_profile.py or --expert-profile-save",+ path.c_str(), version);+ err = buf;+ return false;+ }if ((int64_t) nl != n_layers || (int64_t) ne != n_expert) {std::fclose(f);char buf[256];@@ -123,7 +135,6 @@ bool read_expert_profile(const std::string& path, int64_t n_layers, int64_t n_exranked[(size_t) i] = {l, e};}slots = (int64_t) want;- (void) version; // a future format bumps it; the layout check above is what protects this reader todayreturn true;}diff --git a/tests/core/expert_profile_version_test.cpp b/tests/core/expert_profile_version_test.cppnew file mode 100644index 000000000..38767c05e--- /dev/null+++ b/tests/core/expert_profile_version_test.cpp@@ -0,0 +1,73 @@+// read_expert_profile refuses a profile whose header version is not 1, naming the version it found, the one it+// reads, and the file - before the geometry check, since the fields after the version are only known to be a+// version 1 layout. A version 1 file still loads. CPU only: no device is touched.+#include "strata/core/expert_cache.hpp"++#include <cstdint>+#include <cstdio>+#include <filesystem>+#include <string>+#include <utility>+#include <vector>++namespace {+int fails = 0;+void check(bool ok, const char* what) {+ if (!ok) {+ std::fprintf(stderr, "FAIL: %s\n", what);+ ++fails;+ }+}+// overwrite the little-endian uint32 `version` field at byte 4 (after "STRP") in place+bool set_version(const std::string& path, uint32_t v) {+ std::FILE* f = std::fopen(path.c_str(), "r+b");+ if (f == nullptr) return false;+ uint8_t le[4];+ for (int b = 0; b < 4; ++b) le[b] = (uint8_t) (v >> (8 * b));+ const bool ok = std::fseek(f, 4, SEEK_SET) == 0 && std::fwrite(le, 1, 4, f) == 4;+ return (std::fclose(f) == 0) && ok;+}+bool has(const std::string& s, const std::string& what) { return s.find(what) != std::string::npos; }+} // namespace++int main() {+ using Pair = std::pair<int32_t, int32_t>;+ const int64_t L = 2, E = 3;+ const std::vector<Pair> ranked = {{1, 2}, {0, 0}, {1, 0}};+ const std::filesystem::path dir = std::filesystem::temp_directory_path() / "strata_profile_version_test";+ std::filesystem::create_directories(dir);+ const std::string path = (dir / "profile.bin").string();+ std::string err;+ std::vector<Pair> back;+ int64_t slots = 0;++ // version 1, as --expert-profile-save and tools/make_profile.py write it: loads+ check(strata::core::write_expert_profile(path, L, E, ranked, err), "written");+ check(strata::core::read_expert_profile(path, L, E, back, slots, err) && back == ranked && slots == 3,+ "a version 1 profile loads");++ // the same bytes with the version field at 2: refused, naming 2, 1 and the file+ check(set_version(path, 2), "version field rewritten to 2");+ err.clear();+ check(!strata::core::read_expert_profile(path, L, E, back, slots, err), "a version 2 profile is refused");+ check(has(err, "read_expert_profile: ") && has(err, path), "the refusal names the file");+ check(has(err, "version 2") && has(err, "version 1"), "the refusal names the version found and the one read");++ // version 0 (a zeroed header) is not version 1 either+ check(set_version(path, 0), "version field rewritten to 0");+ check(!strata::core::read_expert_profile(path, L, E, back, slots, err) && has(err, "version 0"),+ "a version 0 profile is refused by its number");++ // the version is checked before the geometry: a version 2 file for another model is refused as version 2+ check(set_version(path, 2), "version field rewritten to 2 again");+ check(!strata::core::read_expert_profile(path, L + 1, E, back, slots, err) && has(err, "version 2"),+ "a version 2 profile of another geometry is refused by its version, not its geometry");++ // and back to 1: it loads again, so the refusal was the version field and nothing else+ check(set_version(path, 1), "version field rewritten to 1");+ check(strata::core::read_expert_profile(path, L, E, back, slots, err) && back == ranked, "version 1 loads again");++ std::filesystem::remove_all(dir);+ if (fails == 0) std::puts("expert_profile_version_test: OK");+ return fails == 0 ? 0 : 1;+}