Metadata-Version: 2.5
Name: xfermat
Version: 0.7.1
Summary: Apple Silicon Metal GPU inference runtime: fused 2-bit/4-bit KIVI KV-cache, sub-second Safetensors loading, SDPA/FlashDecode, Mamba-2 SSD hybrids, and CRT-Ozaki II FP64
Project-URL: Homepage, https://xfermat.com
Project-URL: Documentation, https://xfermat.com/docs
Project-URL: Whitepaper, https://xfermat.com/whitepaper
Project-URL: Repository, https://github.com/xFermat/xFermat
Project-URL: Issues, https://github.com/xFermat/xFermat/issues
Author-email: "Aris Nikolaou (aopas software development)" <ask@xfermat.com>
License: xFermat Open-Core & Commercial Dual License (v0.7.0)
        Copyright (c) 2026 aopas software development (Aris Nikolaou). All rights reserved.
        
        xFermat is distributed under a dual-licensing model designed to keep research,
        solo builders, and technical evaluation free while licensing commercial app
        redistribution and large organizational Mac deployments cleanly.
        
        ================================================================================
        PART A — COMMUNITY, RESEARCH & EVALUATION LICENSE (€0)
        ================================================================================
        
        Permission is hereby granted, free of charge, to individual natural persons,
        students, and academic researchers solely for non-commercial personal evaluation
        and open research on one (1) personal Apple Silicon workstation ("Community
        Tier") to install, run, modify for personal testing, and benchmark the Software
        (`fermat` / `xfermat` CLI, Python package, and Metal kernels), subject to the
        following conditions:
        
        1. Attribution & Truth-in-Benchmarking:
           Published benchmarks, papers, or videos derived from xFermat must preserve
           this notice and clearly state hardware tier, model size, quantization method,
           and whether 2-bit post-training weights or 3-bit/4-bit production tiers were
           evaluated.
        2. Permitted Scope:
           - Strictly non-commercial personal projects, academic papers, and public
             reproducibility benchmarks on one (1) personal workstation.
        3. Excluded Without Commercial License (see Part B):
           - Any commercial business usage, SaaS backend, or multi-workstation company
             deployment (2 or more Macs), whether internal or customer-facing.
           - Bundling, embedding, or redistributing the xFermat runtime, Metal kernels,
             or xFermat-compressed derivatives inside paid or proprietary desktop,
             macOS, iOS, or SaaS products distributed to third parties.
           - Managed organizational fleet deployments of twenty (20) or more Apple Silicon
             workstations.
        
        ================================================================================
        PART B — COMMERCIAL PER-SEAT & ENTERPRISE FLEET LICENSE
        ================================================================================
        
        Commercial usage (individual founders, studios, and businesses across 1–20
        seats under `Pro Commercial`, or organizational fleet deployments of 20+
        workstations / Jamf MDM under `Enterprise Mac Fleet`) requires an active paid
        license agreement issued by:
        
          aopas software development (Owner: Aris Nikolaou)
          Große Brinkgasse 9, 50672 Cologne, Germany · USt-IdNr. DE314648161
        
        - Licensing Tiers & Pilot Requests: https://xfermat.com/pricing
        - Enterprise & Licensing Inquiries: enterprise@xfermat.com (General: ask@xfermat.com)
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY ARISING FROM THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: apple-silicon,inference,kivi,kv-cache,llm,mamba2,metal,mlx,quantization,safetensors
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: GPU
Classifier: Environment :: MacOS X
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: Other/Proprietary License
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.12
Requires-Dist: mlx>=0.20.0
Requires-Dist: numpy>=1.26.0
Requires-Dist: scipy>=1.12.0
Provides-Extra: dev
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Provides-Extra: llm
Requires-Dist: mlx-lm>=0.20.0; extra == 'llm'
Description-Content-Type: text/markdown

# xFermat (`v0.7.1`) — Apple Silicon Open Inference Runtime

**xFermat Open Runtime** provides Apple Silicon Metal GPU kernels, native-speed Safetensors loading, GQA-packed 2-bit/4-bit **KIVI KV-cache** decoding (`--kv-bits 4|2`, `--kv-outlier-ratio`), **3:1 Mamba-2 SSD + SDPA** hybrid layers (`FermatModel`), and an empirical shape autotuner ([`FermatEngine`](https://github.com/xFermat/xFermat/blob/main/src/fermat/engine.py)).

> **Open-Core Architecture:** This public repository and PyPI runtime distribute the transparent, pure-source inference engine (`xfermat info`, `xfermat bench`, `xfermat run`, `load_compressed_model`, `FermatKIVICache`, and verified Metal kernels). Proprietary offline weight compression (`Clip-GPTQ`, `4D VPTQ`, `EfficientQAT`, `PV-Tuning`) and `MOHAWK` distillation modules remain private commercial tools under [`aopas software development`](https://xfermat.com/pricing).

---

## Measured Apple Silicon Summary (`0.5B`–`3B`, Rigorous 5-Run Median ± IQR)

Full disjoint evaluations, null-result boundaries, and reproducible JSON logs live in [`WHITEPAPER.md`](https://github.com/xFermat/xFermat/blob/main/WHITEPAPER.md) and [`benchmarks/v07_rigorous_results.json`](https://github.com/xFermat/xFermat/blob/main/benchmarks/v07_rigorous_results.json):

| Benchmark (`Apple Silicon Unified GPU (applegpu_g14g, 8 GB)`, `mlx 0.32.4`) | Strongest Native / Baseline | **xFermat `v0.7.0`** | Verified Advance |
| :--- | :--- | :--- | :--- |
| **`Qwen2.5-0.5B` 4-Bit WT2 PPL & Speed** | `mlx_lm.awq`: `16.06` PPL (`173.4 ± 0.6 tok/s`) | **`15.20` PPL (`181.8 ± 3.9 tok/s`, `330.0 MB`)** | **-5.4% PPL**, decode parity (`62.9 GB/s` eff bw) |
| **`Qwen2.5-0.5B` 3-Bit Quality** | `mlx_lm.awq`: `23.27` PPL (`0.848` KL) | **`17.99` PPL (`0.606` KL, `287.6 MB`)** | **-22.7% PPL**, **-28.5% KL** (`143.0 ± 5.7 tok/s`), comparable MC (`53.0%` vs `49.8%`) |
| **`TinyLlama-1.1B` 3-Bit Untied Head** | `xfermat` FP16 head: `61.4 ± 4.5 tok/s` (`38.4 GB/s`; `AWQ` `120.7`) | **`head_bits=8`: `98.0 ± 6.7 tok/s` (`55.2 GB/s`)** | **+59.5% internal speedup** at `9.62` WT2 PPL |
| **`Qwen2.5-1.5B` 3-Bit WT2 Perplexity** | `mlx_lm.awq`: `13.02` PPL (`0.585` KL) | **`11.48` PPL (`0.487` KL, `783.9 MB`)** | **-11.8% PPL**, **-16.7% KL** at `54.0 ± 4.4 tok/s` (`3.76×` smaller) |
| **`Qwen2.5-3B` 8 GB Memory Recovery** | BF16: `5,886 MB` (`~5.75 GiB` > `5.33 GiB` limit → OOM) | **`1,474 MB` (`10.42` PPL @ `29.1 tok/s`) / `1,193 MB` mixed (`56.9 tok/s`)** | **Unlocks 3B on 8 GB unified memory** without OS swap thrashing |
| **`16K` Context Mixed KIVI KV Cache** | FP16 `448.0 MB` (`16.0 bpw`) | **`88.6 MB` (`5.06×` smaller, `3.16 bpw`), `5/5` Passkey** | Holds 100% Passkey through 16K (`2.34×` isolated 4b `G=7,D=64`; live parity @ 4K–8K) |
| **Real `0.5B` 3:1 Hybrid Conversion** | Student init: `129.96` PPL | **`14.46` final PPL (`0.575` KL, `6,618 MB` peak)** | **-24.56% 8K KV cache** with near-teacher generation quality |

*(Honest engineering caveat: 3-bit and 4-bit remain the recommended production PTQ tiers; `k_outlier_ratio=0.625` KIVI KV uses ~`3.16` effective bits/element while `k_outlier_ratio=0.0` provides pure 2-bit KV. Under `mode="auto"`, sub-cubic Winograd–Strassen, AlphaEvolve rank-48, ternary LUTs, and CRT FP64 stay opt-in where native Apple GEMM/BLAS wins.)*

---

## Runtime Modules Included (`src/fermat/`)

| Module | Capability |
| :--- | :--- |
| [`src/fermat/kv_quant.py`](https://github.com/xFermat/xFermat/blob/main/src/fermat/kv_quant.py) | `QuantizedKVCache`, `FermatKIVICache`, GQA-packed Metal decode, exact prefill, `effective_bpw`, `uint16` `D>256` support |
| [`src/fermat/persistence.py`](https://github.com/xFermat/xFermat/blob/main/src/fermat/persistence.py) | Sub-second sharded `.safetensors` serialization & `load_compressed_model` |
| [`src/fermat/engine.py`](https://github.com/xFermat/xFermat/blob/main/src/fermat/engine.py) | `FermatEngine(mode="auto")` per-shape median + 10% hysteresis autotuner |
| [`src/fermat/io_algebra.py`](https://github.com/xFermat/xFermat/blob/main/src/fermat/io_algebra.py) | `flash_tiled_attention` (SDPA auto-routing + Split-KV Metal `FlashDecode`) & `WinogradConv2d` |
| [`src/fermat/ssd_mamba.py`](https://github.com/xFermat/xFermat/blob/main/src/fermat/ssd_mamba.py) | Chunked `Q_c=64` Mamba-2 State Space Duality Metal forward + reverse-VJP scan |
| [`src/fermat/structured.py`](https://github.com/xFermat/xFermat/blob/main/src/fermat/structured.py) | `HadamardQuantLinear`, `FermatFinalNorm`, `MonarchLinear`, zero-barrier shuffle FWHT, `fused_swiglu_rht`, `kronecker_hadamard_factor` |
| [`src/fermat/bilinear.py`](https://github.com/xFermat/xFermat/blob/main/src/fermat/bilinear.py) | AlphaEvolve `<4,4,4>`, AlphaTensor, Gauss 3M, Winograd-Strassen + bundled `.npz` tables |
| [`src/fermat/rns_ozaki.py`](https://github.com/xFermat/xFermat/blob/main/src/fermat/rns_ozaki.py) | Explicit 150-bit Garner CRT-Ozaki II GPU FP64 reconstruction & sliced IEEE-754 path |
| [`src/fermat/ternary.py`](https://github.com/xFermat/xFermat/blob/main/src/fermat/ternary.py) | `OzakiHadamardTernaryLinear` (`T-MAC` Metal SRAM LUTs) |

---

## Quickstart & Security Verification

```bash
# Install runtime (add [llm] to load & stream Hugging Face / mlx-lm models with KIVI)
pip install "xfermat[llm]"

# Verify pure-source package integrity & Metal GPU runtime
xfermat info
xfermat bench --json

# Stream any Hugging Face / mlx-lm model with fused 4-bit KIVI KV cache
xfermat run Qwen/Qwen2.5-0.5B-Instruct --kv-bits 4 --prompt "Explain Fermat's principle."

# Or load a saved compressed xFermat safetensors checkpoint in ~0.7s
xfermat run ./path-to-compressed-model --kv-bits 4 --prompt "Explain Fermat's principle."

# Verify runtime suite
pytest -q
```

- **Supply-Chain Transparency ([`SECURITY.md`](https://github.com/xFermat/xFermat/blob/main/SECURITY.md)):** Pure `py3-none-any` source Python + runtime-compiled Metal shaders (zero compiled `.dylib`/`.so` blobs, zero `pickle` checkpoint loading, zero telemetry).
- **Licensing ([`LICENSE`](https://github.com/xFermat/xFermat/blob/main/LICENSE)):** Free (`€0`) for solo personal & academic use on **1 personal Mac**. Commercial redistribution and business fleets (`€39/seat` Pro, `From €750/mo` Enterprise) are licensed via [xfermat.com/pricing](https://xfermat.com/pricing).
