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.
Python amdapple-siliconcudadeepseekexl3exllamav3glminferencellmllm-inferencelocal-llmnvidiaopenai-apiquantizationqwenrocmstrix-halo
evalgate: long-period loop rule for thinking (degenerate windows, not code redrafts) (#178)
Yaniss Amazouza0995f46f6cf
diff --git a/tools/evalgate/loops.py b/tools/evalgate/loops.pyindex 1aa807b..67483fb 100644--- a/tools/evalgate/loops.py+++ b/tools/evalgate/loops.py@@ -30,6 +30,27 @@ def is_loop(text):return zlib_low(text) and max_span_repeat(text) >= SPAN_MIN+LINE_MIN = 40+DEG_WIN, DEG_STEP, DEG_MIN_LINES, DEG_DISTINCT, DEG_ZMIN, DEG_ZRATIO = 10000, 1000, 20, 0.7, 4000, 0.27+++def degenerate(text):+ """Long-period loop rule for thinking text: end offset of the first checkpoint (every DEG_STEP characters, plus the end)+ where the last DEG_WIN characters are degenerate, else None. Degenerate = at least DEG_MIN_LINES lines of LINE_MIN or more+ non-space characters with fewer than DEG_DISTINCT of them distinct, or (DEG_ZMIN characters or more) a zlib ratio below+ DEG_ZRATIO. The tail rules above are blind to loops whose period exceeds their window (a 30-line block repeated).+ A model that redrafts the same code two or three times while thinking is not a loop: its window stays varied.+ Calibrated on 51 sampled 12K probe runs: degenerate loops <= 0.26 distinct (zlib <= 0.12), redrafts >= 0.82 (>= 0.31)."""+ for end in list(range(DEG_STEP, len(text), DEG_STEP)) + [len(text)]:+ s = text[max(end - DEG_WIN, 0):end]+ lines = [l.strip() for l in s.split("\n") if len("".join(l.split())) >= LINE_MIN]+ if len(lines) >= DEG_MIN_LINES and len(set(lines)) < DEG_DISTINCT * len(lines):+ return end+ if len(s) >= DEG_ZMIN and len(zlib.compress(s.encode())) / len(s.encode()) < DEG_ZRATIO:+ return end+ return None++def summarize(recs):"""recs: run_suite jsonl records (_id, text, hit_cap) -> {n, loops, ids, capped}."""ids = sorted(r["_id"] for r in recs if is_loop(r["text"]))diff --git a/tools/evalgate/test_loops.py b/tools/evalgate/test_loops.pynew file mode 100644index 0000000..c203a5d--- /dev/null+++ b/tools/evalgate/test_loops.py@@ -0,0 +1,29 @@+import random++from tools.evalgate.loops import degenerate+++def _varied(n, seed=0):+ rnd = random.Random(seed)+ word = lambda: "".join(rnd.choice("abcdefghijklmnopqrstuvwxyz") for _ in range(rnd.randint(3, 9)))+ return "\n".join(f"Line {i}: " + " ".join(word() for _ in range(10)) for i in range(n))+++def test_block_repeated_beyond_tail_window_fires():+ block = "\n".join(f"Step {i}: check the collision between the player and the wall segment number {i}" for i in range(30))+ text = "Intro paragraph.\n" + (block + "\n") * 4+ assert degenerate(text) is not None+++def test_varied_thinking_does_not_fire():+ assert degenerate(_varied(400)) is None+++def test_three_code_redrafts_inside_varied_thinking_do_not_fire():+ code = "\n".join(["const o=AC.createOscillator(),g=AC.createGain();", "ctx.setTransform(dpr,0,0,dpr,0,0); // reset the canvas"])+ text = _varied(60, 1) + "\n" + code + "\n" + _varied(60, 2) + "\n" + code + "\n" + _varied(60, 3) + "\n" + code + "\n" + _varied(60, 4)+ assert degenerate(text) is None+++def test_short_text_does_not_fire():+ assert degenerate("ok\n" * 50) is None