Instructions to use masahiroid/pyrite-stream with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use masahiroid/pyrite-stream with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # if on a CUDA device, also pip install mlx[cuda] # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("masahiroid/pyrite-stream") prompt = "Once upon a time in" text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- MLX LM
How to use masahiroid/pyrite-stream with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Generate some text mlx_lm.generate --model "masahiroid/pyrite-stream" --prompt "Once upon a time"
- Atomic Chat
- Project Pyrite Phase 2: MoE-Stream Engine
Project Pyrite Phase 2: MoE-Stream Engine
Running 100B+ MoE Models in < 3.6 GB RAM on 16GB Apple Silicon Macs via NVMe On-Demand Expert Streaming
Author: Masahiro NAKATSUGAWA (δΈζ΄₯ε· ζεΌ)
Affiliations: n.p.minerva & Co. (tip.co.jp) / AntenneFrance
ORCID: 0009-0000-3224-0103
Preprint DOI: 10.5281/zenodo.23811995
Zenodo Record: zenodo.org/records/23811995
π Overview
Conventional wisdom states that running massive Mixture-of-Experts (MoE) models such as Mixtral-8x22B (141B parameters) or DeepSeek-Coder-V2-Lite (15.7B parameters) requires at least 80 GB to 300 GB of RAM or multi-GPU workstation clusters (e.g., $4\times$ NVIDIA H100 or Mac Studio Ultra 192GB).
Project Pyrite Phase 2: MoE-Stream Engine completely dismantles this hardware barrier. By decoupling the static resident working set (Attention, LayerNorms, Gating Routers, and Embeddings) from dynamic routed feed-forward experts, MoE-Stream streams active Top-$K$ experts directly from NVMe SSD storage into Apple Silicon Unified Memory with microsecond-level zero-copy mmap tensor slicing and an LRU in-memory cache.
Key Benchmark Results on a Standard 16GB Apple M2 Pro
| Model | Total Parameters | Standard RAM Required | Pyrite MoE-Stream RAM | RAM Reduction | Generation Speed |
|---|---|---|---|---|---|
| DeepSeek-Coder-V2-Lite | 15.7B (64 experts) | 12 GB β 32 GB | 1.55 GB β 2.01 GB | 83% β 93% | 2.83 tok/s |
| Mixtral-8x22B-Instruct | 141.0B (8 experts) | 80 GB β 280 GB | 2.84 GB β 3.61 GB | 95% β 98% | Full 56-layer forward pass verified |
A standard $1,000 consumer laptop (16GB Mac mini / MacBook Air) can now execute a 141-Billion parameter monster model with over 12 GB of free RAM remaining for desktop multitasking!
π¬ Mathematical Foundations: The MoE Sparsity Advantage
Why did previous full-model offloading engines (e.g. AirLLM) achieve only ~0.07 tok/s (14 seconds per token)?
In dense models (e.g. Llama-3-70B), computing every single token requires reading all 70 GB of parameters sequentially across the PCIe bus:
In contrast, Mixture-of-Experts architectures exhibit extreme spatial sparsity:
Resident Working Set in RAM ($W_{\text{resident}}$):
- Self-Attention Mechanism (Q, K, V, O projections)
- LayerNorms & RMSNorms
- Router Gating Matrix ($W_{\text{gate}} \in \mathbb{R}^{K \times D}$)
- Token Embeddings & LM Head $$\text{RAM}_{\text{Resident}} \approx 1.5\text{ GB (DeepSeek)} \quad \text{to} \quad 2.3\text{ GB (Mixtral-8x22B)}$$
Dynamic On-Demand Working Set ($W_{\text{active}}$):
- Only $\text{Top-}K$ experts are activated per token ($K=2$ out of 8 in Mixtral; $K=6$ out of 64 in DeepSeek).
- In Mixtral-8x22B, 1 active expert in 4-bit is $\sim 150\text{ MB}$.
- For Top-2 active experts: $$\Delta_{\text{transfer}} = 2 \times 150\text{ MB} = 300\text{ MB / layer}$$
- With an in-memory Least-Recently-Used (LRU) expert cache (holding e.g. 2 to 4 experts per layer), the cache hit rate on sequential code/text generation reaches 40% to 60%, reducing actual NVMe I/O per token down to ~1.0 GB to 1.5 GB.
Zero-Copy Direct Byte Slicing: Rather than loading multi-gigabyte safetensors shards,
expert_registry.pycomputes the exact linear byte boundaries of individual experts: $$\text{Offset}{\text{expert}(e)} = \text{Base} + e \times \frac{\text{TotalBytes}}{N{\text{experts}}}$$ Achieving 0.068 ms (68 microseconds) extraction latency directly into Apple Metal unified memory buffers without intermediate heap allocation.
ποΈ Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β NVMe SSD Storage (e.g., 2TB APFS) β
β All Switch-MLP Routed Experts (70 GB β 280 GB on-disk) β
βββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β Direct Zero-Copy mmap Slicing (68 Β΅s)
βΌ (Top-K Active Experts Only)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Apple Silicon Unified Memory (RAM: 16GB) β
β β
β [Resident Zone: ~2.0 GB] β
β β’ Multi-Head Latent Attention (MLA / GQA) β
β β’ RMSNorm Layers & Vocabulary Projections β
β β’ Lightweight Router Gates (e.g. 8x768 / 64x2048) β
β β’ Shared Experts (DeepSeek: 2 experts) β
β β
β [Dynamic Expert Cache: ~1.0 GB] β
β β’ Active Top-K Tensor Descriptors β
β β’ LRU In-Memory Expert Buffer (Ring Cache) β
βββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β Zero-Copy Unified Memory Access
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Apple Silicon Metal 4 GPU Hardware β
β β’ Vectorized Quantized / Full Matmul Operations β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Quickstart
1. Installation
git clone https://github.com/tip-corporation/pyrite-stream.git
cd pyrite-stream
pip install -r requirements.txt
2. Running DeepSeek-Coder-V2-Lite (15.7B)
Runs inside 1.55 GB to 2.01 GB RAM on any 16GB Mac:
python3 moe_stream_runner.py
3. Running AntenneFrance Mixtral-8x22B (141B)
Runs inside 2.84 GB to 3.61 GB RAM on any 16GB Mac:
# Download 4-bit Mixtral-8x22B weights (73.7 GB)
hf download mlx-community/Mixtral-8x22B-Instruct-v0.1-4bit \
--local-dir /Volumes/NVMe2TB/AI-LLM/models/Mixtral-8x22B-Instruct-v0.1-4bit
# Run AntenneFrance Streaming Generation
python3 mixtral_runner.py /Volumes/NVMe2TB/AI-LLM/models/Mixtral-8x22B-Instruct-v0.1-4bit "Bonjour ! Qui Γͺtes-vous ?"
π¬ Beyond Quantization: Lossless & Spectral Compression Horizons
Project Pyrite Phase 2 establishes a new paradigm where discrete integer quantization is no longer the only mechanism for consumer LLM execution:
- Uncompressed Full Precision (BF16): Since full 280 GB weights reside on high-speed NVMe SSDs while RAM only hosts the ~8 GB working set, unquantized BF16 execution is fully achievable on a 16GB Mac with zero degradation in reasoning or coding accuracy.
- Lossless Bit-Shuffling & Vectorized Streaming Decompression: Separating IEEE 754 floating-point exponent, sign, and mantissa bitplanes enables lossless entropy compression (LZ4/Zstd) of 1.8x β 2.5x. Apple Silicon hardware can decompress at 20 GB/s to 30 GB/s, doubling effective SSD read bandwidth to 8 β 10 GB/s.
- Low-Rank Singular Value Decomposition (SVD): Decomposing expert weights into principal sub-spaces ($W \approx U \cdot V^T$) reduces floating-point FLOP count and I/O footprint simultaneously without integer discretization noise.
π Citation
@software{nakatsugawa2026moestream,
author = {Nakatsugawa, Masahiro},
title = {Project Pyrite Phase 2: MoE-Stream Engine -- Decoupling Resident Attention and Dynamic NVMe-Streamed Experts for 100B+ MoEs on Unified Memory Consumer Hardware},
year = {2026},
publisher = {Zenodo / n.p.minerva & Co. / AntenneFrance},
doi = {10.5281/zenodo.23811995},
url = {https://doi.org/10.5281/zenodo.23811995}
}