DeimosStream
DeimosStream is a universal low-VRAM Sparse Mixture-of-Experts (MoE) LLM streaming engine — the language-model twin to PhobosStream — built to run large Sparse MoE models (OLMoE, Qwen2/3-MoE, Mixtral, DeepSeek-MoE) inside a tiny, strictly bounded GPU memory footprint with cryptographic Merkle proof verification on every cold expert page streamed from NVMe SSD.
By combining a 16 KB Page-Aligned 4-Bit Cryptographic Merkle Store (DEIMIDX2), a Pre-Allocated Unified-Memory PagedExpertArena (mx.gather_qmm), Zero-GIL C++17 Cross-Layer Residual Lookahead, and Cache-Aware Miss-Only Nucleus Dynamic-K, DeimosStream cuts Peak Metal GPU Memory on a real 13.20 GiB (6.92B) Sparse MoE model from 13,613.4 MiB down to 1,086.8–1,518.8 MiB (88.8%–92.0% VRAM reduction) while sustaining 45.5–57.4 tok/s with zero prefill VRAM spikes and no perplexity degradation.
📊 Verified Empirical Benchmarks (OLMoE-1B-7B, 6.92B Params / 13.20 GiB FP16)
Measured end-to-end on Apple Silicon (M4 Max Metal GPU, real F_NOCACHE random NVMe pread measured at 2.03–2.96 GiB/s) on allenai/OLMoE-1B-7B-0125-Instruct (16 layers × 64 experts = 1,024 SwiGLU experts, Top-8 active per token):
| Execution Mode | Active / Peak Metal VRAM | Peak VRAM Saved | Process RSS | Expert Cache Hit Rate | Decode Speed | Held-Out Quality (PPL ↓) |
|---|---|---|---|---|---|---|
| 1. Monolithic FP16 Baseline (All weights in GPU) | 13,261.5 / 13,613.4 MiB |
0.0% |
13,680+ MiB |
100.0% (Pinned) |
142.24 tok/s |
6.4182 (FP16 Ref) |
2. Naive On-Demand FP16 Streaming (mx.stack) |
1,709.4 / 4,567.9 MiB (+2.85 GiB spike) |
66.4% |
~4,600 MiB |
19.0% |
4.71 tok/s |
6.4182 |
3. DeimosStream Full-Pinned Q4 (--slots 64) |
4,108.8 / 4,154.5 MiB |
69.5% |
~4,220 MiB |
100.0% (Pinned) |
251.48 tok/s (1.77x) | 6.2229 |
4. DeimosStream Low-VRAM Champion (--slots 16 --tau 0.85) |
1,516.8 / 1,518.8 MiB (0 spike) |
88.8% |
1,309.8 MiB | 92.2%–93.3% | 55.62 tok/s (57.4 @ τ=0.78) | 6.2285 |
5. DeimosStream Ultra-Low 1.06 GiB (--slots 8 --tau 0.85) |
1,084.8 / 1,086.8 MiB (0 spike) |
92.0% |
881.7 MiB | 88.4% | 45.53 tok/s | 6.2541 (0.0 diff @ τ=1.0) |
- Bit-Exact Streaming Guarantee (
--tau 1.0): RunningDeimosPagedMoEEngine(..., slots_per_layer=8, miss_tail_tau=1.0)produces0.00000000(0.0) maximum logit difference and 100% identical greedy tokens against Full-64-Slot Pinned Q4 despite continuous LFU+LRU page evictions. - Warm Multi-Turn Merkle KV-Prefix Cache: Across full process restarts on a 54-token prompt,
MerkleKVPrefixCacheverifies and restores48/54cached prompt tokens inO(1)viaDEIMIDX2Robin-Hood hashing, cutting cold-restart TTFT4.29x(1,014.5 ms -> 236.4 ms) with exact output parity.
🏛️ System Architecture
flowchart TD
subgraph STORE["DEIMIDX2 Cryptographic Merkle Store (NVMe SSD)"]
IDX["merkle_tree.idx (320B Header + Flat XOR Tree + Robin-Hood KV Table)"]
CAS[("cas_experts_q4.bin (16 KB Page-Aligned Q4 Expert Leaves)")]
CORE["shared_core.bin + embed_tokens.bin + lm_head_int8.bin"]
end
subgraph PREFILL["Stage 1: Chained SHA-256 Merkle KV-Prefix Cache"]
TOK["Prompt Token IDs"] --> KVH["16-Token Block Hash Chain from model_merkle_root"]
KVH -->|"Robin-Hood Hit"| KVR["Restore .safetensors KV Blocks (4.29x Faster TTFT)"]
end
subgraph LAYER["Stage 2: Per-Layer Paged MoE Execution + Residual Lookahead"]
KVR --> ATTN["UniversalAttention (Fused MHA/GQA + Full/Per-Head/None QK-Norm)"]
ATTN --> LA["Residual Lookahead: W_gate^(l+1) * RMSNorm(h^(l)) (83.9% Recall)"]
LA -.->|"Zero-GIL C++17 Async Worker (F_NOCACHE pread + CC_SHA256)"| NEXT["Disjoint PagedExpertArena[l+1]"]
CAS ==>|"Cold Leaf DMA + Tier-2 SHA-256 Proof"| NEXT
ATTN --> DYNK["Cache-Aware Miss-Only Nucleus Dynamic-K (tau=0.85)"]
DYNK --> QMM["Zero-Copy mx.gather_qmm on PagedExpertArena[l]"]
end
Core Architectural Mechanisms
- Universal
DEIMIDX2Cryptographic Merkle Index (deimos_merkle.mm):- Supports arbitrary
(num_layers, num_experts, vocab_size)topologies (non-power-of-2 leaf counts automatically padded totree_leaf_cap = 2^⌈log2(L·E)⌉). - Tier-1 Startup Proof: Verifies all leaf-to-root XOR sibling paths and the 4-branch
model_merkle_root(embedding || shared_core || expert_tree || lm_head) in2.08 ms(3.1 nsO(1)C-struct lookup). - Tier-2 Cold Leaf Proof: Hardware-accelerated ARMv8
CC_SHA256verifies every cold expert's raw 4-bit payload bytes on NVMepread/mmapbefore weights enter GPU memory, raisingDeimosMerkleIntegrityErroron even a 1-bit disk flip.
- Supports arbitrary
- Pre-Allocated Unified-Memory
PagedExpertArena(deimos_arena.mm):- Eliminates
mx.stackallocation spikes by pre-allocating a fixed[C, ...]Q4 tensor pool per layer in Apple Silicon Unified Memory. - Cache hits execute directly in-place via
mx.gather_qmm(..., rhs_indices=phys_slots)with zero intermediate tensor copies; cache misses overwrite the LFU+LRU victim slot in-place via zero-GIL C++17memcpy+POSIX_MADV_DONTNEED.
- Eliminates
- Cross-Layer Residual Lookahead (
83.91%Top-8 Recall):- Exploits residual stream continuity ($h^{(l+1)} = h^{(l)} + \Delta_{\text{MoE}}^{(l)} + \Delta_{\text{Attn}}^{(l+1)}$): predicts Layer
l+1experts using $W_{\text{gate}}^{(l+1)} \cdot \text{RMSNorm}(h_{\text{post-attn}}^{(l)})$ and stages coldl+1leaves on a background C++17 worker thread into disjointarena[l+1]while the Metal GPU computesMoE(l)andAttention(l+1)— eliminating 83.6% of synchronous SSD misses with zero race conditions.
- Exploits residual stream continuity ($h^{(l+1)} = h^{(l)} + \Delta_{\text{MoE}}^{(l)} + \Delta_{\text{Attn}}^{(l+1)}$): predicts Layer
- Cache-Aware Miss-Only Nucleus Dynamic-K (
--tau):- Never drops experts already resident in GPU VRAM (since cache hits cost
<0.05 mson Metal). Only skips low-weight tail SSD misses beyondmin_konce cumulative routing mass reaches $\tau$ (0.85), rescaling kept weights to preserve layer activation norm.
- Never drops experts already resident in GPU VRAM (since cache hits cost
📐 Scaling Envelope & Honest Hardware Scope
Why Sparse MoE streaming achieves 45–57 tok/s while dense weight streaming cannot:
- A dense model touches 100% of its parameters on every single token (
e.g. 14 GB / 3 GB/s ≈ 0.2 tok/sphysics ceiling). - A Sparse MoE activates only $k / E$ (
3%–12.5%) of expert parameters per token, exhibits strong conversational topic locality (88%–93%hit rate in a12.5%–25%slot arena), and exposes cross-layer residual predictability (~84%lookahead recall).
| Sparse MoE Model Class | Original FP16 Size | Q4 DEIMIDX2 Disk Store |
Active Backbone + KV | Paged Arena (16–25% Slots) |
Total GPU VRAM Needed |
|---|---|---|---|---|---|
OLMoE-1B-7B (6.9B, A1.3B) (Verified) |
13.2 GiB |
3.38 GiB |
~0.65 GiB |
0.43–0.86 GiB (8–16/64) |
1.08 – 1.52 GiB |
Qwen3-30B-A3B (30.5B, 128E Top-8) |
~61 GiB |
~15.5 GiB |
~1.6 GiB |
~2.4 GiB (20/128) |
~4.0 – 4.5 GiB (8 GB Mac) |
Mixtral-8x7B (46.7B, 8E Top-2) |
~93 GiB |
~23.5 GiB |
~2.1 GiB |
~3.8 GiB (2–3/8) |
~5.8 – 6.5 GiB (8–16 GB Mac) |
Qwen3-235B-A22B (235B, 128E Top-8) |
~470 GiB |
~118 GiB |
~8.5 GiB |
~11.5 GiB (16/128) |
~20 – 22 GiB (24–32 GB Mac) |
(Note: OLMoE-1B-7B figures are live hardware measurements on M4 Max; larger rows show analytical DEIMIDX2 Q4 memory footprints from exact tensor dimensions.)
⚡ Quick Start
1. Install (PyPI — Apple Silicon MLX or Linux/Cloud CUDA)
# macOS Apple Silicon (uses native MLX Metal gather_qmm + zero-copy Unified Memory):
pip install deimos-stream
# Linux / Cloud NVIDIA CUDA GPUs (installs PyTorch pinned-DMA + FlashAttention SDPA backend):
pip install "deimos-stream[cuda]"
Or install from source for development:
git clone https://github.com/martianacademy/deimos-stream.git
cd deimos-stream
uv venv --python 3.12 && source .venv/bin/activate
uv pip install -e ".[cuda,dev]"
pytest -v
(Hardware routing --backend auto: on Apple Silicon, DeimosStream always selects native mlx rather than mps for zero-copy Unified-Memory pointers and fused 4-bit mx.gather_qmm Metal kernels; on Linux/Windows with NVIDIA/ROCm GPUs, it selects cuda with pin_memory=True async PCIe stream DMA and ABA-safe slot_gen slot synchronization over the exact same DEIMIDX2 Merkle store.)
2. Convert Any .safetensors Sparse MoE Checkpoint & Stream Chat
Supports HuggingFace & MLX .safetensors checkpoints across OLMoE, Qwen2-MoE / Qwen3-MoE (including GQA, per-head QK-Norm, and shared_expert), Mixtral (w1/w2/w3), and DeepSeek-MoE:
# 1. Convert a .safetensors Sparse MoE checkpoint into a 16 KB page-aligned DEIMIDX2 Q4 store:
deimos-stream convert \
--model-dir /path/to/OLMoE-1B-7B-0125-Instruct \
--output-dir ./olmoe_deimos_q4
# 2. Cryptographically verify the Tier-1 XOR Merkle tree & all Tier-2 SHA-256 expert leaves:
deimos-stream inspect --store-dir ./olmoe_deimos_q4 --verify-leaves
# 3. Launch interactive Low-VRAM streaming chat (1.52 GiB VRAM @ ~56 tok/s):
deimos-stream chat --store-dir ./olmoe_deimos_q4 --slots 16 --tau 0.85
# Ultra-Low 1.08 GiB VRAM mode (8 slots/layer):
deimos-stream chat --store-dir ./olmoe_deimos_q4 --slots 8 --tau 0.85
Inside interactive deimos-stream chat, switch VRAM budgets and routing thresholds live:
/slots <8|16|32|64>— hot-rebuildPagedExpertArenacapacity on the fly/tau <0.50..1.00>— adjust Miss-Only Nucleus Dynamic-K (1.00= bit-exact Top-K)/lookahead <on|off>— toggle C++17 cross-layer Residual Lookahead prefetch
3. OpenAI-Compatible API Gateway (deimos-stream serve)
Expose any DEIMIDX2 Sparse MoE store as a local OpenAI /v1/chat/completions server (streaming SSE + JSON, compatible with the openai SDK, Cursor, Continue, OpenCode, and OpenWebUI):
deimos-stream serve \
--store-dir ./olmoe_deimos_q4 \
--host 127.0.0.1 \
--port 8080 \
--slots 16 \
--tau 0.85 \
--model-name olmoe-1b-7b-q4
curl http://127.0.0.1:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "olmoe-1b-7b-q4",
"stream": true,
"max_tokens": 128,
"messages": [{"role": "user", "content": "Explain Merkle trees in two sentences."}]
}'
4. Python API (DeimosPagedMoEEngine)
from pathlib import Path
from deimos_stream import DeimosPagedMoEEngine, convert_safetensors_moe_to_deimos_q4
# One-time conversion from HuggingFace / MLX .safetensors:
store_dir = convert_safetensors_moe_to_deimos_q4(
source_model_dir=Path("/path/to/moe-checkpoint"),
output_store_dir=Path("./moe_deimos_q4"),
)
# Run inside a fixed 16-slot/layer Unified-Memory Arena:
engine = DeimosPagedMoEEngine(
store_dir=store_dir,
slots_per_layer=16,
use_nocache_pread=True,
enable_lookahead=True,
miss_tail_tau=0.85, # Set 1.0 for bit-exact parity vs full-pinned Q4
)
try:
metrics = engine.benchmark_generation(
"<|user|>\nExplain Merkle trees in two sentences.\n<|assistant|>\n",
max_new_tokens=64,
)
print(metrics["generated_text"])
print(f"Peak VRAM: {metrics['peak_vram_mb']} MiB | Speed: {metrics['decode_tok_per_s']} tok/s")
finally:
engine.close()
🌌 Martian Academy Streaming Suite
- PhobosStream — Universal Zero-VRAM Video & Image Diffusion (
DiT) Streaming Engine (Wan2.1,FLUX.1,HunyuanVideo,Z-Image-Turbo•93.9%–95.3%VRAM saved). - DeimosStream — Universal Low-VRAM Sparse MoE & LLM Merkle-Paged Streaming Engine (
OLMoE,Qwen2/3-MoE,Mixtral,DeepSeek-MoE•88.8%–92.0%VRAM saved).
📜 License
MIT License — free for commercial and personal use.
Metadata
Release files for deimos-stream 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| deimos_stream-0.3.0.tar.gz | 114.2 kB | With provenance | Details for deimos_stream-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| deimos_stream-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for deimos_stream-0.3.0-py3-none-any.whl |
Total release size: 202.8 kB
Release files / deimos_stream-0.3.0.tar.gz
| Download URL | deimos_stream-0.3.0.tar.gz |
|---|---|
| Size | 114.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
841155e99374c8c138f734423e18d97bb9d281c22655a18acf74a3d610f7dc91
|
|
BLAKE2b-256 checksum How to use checksums |
8900619d2764163b3e3b42d6ceedec5192f991e979c9e6825c596417534e8b51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / deimos_stream-0.3.0-py3-none-any.whl
| Download URL | deimos_stream-0.3.0-py3-none-any.whl |
|---|---|
| Size | 88.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
95bbdd8f3557c5e10f5c68689bd3787bb1f5e183ec54ec0b4de4fce82572684d
|
|
BLAKE2b-256 checksum How to use checksums |
63346aed5778c6dd1d00492fccd242fed46ad27e0bb187f6922aca86f89e0686
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logSecurity for deimos-stream 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for deimos_stream-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.