colibri: size the context window (CTX) from n_ctx — fixes "prompt does not fit"

colibri's context is the CTX env (default 4096), DISTINCT from NGEN (max new tokens).
We only set NGEN, so any prompt over ~4095 tokens was rejected ("prompt does not fit
… CTX=4096") — coding clients with big system prompts always tripped it.

MuxEngine now sets CTX from the model's configured n_ctx (a caller/extra_env CTX still
wins). GLM-5.2 (glm_moe_dsa) uses compressed MLA KV held in host RAM, so large contexts
cost RAM, not VRAM — the model itself supports up to 1,048,576 positions.
Co-Authored-By: 's avatarClaude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoSpEthysqmseCc6Geizty
parent 63904b77
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
# Canonical product version for CoderAI — single source of truth. Both the API # Canonical product version for CoderAI — single source of truth. Both the API
# metadata and the admin web UI read from here. # metadata and the admin web UI read from here.
__version__ = "0.1.73" __version__ = "0.1.74"
# Configure the CUDA caching allocator BEFORE torch is imported anywhere. # Configure the CUDA caching allocator BEFORE torch is imported anywhere.
# expandable_segments lets the allocator return freed pages to the driver even # expandable_segments lets the allocator return freed pages to the driver even
......
...@@ -241,8 +241,15 @@ class MuxEngine: ...@@ -241,8 +241,15 @@ class MuxEngine:
def __init__(self, binary: Path, model_dir: str, *, cap: int = 8, def __init__(self, binary: Path, model_dir: str, *, cap: int = 8,
max_tokens: int = 1024, kv_slots: int = 1, env: Optional[dict] = None): max_tokens: int = 1024, kv_slots: int = 1, env: Optional[dict] = None):
kv_slots = max(1, min(16, int(kv_slots or 1))) kv_slots = max(1, min(16, int(kv_slots or 1)))
# colibri's context window is the CTX env (default 4096) — DISTINCT from NGEN
# (max new tokens). Without CTX the engine rejects any prompt over ~4095 tokens
# ("prompt does not fit … CTX=4096"), which breaks coding clients that send
# large system prompts + tools. Size CTX to the model's configured n_ctx (the
# value passed here). A caller-set CTX in the env still wins.
ctx = max(512, int(max_tokens or 4096))
child_env = dict(env or os.environ, SNAP=str(model_dir), SERVE="1", child_env = dict(env or os.environ, SNAP=str(model_dir), SERVE="1",
SERVE_BATCH="1", NGEN=str(max_tokens), KV_SLOTS=str(kv_slots)) SERVE_BATCH="1", NGEN=str(max_tokens), KV_SLOTS=str(kv_slots))
child_env.setdefault("CTX", str(ctx))
self.model_dir = str(model_dir) self.model_dir = str(model_dir)
self.kv_slots = kv_slots self.kv_slots = kv_slots
self.process = subprocess.Popen( self.process = subprocess.Popen(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment