Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
exclusive RAM/VRAM: build without Vulkan, and the victim tests' new arguments
JustVugg562785192417
diff --git a/c/deepseek_v4.c b/c/deepseek_v4.cindex b5fef8de..d9e17b9a 100644--- a/c/deepseek_v4.c+++ b/c/deepseek_v4.c@@ -9662,6 +9662,9 @@ void coli_v4_expert_store_prefill_pool(ColiExpertStore *store, int layer) {pthread_mutex_unlock(&state->mutex);}+int (*coli_v4_expert_store_ram_first)(int layer, int expert); /* exclusive RAM/VRAM: NULL unless a Vulkan tier sets it */+void (*coli_v4_expert_store_ram_gave)(void);+#ifdef COLI_VULKAN/* The Vulkan routed-expert tier's side of the store (deepseek_v4_internal.h). A* routing the device served never comes through lookup_hot, so it is counted here@@ -9670,8 +9673,6 @@ void coli_v4_expert_store_prefill_pool(ColiExpertStore *store, int layer) {* routing's, whichever side computed it. The store's hit and miss counters are not* touched: they describe the RAM cache. */int (*coli_v4_expert_store_device_tier)(int layer, int expert);-int (*coli_v4_expert_store_ram_first)(int layer, int expert);-void (*coli_v4_expert_store_ram_gave)(void);void coli_v4_expert_store_note_routed(ColiExpertStore *store, ColiExpertKey key) {if (!store || !store->state) return;diff --git a/c/deepseek_v4_internal.h b/c/deepseek_v4_internal.hindex 9e8a1bb5..cf826374 100644--- a/c/deepseek_v4_internal.h+++ b/c/deepseek_v4_internal.h@@ -684,6 +684,12 @@ int coli_deepseek_v4_expert_store_open_base(* Alternative registered ExpertStore backends safely ignore the request. */void coli_v4_expert_store_prefill_pool(ColiExpertStore *store, int layer);+/* Exclusive RAM/VRAM (vk_tier.h's vkt_ram_first): when set, a full RAM cache gives up+ * first a slot whose expert the device holds, and reports it through ram_gave. The+ * store's eviction reads them in every build; only a Vulkan one sets them. */+extern int (*coli_v4_expert_store_ram_first)(int layer, int expert);+extern void (*coli_v4_expert_store_ram_gave)(void);+#ifdef COLI_VULKAN/* The Vulkan routed-expert tier (vk_tier.c, Makefile.deepseek-v4 VK=1). The MoE* units reach it through this table, which the engine's own unit fills when@@ -720,10 +726,6 @@ uint64_t coli_v4_expert_store_record_bytes(ColiExpertStore *store);int coli_v4_expert_store_read_private(ColiExpertStore *store, ColiExpertKey key,unsigned char *buffer, ColiExpertView *view);extern int (*coli_v4_expert_store_device_tier)(int layer, int expert);-/* Exclusive RAM/VRAM (vk_tier.h's vkt_ram_first): when set, a full RAM cache gives up- * first a slot whose expert the device holds, and reports it through ram_gave. */-extern int (*coli_v4_expert_store_ram_first)(int layer, int expert);-extern void (*coli_v4_expert_store_ram_gave)(void);/* The dense chain (deepseek_v4_chain.h, COLI_VK_CHAIN): a layer's attention state as its* units keep it, so the chain can mirror it on the device and write back what a forwarddiff --git a/c/tests/test_eslot_inflight.c b/c/tests/test_eslot_inflight.cindex 464bffc6..5bfebf7a 100644--- a/c/tests/test_eslot_inflight.c+++ b/c/tests/test_eslot_inflight.c@@ -14,28 +14,28 @@ int main(void){ESlot slots[3]={0};for(int i=0;i<3;i++){ slots[i].slab=dummy; slots[i].used=(uint64_t)i+1; }- if(eslot_lru_victim(slots,3,3)!=0) return 1;+ if(eslot_lru_victim(slots,3,3,0)!=0) return 1;eslot_acquire(&slots[0]);- if(eslot_lru_victim(slots,3,3)!=1) return 2;+ if(eslot_lru_victim(slots,3,3,0)!=1) return 2;eslot_acquire(&slots[1]); eslot_acquire(&slots[2]);- if(eslot_lru_victim(slots,3,3)!=-1) return 3;+ if(eslot_lru_victim(slots,3,3,0)!=-1) return 3;eslot_release(&slots[0]); eslot_release(&slots[1]); eslot_release(&slots[2]);- if(eslot_lru_victim(slots,3,3)!=0) return 4;+ if(eslot_lru_victim(slots,3,3,0)!=0) return 4;/* #1034: slot svuotato da rss_guard (eid=-1, slab=NULL) */slots[1].eid=-1; slots[1].slab=NULL;- if(eslot_lru_victim(slots,3,2)!=0) return 5; /* live=2>=ecap=2: eviction, non crescita */- if(eslot_lru_victim(slots,3,3)!=1) return 6; /* live=2<ecap=3: il vuoto si puo' riusare */+ if(eslot_lru_victim(slots,3,2,0)!=0) return 5; /* live=2>=ecap=2: eviction, non crescita */+ if(eslot_lru_victim(slots,3,3,0)!=1) return 6; /* live=2<ecap=3: il vuoto si puo' riusare *//* slot libero che possiede ancora lo slab: riuso a costo zero, sempre preferito */slots[0].eid=-1;- if(eslot_lru_victim(slots,3,2)!=0) return 7;+ if(eslot_lru_victim(slots,3,2,0)!=0) return 7;/* prenotazione in volo (eid<-1): mai vittima, e conta come slab vivo */slots[0].eid=0; slots[2].eid=-5;- if(eslot_lru_victim(slots,3,2)!=0) return 8; /* live=2 (slot0 + prenotazione) >= ecap */- if(eslot_lru_victim(slots,3,3)!=1) return 9; /* live=2<ecap=3: di nuovo il vuoto */+ if(eslot_lru_victim(slots,3,2,0)!=0) return 8; /* live=2 (slot0 + prenotazione) >= ecap */+ if(eslot_lru_victim(slots,3,3,0)!=1) return 9; /* live=2<ecap=3: di nuovo il vuoto */puts("test_eslot_inflight: ok");return 0;diff --git a/c/tests/test_qwen36_cache_index.c b/c/tests/test_qwen36_cache_index.cindex f8757c10..b383abcd 100644--- a/c/tests/test_qwen36_cache_index.c+++ b/c/tests/test_qwen36_cache_index.c@@ -45,24 +45,24 @@ static void check_lookup_scaling(int cap) {static void check_victim(void) {Model m; init_cache(&m, 6, 3); LCache *lc = &m.cache[0]; lc->n = 3;for (int i = 0; i < 3; i++) { cache_publish(&m, 0, &lc->slots[i], i); lc->slots[i].used = (uint64_t)(i + 1); }- CHECK(slot_victim(lc, 0) == 0, "LRU victim is not the oldest slot");+ CHECK(slot_victim(lc, 0, 0) == 0, "LRU victim is not the oldest slot");Slot *h = expert_hold(&m, 0, 0); /* a resident expert: the hit path holds too */CHECK(h == &lc->slots[0] && slot_busy(h), "expert_hold did not hold the resident slot");- CHECK(slot_victim(lc, 0) == 1 && slot_victim(lc, 1) == 1, "a held slot was chosen for eviction");+ CHECK(slot_victim(lc, 0, 0) == 1 && slot_victim(lc, 0, 1) == 1, "a held slot was chosen for eviction");lc->slots[1].pinned = 1; slot_hold(&lc->slots[2]); slot_hold(&lc->slots[2]); /* routed twice in one run */- CHECK(slot_victim(lc, 0) == -1, "an unpinned victim came from pinned and held slots");- CHECK(slot_victim(lc, 1) == 1, "the pinned fallback missed the one pinned free slot");+ CHECK(slot_victim(lc, 0, 0) == -1, "an unpinned victim came from pinned and held slots");+ CHECK(slot_victim(lc, 0, 1) == 1, "the pinned fallback missed the one pinned free slot");cache_hide(&m, 0, &lc->slots[1]); /* now being loaded */- CHECK(slot_victim(lc, 1) == -1, "a slot being loaded was chosen for eviction");+ CHECK(slot_victim(lc, 0, 1) == -1, "a slot being loaded was chosen for eviction");slot_release(&lc->slots[2]);- CHECK(slot_victim(lc, 1) == -1, "one release freed a slot held twice");+ CHECK(slot_victim(lc, 0, 1) == -1, "one release freed a slot held twice");slot_release(&lc->slots[2]);- CHECK(slot_victim(lc, 1) == 2, "a fully released slot stayed unevictable");+ CHECK(slot_victim(lc, 0, 1) == 2, "a fully released slot stayed unevictable");slot_release(h);- CHECK(slot_victim(lc, 1) == 0, "the released oldest slot is not the victim");+ CHECK(slot_victim(lc, 0, 1) == 0, "the released oldest slot is not the victim");free_cache(&m);}