Skip to main content

DeimosStream Icon DeimosStream

PyPI Version CI Tests Martian Suite: PhobosStream Backend Python 3.10+ License: MIT

DeimosStream is a universal low-VRAM Sparse Mixture-of-Experts (MoE) LLM streaming engine — the language-model twin to PhobosStream — built to run massive 2026 Sparse & Hybrid MoE models (Qwen3.6-35B-A3B, Qwen3.5/3-MoE, OLMoE, Mixtral, DeepSeek-MoE) inside a tiny, strictly bounded GPU memory footprint with cryptographic Merkle proof verification on every cold expert page streamed from SSD.

By combining a 16 KB Page-Aligned 4-Bit Cryptographic Merkle Store (DEIMIDX2), a Zero-RAM meta-Skeleton Hybrid Streamer, a Pre-Allocated PagedExpertArena (MLX mx.gather_qmm on Apple Silicon • CUDA pin_memory=True async stream DMA on NVIDIA GPUs), Zero-GIL C++17 Cross-Layer Residual Lookahead, and Cache-Aware Miss-Only Nucleus Dynamic-K, DeimosStream runs:

  • 35B Qwen/Qwen3.6-35B-A3B (66.97 GiB BF16, 10,240 experts) on a single 15 GB NVIDIA Tesla T4 GPU inside 3.74–5.32 GiB Active VRAM (-91.2% to -93.9% VRAM saved) with 0.00000000 bit-exact CUDA logit parity (8 vs 32 slots @ tau=1.0) and 100% (10,240/10,240) cold SHA-256 Merkle proofs verified — even on a 12.7 GiB RAM Free Colab VM where CPU RAM + GPU VRAM combined (27 GiB) is 2.5× smaller than the model!
  • 6.92B OLMoE-1B-7B (13.20 GiB FP16) on Apple Silicon (M4 Max Metal) inside 1.06–1.48 GiB VRAM (-88.8% to -92.0% saved) at 45.5–57.4 tok/s with zero prefill VRAM spikes and no perplexity degradation.

🚀 Verified 2026 Frontier MoE CUDA Benchmark (Qwen/Qwen3.6-35B-A3B, 35B Params / 66.97 GiB BF16)

Measured end-to-end with deimos-stream==0.3.1 (PyTorch 2.11+cu130, Transformers 5.24.1) on a single NVIDIA Tesla T4 (14.56 GiB VRAM) running Qwen/Qwen3.6-35B-A3B (40 hybrid layers: 30 GatedDeltaNet + 10 GQA × 256 experts = 10,240 experts, Top-8 active, 248,320 vocab). Standard BF16 (66.97 GiB, 4.6× larger than T4) and full-resident Q4 (~21 GiB) both immediately OOM on a single T4.

Configuration (Tesla T4, Kaggle 30 GiB Host RAM) Active / Peak CUDA VRAM VRAM Saved vs BF16 Expert Arena Pool Expert Cache Hit Rate Residual Lookahead Hits Decode Speed (64 tok)
Monolithic BF16 Baseline (Qwen3.6-35B-A3B) 66,965 MiB (OOM on T4) 0.0% — 100.0% — OOM (>4.6× T4)
DeimosStream Ultra-Low (--slots 8 --tau 0.85) 3,830.6 / 4,214.9 MiB -93.85% (4–6 GB GPU) 540.0 MiB (3.1%) 85.77% 8,287 1.65 tok/s
DeimosStream Low-VRAM (--slots 16 --tau 0.85) 4,370.6 / 4,754.9 MiB -93.07% (6 GB GPU) 1,080.0 MiB (6.3%) 89.56% 6,512 1.84 tok/s
DeimosStream T4 Sweet Spot (--slots 32 --tau 0.85) 5,449.7 / 6,066.3 MiB -91.15% (8 GB GPU) 2,160.0 MiB (12.5%) 93.25% 4,590 2.61 tok/s
DeimosStream Exact Zero-Skip (--slots 32 --tau 1.00) 5,449.7 / 6,066.3 MiB -91.15% 2,160.0 MiB (12.5%) 87.93% 4,398 2.56 tok/s (Avg K=8.0)
DeimosStream High-Hit (--slots 64 --tau 0.85) 7,609.7 / 8,841.6 MiB -87.11% (12 GB GPU) 4,320.0 MiB (25.0%) 95.61% 2,308 1.98 tok/s
  • Bit-Exact 35B CUDA Parity (--tau 1.0): Verified max_abs_diff = 0.00000000 (top1 = (2, 2)) across all 248,320 logits and all 40 hybrid layers between 8/256-slot and 32/256-slot paging on real NVIDIA Tesla T4 CUDA hardware (WAW/WAR CUDA stream fence + per-layer DMA torch.cuda.Event sync).
  • Cryptographic Integrity at 10,240-Expert Scale: Converted 66.965 GiB BF16 -> 20.985 GiB DEIMIDX2 Q4 store in 526.96s via shard-by-shard deletion (cas_experts_q4.bin: 17,280 MiB, hf_backbone.safetensors: 2,730 MiB, embed_tokens.bin: 970 MiB zero-VRAM CPU mmap, lm_head_int8.bin: 485.5 MiB, merkle_tree.idx: 1.70 MiB); verified Tier-1 startup root (35.3–70.2 ms) and 10,240 / 10,240 (100%) cold SHA-256 leaf proofs (model_merkle_root: 40b90275ba8b...).
  • Extreme Constrained Host Verification (Free Google Colab Tesla T4, 12.67 GiB Host RAM, 0 Swap): Successfully converted and streamed the entire 66.97 GiB model inside 3,829.2 MiB Active / 4,213.5 MiB Peak VRAM (-93.86%, 86.6%–95.99% hit rate, 0.71–1.21 tok/s over Colab network Persistent Disk) with zero OOMs. (Note: slots=128 on T4 requires ~13.0 GiB base VRAM leaving insufficient scratch headroom on 14.56 GiB T4; slots=32 is the optimal pinned-DMA operating point on 15 GB T4 GPUs.)

📊 Verified Apple Silicon MLX 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): Running DeimosPagedMoEEngine(..., slots_per_layer=8, miss_tail_tau=1.0) produces 0.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, MerkleKVPrefixCache verifies and restores 48/54 cached prompt tokens in O(1) via DEIMIDX2 Robin-Hood hashing, cutting cold-restart TTFT 4.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

  1. Universal DEIMIDX2 Cryptographic Merkle Index (deimos_merkle.mm):
    • Supports arbitrary (num_layers, num_experts, vocab_size) topologies (non-power-of-2 leaf counts automatically padded to tree_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) in 2.08 ms (3.1 ns O(1) C-struct lookup).
    • Tier-2 Cold Leaf Proof: Hardware-accelerated ARMv8 CC_SHA256 verifies every cold expert's raw 4-bit payload bytes on NVMe pread/mmap before weights enter GPU memory, raising DeimosMerkleIntegrityError on even a 1-bit disk flip.
  2. Pre-Allocated Unified-Memory PagedExpertArena (deimos_arena.mm):
    • Eliminates mx.stack allocation 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++17 memcpy + POSIX_MADV_DONTNEED.
  3. 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+1 experts using $W_{\text{gate}}^{(l+1)} \cdot \text{RMSNorm}(h_{\text{post-attn}}^{(l)})$ and stages cold l+1 leaves on a background C++17 worker thread into disjoint arena[l+1] while the Metal GPU computes MoE(l) and Attention(l+1) — eliminating 83.6% of synchronous SSD misses with zero race conditions.
  4. Cache-Aware Miss-Only Nucleus Dynamic-K (--tau):
    • Never drops experts already resident in GPU VRAM (since cache hits cost <0.05 ms on Metal). Only skips low-weight tail SSD misses beyond min_k once cumulative routing mass reaches $\tau$ (0.85), rescaling kept weights to preserve layer activation norm.

📐 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/s physics 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 a 12.5%–25% slot arena), and exposes cross-layer residual predictability (~84% lookahead recall).
Sparse MoE Model Class Original BF16/FP16 Size Q4 DEIMIDX2 Disk Store Active Backbone + Head Paged Arena (3%–25% Slots) Total GPU VRAM Needed
OLMoE-1B-7B (6.9B, A1.3B) (Verified MLX) 13.2 GiB 3.38 GiB ~0.65 GiB 0.43–0.86 GiB (8–16/64) 1.08 – 1.52 GiB
Qwen/Qwen3.6-35B-A3B (35B, 256E Top-8) (Verified T4 CUDA) 66.97 GiB 20.99 GiB 3.21 GiB (0-VRAM mmap emb) 0.53–2.11 GiB (8–32/256) 3.74 – 5.32 GiB (Single T4 / 6–8 GB GPU)
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 GPU)
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 GPU)

(Note: OLMoE-1B-7B on Apple M4 Max and Qwen/Qwen3.6-35B-A3B on NVIDIA Tesla T4 are live hardware measurements; Mixtral/235B rows show analytical DEIMIDX2 Q4 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 or HuggingFace 2026 Hybrid-MoE Checkpoint & Stream Chat

Supports local .safetensors checkpoints and direct shard-by-shard HuggingFace Hub streaming across Qwen3.6-35B-A3B / Qwen3.5-MoE (hybrid GatedDeltaNet + GQA + 256 experts), OLMoE, Qwen2/3-MoE, Mixtral, and DeepSeek-MoE:

# 1a. Stream & convert 2026 35B Qwen/Qwen3.6-35B-A3B (66.97 GiB BF16 -> 20.99 GiB DEIMIDX2 Q4, auto-deleting shards):
deimos-stream convert \
  --model-dir Qwen/Qwen3.6-35B-A3B \
  --output-dir ./qwen36_35b_deimos_q4

# 1b. Or convert any local .safetensors Sparse MoE (e.g. OLMoE-1B-7B):
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 ./qwen36_35b_deimos_q4 --verify-leaves

# 3. Launch interactive Low-VRAM streaming chat (Qwen3.6-35B inside 5.32 GiB VRAM on a single T4):
deimos-stream chat --store-dir ./qwen36_35b_deimos_q4 --slots 32 --tau 0.85

# Ultra-Low 3.74 GiB VRAM mode for 35B Qwen3.6 (or 1.06 GiB for 7B OLMoE):
deimos-stream chat --store-dir ./qwen36_35b_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-rebuild PagedExpertArena capacity 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.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for deimos-stream 0.4.0
File Size Uploaded Provenance Actions
deimos_stream-0.4.0.tar.gz 119.0 kB With provenance Details for deimos_stream-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for deimos-stream 0.4.0
File Interpreter ABI Platform Actions
deimos_stream-0.4.0-py3-none-any.whl Python 3 none any Details for deimos_stream-0.4.0-py3-none-any.whl

Total release size: 212.9 kB

Release files / deimos_stream-0.4.0.tar.gz

Download URL deimos_stream-0.4.0.tar.gz
Size 119.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9660467bc3398c3c70c8f56a70fe790ecd7425ecf52833f4d1a0105442c35214
BLAKE2b-256 checksum
How to use checksums
72148a95d36795b8ac784b189aa06294bd3f259030e33815e3265b167303b380
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 26, 2026.

Transparency log

Release files / deimos_stream-0.4.0-py3-none-any.whl

Download URL deimos_stream-0.4.0-py3-none-any.whl
Size 93.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15a07a884a3bb5d41eef3abea716751575653fc54b848d8af5fafbebee1938d5
BLAKE2b-256 checksum
How to use checksums
4a06f019ec0bae67c472f65eb59d74bfd237cda890268f5ad1171598a8bbf6cc
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 26, 2026.

Transparency log

Security for deimos-stream 0.4.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.

Select from 2 files

Attestation for deimos_stream-0.4.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 26, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page