Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
test(v4): make the ExpertStore knobs reach getenv() on Windows
dajiaohuang9d86d9b30dd2
diff --git a/c/tests/test_deepseek_v4.c b/c/tests/test_deepseek_v4.cindex 70cb07eb..fe59308c 100644--- a/c/tests/test_deepseek_v4.c+++ b/c/tests/test_deepseek_v4.c@@ -5,6 +5,7 @@#include "../native_quant_fp4_rows16.h"#include <assert.h>+#include <errno.h>#include <fcntl.h>#include <limits.h>#include <math.h>@@ -15,6 +16,36 @@#include <string.h>#include <unistd.h>+/* compat.h maps setenv() onto SetEnvironmentVariableA, which updates the Win32+ * environment block -- but getenv() reads the CRT's own copy of it and never+ * sees the value. The three ExpertStore tests below set knobs that the engine+ * reads with getenv(), so on Windows the setenv() spelling was a no-op and they+ * ran with the very defaults they meant to override. The same trap is spelled+ * out in test_qwen36_ctx.c and test_inkling_shared_batch.c; _putenv_s updates+ * the copy getenv() reads. */+static void env_set(const char *name, const char *value) {+#ifdef _WIN32+ _putenv_s(name, value);+#else+ setenv(name, value, 1);+#endif+}++/* mkdtemp() hands out a scratch directory, the engine appends <snap>/.coli_usage+ * to it whenever it saves its expert history, and rmdir() then fails on a+ * directory that is no longer empty. Nothing was listening to that failure, so+ * a knob that did not arrive left the directory behind and the test still said+ * ok. Removing the fixture and checking the rmdir turns that back into a+ * failure. */+static int scratch_remove(const char *directory, const char *fixture) {+ unlink(fixture);+ if (rmdir(directory) == 0) return 0;+ fprintf(stderr, "scratch directory %s survived its test (errno=%d): the "+ "engine wrote into it, so the knobs this test sets did not "+ "reach getenv()\n", directory, errno);+ return 1;+}+/* ==== begin test_deepseek_v4_attention_cache.c ==== *//* umbrella headers *//* <math.h> */@@ -611,9 +642,9 @@ static int test_expert_store(void) {/* Native MinGW binaries do not resolve the MSYS /tmp mount. */char directory[] = "colibri-v4-store-XXXXXX";char path[256], error[256];- setenv("COLI_V4_AUTOPIN", "0", 1);- setenv("COLI_V4_SAVE_USAGE", "0", 1);- setenv("COLI_V4_ROWS16", "0", 1);+ env_set("COLI_V4_AUTOPIN", "0");+ env_set("COLI_V4_SAVE_USAGE", "0");+ env_set("COLI_V4_ROWS16", "0");if (!mkdtemp(directory)) { perror("mkdtemp"); return 1; }snprintf(path, sizeof(path), "%s/model.safetensors", directory);if (write_fixture(path) != 0) { perror("write_fixture"); return 1; }@@ -780,8 +811,7 @@ static int test_expert_store(void) {return 1;}store->ops->destroy(store);- unlink(path);- rmdir(directory);+ if (scratch_remove(directory, path)) return 1;puts("DeepSeek-V4 ExpertStore tests: ok");return 0;}@@ -808,9 +838,9 @@ static int test_expert_store_prefill_pool(void) {enum { LAYERS = 2, EXPERTS = 8, SLOTS_PER_LAYER = 6 };char directory[] = "colibri-v4-pool-XXXXXX";char path[256], error[256];- setenv("COLI_V4_AUTOPIN", "0", 1);- setenv("COLI_V4_SAVE_USAGE", "0", 1);- setenv("COLI_V4_ROWS16", "0", 1);+ env_set("COLI_V4_AUTOPIN", "0");+ env_set("COLI_V4_SAVE_USAGE", "0");+ env_set("COLI_V4_ROWS16", "0");if (!mkdtemp(directory)) { perror("mkdtemp pool"); return 1; }snprintf(path, sizeof(path), "%s/model.safetensors", directory);if (write_fixture_layers(path, LAYERS, EXPERTS)) {@@ -956,8 +986,7 @@ static int test_expert_store_prefill_pool(void) {failed = 1;}store->ops->destroy(store);- unlink(path);- rmdir(directory);+ failed |= scratch_remove(directory, path);if (failed) return 1;puts("DeepSeek-V4 ExpertStore prefill pool: ok ""(A/B bytes 816->408, second sweep=0 reads, warm entries + decode reserve retained)");@@ -1030,9 +1059,9 @@ static int run_expert_miss_scaling_case(const char *directory, int experts,static int test_expert_store_miss_scaling(void) {char directory[] = "colibri-v4-scaling-XXXXXX";char path[256];- setenv("COLI_V4_AUTOPIN", "0", 1);- setenv("COLI_V4_SAVE_USAGE", "0", 1);- setenv("COLI_V4_ROWS16", "0", 1);+ env_set("COLI_V4_AUTOPIN", "0");+ env_set("COLI_V4_SAVE_USAGE", "0");+ env_set("COLI_V4_ROWS16", "0");if (!mkdtemp(directory)) { perror("mkdtemp scaling"); return 1; }snprintf(path, sizeof(path), "%s/model.safetensors", directory);if (write_fixture_experts(path, 256)) {@@ -1043,8 +1072,7 @@ static int test_expert_store_miss_scaling(void) {int result = run_expert_miss_scaling_case(directory, 256, 44) ||run_expert_miss_scaling_case(directory, 256, 104) ||run_expert_miss_scaling_case(directory, 256, 208);- unlink(path);- rmdir(directory);+ result |= scratch_remove(directory, path);if (result) return 1;puts("DeepSeek-V4 ExpertStore miss scaling: ok ""(44/104/208 slots=1 probe each)");