Skip to main content

PhobosStream Icon PhobosStream

PyPI Version Comfy Registry CI Tests Python 3.10+ License: MIT

PhobosStream is a universal zero-VRAM diffusion streaming engine built to run massive 12B–20B+ Video and Image Diffusion Transformers (DiTs) — including Alibaba Wan2.1 (14B), Black Forest Labs FLUX.1 (12B), Lumina2 / Z-Image-Turbo, and Tencent HunyuanVideo (13B) — on consumer hardware without Out-Of-Memory (OOM) crashes.

By combining 3-Stage Sequential Offloading (Text Encoder -> DiT -> Tiled VAE) with Hook-Based Zero-Copy mmap Block-by-Block Streaming (TorchBlockStreamer & MLXBlockStreamer), PhobosStream cuts Peak GPU Memory on a real 19.5 GB BF16 pipeline from 26.45 GB down to 1.25–1.60 GB (93.9%–95.3% VRAM reduction) with zero quantization quality loss.


📊 Verified Empirical Benchmarks

A. NVIDIA CUDA GPU — 8.0 GiB Hardware VRAM Cap & 3-Tier HYBRID_BUDGET (Tesla T4)

1. Real Wan-AI/Wan2.1-T2V-1.3B-Diffusers (~14.5 GB BF16: UMT5-XXL + 30-block WanDiT + 3D WanVAE) under an enforced 8.00 GiB CUDA VRAM limit (torch.cuda.set_per_process_memory_fraction, native widescreen 832×480, 25 frames, 40 steps, flow_shift=3.0 via standalone FastAPI /v1/videos/generations):

Pipeline Configuration Enforced CUDA Cap Peak CUDA VRAM Result
Standard Monolithic WanPipeline.to("cuda") 8,192.0 MB (8.0 GiB) > 8,192 MB (OOM) ❌ Crashes (CUDA out of memory)
phobos-stream serve (HYBRID_BUDGET + Fused SDPA) 8,192.0 MB (8.0 GiB) 3,263.9 MB (3.19 GiB) ✅ Crisp 25-frame 832×480 H.264 .mp4 (fits even 4 GB–8 GB GPUs!)

2. 3-Tier TorchBlockStreamer Benchmark on NVIDIA Tesla T4 (24-block 2.3 GB FP16 DiT, 4 steps, double-buffered CUDA record_stream prefetch):

Streaming Mode Block Residency (GPU / CPU / NVMe) Peak CUDA VRAM VRAM Saved 4-Step Latency Max Abs Diff vs Monolithic
Monolithic FP16 24 / 0 / 0 4,610.0 MB 0.0% 1.024 s 0.0 (Reference)
cpu_offload (Pinned + Async CUDA Stream) 0 / 24 / 0 322.2 MB 93.0% 1.074 s (only +4.9%!) 0.0 (Bit-Exact)
hybrid_budget (3-Tier Smart Split) 7 / 9 / 8 994.3 MB 78.4% 2.418 s (2.34× faster than mmap) 0.0 (Bit-Exact)
mmap_stream (Zero-RAM meta + NVMe) 0 / 0 / 24 226.1 MB 95.1% 5.653 s 0.0 (Bit-Exact)

B. Apple Silicon Metal GPU — Real 19.5 GB Model Suite (1024×1024, 8 Steps)

Measured end-to-end across isolated fresh subprocesses (scripts/benchmark_real_phobos_optimization.py) using qwen_3_4b.safetensors (7.5 GB, 36 layers) + z_image_turbo_bf16.safetensors (11.7 GB, 34 blocks) + ae.safetensors (320 MB):

Execution Mode Peak Metal GPU Memory VRAM Saved Active Resident Weights Denoising (Per Step) Total Wall Time Visual Quality
1. Monolithic Baseline (All 3 in GPU RAM) 26,445.0 MB 0.0% 19,637.5 MB 36.80 s (4.60 s) 41.97 s Reference BF16
2. Phobos 3-Stage Offload (BF16) 12,906.4 MB 51.2% 11,742.5 MB 44.14 s (5.52 s) 46.99 s Lossless BF16 (32.68 dB PSNR vs non-strip VAE)
3. Phobos 3-Stage + Q4 Quantized 4,814.7 MB 81.8% 3,310.4 MB 66.89 s (8.36 s) 69.72 s 4-bit Quantized (19.25 dB PSNR)
4. Phobos Zero-VRAM Block-Stream (Full BF16) 1,601.0 MB (DiT: 1,248.2 MB) 93.9% (DiT: 95.3%) 23.2 MB (91.6 MB active) 71.45 s (8.93 s) 75.04 s Bit-Exact BF16 (0.0000 px diff vs Stage-Offload)

Key Architectural Mechanisms

  1. Native BF16/FP16 Zero-Copy mmap (MMapTensorLoader): Slices tensor byte-ranges directly from .safetensors on NVMe SSD into native torch.bfloat16 (read_torch_tensor) and mlx.core.bfloat16 (read_mlx_array) without expanding weights to FP32 in host RAM.
  2. Hook-Based Per-Block Streaming (TorchBlockStreamer & MLXBlockStreamer):
    • PyTorch (CUDA / MPS / ROCm / CPU): Supports cpu_offload (read-only pinned CPU shadow + async CUDA prefetch stream, zero GPU→CPU writeback) and mmap_stream (zero-RAM torch.device("meta") skeleton support + immediate 0-element parameter eviction after each block).
    • Apple Silicon (MLX): Enforces mx.eval boundaries per transformer block so MLX lazy graphs never accumulate multi-GB block weights simultaneously in unified memory.
  3. 3-Stage Sequential Offloading & Tiled VAE (StageSequentialRunner): Isolates Text Encoder, DiT, and spatial-feather-blended Tiled/Strip VAE stages with explicit accelerator cache reclamation between stages, plus single-pass batched Classifier-Free Guidance (cutting disk reads per CFG step by 50%).

🏛️ System Architecture

flowchart TD
    subgraph STAGE1["Stage 1: Text Encoding"]
        P["User Prompt"] --> TE["Qwen / T5-XXL / DualCLIP"]
        TE --> EMB["Conditioning Tensor (~2–5 MB)"]
        TE -.->|"Immediate Unload + Cache Flush"| FREE1["Text Encoder Freed"]
    end

    subgraph STAGE2["Stage 2: Hook-Streamed DiT Denoising"]
        EMB --> DIT["TorchBlockStreamer / MLXBlockStreamer"]
        NVME[("NVMe SSD (.safetensors mmap)")] ==>|"Stream Active Block N (~360 MB)"| BLK["Native DiT Block Forward"]
        BLK -.->|"Eval + Evict Block N to 0 Bytes"| NVME
        BLK --> ODE["Batched CFG + Flow Matching Step"]
    end

    subgraph STAGE3["Stage 3: Tiled / Strip VAE Reconstruction"]
        ODE --> VAE["Feather-Blended Tiled / Strip VAE"]
        VAE --> OUT["PNG Image / H.264 MP4 Video"]
    end

⚡ Quick Start

1. Install from PyPI

pip install phobos-stream
# With HuggingFace Diffusers (Wan2.1 / FLUX / SDXL) or GGUF extras:
pip install "phobos-stream[diffusers,gguf]"

Or install from source for development:

git clone https://github.com/martianacademy/phobos-stream.git
cd phobos-stream
uv venv --python 3.12 && source .venv/bin/activate
uv pip install -e ".[dev]"
pytest -v

2. Python API: Stream Any Real PyTorch DiT in 4 Lines

import torch
from phobos_stream.streaming import BlockStreamMode, TorchBlockStreamer

with torch.device("meta"):
    model = MyDiffusionTransformer().to(torch.bfloat16)

with TorchBlockStreamer(
    model,
    compute_device="auto",
    mode=BlockStreamMode.MMAP_STREAM,
    safetensors_paths=["model_bf16.safetensors"],
):
    output = model(latents, timestep, context)

3. CLI & OpenAI / Sora-Compatible Video & Image API Gateway

# Launch standalone Diffusers video/image server under a strict 3-tier VRAM/RAM budget (runs Wan2.1 in ~4.3 GiB VRAM!):
phobos-stream serve --port 8088 \
  --hf-model Wan-AI/Wan2.1-T2V-1.3B-Diffusers \
  --stream-mode hybrid_budget \
  --vram-budget-mb 3200

# Or index a local .safetensors checkpoint directory into a zero-copy virtual manifest:
phobos-stream shard --model-dir /path/to/models --architecture wan2.1
phobos-stream serve --port 8088 --manifest-path /path/to/models/shards/manifest.json --backend auto

🎨 ComfyUI Custom Node Extension (ComfyUI-PhobosStream)

Published on both the Official Comfy Registry and ComfyUI-Manager (repository):

comfy node install comfyui-phobosstream
  • 🚀 Phobos Zero-VRAM 2K/4K & Video Pipeline: 3-stage sequential offloader supporting single & DualCLIPLoader, dynamic 4-ch/16-ch 4D image and 5D video latents (Wan2.1, HunyuanVideo, FLUX, Lumina2, SDXL), VAEDecodeTiled, and per-block streaming.
  • 🔌 PhobosStream Block-Streamer (Any MODEL): Drop-in MODEL -> MODEL hook patcher (cpu_offload / mmap_stream) compatible with standard ComfyUI workflows (LoRAs, ControlNet, WanVideo, FLUX).
  • 🌌 PhobosStream Model Loader, ⚡ PhobosStream Diffusion Sampler, and 🎞️ PhobosStream Tiled VAE Decoder.

📜 License

MIT License — free for commercial and personal use.

Metadata

Release files for phobos-stream 0.2.2

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

Source distribution (sdist)

Source distribution for phobos-stream 0.2.2
File Size Uploaded Provenance Actions
phobos_stream-0.2.2.tar.gz 218.6 kB With provenance Details for phobos_stream-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for phobos-stream 0.2.2
File Interpreter ABI Platform Actions
phobos_stream-0.2.2-py3-none-any.whl Python 3 none any Details for phobos_stream-0.2.2-py3-none-any.whl

Total release size: 305.5 kB

Release files / phobos_stream-0.2.2.tar.gz

Download URL phobos_stream-0.2.2.tar.gz
Size 218.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b96556cfca839d8514f92380db6a254933b4d57521267ca260c52e59a4280b6b
BLAKE2b-256 checksum
How to use checksums
ff49533168ee9fe2fd2a2ecee20d2cb5f8bc5f9b6e7d1c36d799a8d8b0dc2877
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 log

Release files / phobos_stream-0.2.2-py3-none-any.whl

Download URL phobos_stream-0.2.2-py3-none-any.whl
Size 86.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a177990545a392ccbf5db7ceeed12de05fb3a0b8c83d5c4f78be0900bc88cf95
BLAKE2b-256 checksum
How to use checksums
889951efa6a98a47255bde14d3a215a802a2dc2aa63def96869d197c3801b130
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 log

Security for phobos-stream 0.2.2

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 phobos_stream-0.2.2.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 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