Skip to content

Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.

ds41 serve: size the auto tier reserve from measured post-load growth (4.5 GiB runtime, was 1.5) and pace the pool allocation (#130)

Yaniss Amazouz396959b2bd01
diff --git a/exllamav3/modules/expert_store.py b/exllamav3/modules/expert_store.py
index e037354..e21f61f 100644
--- a/exllamav3/modules/expert_store.py
+++ b/exllamav3/modules/expert_store.py
@@ -851,6 +851,7 @@ class ExpertStore:
remaining = max(self.budget - used, 0)
tot = sum(c.total_bytes for c in new)
dev = self.device
+ alloc_pace = float(os.environ.get("EXL3_EXPERT_ALLOC_GIBPS", "6")) * (1 << 30) # pool allocation pace, bytes/s (0 = unpaced)
shares = self._split_budget(new, remaining)
for c in new:
share = shares[c.cid]
@@ -862,6 +863,8 @@ class ExpertStore:
for i in range(nch):
n = min(c.spc, c.nslots - i * c.spc)
c.chunks.append(torch.empty(n * c.slot_bytes, dtype = torch.uint8, device = dev))
+ if alloc_pace:
+ time.sleep(c.chunks[-1].numel() / alloc_pace) # a 90 GiB pool in 5 s reads as a memory runaway to host watchdogs
c.slot_addr = np.array(
[c.chunks[s // c.spc].data_ptr() + (s % c.spc) * c.slot_bytes for s in range(c.nslots)], dtype = np.int64)
c.owner_layer = np.full(c.nslots, -1, dtype = np.int32)
@@ -950,6 +953,7 @@ class ExpertStore:
need = max(c.entry_bytes for c in self.classes.values())
ring = self.ring_n * _ceil(need, ALIGN)
cap = float(os.environ.get("EXL3_EXPERT_BUDGET_MAX_GIB", "inf")) * (1 << 30)
+ print(f" -- expert store: auto budget inputs: free {free / 2**30:.1f} GiB, reserve {self.reserve_gib:.1f} GiB, ring {ring / 2**30:.1f} GiB", flush = True)
return int(max(min(free - self.reserve_gib * (1 << 30) - ring, cap), 0))
def _fd(self, fid: int) -> int:
diff --git a/tools/ds41/ds41_env.sh b/tools/ds41/ds41_env.sh
index 283ef73..338853c 100644
--- a/tools/ds41/ds41_env.sh
+++ b/tools/ds41/ds41_env.sh
@@ -48,7 +48,7 @@ pack_gib=$(du -cbL "$DS41_PACK"/*.safetensors 2>/dev/null | tail -1 | awk '{prin
avail=$(mem_gib)
budget_set=${DS41_BUDGET_GIB:+1}
# DS41_BUDGET_GIB=auto: the pool takes what is free AFTER the non-expert weights are loaded, minus a reserve for what grows later:
-# prefill workspace (chunk/4096 + 6 GiB: peak torch use above the weights, measured 3-7 GiB at chunk 4096 on 8K-80K prompts, 8 GiB at chunk 32768), prefix snapshots (DS41_PFX_GIB, 4), KV + runtime (1.5), margin (DS41_AUTO_MARGIN_GIB, 2)
+# prefill workspace (chunk/4096 + 6 GiB: peak torch use above the weights, measured 3-7 GiB at chunk 4096 on 8K-80K prompts, 8 GiB at chunk 32768), prefix snapshots (DS41_PFX_GIB, 4), runtime = what the serve allocates AFTER the pool is sized: KV, Engram and drafter buffers (3.1 GiB of GTT) + python heap growth (1.4 GiB), measured at ctx 131072 draft 5 (DS41_RUNTIME_GIB, 4.5), margin (DS41_AUTO_MARGIN_GIB, 2)
# Default since 20/10 (briefs/ds41_pool.md): auto, 86 GiB pool vs 78 on a quiet box, -13.5 % GB read per session, tokhash identical.
if [ "${DS41_BUDGET_GIB:-auto}" = auto ]; then
DS41_AUTO=1; DS41_BUDGET_GIB=$(( avail - 30 ))
@@ -63,7 +63,7 @@ if [ "$DS41_TIER" = 1 ]; then
export EXL3_EXPERT_RING=${EXL3_EXPERT_RING:-128} # pinned staging entries (12.7 MiB each): 128 = 1.6 GiB instead of 4 GiB at the old 320
if [ "${DS41_AUTO:-}" = 1 ]; then
export EXL3_EXPERT_BUDGET_GIB=auto
- export EXL3_EXPERT_RESERVE_GIB=$(LC_ALL=C awk -v c="${DS41_CHUNK:-4096}" -v p="${DS41_PFX_GIB:-4}" -v m="${DS41_AUTO_MARGIN_GIB:-2}" 'BEGIN{printf "%.1f", c/4096+6+p+1.5+m}')
+ export EXL3_EXPERT_RESERVE_GIB=$(LC_ALL=C awk -v c="${DS41_CHUNK:-4096}" -v p="${DS41_PFX_GIB:-4}" -v m="${DS41_AUTO_MARGIN_GIB:-2}" -v r="${DS41_RUNTIME_GIB:-4.5}" 'BEGIN{printf "%.1f", c/4096+6+p+r+m}')
fi
export EXL3_EXPERT_HALFLIFE=${EXL3_EXPERT_HALFLIFE:-16}
export EXL3_EXPERT_AHEAD=${EXL3_EXPERT_AHEAD:-0}