# Cutting Tokens by up to 63% (and Breaking Reasoning Ceilings) on a 6 GB RTX 4050

> Stacking LoopCD-Hidden + `pi` LoRA on Inkling 2 Mini

- **URL:** https://turingalab.in/blogs/loopcd-pi-lora-rtx4050-6gb/
- **Author:** Prajwal
- **Published:** 2026-11-30
- **Read Time:** 14 min read
- **Tags:** Local LLMs, LoopCD, LoRA, RTX 4050, PolyStrata, Coding Agents

## Why This Follow-Up Exists

Getting a 26.4B-parameter MoE model (a mixture-of-experts model, where only a small slice of the network runs per token) to run at 34+ tokens/second on a 6 GB RTX 4050 Laptop GPU solves the *hardware* problem — but anyone who has used a looped reasoning model inside a live coding agent knows there is a second bottleneck: **token waste and reasoning loops** (the model burning tokens second-guessing itself instead of doing the task).

Even at 35 tok/s, a model that burns 6,200 tokens second-guessing a regex, or writes 80 tokens of preamble before calling `bash`, still feels sluggish. Worse, on multi-constraint logic and regex tasks, looped models can spiral into repetitive self-doubt until they hit their reasoning budget and output a half-baked answer.

In this follow-up lab notebook, I tested two zero-VRAM-overhead upgrades on top of my tuned PolyStrata (`strata-poly`) RTX 4050 setup for **Inkling 2 Mini (`UD-Q2_K_XL`)**:

- **LoopCD-Hidden (Loop Contrastive Decoding, Apple arXiv:2610.02185):** a training-free decoding technique (no retraining needed) that extrapolates hidden states across recurrent loops at ~0% decode overhead.
- **Offline-Merged `pi` LoRA (`Inkling-2-Mini-pi-adapted-preview`):** a lightweight 26 MB attention adapter (a small fine-tuned add-on) trained specifically for snappy, action-oriented tool calling inside the `pi` coding agent — merged offline into the GGUF for 0% runtime overhead.

Across two controlled benchmark suites — including an execution-graded "hard" sweep across seven values of ω ∈ [0.0, 0.50] — stacking the merged `pi` LoRA with **ω = 0.25** delivered:

- **6/6 pass rate** on the execution-graded hard suite (the *only* configuration to clear 100%, beating both ω = 0.0 and ω = 0.50 at 5/6)
- **26% to 63% fewer completion tokens**, depending on task complexity
- **44% leaner tool-calling overhead** (`tool_bash_fix` dropped from 80 tokens down to 45)
- **Zero decode speed penalty** — actually rising to **34.75 tok/s average** (peaking at **39.2 tok/s**) on a 6 GB laptop GPU

## 1. The Two Techniques (and Why They Stack Cleanly)

### LoopCD-Hidden (Loop Contrastive Decoding)

Inkling 2 Mini is a Looped Transformer: it has 24 physical layers, with its 12 middle layers looped three times per token (48 effective layers). **LoopCD** exploits that recurrence without loading a second draft model or spending extra VRAM. Instead of taking the final loop's representation as-is, it contrasts the final loop (R) against the early loop (1) using a guidance weight ω:

- **LoopCD-Hidden:** blends hidden states right before the coda/LM head (the final output layer): h' = h_R + ω(h_R − h_1). Because it operates directly on the hidden state vector once per token, it adds effectively **0% tok/s overhead** and requires **0 extra bytes of VRAM**. PolyStrata exposes this natively via `--loopcd-hidden <omega>` (or `STRATA_INK_LOOPCD_HIDDEN=<omega>`).
- **LoopCD-Logits:** blends logits directly (z' = z_R + ω(z_R − z_1)), which supports adaptive ω at the cost of an extra coda/head pass.

### Stacking with the `pi` Harness LoRA

`Inkling-2-Mini-pi-adapted-preview` is a step-200 LoRA adapter (`Inkling-2-Mini-pi-lora-F16.gguf`, 26 MB) trained to sharpen Inkling 2 Mini's agentic behavior inside the `pi` coding harness.

Because the LoRA modifies attention weights while LoopCD operates at loop exit during decoding, the two are orthogonal (they touch different parts of the model). Prior community observations suggested that accuracy gains do not stack infinitely beyond LoopCD alone, **but** combining them cuts token usage dramatically and tightens tool calls — provided you don't over-suppress reasoning by setting ω too high.

## 2. Experimental Setup & Offline LoRA Merging

To keep every measurement apples-to-apples against my daily-driver 32K RTX 4050 config, all tests were isolated in a separate git worktree on dedicated port `8099` with identical hardware pinning and decoding parameters:

| Parameter | Value |
| --- | --- |
| Hardware | Lenovo LOQ, RTX 4050 Laptop (6 GB GDDR6, `sm_89`), i5-12450HX, 16 GB DDR5 |
| CPU Pinning | `taskset -c 0-7` + `--threads 4` (strictly P-cores) |
| Base Quant | `Inkling-2-Mini-UD-Q2_K_XL.gguf` (9.14 GB) |
| Engine Flags | `--max-context 32768 --vram-reserve-mib 256 --ram-experts-mib -1 --attn-requant q5_k --loop-bf16 --tail-skip 4 --kv fp8` |
| Prefix Cache | Isolated cache directory, `--pin-cache-mib 1024` |
| Decoding | Greedy (`temperature = 0.0`), `reasoning_effort: "medium"`, `max_tokens: 8192` |

### Why We Merged the LoRA Offline

`strata-poly` does not apply runtime LoRA adapters. Rather than viewing that as a limitation, merging the 26 MB F16 LoRA directly into a copy of the base GGUF via `llama-export-lora` is strictly better for a 6 GB GPU:

```bash
llama-export-lora \
  -m /mnt/ssd/Models/Inkling-2-Mini-UD-Q2_K_XL.gguf \
  -o /mnt/ssd/Models/Inkling-2-Mini-UD-Q2_K_XL-pi-merged.gguf \
  --lora ./adapters/pi-lora/Inkling-2-Mini-pi-lora-F16.gguf \
  -t 4
```

The merge touched **96 attention tensors** and copied the remaining tensors (all 3,072 MoE experts intact) straight through to the 744-tensor output file (`Inkling-2-Mini-UD-Q2_K_XL-pi-merged.gguf`). Result: **0% runtime adapter overhead** and the exact same VRAM footprint.

## 3. Phase 1: The 4-Arm A/B Benchmark (Suite 1)

Suite 1 tested 6 tasks designed to stress tool calling, concise coding/math accuracy, and known runaway-loop triggers:

1. `tool_bash_fix`: Emit a `bash` tool call running `pytest` with verbose + stop-on-first-failure flags.
2. `tool_no_call`: Answer a conceptual question (`merge sort` worst-case complexity) *without* triggering an unnecessary tool call.
3. `code_lru_bug`: Fix a missing `move_to_end` bug in a Python `OrderedDict` LRU cache.
4. `math_modulo_edge`: Compute 7^2026 mod 10 cleanly.
5. `loop_trap_constraints`: A 5-server spatial constraint puzzle (intentionally underspecified to test whether the model spirals or recognizes multiple valid orders).
6. `loop_trap_regex`: Write a single Python regex (no lookbehind) matching non-empty binary strings with an even number of `0`s and no `11` substring.

### Suite 1 Results (Per-Task Token Counts & Decode Speed)

| Task | Baseline (ω = 0) | LoopCD (ω = 0.25) | LoopCD (ω = 0.50) | Stacked (`pi` LoRA + ω = 0.50) |
| --- | --- | --- | --- | --- |
| `tool_bash_fix` | 80 tok (28.1 tok/s) | 64 tok (23.7 tok/s) | 66 tok (23.8 tok/s) | **45 tok** (27.1 tok/s) |
| `tool_no_call` | 65 tok (17.8 tok/s) | 56 tok (20.8 tok/s) | 55 tok (16.5 tok/s) | **56 tok** (20.8 tok/s) |
| `code_lru_bug` | 236 tok (22.1 tok/s) | 288 tok (24.3 tok/s) | 182 tok (20.0 tok/s) | **178 tok** (21.0 tok/s) |
| `math_modulo_edge` | 170 tok (27.3 tok/s) | 194 tok (28.5 tok/s) | 168 tok (24.0 tok/s) | **189 tok** (32.4 tok/s) |
| `loop_trap_constraints` | 1,995 tok (33.6 tok/s) | 1,443 tok (34.9 tok/s) | 1,424 tok (33.5 tok/s) | **1,490 tok** (36.3 tok/s) |
| `loop_trap_regex` | 6,258 tok (35.3 tok/s) | 6,299 tok (35.7 tok/s) | 3,039 tok (33.6 tok/s) | **1,297 tok** (35.8 tok/s) |
| **Suite Total** | **8,804 tok** | **8,344 tok (-5.2%)** | **4,934 tok (-44.0%)** | **3,255 tok (-63.0%)** |
| **Pass / Runaways** | 6/6 \| 0 runaways | 6/6 \| 0 runaways | 6/6 \| 0 runaways | 6/6 \| 0 runaways |
| **Avg Speed** | 27.37 tok/s | 27.98 tok/s | 25.23 tok/s | **28.90 tok/s** |

### The Catch We Caught Manually

On paper, `stacked_0.5` looked like an absolute blowout: **63% fewer tokens**, **79% shorter regex reasoning** (6,258 → 1,297 tokens), and **36.3 tok/s** peak decode.

When I inspected the raw outputs of the two loop traps, however, a subtle trade-off appeared:

- **`loop_trap_constraints` (10/10):** It didn't hallucinate or loop — it cleanly proved the constraints were underspecified and gave both exact valid orders (`A,B,C,E,D` and `A,B,D,C,E`).
- **`loop_trap_regex` (90% there, slightly rushed):** It produced `^(?=(?:[^0]*0[^0]*0)*$)(?:0|1(?!1))+$`. It avoided lookbehind and passed the four examples in the prompt, **but** it omitted a trailing `[^0]*` inside the positive lookahead — meaning valid strings ending in `1` (like `1` or `001`) would fail `re.fullmatch()`. It also miscounted `01010` as having two `0`s in its prose summary.

That single manual check saved us from blindly shipping ω = 0.50. It raised the real engineering question: **are we trading edge-case accuracy for speed at ω = 0.50, and is there a Goldilocks ω between 0.20 and 0.50?**

## 4. Phase 2: The Execution-Graded Hard Suite (ω Sweep)

To stop fooling ourselves with substring checks, I built an automated sweep harness (`run_omega_sweep.py`) that spawns `strata-poly` across seven values of ω ∈ {0.0, 0.20, 0.25, 0.30, 0.35, 0.40, 0.50} on the merged `pi` LoRA GGUF and grades 6 harder tasks **by actual execution**:

1. `hard_regex_exec`: Must compile with `re.compile()`, contain no lookbehind, and pass **10 unit tests** via `re.fullmatch()` — explicitly including `'1'`, `'001'`, `'010'`, `''`, `'0'`, `'1100'`, and `'01010'`.
2. `hard_code_exec`: Write `decode_str(s)` for nested `k[encoded]` strings; graded by `exec()` against 4 unit assertions (`'3[a2[c]]'`, `'10[a]'`, `'2[ab]3[c]d'`, `'abc'`).
3. `hard_math_exact`: Exact last two digits of 3^2026 mod 100 (answer: `29`).
4. `hard_logic_exact`: Uniquely constrained 5-server ordering (answer: `A,E,B,C,D`).
5. `hard_tool_escape`: Call `bash` with properly escaped regex `grep -rnE 'foo\(bar\)' src/`.
6. `hard_tool_precision`: Choose `read_file` over `bash` when inspecting `engine/src/poly/main.cpp`.

### Full ω Sweep Summary (Merged `pi` LoRA)

| ω | Pass Rate | Total Tokens | Avg Speed | `hard_regex_exec` Outcome |
| --- | --- | --- | --- | --- |
| `0.00` | 5/6 | 8,038 | 33.33 tok/s | Fail at 6,189 tok (failed on `'010'`) |
| `0.20` | 5/6 | 8,600 | 34.00 tok/s | Fail at 6,207 tok (failed on `''`) |
| **`0.25`** | **6/6** | **5,958** | **34.75 tok/s** | **PASS at 4,025 tok (38.2 tok/s)** |
| `0.30` | 5/6 | 7,931 | 33.97 tok/s | Fail at 6,186 tok (failed on `'0'`) |
| `0.35` | 5/6 | 8,066 | 31.82 tok/s | Fail at 6,190 tok (failed on `'1010'`) |
| `0.40` | 5/6 | 7,864 | 32.80 tok/s | Fail at 6,191 tok (failed on `'1010'`) |
| `0.50` | 5/6 | 7,889 | 33.67 tok/s | Fail at 6,185 tok (failed on `''`) |

### Per-Task Breakdown at the Winning Setting (ω = 0.25 + `pi` LoRA)

| Task | Result | Tokens | Decode Speed | Verified Output |
| --- | --- | --- | --- | --- |
| `hard_regex_exec` | **PASS** | 4,025 | 38.2 tok/s | Passed all 10 `re.fullmatch` cases |
| `hard_code_exec` | **PASS** | 688 | 35.3 tok/s | Passed all 4 `exec()` unit tests |
| `hard_math_exact` | **PASS** | 434 | 39.2 tok/s | `29` |
| `hard_logic_exact` | **PASS** | 661 | 37.0 tok/s | `A,E,B,C,D` |
| `hard_tool_escape` | **PASS** | 78 | 27.6 tok/s | `grep -rnE 'foo\(bar\)' src/` |
| `hard_tool_precision` | **PASS** | 72 | 31.2 tok/s | `engine/src/poly/main.cpp` |

### What the Failure Pattern Actually Revealed

1. **Everything except zero-tool regex passed 7 out of 7 times.** Coding (`decode_str`), modular arithmetic, logic deduction, shell escaping, and tool precision were rock-solid across every ω.
2. **The ~6,190-token reasoning ceiling:** Look at the token count on all six failed `hard_regex_exec` runs: `6189, 6207, 6186, 6190, 6191, 6185`. Because the prompt gave the model *no tools*, it tried to mentally simulate a regex engine across 10 edge cases in its head, burned its entire reasoning budget second-guessing itself, and dumped a broken pattern at the cutoff.
3. **Why ω = 0.25 won:** At `0.00` and `0.20`, the model lacked enough contrastive damping to break out of its self-doubt loop. At `0.30`–`0.50`, guidance over-extrapolated on top of the `pi` LoRA and still hit the ceiling with edge-case slips. **ω = 0.25 hit the exact sweet spot**: it converged in 4,025 tokens (-35% vs. the ceiling), passed all 10 regex assertions, cut total suite tokens by **25.9%** vs. LoRA-only (5,958 vs. 8,038), and achieved the highest average speed of the entire sweep (**34.75 tok/s**).

## 5. Production Hardening Inside `pi` (Verify-by-Execution)

Running a 2-bit, 5.4B-active MoE model on a 6 GB laptop for production builds requires being honest about where small local models shine and where they slip:

- **Strengths:** Fast multi-turn editing (34–39 tok/s), clean tool selection, accurate shell escaping, refactoring, and standard algorithms.
- **Weakness:** Zero-shot mental simulation of tricky state machines (complex regexes, subtle off-by-one invariants, bit-twiddling) when deprived of an interpreter.

A generic system prompt like *"always double-check your code"* actually makes this **worse** — it encourages the model to burn another 4,000 thinking tokens in its head. Instead, the fix inside `pi` is **Verify-by-Execution**: force the agent to offload edge-case verification from its weights to Python/bash.

I appended this concise policy block to `~/.pi/agent/AGENTS.md`:

```markdown
## Verification Policy (Mandatory)
- **Execute, never simulate:** Never mentally verify regexes, parsers, bit-twiddling, or edge-case logic. Immediately run a quick `python3 -c` assertion via `bash` covering: empty input, boundary cases, valid matches, and invalid rejections.
- **No silent assumptions:** Before finishing any code edit, run the relevant test suite (`pytest`, linter, or typecheck) via `bash` and confirm exit code 0.
- **Stop looping:** If you are unsure about an edge case after 2 paragraphs of reasoning, write a 5-line test script and run it instead of thinking further.
```

Paired with two operational rules for production work:

- **Append `--tail-skip 0` for critical PRs:** Daily interactive coding uses `--tail-skip 4` (+49% decode speed, ~98% top-1 token agreement). For high-stakes production logic, overriding with `--tail-skip 0` keeps 100% of routed experts intact.
- **Deterministic gates outside the model:** Always gate merges behind `pytest`, `ruff`/`mypy`, and a human `git diff` review.

## 6. Locking It Into Main PolyStrata (`main.cpp` Presets)

With ω = 0.25 validated, I baked `o.loopcd_hidden = 0.25f` directly into all three one-word RTX 4050 presets (`--rtx4050-32k`, `--rtx4050-64k`, `--rtx4050-100k`) in `engine/src/poly/main.cpp`:

```cpp
else if (a == "--rtx4050-32k" || a == "--rtx4050-64k" || a == "--rtx4050-100k") {
    const bool is100k = (a == "--rtx4050-100k");
    const bool isLong = is100k || (a == "--rtx4050-64k");
    o.max_context = is100k ? 102400 : (isLong ? 65536 : 32768);
    o.threads = 4;
    o.vram_reserve_mib = 256;
    o.ram_experts_mib = -1;
    o.attn_requant = "q5_k";
    o.loop_bf16 = true;
    o.tail_skip = 4;
    o.loopcd_hidden = 0.25f;
    o.kv_format = isLong ? KvFmt::kQ8_0 : KvFmt::kFp8;
#if !defined(_WIN32)
    if (isLong) setenv("STRATA_KV_INT8", "1", 0);
#endif
    std::fprintf(stderr,
                 "strata-poly: preset %s active (%s ctx, %s KV, q5_k attn, bf16 loop, tail-skip 4, loopcd-hidden 0.25)\n",
                 a.c_str() + 2, is100k ? "100K" : (isLong ? "64K" : "32K"), isLong ? "q8_0+int8" : "fp8");
}
```

Because `strata-poly` evaluates the preset block before the CLI flag loop, `--loopcd-hidden` and `STRATA_INK_LOOPCD_HIDDEN` are intentionally ignored under the one-word presets — the 0.25 value is baked in.

To use the merged `pi` LoRA GGUF, point the config at the merged file and drop the `--lora` flag:

```json
{
  "exe": "/home/prajwaldwivedi/PolyStrata/engine/build/strata-poly",
  "cwd": "/home/prajwaldwivedi/PolyStrata",
  "args": [
    "--model", "/mnt/ssd/Models/Inkling-2-Mini-UD-Q2_K_XL-pi-merged.gguf",
    "--rtx4050-32k",
    "--expert-prof", "/home/prajwaldwivedi/PolyStrata/cache/pins/expert-pins.json"
  ]
}
```

The `pi` harness config (`~/.pi/agent/models.json`) stays identical — same `baseUrl`, same `apiKey`, same model id. The only change is the model file behind the endpoint.

## 7. Final Verdict & Honest Caveats

**What works:**

- **6/6 pass rate** on the execution-graded hard suite — the only configuration to clear 100%.
- **26%–63% fewer completion tokens**, depending on task complexity.
- **44% leaner tool-calling overhead** (`tool_bash_fix`: 80 → 45 tokens).
- **Zero decode speed penalty** — 34.75 tok/s average, peaking at 39.2 tok/s.

**What doesn't:**

- **Zero-shot mental simulation of tricky state machines** (complex regexes, subtle off-by-one invariants, bit-twiddling) when deprived of an interpreter.
- **The ~6,190-token reasoning ceiling** on zero-tool regex tasks — the model burns its entire budget second-guessing itself.
- **No runtime LoRA support** in `strata-poly` — the offline merge is the only path.

**The honest takeaway:** LoopCD-Hidden + the merged `pi` LoRA is a genuinely excellent stack for *agentic* work — tool calling, shell escaping, refactoring, standard algorithms — where the model is allowed to execute and verify. It is not a magic fix for zero-shot mental simulation of tricky state machines.

The right production posture is **Verify-by-Execution**: force the agent to offload edge-case verification from its weights to Python/bash, gate merges behind `pytest`/`ruff`/`mypy`, and keep `--tail-skip 0` for critical PRs.

> **GitHub**
> https://github.com/prajwal257/PolyStrata/tree/rtx4050-6gb-presets
