Focal Macro-Recurrence is a zero-training, architecture-agnostic test-time latent manifold refinement framework implemented directly within the C++20 / GGML inference engine (llama.cpp).
Standard autoregressive language models generate tokens through a sequential feedforward pass across
Focal Macro-Recurrence addresses this limitation by introducing inference-time recursive refinement localized to the semantic reasoning sub-manifold (Focal Reasoning Nexus,
- A Focal Macro-Reasoning Loop that refines latent representations across multiple passes over the reasoning layers.
-
Nesterov-Accelerated Latent Momentum (NALM) (
$\mu$ ) to accelerate trajectory convergence towards optimal fixed points. - An Exit Damping Projection (
$\alpha_{\text{exit}}$ ) stabilizing output logit variance against anchor states. - A Key-Value Cache Invariant ensuring
$O(1)$ cache allocation without memory expansion.
For the complete formal mathematical specification, proofs, and error bounds, refer to WHITE_PAPER.md (or docs/focal_dual_stream_paper.md).
[Layer 0 ... l_start-1] ──> h_0 (State Anchor)
│
▼
Pass 1: h^(1) = G_nexus(h_0)
│
▼
Pass 2: h^(2) = G_nexus((1 - b_alpha)*h_0 + b_alpha*h^(1) + mu*Delta_m)
│
▼
Exit Damping: h_final = (1 - alpha_exit)*h^(1) + alpha_exit*h^(2)
│
▼
[Layer l_end+1 ... L] ──> Logits
Given total layer depth
-
State Anchoring: $$\mathbf{h}0 = \mathbf{h}{l_{\text{start}}-1} \in \mathbb{R}^{B \times S \times d}$$
-
Recursive Latent Refinement (
$k \ge 2$ ): $$\mathbf{s}{\text{orig}} = (1 - b\alpha) \mathbf{h}0, \quad \mathbf{s}{\text{cur}} = b_\alpha \mathbf{h}^{(k-1)}$$ $$\mathbf{h}{\text{in}}^{(k)} = \mathbf{s}{\text{orig}} + \mathbf{s}{\text{cur}} + \mu (\mathbf{s}{\text{cur}} - \mathbf{s}{\text{orig}})$$ $$\mathbf{h}^{(k)} = \mathcal{G}{\text{nexus}}(\mathbf{h}_{\text{in}}^{(k)})$$ -
Exit Damping Projection: $$\mathbf{h}{\text{final}} = (1 - \alpha{\text{exit}}) \mathbf{h}^{(1)} + \alpha_{\text{exit}} \mathbf{h}^{(K)}, \quad \alpha_{\text{exit}} = 0.62$$
Focal Dual-Stream Recurrence is implemented for the following model families:
- LLaMA Family (
src/models/llama.cpp): LLaMA, LLaMA 2, LLaMA 3, LLaMA 3.1, LLaMA 3.2, LLaMA 3.3. - Qwen Family (
src/models/qwen2.cpp,src/models/qwen3.cpp,src/models/qwen35.cpp): Qwen 2, Qwen 2.5, Qwen 3, Qwen 3.5 (Dense and Hybrid Gated Delta Net). - Qwen MoE Family (
src/models/qwen2moe.cpp,src/models/qwen3moe.cpp,src/models/qwen35moe.cpp): Sparse mixture-of-experts architectures. - Gemma Family (
src/models/gemma2.cpp): Gemma 2 (9B, 27B) with sliding-window and global attention. - Mistral Family (
src/models/mistral3.cpp): Mistral 7B (v0.1, v0.2, v0.3) and Mixtral 8x7B / 8x22B.
- CMake
$\ge 3.18$ - C++20 compliant compiler (
gcc$\ge 11$ ,clang$\ge 14$ , orMSVC$\ge 2019$ ) - Accelerators (Optional): CUDA Toolkit
$\ge 12.0$ , ROCm$\ge 5.6$ , Vulkan SDK, or Metal
cmake -B build -DGGML_CUDA=ON -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release -j$(nproc)cmake -B build -DGGML_VULKAN=ON -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release -j$(nproc)cmake -B build -DGGML_METAL=ON -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release -j$(sysctl -n hw.ncpu)cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release -j$(nproc)Recurrence behavior is configured via environment variables or engine parameters:
| Variable | Type | Default | Description |
|---|---|---|---|
RECURRENT_BLOCK_LOOPS |
Integer | 2 |
Number of macro passes through the Focal Reasoning Nexus ( |
RECURRENT_DUAL_STREAM |
Boolean | 1 |
Enables adversarial counter-stream evaluation ( |
RECURRENT_BLOCK_START_PCT |
Integer | 40 |
Starting layer percentile for the Reasoning Nexus ( |
RECURRENT_BLOCK_END_PCT |
Integer | 66 |
Ending layer percentile for the Reasoning Nexus ( |
RECURRENT_BLOCK_ALPHA |
Float | 0.20 |
Primary recursive refinement step coefficient ( |
RECURRENT_COUNTER_BETA |
Float | 0.06 |
Adversarial counter-perturbation displacement scale ( |
RECURRENT_BLOCK_EXIT_ALPHA |
Float | 0.62 |
Exit projection consensus interpolation weight ( |
# Launch OpenAI-compatible API server with Focal Dual-Stream active
RECURRENT_BLOCK_LOOPS=2 RECURRENT_DUAL_STREAM=1 ./build/bin/llama-server \
-m models/qwen2.5-coder-7b-instruct-q4_k_m.gguf \
--port 8080 \
--ctx-size 8192 \
-ngl 99A standalone benchmarking harness is provided in eval/ for empirical verification on academic reasoning splits.
# Evaluate baseline (clean upstream)
python3 eval/run_gsm8k.py --mode baseline --limit 100 --port 8080 --output eval/baseline_100.json
# Evaluate Focal Dual-Stream
python3 eval/run_gsm8k.py --mode dualstream --limit 100 --port 8080 --output eval/dualstream_100.jsonpython3 eval/sync_doc_params.pyEvaluated on Qwen 2.5 Coder 7B Instruct (Q4_K_M, greedy decoding
| Benchmark | Baseline (b10485) |
Focal Dual-Stream | Delta ( |
Statistical Significance |
|---|---|---|---|---|
| GSM8K ( |
||||
| MBPP ( |
||||
| SWE-bench Lite ( |
@article{ryzen2026focaldualstream,
title={Focal Dual-Stream Recurrence: Inference-Time Latent Manifold Refinement for Autoregressive Transformers},
author={Ryzen Architecture Research Group},
journal={Technical Report},
year={2026}
}This project is licensed under the MIT License. See LICENSE for details.