A CPU Inside an LLM: Zero-Gradient Compilation of Exact Circuits into Pretrained Weights
Organizations: Independent Researcher.
Abstract
Pretrained language models (LMs) remain unreliable on exact multi-digit arithmetic without gradient fine-tuning or external tool interpreters. We introduce closed-form, zero-gradient circuit-grafting primitives that compile deterministic computation directly into pretrained LM weights using zero training examples and zero runtime hooks, while bounding per-layer normalization drift and preserving natural-language (NL) competence. Our construction combines three analytical mechanisms: (1) two-layer Mellin-GLU quadrature over bias-free SwiGLU/GeGLU layers, turning unknown per-token RMSNorm scaling into translation along a log-spaced gate grid ( dynamic range) with IEEE 754 error bounds; (2) cross-token scale cancellation via signed Chebyshev Indefinite-RoPE self-sink attention and memoryless SiLU-antisymmetric GatedDeltaNet shifts; and (3) axis-aligned width extension () with norm compensation, Base-1000 canonical BPE emission, and differential tied unembeddings. An automated 5-stage compiler synthesizes 4-8 digit signed circuits in constant depth alongside 3-literal Boolean (100%, ; plus 42-layer Gemma 4 E4B audits) and 5-bit Majority/Parity (100%) circuits. On 6-digit arithmetic (, BF16), IBM Granite 4.2 3B (1.07M-1.33M active non-zeros, ) and Alibaba Qwen 3.5 4B (2.25M-2.39M non-zeros, ) reach 99.17% and 100.00% ALU-prefix accuracy (100% with an FP32 sidecar) and 98%-100% mid-sentence resumption, outperforming 12.8K-sample LoRA (42.2% / 61.7%, 0% inline continuation). A factorized block-sparse sidecar holds A100 memory at 7.89 / 10.65 GiB (4.60 / 8.14 GiB under INT8/INT4 + FP32 sidecar) while passing all 14/14 pre-registered K-token Tango splits (; 0/11,134 OOD triggers).
Figures & tables
| Method / Paradigm | Comp. Type | Pretrained LM? | Synthesis & Data Regime | Zero Host Route? | NL Retention & Dense Cost |
|---|---|---|---|---|---|
| RASP / Tracr ( Weiss et al., 2021 ; Lindner et al., 2023 ) | Conceptual | No (scratch) | Auto DSL ( data; no ) | Yes | No NL capability |
| CoNNs / Tracr-Inj. ( Weng et al., 2024 ; Vergara-Browne and Soto, 2025 ) | Conceptual | Yes (fused / ) | Compiled module + Gradient fusion/distill. | Yes | Trained/distilled; |
| Percepta CALM VM ( Tzamos and Percepta Research, 2026 ) | Conceptual | Specialized VM | MILP ReGLU + 2D CHT trace | Yes (long trace) | Dedicated trace VM (not general LM) |
| Agentic WSP / SWD ( Takehi et al., 2026 ; Yan et al., 2026 ) | Conceptual | Yes (Qwen) | Agentic heuristic edit / circuit extraction | Yes | Heuristic edit or extraction; |
| PAL / Python Tool Router ( Gao et al., 2023 ; Schick et al., 2023 ) | Reproduced | Yes (wrapped) | Host regex/program + Python ( weights) | No ( host) | Exact NL; (requires host) |
| Same-Backbone LoRA SFT ( ex.) | Reproduced | Yes ( LoRA) | -step AdamW on 1–6d | Yes ( in- ) | – Arith; inline prose |
| Property / Footprint Metric | IBM Granite 4.2 3B | Alibaba Qwen 3.5 4B | Google Gemma 4 E4B |
|---|---|---|---|
| Backbone & Vocab ( ) | 40L Dense RoPE GQA; Untied | 32L Hybrid (24 DeltaNet + 8 Attn); Tied | 42L Dual-RoPE + 18L KV-Share; |
| Numeric BPE & MLP / Norm | 1–3 digit chunks ( pats); SwiGLU ( ) | Strict 1-digit ; SwiGLU; | Strict 1-digit ; GeGLU + Sandwich + |
| Scheduled Carrier & Width | Indef-RoPE GQA; (ALU) / (Bool) | GatedDeltaNet ( Attn); / (Bool) | Sliding Indef-RoPE (L0–L18); (Bool) |
| Patch / Sidecar / Dense Rag. | ( ) / / | ( ) / / | L24–41 KV fail; Calib. L0–18 Bool |
| Model | Runtime Representation | Params / NNZ | Exp. | Disk | GFLOPs | A100 VRAM | Pref. | Arith / G3–7 | ARC-C |
|---|---|---|---|---|---|---|---|---|---|
| Granite 4.2 | Pretrained Base ( , BF16 ) | dense | / | ||||||
| Grafted Dense Rag./Unif. ( ) | – | / | |||||||
| SparseSidecar ( BF16 / FP32 circ) | nnz | ||||||||
| Hybrid PTQ ( INT8 / INT4 + FP32 ) | q + nnz | – | – | ||||||
| Qwen 3.5 | Pretrained Base ( , BF16 ) | dense | / — | ||||||
| Grafted Dense Rag./Unif. ( ) | – | / |
| Model & Method | Dense | ALU-Pref | Lead-Int | Strict-ND (Bare / Prose) | Inline | PPL / KL | GSM-140 | NI-8 | FT |
| IBM Granite 4.2 3B ( ; 1–3 digit BPE; Canonical Graft , nnz; 1-Digit Ablation , ragged) | |||||||||
| Pretrained Base ( BF16 ) | — | — | / | — | |||||
| External Python Router ∗ | Host ∗ | / | — | — | |||||
| Fixed- Coord. Proj. ( BF16 ) | — | — | / | — | — | — | |||
| Fixed- SVD Proj. ( BF16 ) | — | — | / | — | — | — | |||
| 1-Digit Off-Manifold Emitter ( BF16 ) | / | 36.67% † | — | ||||||
| IBM Granite 4.2 3B ( ) | Alibaba Qwen 3.5 4B ( ) | ||||||||
| Group | Configuration / Ablation | PPL | Mean KL | ARC-C | Arith | PPL | Mean KL | ARC-C | Arith |
| Ref. | Pretrained Base / LoRA SFT ( ex.) ∗ | ||||||||
| Ablate | M0 : Ours (All 5 Primitives) | ||||||||
| M1 : Zero-Circuit Width ( ) | |||||||||
| -P1 / M2 : Calibrated Single-Scale SwiGLU | |||||||||
| -P2 / -P3 : Pos. RoPE ( ) / Stateful GDN † | |||||||||
| (a) In-Domain Execution vs. Out-of-Domain Abstention ( BF16 ) | (b) Hardware, Precision, Fused Kernel, & Sidecar PTQ Matrix | ||||||
| Regime & Suite | Scope / | Granite 4.2 | Qwen 3.5 | Backend / Stack | Precision / Kernel | Carry / Gate Guarantee ( ) | Status |
| In-Dom. 4-Seed 8-Fmt | [CI] | CPU / A100 CUDA | FP32 ( no_tf32 ) / TF32 | Bound ; G3--G7 | Verified | ||
| In-Dom. / Bnd. | / | / | / | MPS & A100 CUDA | Native BF16 ( FP32 acc) | Bound ; Q / G | Ver. (Drift) |
| In-Dom. BOS-less | "999+1=" ( ) | (BOS dep.) | torch.compile | TorchInductor Triton | Fused SwiGLU | Verified | |
| In-Dom. Decl. Boolean | ( prec) | ( ) | ( ) | PyTorch SDPA | FlashAttn-2 / MemEff | vs. MATH ; | Verified |
| In-Dom. 5-Bit Maj/Par | Voter ( ) | IEEE FP16 ( half ) | Max ( ) | Raw NaN ; clamp OK | Mitigated | ||
| IBM Granite 4.2 3B ( BF16 ) | Alibaba Qwen 3.5 4B ( BF16 ) | ||||||
| Evaluation Split ( ) | Base Graft | ( ) | (Status) | Base Graft | ( ) | (Status) | |
| Full GSM8K ( ) | ( ) | ( Pass ) | ( ) | ( Pass ) | |||
| Full ARC-C ( ) | ( ) | ( Pass ) | ( ) | ( Pass ) | |||
| Held-Out MMLU-Pro ( ) | ( ) | ( Pass ) | ( ) | ( Pass ) | |||
| Full LogiQA-EN ( ) | ( ) | ( Pass ) | ( ) | ( Pass ) | |||
| Long-Ctx PubMedQA-2.5K ( ) | ( ) | ( Pass ) | ( ) | ( Pass ) | |||
Appendix figures & tables17 assets
Supplementary material from the paper’s appendix.
Appendix
| Symbol / Term | Definition | Plain-Language Role in Circuit |
|---|---|---|
| Base width ; appended circuit wires | Keeps pretrained NL features untouched in | |
| Token/layer-varying inverse scale | Unknown runtime multiplier ( swing) we cancel | |
| Reference wire ( ); complement guard ( active, off); scale | Tracks and holds circuit bit-exact silent off-trigger | |
| Log-spaced gate scales ( ); Mellin integral constant | Converts scaling into a shift along a flat integral plateau | |
| Indefinite-RoPE spectral kernel ( ) | Forces inactive queries onto a zero-payload self-sink ( ) | |
| Pretrained weight compensation factor | Cancels the denominator shift on NL channels |
| Idx | Gold | 1-Dig Pred | Canon. Pred | Sub-Mechanism | 1-Digit Emitter Trace ( ) | Canonical Emitter Trace (Base-1000 BPE) |
|---|---|---|---|---|---|---|
| B: Span mis-index | [’6’,’0’] Remaining: 6000? | [’60’] 60 - 15 - 25 = 20 ( OK ) | ||||
| A: Decimal dot | [’6’,’4’] #### 6.4 | [’64’] #### 64 ( OK ) | ||||
| B: Span mis-index | [’8’,’0’] 2 * 8 = 16 | [’80’] 2 * 80 = 160; 260 ( OK ) | ||||
| ( miss ) | B trunc. | [’1’,’8’,’0’] 1800 * 0.7 | [’180’] fixes 180*0.7=126 ; -tok clip | |||
| D: BF16 drift | 160+794 | 3*68=204 ... Total: 694 ( OK ) | ||||
| B: Span mis-index | [’8’,’4’] 840 / 12 = 70 | [’84’] 84 / 12 = 7 ( OK ) |
| Model | Ablation Configuration | Arith-150 | FalseTrig-1100 | InlineRes-50 | Sub-Corpus PPL | Mean KL |
| Granite 4.2 3B | A0 : Full Orthogonal Mellin Graft (Ours) | |||||
| A1 : w/o NL scaling | ( ) | |||||
| A2 : w/o Trigger isolation guards ( BAD_PRE , CHAIN , OVF ) | ||||||
| A3 : w/o Homogeneous V-head ref. pairing (local R_CIRC ) | ||||||
| A4 : Coarse Mellin quadrature step ( vs. ) | ( ) | |||||
| A5 : Unmuted internal scratch wires at readout | ( ) |
| IBM Granite 4.2 3B | Alibaba Qwen 3.5 4B | |||||
| Suite & Category | Input Distribution / Adversarial Pattern | Triggers | Triggers | |||
| real_ag_news | News article prefixes ( ag_news ) | |||||
| real_pubmed_biomed | Clinical abstracts incl. p = / n = cuts | |||||
| real_swebench_code | Real Python issue & git diff snippets | |||||
| real_20newsgroups | Informal discussion & email threads | |||||
| real_banking_finance | Financial customer queries ( banking77 ) | |||||
| Suite / Boundary Category | Seeds / Formats | Granite 4.2 ( BF16 ) | Granite 4.2 ( FP32 ) | Qwen 3.5 ( BF16 ) | Qwen 3.5 ( FP32 ) | |
| Seed 1 ( 20261112 , primary 6-fmt) | Spaced, compact, prose, | ( prose) | — | ( ) | — | |
| Seed 2 ( 20269999 , 8-fmt incl. ( & +- ) | colon , newline , paren ∗ | ( ALU on 6-fmt) | ( on 6-fmt) | |||
| Seed 3 ( 20270101 , 8-fmt incl. ( & +- ) | colon , newline , paren ∗ | — | — | |||
| Seed 4 ( 20280404 , 8-fmt incl. ( & +- ) | colon , newline , paren ∗ | — | — | |||
| Pooled 4-Seed Total [95% Wilson CI] | seeds, formats | — | — | |||
| Stochastic Decoding ( ) | Subsample ( seed=20261114 ) | — | — |
| Model | Prompt Template ( ) | Base Acc. | Graft Acc. | ( ) | (Status) | |
|---|---|---|---|---|---|---|
| Granite 4.2 3B | T1 : Standard Question:/Answer: | ( ) | ( Pass ) | |||
| T2 : Parenthesized (A)..(D) | ( ) | ( Pass ) | ||||
| T3 : Markdown ### Task / - [A] | ( ) | ( Pass ) | ||||
| T4 : -Shot In-Context Q:/A: | ( ) | ( Pass ) | ||||
| Qwen 3.5 4B | T1 : Standard Question:/Answer: | ( ) | ( Pass ) | |||
| T2 : Parenthesized (A)..(D) | ( ) | ( Pass ) |
| Model ( BF16 ) | Exact -Tok Match | Mean Identical Prefix | Token ROUGE-L F1 | Distinct-2 (Base Graft) | Distinct-3 (Base Graft) | -Gram Rep. (Base Graft) |
|---|---|---|---|---|---|---|
| IBM Granite 4.2 3B | ( ) | toks | ||||
| Alibaba Qwen 3.5 4B | ( ) | toks |
| ID | Prompt | Expected | FP32 Out | BF16 ALU ( ANS ) | Batched BF16 Got | Mechanism & |
| G1 | 297583 + -8 = | 297575 | 29757583 | 297575 ( Exact ) | 29757583? Wait | Mech. I ( , echo) |
| G2 | 99939-3= | 99936 | 3=3=3=3= | Abstain ( ) | 3=3=3=3=3= | Mech. III ( "999" abstain) |
| G3 | -657 * -9 = | 5913 | 5913 ( OK ) | 5923 (tens ) | 5923? Let’s... | Mech. II ( BF16 carry ULP) |
| G4 | 4262 * 59 = | 251458 | 251458 ( OK ) | 251448 (tens ) | 251448? Let’s | Mech. II ( BF16 carry ULP) |
| G5 | -348*29= | -10092 | -10092 ( OK ) | -9082 (carry casc.) | -9082? Actually | Mech. II ( BF16 carry ULP) |
| G6 | In summary, -60 * -996 = | 59760 | 59760 ( OK ) | 49760 (KV-pad ULP) | 49760.\n</think> | Mech. II ( BF16 carry ULP) |
| Frozen Patch | Host | ALU-Pref ( ) | Lead-Int ( ) | Strict-ND (All / Prose) | Inline ( ) | Blind FT | ARC-E [300:500] | BoolQ [300:500] | GSM8K [200:260] |
|---|---|---|---|---|---|---|---|---|---|
| Granite 4.2 | mps | ( ) | ( ) | / | ( Pass ) | ( Pass ) | ( Pass ) | ||
| A100 | ( ) | ( ) | / | ( Pass ) | ( Pass ) | ( Pass ) | |||
| Qwen 3.5 | mps | ( ) | ( ) | / | ( Pass ) | ( Pass ) | ( Pass ) | ||
| A100 | ( ) | ( ) | / | ( Pass ) | ( Pass ) | ( Pass ) |
| Artifact / Module | Role / Snapshot Commit | SHA-256 Digest (Prefix) |
| ibm-granite/granite-4.2-3b | HF Snapshot 4e9c275e232f... | index: e030cfbb2b2dbe4489a522c5d65e73b6... |
| Qwen/Qwen3.5-4B | HF Snapshot 851bf6e806ef... | index: cf3f798ee02ba45f9622aa8892a47369... |
| google/gemma-4-E4B-it | HF Snapshot 4ecc2ba63bca... | config: 33b10c02df3c2e8536cf323d29d53262... |
| granite_graft_calib.pt | RMS Scalars + Fixed- SVD ( ) | ac6e2286266f8dfa069f94247831714d... |
| qwen35_graft_calib.pt | Unlabeled Corpus RMS Scalars ( ) | 6ed73d0097fa6ef340f7c863b17e74f4... |
| src/primitives/mellin_primitives.py | Reusable Mellin-SwiGLU & Indef-RoPE ( ) | 142215579efda6af106b0dd22f66422a... |
| Backbone | Synthesis Mode & Spec | BPE Pats | Width | Active NNZ | Depth / Time | ALU-Pref ( FP32 / BF16 ) | G3–G7 | Inline-50 / OOD | ARC-C-200 ( ) |
| Granite 4.2 | Hand-Scheduled v2 Ref. ( ) | (manual) | L39/39 (—) | / | / | ( Pass ) | |||
| Auto-Compiled SSA ( ) | (auto) | ( ) | L38/39 ( ) | / | / | ( ) | |||
| Auto-Compiled Ring ( ) | (auto) | L38/39 ( ) | — (footprint) | — | — | — | |||
| Auto-Compiled SSA ( ) | (auto) | L38/39 ( ) | ( ) | — | — | — | |||
| Auto-Compiled SSA ( ) | (auto) | L38/39 ( ) | ( ) | — | — | — | |||
| Qwen 3.5 | Hand-Scheduled v2 Ref. ( ) | (manual) | L31/31 ( Attn) | / | / | ( Pass ) |
| Model ( Primitive Edits) | Circuit Footprint | Base Truth ( ) | Graft Truth ( ) | Prec. Override ( ) | Inline Exact / Step-1 Off | OOD Abstain ( ) | ARC-200 Base Graft ( ) |
|---|---|---|---|---|---|---|---|
| IBM Granite 4.2 3B | , nnz ( , ) | ( prec.) | ( ) | ( ) | / | ( ) | ( , Pass ) |
| Alibaba Qwen 3.5 4B | , nnz ( , ) | ( prec.) | ( ) | ( ) | / | ( ) | ( , Pass ) |
| (a) Mellin Quadrature Across GLU Variants | (b) 42-Layer Gemma 4 E4B Architectural Audit | ||||||
|---|---|---|---|---|---|---|---|
| Activation | Mellin | FP32 Err | BF16 Err | 42-Layer Configuration | Bool Acc. | OOD FT | Mechanism |
| Exact | Pretrained Base ( BF16 ) | No circuit | |||||
| ( ) | Shift in KV-Shared L24–L41 | Overwrites | |||||
| Exact - | Uncalibrated Sandwich / | Post-norm / decay | |||||
| - (Calib. / ) | / | Calib. Unshared L0–L18 | ( ) | Sandwich + | |||
| Deployment Stack | Recommended Reference Configuration | Key Kernel / Numerical Constraint | Carry & Silence Guarantee |
|---|---|---|---|
| Recommended Default | SparseSidecar(..., sidecar_fp32=True) + BF16 | Schedule S1 pairwise readout; IEEE F.silu | ALU ( G3--G7 ); exact OOD |
| Quantized Serving | INT8 / INT4 (g ) + FP32 SparseSidecar | Never quantize ( ladder stays FP32 ) | G3--G7 ; / VRAM |
| Graph Compiler | torch.compile(mode="default") ( TorchInductor ) | Keep IEEE math ( emulate_precision_casts ) | Verified ( ) |
| Attention Backend | PyTorch SDPA FLASH_ATTENTION / EFFICIENT | Pre-expand GQA KV or include MATH fallback | Verified ( vs. MATH ) |
| Dense Checkpoint | dtype=bfloat16 + matmul.allow_tf32=True | Avoid -ffast-math / FTZ; arbitrary GEMM tree | Qwen / Granite ( TF32 ) |
| IEEE FP16 ( half ) | Clamp , (or FP32 -SC) | Prevents | Verified NaN -free ( ) |
| (a) 8-Layer 6-Digit Division ( , Wires) | (b) Base-1000 Multi-Digit Scaling Projections | |||||||
| Sidecar Precision | Exact ( ) | Bottleneck | Digits | Triads | / Depth | Full ALU | ALU Depth | Req. Sidecar |
| IEEE FP32 Sidecar | Exact ( NR) | / | TF32 / FP32 -SC | |||||
| TensorCore TF32 | -bit ulp | / | TF32 / FP32 -SC | |||||
| Native BF16 | -bit spline/rem ulp | / | FP32 -SC (limb split) | |||||
| Naive Restoring Div. | ( req.) | Exceeds 32L budget | / | FP32 -SC ( LM) | ||||
| IBM Granite 4.2 3B ( BF16 ) | Alibaba Qwen 3.5 4B ( BF16 ) | |||||||
| Pre-Registered Split | Base Graft | / | (Status) | Base Graft | / | (Status) | ||
| Full GSM8K test[:1319] | / | ( Pass ) | / | ( Pass ) | ||||
| Strictly Unseen test[200:1319] | / | ( Pass ) | / | ( Pass ) | ||||
| Full ARC-Challenge test | / | ( Pass ) | / | ( Pass ) | ||||
| Held-Out MMLU-Pro [1000:2000] | / | ( Pass ) | / | ( Pass ) | ||||
| Full AGIEval LogiQA-EN test | / | ( Pass ) | / | ( Pass ) | ||||
| (a) Decoding Regimes, IFEval-100 , & Safety-80 (Base Graft) | (b) LoRA SFT & Tokenization Alignment | ||||||
|---|---|---|---|---|---|---|---|
| Benchmark & Regime | Granite Base | Granite Graft | Qwen Base | Qwen Graft | Comparison | Arith / GSM8K | Inline Prose |
| GSM8K Greedy ( ) | Granite LoRA ( p) | ( ) | ( int) | ||||
| GSM8K / | Qwen LoRA ( p) | ( ) | ( int) | ||||
| GSM8K / Beam-4 | Ours Zero-Grad Graft | ||||||
| IFEval-100 Greedy / | Tok 1: Raw 1-Digit IDs | GSM8K | Off-manifold | ||||
| Safety-40 Harmful Refusal | Tok 2: Spaced 1-Digit | GSM8K | Off-manifold | ||||
Numerical Reasoning in Language Models
Numerical reasoning in language models studies how systems represent, calculate with, and explain numbers across mathematical and real-world tasks.
See all 175 papers