Skip to content

About

Break silent thinking loops and verify hard answers on one GPU — LoopCD-Logits + Gated Cortheon + Patch 0050

Topics

Resources

Security policy

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

LoopCD-Cortheon

LoopCD-Cortheon

Get more right answers from a local reasoning model on one GPU, and stop it from burning minutes in silent thinking loops.

LoopCD-Cortheon combines LoopCD-Logits (trimming runaway internal thinking loops inside the engine), Gated Cortheon (hardware-aware routing and sandboxed Python/SymPy/Z3/code verification), and Patch 0050 (rescuing stray tool calls instead of dropping turns). Use the verification proxy on any local OpenAI-compatible server, or run the full stack natively on Linux + NVIDIA CUDA GPUs.


Why tokens per second is the wrong number

Reasoning models can get stuck thinking in circles: re-checking the same step or hitting length caps without writing an answer. A server can look fast on a tok/s counter while the model spends those tokens going nowhere.

What you actually wait for is time until a verified, working answer. Even though LoopCD-Logits lowers raw single-stream decode speed slightly (11–18%), real agent loops finish faster with fewer tokens, and hard tasks solve dramatically more often.

Start Here (Repo Map)

Goal Where to look
Run the stack right now Quickstart · GETTING_STARTED.md
See where we started → every patch → exact gains docs/HOW_WE_GOT_HERE.md · patches/README.md
Skip already-tested dead ends docs/EXPERIMENTS_AND_DECISIONS.md · docs/FAILURES_AND_LESSONS.md
Build on isolated wins & inference optimizations Promising Isolated Wins · Inference Optimization Roadmap
Inspect verified benchmarks & raw JSONLs docs/REPORT.md · results/history/ · 07_spark_adapter_cortheon_20261203

What you get

All numbers below are paired measurements in docs/REPORT.md on Inkling 2 Mini (EXL3 4.0 bpw + DFlash2) on a single 32 GB RTX PRO 4500 Blackwell:

Agents finish faster. On Python REPL coding agent tasks (n=12), LoopCD-Logits cut median time from 35.8 s → 18.1 s (−49.5%) and median tokens from 7,442 → 3,130 (−57.9%). Across all 36 multi-turn agent tasks, passes rose from 16/36 → 20/36; on jointly solved tasks, agents finished 17% faster with 29% fewer tokens, and degenerate loop traps dropped from 3 → 0.

More tasks solved. Gated Cortheon + LoopCD-Logits lifted overall accuracy across 8 benchmarks (n=336 paired) from 58.9% → 72.9% (+14.0 pp, 245/336, 95% CI +9.8 to +18.5, McNemar p < 0.0001):

  • LiveCodeBench hard: 20.0% → 45.0% (12/60 → 27/60)
  • AIME 2026: 76.7% → 93.3% (23/30 → 28/30)
  • HMMT Feb 2026: 56.7% → 73.3% (17/30 → 22/30)
  • SuperGPQA: 46.7% → 63.3% (28/60 → 38/60)

Open-ended synthesis actually finishes. On 10 open-ended tasks at an 8K budget: 0/10 → 9/10. Even against a plain run given twice the output budget (16K tokens), LoopCD-Cortheon improved 4/10 → 9/10 in 38% less median time (80.2 s → 50.1 s) and 52% fewer tokens (16,384 → 7,939).

Stray tool calls are rescued, not lost. Patch 0050 recovered stray tool/code turns in 6/6 A/B probes on each of two DGX Sparks with bit-identical non-stray generation.

Honest trade-offs. Raw decode speed drops ~11–18% with LoopCD-Logits on (11% on EXL3 C=1, up to 18% on NVFP4). Agent loops and open-ended synthesis still finish faster overall; hard competitive coding takes longer (~1.9–2.0× median wall time) to more than double solved problems (12 → 27 of 60).


Requirements (CUDA vs. Universal Proxy)

Mode What You Get Platform & Hardware Requirements
Option A — Cortheon Proxy Gated Cortheon routing, sandboxed B=4 Python/SymPy/Z3 & CodeForge consensus, client-side stray-call rescue Any OS (Linux, macOS, Windows), Python 3.11+, any local OpenAI-compatible server (Ollama, llama.cpp, vLLM, LM Studio, TensorFold)
Option B — Full Native CUDA Stack Everything in Option A + LoopCD-Logits engine decoding + SM-aware EXL3 kernels + Patch 0050 (required to reproduce the LoopCD + Cortheon numbers) Linux + NVIDIA CUDA GPU required: RTX 30 (sm_86), RTX 40 (sm_89), RTX 50 / RTX PRO Blackwell (sm_120), or DGX Spark (sm_121). Requires NVIDIA CUDA 13+ driver, nvcc 13.2+ (13.4 recommended for Blackwell), Zig 0.17.0, and 16 GB+ VRAM (3.3bpw) or 24–32 GB+ (4.0bpw + parallel verification)

(Python verification code executes inside an OS sandbox — bubblewrap (bwrap) on Linux or Seatbelt on macOS. See SECURITY.md for sandbox guarantees and cortheon guard's non-Python runner note.)


Quickstart

Let your coding agent set it up

Copy and paste this prompt into Claude Code, Codex, Cursor, or OpenCode:

Set up LoopCD-Cortheon on this machine:
1. Check `nvidia-smi`, OS, `python3`, `zig`, and `nvcc` first.
   - If I have an NVIDIA CUDA GPU (`sm_86`/`sm_89`/`sm_120`/`sm_121`) with CUDA 13+, `nvcc >= 13.2`, and Zig `0.17.0`, build the full native TensorFold stack (Option B):
     - Clone `https://github.com/Maxrio9/TensorFold.git` branch `inkling2-mini-sm-aware` (contains LoopCD-Logits, SM-aware EXL3 kernels, and Patch 0050 pre-applied).
     - Compile with `zig build native -Dsm=<detected_sm> -Dnvcc="$(command -v nvcc)" -Doptimize=safe` (add `-Dtarget=aarch64-linux-gnu.2.28` on DGX Spark `sm_121`).
     - Download `Maxrio/Inkling-2-Mini-exl3` (`3.3bpw` on 16 GB VRAM or `4.0bpw` on 24 GB+) plus DFlash2 (`Maxrio/Inkling-2-Mini-DFlash2-FP8` on Blackwell or `incoai/Inkling-2-Mini-DFlash2` on RTX 30/40) and start `tensorfold-native serve` with `--kv-cache fp8 --parallel 8 --loopcd-logits 0.5 --port 8080`.
   - Otherwise, use my already-running local OpenAI-compatible server as upstream (`http://127.0.0.1:8080/v1`, Ollama `:11434/v1`, or LM Studio `:1234/v1`).
2. Clone `https://github.com/Maxrio9/loopcd-cortheon.git`, create a venv with Python 3.11+ (`uv venv .venv && uv pip install --python .venv/bin/python -e .`), run `.venv/bin/cortheon doctor`, and test `.venv/bin/cortheon showdown --url http://127.0.0.1:8080/v1`.
3. Start `.venv/bin/cortheon proxy --upstream http://127.0.0.1:8080/v1 --port 18652` and tell me the ready OpenAI endpoint (`http://127.0.0.1:18652/v1`) and Cockpit URL (`http://127.0.0.1:18652/ui`).

Option A: One-command quickstart (works today with any local server)

Use this with Ollama, llama.cpp, vLLM, LM Studio, or TensorFold:

git clone https://github.com/Maxrio9/loopcd-cortheon.git && cd loopcd-cortheon && \
  (command -v uv >/dev/null && uv venv .venv && uv pip install --python .venv/bin/python -e . || { python3 -m venv .venv && .venv/bin/pip install -e .; }) && \
  .venv/bin/cortheon showdown --url http://127.0.0.1:8080/v1 && \
  .venv/bin/cortheon proxy --upstream http://127.0.0.1:8080/v1 --port 18652

Swap --upstream for your server (http://127.0.0.1:11434/v1 for Ollama, :8080/v1 for llama.cpp/TensorFold, :1234/v1 for LM Studio). Add --model <id> if your backend requires a specific model name.

  • Point your apps at http://127.0.0.1:18652/v1 using model cortheon (auto-routes), cortheon:reason, cortheon:code, cortheon:think, or cortheon:fast, or open the live dashboard at http://127.0.0.1:18652/ui.
  • Install /cortheon into Claude Code, Codex, Cursor, OpenCode, OMP, or Pi: .venv/bin/cortheon install-commands --harness all.
  • Run .venv/bin/cortheon doctor anytime to verify your sandbox (bwrap on Linux) and backend connection. See GETTING_STARTED.md for per-harness configs and challenge prompts.

(Option A gives you Gated Cortheon and client-side stray_rescue.py; for engine-level LoopCD-Logits, use Option B on NVIDIA CUDA.)

Option B: Full native stack on NVIDIA CUDA (LoopCD-Logits + Patch 0050 + Cortheon)

The branch inkling2-mini-sm-aware on Maxrio9/TensorFold already includes the full f69e94bd4 LoopCD-Logits engine base plus all 5 patches from patches/tensorfold-v5-sm-aware/ pre-applied (453914542):

1. Build TensorFold for your NVIDIA CUDA GPU (Linux, Zig 0.17.0, CUDA nvcc 13.2+ / 13.4 recommended for Blackwell):

git clone -b inkling2-mini-sm-aware https://github.com/Maxrio9/TensorFold.git
cd TensorFold
zig build native -Dsm=120 -Dnvcc="$(command -v nvcc)" -Doptimize=safe

Set -Dsm= to match your CUDA card: 86 (RTX 30), 89 (RTX 40), 120 (RTX 50 / RTX PRO Blackwell), 86,89,120 (multi-arch desktop), or -Dsm=121 -Dtarget=aarch64-linux-gnu.2.28 (DGX Spark). Binary builds at ./zig-out/native/bin/tensorfold-native.

2. Download weights (4.0bpw for 24–32 GB+, 3.3bpw for 16 GB) + DFlash2 drafter, and serve with LoopCD-Logits:

hf download Maxrio/Inkling-2-Mini-exl3 --revision 4.0bpw --local-dir ./inkling-mini
(cd ./inkling-mini && sha256sum --check --strict SHA256SUMS)
# Drafter: Maxrio/Inkling-2-Mini-DFlash2-FP8 (RTX 50 / RTX PRO / Spark) or incoai/Inkling-2-Mini-DFlash2 (RTX 30 / 40)
hf download Maxrio/Inkling-2-Mini-DFlash2-FP8 --local-dir ./inkling-mini/dflash2

export INKLING_THINK_CLOSE_NOTE=$'\n\nThinking budget reached; I act now.'
./zig-out/native/bin/tensorfold-native serve ./inkling-mini \
  --name inkling-2-mini --drafter ./inkling-mini/dflash2 \
  --kv-cache fp8 --parallel 8 --loopcd-logits 0.5 --port 8080

Then start cortheon proxy --upstream http://127.0.0.1:8080/v1 --port 18652 from your loopcd-cortheon checkout. Prefer automatic GPU detection & per-card VRAM sizing (16 GB / 24 GB / 32 GB / DGX Spark)? Use Maxrio9/inkling-2-mini-exl3-recipes.

Inspecting or replaying the 5 engine patches manually on base commit f69e94bd4

Both inkling2-mini-decode-hill (f69e94bd4, LoopCD-Logits base) and inkling2-mini-sm-aware (453914542, with all 5 patches applied) are published on Maxrio9/TensorFold. To audit or apply the series by hand:

git clone -b inkling2-mini-decode-hill https://github.com/Maxrio9/TensorFold.git && cd TensorFold
git am /path/to/loopcd-cortheon/patches/tensorfold-v5-sm-aware/*.patch

See patches/README.md for patch-by-patch details.


How it works

  • LoopCD-Logits. Inkling 2 Mini runs its shared recurrent core 3 times per token. LoopCD-Logits keeps all 3 core passes intact, runs an independent pass-1 reference coda with control/thinking delimiters shielded bitwise, and adaptively contrasts final vs. early logits (0.5). The model commits to answers instead of spinning in loops.
  • Gated Cortheon (v2.8.0 base). Built on upstream ashhart/Cortheon v2.8.0 (SkillForge card-free JIT discovery & ACE/GEPA playbook, ReasonForge v5, CodeForge v9 polyglot TIR, RepoForge v2, sandboxed Lean 4 prover, Cortheon Evolve v2, and optional Rust orchestrator). Requests route dynamically: easy prompts stay direct, hard math goes to reason (parallel execution-verified Python/SymPy/Z3 consensus with Wave-1 early abort), coding goes to CodeForge, Lean theorems go to lean, and architecture/design questions go to think. A hardware gate reads your GPU's concurrency scaling curve so verification only spends parallel streams where they pay off on a single card.
  • Patch 0050 (stray_rescue). Recovers usable tool calls or code blocks emitted outside expected parser delimiters — both inside TensorFold (TF_INKLING2_STRAY_CALLS=1) and client-side across Ollama, vLLM, SGLang, llama.cpp, and LM Studio (flash_forge/stray_rescue.py).

Benchmark summary

Test Baseline LoopCD-Cortheon Notes
36 multi-turn agent tasks (pass) 16/36 20/36 +11.1 pp, loop traps 3 → 0
Python REPL agents (median time / tokens) 35.8 s / 7,442 18.1 s / 3,130 LoopCD-Logits only (−49.5% wall / −57.9% tok)
8 benchmarks, n=336 paired items 198/336 (58.9%) 245/336 (72.9%) +14.0 pp, +55/−8, McNemar p < 0.0001
LiveCodeBench hard 12/60 (20.0%) 27/60 (45.0%) ~1.9–2.0× wall time
AIME 2026 23/30 (76.7%) 28/30 (93.3%)
HMMT Feb 2026 17/30 (56.7%) 22/30 (73.3%)
SuperGPQA 28/60 (46.7%) 38/60 (63.3%)
Open-ended synthesis (n=10) 0/10 (4/10 at 16K) 9/10 50.1 s vs 80.2 s median at 16K (−52% tokens)

Full paired statistics, confidence intervals, raw receipts, negative ablations (including LoopCD-Hidden, kernel hill-climb ledger, last_loop KV tradeoffs, raw CodeForge budget traps, and Spark adapter+Cortheon Phase 2D receipts) live in docs/HOW_WE_GOT_HERE.md, docs/REPORT.md, docs/FAILURES_AND_LESSONS.md, docs/EXPERIMENTS_AND_DECISIONS.md, and results/ (results/history/).

Where We Started → How We Got Here

We started from upstream ashhart/TensorFold + thinkingmachines/Inkling-2-Mini + raw ashhart/Cortheon. Out of the box, plain Inkling-2-Mini stalled in multi-turn loops (16/36 EXL3; 0/10 open-ended at 8K), while raw Cortheon ignored Inkling's <|end_message|> think-close tag (231/267 math caps burned), lost -20 pp on LCB v6 hard (14/60 vs 26/60), misrouted 10/10 MCQs and 8/10 IFBench prompts, and took a -30% raw decode hit from unbatched LoopCD unembed reads.

Five focused layers turned that baseline into main (see docs/HOW_WE_GOT_HERE.md for every delta and receipt):

  1. Think-close & LoopCD-Logits 0.5 + Kernel Hill-Climb (Maxrio9/TensorFold f69e94bd4): #5362 think-close fix (+15 pp math), bitwise-verified pass-1 coda contrasting (5,492/5,492 FP32 match), skip_ref_head + batched [final; ref] LM head + online softmax (161.4 → 568.0 tok/s C=1..16 on 4.0bpw EXL3) → EXL3 agents 16/36 → 20/36 (-49.5% Python REPL time), NVFP4 agents 14/36 → 20/36.
  2. SM-Aware EXL3 Kernels, CUDA Round Profiler & Patch 0050 (patches/tensorfold-v5-sm-aware/): Pre-applied on branch inkling2-mini-sm-aware (453914542), rescuing 6/6 stray tool/code calls on both DGX Sparks (6/6 bit-identical hashes).
  3. CodeForge CF-2 & ReasonForge cf3b (flash_forge/): Pruning w3_repair + Red-Team while keeping code_hc2=True pushed LCB v6 hard from 14/60 → 28/60 (46.7%) (p=0.00012); low-T PAL + 26k conditional deep_escalate lifted AIME26 to 28/30 and HMMT26 to 26/30 at -64..-65.6% median tokens.
  4. Default-direct Router + Hardware Gate (router.py, hardware.py): Fixed MCQ/constraint misroutes (94/94 = 100% live routing, 0/44 false escalations) and scaled streams by ScalingCurve (+14.0 pp across 336 paired D2 tasks, p < 0.0001; 0/10 → 9/10 open-ended).
  5. Strict bwrap Sandbox & Upstream v2.8.0 Upgrade (sandbox.py): Restricted ro_paths allow-list (blocking ~/.ssh), added universal client-side stray_rescue.py, fixed SIGALRM worker-thread math_verify, and rebased onto Cortheon v2.8.0.

Building On This Repo (Isolated Wins & Inference Optimization)

We did not fold half-tested ideas blindly into main. Several findings already show clear signal in isolated receipts and are left open for contributors to validate end-to-end (details in docs/HOW_WE_GOT_HERE.md):

  • Isolated / Not Yet Integrated Into main Defaults:
    • Self-router math under-escalation on unadapted weights (isolated DGX Spark diagnostic — not yet implemented in router.py): ReasonForge scored 12/12 (100%) on aime26 and 13/16 (81.2%) on hmmt_feb26 when escalated on base NVFP4, yet the router left 32/60 base math prompts in direct_default (65.6%). Adding a Stage-0 Olympiad-math trigger is untested but high-leverage.
    • Adapter + LoopCD + Gated Cortheon stacking (isolated DGX Spark NVFP4 receipts; see 07_spark_adapter_cortheon_20261203): mo_prime_cortheon hit 30/30 (100%) aime26 in 0.870× wall time vs base and cut lcb_hard (0.215× wall) and ifbench (0.498× wall) by 2×–4.6×; meanwhile pi-plus-prime shows the saturation boundary where single-pass already gets 28/30 & 22/30.
    • hc_tight_fast (num_streams=3, code_hc2=True) (isolated Desktop D3 receipt — main default stays 4): Matched 85/130 vs 86/130 (p=1.0) at 0.876× wall time and 0.905× tokens.
    • Decode MoE pruning (Patch 0004, default OFF) & multi-GPU v2.8.0 (SkillForge + parallel CodeForge v9): Flags (TF_INKLING2_MOE_TOPK, TF_INKLING2_MOE_BATCH_PRUNE) and v2.8.0 code paths exist and pass unit tests, but remain untested end-to-end on full multi-suite Inkling-2-Mini runs.
  • High-Leverage Inference Optimization Targets (Roadmap):
    1. Cut the 0.922 GB BF16 unembed read in LoopCD-Logits: Two-stage top-K shortlist or FP8/INT8 quantized pass-1 reference unembed, plus fused [final; ref] online-softmax GEMM epilogue (TF_INKLING2_PROFILE_ROUND=1).
    2. Cross-stream KV prefix sharing across Cortheon waves: Reuse identical system + problem KV pages across the 3–4 parallel streams in ReasonForge/CodeForge/ThinkForge and release pages immediately on Wave-1 early abort.
    3. DFlash2 × LoopCD=0.5 co-tuning & sm_121/sm_120 C=2 scaling: Pushing single-card curve.speedup_c2 above 1.50× (currently 1.10–1.29×) unlocks parallel CodeForge v9 without slowing single-GPU Python.
    4. LoopCD-Logits on varloop (2- vs 3-pass) & selective last_loop KV: Combine +34% 2-pass decode and 50% KV savings without hurting two_hop long-context fidelity.

Branches

  • main (default) — verified LoopCD-Logits + Patch 0050 + Gated Cortheon stack upgraded onto upstream Cortheon v2.8.0 (SkillForge, CodeForge v9, RepoForge v2, Lean 4 verifier, Evolve v2, Rust CLI); paired D1–D3 benchmark receipts were recorded on v2.4.0.
  • cortheon-v2.6.0 — preserved Cortheon v2.6.0 head-to-head comparison branch (79/130 vs 86/130, p = 0.09 on single GPU where stricter gating routes more lcb_hard items direct).

Repository layout


License and credits

MIT License — see LICENSE.

About

Break silent thinking loops and verify hard answers on one GPU — LoopCD-Logits + Gated Cortheon + Patch 0050

Topics

Resources

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages