phobos-stream 0.2.0__tar.gz → 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. phobos_stream-0.2.1/.github/workflows/ci.yml +27 -0
  2. phobos_stream-0.2.1/HANDOFF.md +79 -0
  3. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/PKG-INFO +29 -20
  4. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/README.md +28 -19
  5. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/pyproject.toml +1 -1
  6. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/media/video_writer.py +33 -34
  7. phobos_stream-0.2.0/.github/workflows/ci.yml +0 -19
  8. phobos_stream-0.2.0/HANDOFF.md +0 -136
  9. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/.github/workflows/publish-pypi.yml +0 -0
  10. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/.gitignore +0 -0
  11. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/LICENSE +0 -0
  12. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/assets/icon.png +0 -0
  13. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/examples/benchmark_streaming.py +0 -0
  14. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/examples/phobos_2k_comfyui_workflow.json +0 -0
  15. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/examples/test_live_server.py +0 -0
  16. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/scripts/benchmark_2k_phobos_vs_direct.py +0 -0
  17. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/scripts/benchmark_mlx_lm_optimizations.py +0 -0
  18. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/scripts/benchmark_real_phobos_optimization.py +0 -0
  19. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/scripts/generate_z_image_mlx_phobos.py +0 -0
  20. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/scripts/run_z_image_turbo.py +0 -0
  21. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/__init__.py +0 -0
  22. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/adapters/__init__.py +0 -0
  23. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/adapters/base.py +0 -0
  24. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/adapters/cogvideo_adapter.py +0 -0
  25. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/adapters/factory.py +0 -0
  26. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/adapters/flux_adapter.py +0 -0
  27. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/adapters/hunyuan_adapter.py +0 -0
  28. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/adapters/wan_adapter.py +0 -0
  29. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/backends/__init__.py +0 -0
  30. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/backends/base.py +0 -0
  31. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/backends/cuda_backend.py +0 -0
  32. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/backends/factory.py +0 -0
  33. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/backends/gguf_backend.py +0 -0
  34. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/backends/mlx_backend.py +0 -0
  35. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/cli.py +0 -0
  36. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/integrations/__init__.py +0 -0
  37. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/integrations/comfyui/__init__.py +0 -0
  38. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/integrations/comfyui/comfy_runtime.py +0 -0
  39. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/integrations/comfyui/nodes.py +0 -0
  40. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/media/__init__.py +0 -0
  41. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/models/__init__.py +0 -0
  42. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/models/attention.py +0 -0
  43. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/models/dit_block.py +0 -0
  44. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/models/rotary.py +0 -0
  45. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/pipeline/__init__.py +0 -0
  46. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/pipeline/offloader.py +0 -0
  47. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/pipeline/scheduler.py +0 -0
  48. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/pipeline/stage_runner.py +0 -0
  49. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/pipeline/stream_engine.py +0 -0
  50. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/pipelines/__init__.py +0 -0
  51. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/pipelines/mlx_zimage.py +0 -0
  52. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/pipelines/mlx_zimage_blocks.py +0 -0
  53. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/pipelines/mlx_zimage_vae.py +0 -0
  54. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/server/__init__.py +0 -0
  55. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/server/app.py +0 -0
  56. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/server/schemas.py +0 -0
  57. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/server/ws_progress.py +0 -0
  58. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/storage/__init__.py +0 -0
  59. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/storage/layout.py +0 -0
  60. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/storage/mmap_loader.py +0 -0
  61. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/storage/sharder.py +0 -0
  62. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/streaming/__init__.py +0 -0
  63. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/streaming/mlx_block_streamer.py +0 -0
  64. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/streaming/torch_block_streamer.py +0 -0
  65. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/src/phobos_stream/types.py +0 -0
  66. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/tests/test_adapters.py +0 -0
  67. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/tests/test_backends.py +0 -0
  68. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/tests/test_comfyui.py +0 -0
  69. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/tests/test_models.py +0 -0
  70. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/tests/test_pipeline.py +0 -0
  71. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/tests/test_real_streaming.py +0 -0
  72. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/tests/test_server.py +0 -0
  73. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/tests/test_storage.py +0 -0
  74. {phobos_stream-0.2.0 → phobos_stream-0.2.1}/uv.lock +0 -0
@@ -0,0 +1,27 @@
1
+ name: CI Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - name: Populate ComfyUI-PhobosStream bundle for standalone integration test
15
+ run: |
16
+ if [ ! -f ComfyUI-PhobosStream/__init__.py ]; then
17
+ rm -rf ComfyUI-PhobosStream
18
+ git clone --depth 1 https://github.com/martianacademy/ComfyUI-PhobosStream.git ComfyUI-PhobosStream
19
+ fi
20
+ - uses: astral-sh/setup-uv@v4
21
+ - name: Ensure ffmpeg is available for MP4 video export tests
22
+ run: which ffmpeg || (sudo apt-get update && sudo apt-get install -y --no-install-recommends ffmpeg)
23
+ - name: Install dependencies & run pytest
24
+ run: |
25
+ uv venv --python 3.12
26
+ uv pip install -e ".[dev]"
27
+ uv run pytest -v
@@ -0,0 +1,79 @@
1
+ # <img src="https://raw.githubusercontent.com/martianacademy/phobos-stream/main/assets/icon.png" width="38" align="top" alt="PhobosStream Icon" /> Project Handoff & Architecture Guide
2
+
3
+ **Project:** `PhobosStream` (`v0.2.1`)
4
+ **GitHub Repository:** [https://github.com/martianacademy/phobos-stream](https://github.com/martianacademy/phobos-stream)
5
+ **PyPI Package:** [https://pypi.org/project/phobos-stream/](https://pypi.org/project/phobos-stream/)
6
+ **Comfy Registry:** [https://registry.comfy.org/publishers/martianacademy/nodes/comfyui-phobosstream](https://registry.comfy.org/publishers/martianacademy/nodes/comfyui-phobosstream)
7
+ **ComfyUI Extension Repo:** [https://github.com/martianacademy/ComfyUI-PhobosStream](https://github.com/martianacademy/ComfyUI-PhobosStream)
8
+ **License:** MIT
9
+
10
+ ---
11
+
12
+ ## 🎯 Executive Summary
13
+
14
+ `PhobosStream` is a universal zero-VRAM diffusion streaming engine designed to run **12B–20B+ Video and Image Diffusion Transformers (DiTs)** on consumer Apple Silicon Macs and 8GB/12GB NVIDIA/AMD GPUs without Out-Of-Memory (OOM) crashes.
15
+
16
+ By combining **3-Stage Sequential Offloading** (`Text Encoder -> DiT -> Tiled/Strip VAE`) with **Hook-Based Per-Block Zero-Copy `mmap` Streaming** (`TorchBlockStreamer` & `MLXBlockStreamer`), PhobosStream reduces Peak Metal GPU memory on a real **19.5 GB BF16 pipeline (`Qwen 3.4B` + `Z-Image-Turbo` + `VAE`) from 26.45 GB down to 1.25–1.60 GB (93.9%–95.3% reduction)** while preserving **bit-exact BF16 output**.
17
+
18
+ ---
19
+
20
+ ## 🏗️ Codebase Directory Structure
21
+
22
+ ```text
23
+ phobos-stream/
24
+ ├── pyproject.toml # Build config, PyPI metadata, and CLI entrypoint
25
+ ├── README.md # Main user & developer documentation
26
+ ├── HANDOFF.md # Architecture & release handoff guide
27
+ ├── assets/icon.png # Martian brand mark (#181110, #EE6A3E, #FFF7F0)
28
+ ├── ComfyUI-PhobosStream/ # Self-contained ComfyUI custom node repository
29
+ ├── src/phobos_stream/
30
+ │ ├── types.py # GenerationConfig, BackendType, PipelineMetrics
31
+ │ ├── cli.py # CLI (`serve`, `generate`, `shard`, `benchmark`)
32
+ │ ├── storage/
33
+ │ │ ├── layout.py # ModelShardsManifest & BlockMetadata
34
+ │ │ ├── mmap_loader.py # Zero-copy safetensors mmap (NumPy, PyTorch BF16, MLX BF16)
35
+ │ │ └── sharder.py # Virtual indexer & physical block partitioner
36
+ │ ├── streaming/
37
+ │ │ ├── torch_block_streamer.py # Hook-based PyTorch CPU-offload & meta-device mmap streamer
38
+ │ │ └── mlx_block_streamer.py # Per-block MLX mmap streamer with mx.eval boundaries
39
+ │ ├── pipeline/
40
+ │ │ ├── stage_runner.py # StageSequentialRunner & feather-blended tiled_spatial_decode
41
+ │ │ ├── scheduler.py # Flow Matching Euler ODE scheduler
42
+ │ │ ├── offloader.py # Shard streaming coordinator
43
+ │ │ └── stream_engine.py # Batched single-pass CFG denoising engine
44
+ │ ├── pipelines/
45
+ │ │ ├── mlx_zimage.py # End-to-end Apple Metal MLX Z-Image-Turbo pipeline
46
+ │ │ ├── mlx_zimage_blocks.py # Fused QKV/W13 kernels & per-block mmap streaming
47
+ │ │ └── mlx_zimage_vae.py # Low-memory MLX Strip-VAE weight mapper
48
+ │ ├── media/
49
+ │ │ └── video_writer.py # PNG & H.264/MPEG-4 MP4 video encoder
50
+ │ ├── integrations/comfyui/
51
+ │ │ ├── comfy_runtime.py # 3-stage offload, 4D/5D latents, DualCLIP, Tiled VAE
52
+ │ │ └── nodes.py # 5 registered ComfyUI custom nodes
53
+ │ ├── backends/ # MLX, CUDA/ROCm, and GGUF/CPU compute backends
54
+ │ ├── models/ # Standalone attention, 3D-RoPE, and DiT block primitives
55
+ │ ├── adapters/ # Wan2.1, FLUX, HunyuanVideo, CogVideoX weight mappers
56
+ │ └── server/ # FastAPI HTTP + WebSocket OpenAI/Sora-compatible gateway
57
+ ├── scripts/
58
+ │ └── benchmark_real_phobos_optimization.py # Isolated 4-mode empirical benchmark on 19.5 GB suite
59
+ └── tests/ # 27 passing unit & integration tests (<3s runtime)
60
+ ```
61
+
62
+ ---
63
+
64
+ ## 📊 Verified Empirical Results (`1024×1024`, 8 Steps, Real 19.5 GB Suite)
65
+
66
+ | Mode | Peak Metal GPU | VRAM Saved | Active Resident | Wall Time | Fidelity |
67
+ | :--- | :---: | :---: | :---: | :---: | :--- |
68
+ | `monolithic` | `26,445.0 MB` | `0.0%` | `19,637.5 MB` | `41.97 s` | Reference |
69
+ | `stage_offload` | `12,906.4 MB` | `51.2%` | `11,742.5 MB` | `46.99 s` | `32.68 dB` PSNR (Strip-VAE) |
70
+ | `q4_stage_offload` | `4,814.7 MB` | `81.8%` | `3,310.4 MB` | `69.72 s` | `19.25 dB` PSNR (4-bit) |
71
+ | `block_stream` | `1,601.0 MB` (`1,248.2 MB` DiT) | `93.9%` (`95.3%` DiT) | `23.2 MB` | `75.04 s` | Bit-exact BF16 (`0.0 px` diff vs `stage_offload`) |
72
+
73
+ ---
74
+
75
+ ## 🚀 Release & CI Automation
76
+
77
+ - **GitHub CI (`.github/workflows/ci.yml`):** Runs all 27 `pytest` checks on Ubuntu 24.04 on every push/PR.
78
+ - **PyPI Auto-Publish (`.github/workflows/publish-pypi.yml`):** Publishes to `pypi.org/project/phobos-stream/` via GitHub OIDC Trusted Publisher on release or manual `workflow_dispatch` (bump `version` in `pyproject.toml` first).
79
+ - **Comfy Registry Auto-Publish (`ComfyUI-PhobosStream/.github/workflows/publish.yml`):** Publishes to `registry.comfy.org` via `Comfy-Org/publish-node-action` whenever `ComfyUI-PhobosStream/pyproject.toml` version is bumped on `main`.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: phobos-stream
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Universal Zero-VRAM Video & Image Diffusion Streaming Engine (MLX • CUDA • MPS • ROCm • GGUF)
5
5
  Project-URL: Homepage, https://github.com/martianacademy/phobos-stream
6
6
  Project-URL: Repository, https://github.com/martianacademy/phobos-stream
@@ -36,14 +36,15 @@ Provides-Extra: gguf
36
36
  Requires-Dist: gguf>=0.10.0; extra == 'gguf'
37
37
  Description-Content-Type: text/markdown
38
38
 
39
- # <img src="assets/icon.png" width="42" align="top" alt="PhobosStream Icon" /> PhobosStream
39
+ # <img src="https://raw.githubusercontent.com/martianacademy/phobos-stream/main/assets/icon.png" width="42" align="top" alt="PhobosStream Icon" /> PhobosStream
40
40
 
41
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
41
+ [![PyPI Version](https://img.shields.io/pypi/v/phobos-stream?color=EE6A3E&label=PyPI)](https://pypi.org/project/phobos-stream/)
42
+ [![Comfy Registry](https://img.shields.io/badge/Comfy_Registry-v0.2.3-EE6A3E)](https://registry.comfy.org/publishers/martianacademy/nodes/comfyui-phobosstream)
43
+ [![CI Tests](https://github.com/martianacademy/phobos-stream/actions/workflows/ci.yml/badge.svg)](https://github.com/martianacademy/phobos-stream/actions/workflows/ci.yml)
42
44
  [![Python 3.10+](https://img.shields.io/badge/Python-3.10%2B-brightgreen.svg)](https://www.python.org/)
43
- [![Backends](https://img.shields.io/badge/Backends-MLX%20•%20CUDA%20•%20MPS%20•%20ROCm%20•%20GGUF-purple.svg)]()
44
- [![Tests Passing](https://img.shields.io/badge/Tests-27%20Passing-success.svg)]()
45
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/martianacademy/phobos-stream/blob/main/LICENSE)
45
46
 
46
- **PhobosStream** is a universal zero-VRAM diffusion streaming engine designed 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.
47
+ **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.
47
48
 
48
49
  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**.
49
50
 
@@ -96,24 +97,24 @@ flowchart TD
96
97
 
97
98
  ## ⚡ Quick Start
98
99
 
99
- ### 1. Installation
100
+ ### 1. Install from PyPI
100
101
 
101
102
  ```bash
102
- git clone https://github.com/martianacademy/phobos-stream.git
103
- cd phobos-stream
104
-
105
- uv venv --python 3.12
106
- source .venv/bin/activate
107
- uv pip install -e ".[dev]"
103
+ pip install phobos-stream
104
+ # With PyTorch CUDA/MPS or GGUF extras:
105
+ pip install "phobos-stream[cuda,gguf]"
108
106
  ```
109
107
 
110
- ### 2. Run Test Suite (27 Unit & Integration Tests)
111
-
108
+ Or install from source for development:
112
109
  ```bash
110
+ git clone https://github.com/martianacademy/phobos-stream.git
111
+ cd phobos-stream
112
+ uv venv --python 3.12 && source .venv/bin/activate
113
+ uv pip install -e ".[dev]"
113
114
  pytest -v
114
115
  ```
115
116
 
116
- ### 3. Python API: Hook Any Real PyTorch DiT in 4 Lines
117
+ ### 2. Python API: Stream Any Real PyTorch DiT in 4 Lines
117
118
 
118
119
  ```python
119
120
  import torch
@@ -131,17 +132,25 @@ with TorchBlockStreamer(
131
132
  output = model(latents, timestep, context)
132
133
  ```
133
134
 
134
- ### 4. Launch OpenAI / Sora-Compatible REST & WebSocket API
135
+ ### 3. CLI & OpenAI / Sora-Compatible API Gateway
135
136
 
136
137
  ```bash
137
- phobos-stream serve --port 8088 --manifest-path shards/manifest.json --backend auto
138
+ # Index a .safetensors checkpoint directory into a zero-copy virtual manifest:
139
+ phobos-stream shard --model-dir /path/to/models --architecture wan2.1
140
+
141
+ # Launch REST & WebSocket API server (/v1/images/generations, /v1/videos/generations):
142
+ phobos-stream serve --port 8088 --manifest-path /path/to/models/shards/manifest.json --backend auto
138
143
  ```
139
144
 
140
145
  ---
141
146
 
142
147
  ## 🎨 ComfyUI Custom Node Extension (`ComfyUI-PhobosStream`)
143
148
 
144
- **ComfyUI-PhobosStream** is registered in **ComfyUI-Manager** ([standalone repository](https://github.com/martianacademy/ComfyUI-PhobosStream)) and works out-of-the-box with zero unpublished dependencies:
149
+ Published on both the [**Official Comfy Registry**](https://registry.comfy.org/publishers/martianacademy/nodes/comfyui-phobosstream) and **ComfyUI-Manager** ([repository](https://github.com/martianacademy/ComfyUI-PhobosStream)):
150
+
151
+ ```bash
152
+ comfy node install comfyui-phobosstream
153
+ ```
145
154
 
146
155
  * **`🚀 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.
147
156
  * **`🔌 PhobosStream Block-Streamer (Any MODEL)`**: Drop-in `MODEL -> MODEL` hook patcher (`cpu_offload` / `mmap_stream`) compatible with standard ComfyUI workflows (LoRAs, ControlNet, WanVideo, FLUX).
@@ -151,4 +160,4 @@ phobos-stream serve --port 8088 --manifest-path shards/manifest.json --backend a
151
160
 
152
161
  ## 📜 License
153
162
 
154
- MIT License — free for commercial and personal use.
163
+ [MIT License](https://github.com/martianacademy/phobos-stream/blob/main/LICENSE) — free for commercial and personal use.
@@ -1,11 +1,12 @@
1
- # <img src="assets/icon.png" width="42" align="top" alt="PhobosStream Icon" /> PhobosStream
1
+ # <img src="https://raw.githubusercontent.com/martianacademy/phobos-stream/main/assets/icon.png" width="42" align="top" alt="PhobosStream Icon" /> PhobosStream
2
2
 
3
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
3
+ [![PyPI Version](https://img.shields.io/pypi/v/phobos-stream?color=EE6A3E&label=PyPI)](https://pypi.org/project/phobos-stream/)
4
+ [![Comfy Registry](https://img.shields.io/badge/Comfy_Registry-v0.2.3-EE6A3E)](https://registry.comfy.org/publishers/martianacademy/nodes/comfyui-phobosstream)
5
+ [![CI Tests](https://github.com/martianacademy/phobos-stream/actions/workflows/ci.yml/badge.svg)](https://github.com/martianacademy/phobos-stream/actions/workflows/ci.yml)
4
6
  [![Python 3.10+](https://img.shields.io/badge/Python-3.10%2B-brightgreen.svg)](https://www.python.org/)
5
- [![Backends](https://img.shields.io/badge/Backends-MLX%20•%20CUDA%20•%20MPS%20•%20ROCm%20•%20GGUF-purple.svg)]()
6
- [![Tests Passing](https://img.shields.io/badge/Tests-27%20Passing-success.svg)]()
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/martianacademy/phobos-stream/blob/main/LICENSE)
7
8
 
8
- **PhobosStream** is a universal zero-VRAM diffusion streaming engine designed 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.
9
+ **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.
9
10
 
10
11
  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**.
11
12
 
@@ -58,24 +59,24 @@ flowchart TD
58
59
 
59
60
  ## ⚡ Quick Start
60
61
 
61
- ### 1. Installation
62
+ ### 1. Install from PyPI
62
63
 
63
64
  ```bash
64
- git clone https://github.com/martianacademy/phobos-stream.git
65
- cd phobos-stream
66
-
67
- uv venv --python 3.12
68
- source .venv/bin/activate
69
- uv pip install -e ".[dev]"
65
+ pip install phobos-stream
66
+ # With PyTorch CUDA/MPS or GGUF extras:
67
+ pip install "phobos-stream[cuda,gguf]"
70
68
  ```
71
69
 
72
- ### 2. Run Test Suite (27 Unit & Integration Tests)
73
-
70
+ Or install from source for development:
74
71
  ```bash
72
+ git clone https://github.com/martianacademy/phobos-stream.git
73
+ cd phobos-stream
74
+ uv venv --python 3.12 && source .venv/bin/activate
75
+ uv pip install -e ".[dev]"
75
76
  pytest -v
76
77
  ```
77
78
 
78
- ### 3. Python API: Hook Any Real PyTorch DiT in 4 Lines
79
+ ### 2. Python API: Stream Any Real PyTorch DiT in 4 Lines
79
80
 
80
81
  ```python
81
82
  import torch
@@ -93,17 +94,25 @@ with TorchBlockStreamer(
93
94
  output = model(latents, timestep, context)
94
95
  ```
95
96
 
96
- ### 4. Launch OpenAI / Sora-Compatible REST & WebSocket API
97
+ ### 3. CLI & OpenAI / Sora-Compatible API Gateway
97
98
 
98
99
  ```bash
99
- phobos-stream serve --port 8088 --manifest-path shards/manifest.json --backend auto
100
+ # Index a .safetensors checkpoint directory into a zero-copy virtual manifest:
101
+ phobos-stream shard --model-dir /path/to/models --architecture wan2.1
102
+
103
+ # Launch REST & WebSocket API server (/v1/images/generations, /v1/videos/generations):
104
+ phobos-stream serve --port 8088 --manifest-path /path/to/models/shards/manifest.json --backend auto
100
105
  ```
101
106
 
102
107
  ---
103
108
 
104
109
  ## 🎨 ComfyUI Custom Node Extension (`ComfyUI-PhobosStream`)
105
110
 
106
- **ComfyUI-PhobosStream** is registered in **ComfyUI-Manager** ([standalone repository](https://github.com/martianacademy/ComfyUI-PhobosStream)) and works out-of-the-box with zero unpublished dependencies:
111
+ Published on both the [**Official Comfy Registry**](https://registry.comfy.org/publishers/martianacademy/nodes/comfyui-phobosstream) and **ComfyUI-Manager** ([repository](https://github.com/martianacademy/ComfyUI-PhobosStream)):
112
+
113
+ ```bash
114
+ comfy node install comfyui-phobosstream
115
+ ```
107
116
 
108
117
  * **`🚀 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.
109
118
  * **`🔌 PhobosStream Block-Streamer (Any MODEL)`**: Drop-in `MODEL -> MODEL` hook patcher (`cpu_offload` / `mmap_stream`) compatible with standard ComfyUI workflows (LoRAs, ControlNet, WanVideo, FLUX).
@@ -113,4 +122,4 @@ phobos-stream serve --port 8088 --manifest-path shards/manifest.json --backend a
113
122
 
114
123
  ## 📜 License
115
124
 
116
- MIT License — free for commercial and personal use.
125
+ [MIT License](https://github.com/martianacademy/phobos-stream/blob/main/LICENSE) — free for commercial and personal use.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "phobos-stream"
7
- version = "0.2.0"
7
+ version = "0.2.1"
8
8
  description = "Universal Zero-VRAM Video & Image Diffusion Streaming Engine (MLX • CUDA • MPS • ROCm • GGUF)"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -81,40 +81,39 @@ def save_rgb_mp4(rgb_frames: np.ndarray, path: Path, fps: int = 24) -> Path:
81
81
  _, height, width, _ = frames.shape
82
82
  ffmpeg_bin = shutil.which("ffmpeg")
83
83
  if ffmpeg_bin:
84
- cmd = [
85
- ffmpeg_bin,
86
- "-y",
87
- "-loglevel",
88
- "error",
89
- "-f",
90
- "rawvideo",
91
- "-vcodec",
92
- "rawvideo",
93
- "-pix_fmt",
94
- "rgb24",
95
- "-s",
96
- f"{width}x{height}",
97
- "-r",
98
- str(max(1, int(fps))),
99
- "-i",
100
- "-",
101
- "-vf",
102
- "pad=ceil(iw/2)*2:ceil(ih/2)*2",
103
- "-c:v",
104
- "libx264",
105
- "-preset",
106
- "ultrafast",
107
- "-crf",
108
- "18",
109
- "-pix_fmt",
110
- "yuv420p",
111
- "-movflags",
112
- "+faststart",
113
- str(out_path),
114
- ]
115
- proc = subprocess.run(cmd, input=frames.tobytes(), capture_output=True, check=False)
116
- if proc.returncode == 0 and out_path.exists() and out_path.stat().st_size > 0:
117
- return out_path
84
+ for codec_args in (
85
+ ["-c:v", "libx264", "-preset", "ultrafast", "-crf", "18"],
86
+ ["-c:v", "mpeg4", "-q:v", "3"],
87
+ ):
88
+ cmd = [
89
+ ffmpeg_bin,
90
+ "-y",
91
+ "-loglevel",
92
+ "error",
93
+ "-f",
94
+ "rawvideo",
95
+ "-vcodec",
96
+ "rawvideo",
97
+ "-pix_fmt",
98
+ "rgb24",
99
+ "-s",
100
+ f"{width}x{height}",
101
+ "-r",
102
+ str(max(1, int(fps))),
103
+ "-i",
104
+ "-",
105
+ "-vf",
106
+ "pad=ceil(iw/2)*2:ceil(ih/2)*2",
107
+ *codec_args,
108
+ "-pix_fmt",
109
+ "yuv420p",
110
+ "-movflags",
111
+ "+faststart",
112
+ str(out_path),
113
+ ]
114
+ proc = subprocess.run(cmd, input=frames.tobytes(), capture_output=True, check=False)
115
+ if proc.returncode == 0 and out_path.exists() and out_path.stat().st_size > 0:
116
+ return out_path
118
117
 
119
118
  # Fallback to OpenCV VideoWriter if ffmpeg is absent or lacks libx264
120
119
  try:
@@ -1,19 +0,0 @@
1
- name: CI Tests
2
-
3
- on:
4
- push:
5
- branches: [main]
6
- pull_request:
7
- branches: [main]
8
-
9
- jobs:
10
- test:
11
- runs-on: ubuntu-latest
12
- steps:
13
- - uses: actions/checkout@v4
14
- - uses: astral-sh/setup-uv@v4
15
- - name: Install dependencies & run pytest
16
- run: |
17
- uv venv --python 3.12
18
- uv pip install -e ".[dev]"
19
- uv run pytest -v
@@ -1,136 +0,0 @@
1
- # Project Handoff & Architecture Guide 🌌
2
-
3
- **Project:** `PhobosStream`
4
- **GitHub Repository:** [https://github.com/martianacademy/phobos-stream](https://github.com/martianacademy/phobos-stream)
5
- **Target Hardware:** Universal (Apple Silicon M1/M2/M3/M4 via MLX, NVIDIA GeForce RTX via CUDA, AMD ROCm, and GGUF/CPU)
6
- **Target Models:** Alibaba Wan2.1 (14B), Black Forest Labs FLUX.1 (12B), Tencent HunyuanVideo (13B), THUDM CogVideoX
7
- **License:** MIT (100% Free & Open-Source)
8
-
9
- ---
10
-
11
- ## 🎯 Executive Summary
12
-
13
- `PhobosStream` is a universal zero-VRAM diffusion streaming engine created to run massive **12B–20B+ Video and Image Diffusion Transformers (DiTs)** on consumer hardware that would otherwise experience Out-Of-Memory (OOM) crashes.
14
-
15
- By executing **3-Stage Sequential Offloading** (Text Encoder -> DiT Blocks -> VAE) combined with **Zero-Copy `mmap` Block-by-Block Streaming**, PhobosStream reduces peak VRAM requirements from **>28 GB down to <800 MB** (>97% memory reduction), enabling professional video generation on 16GB/24GB Apple Silicon Macs and 8GB/12GB RTX GPUs.
16
-
17
- ---
18
-
19
- ## 🏗️ Codebase Directory Structure
20
-
21
- ```
22
- phobos-stream/
23
- ├── pyproject.toml # Build configuration, dependencies, and CLI entrypoints
24
- ├── README.md # Complete architectural guide, benchmarks, and API reference
25
- ├── HANDOFF.md # Developer handoff documentation (this file)
26
- ├── src/phobos_stream/
27
- │ ├── types.py # GenerationConfig, ModelArchitecture, BackendType schemas
28
- │ ├── cli.py # CLI commands (`serve`, `generate`, `benchmark`)
29
- │ ├── backends/
30
- │ │ ├── base.py # BaseBackend abstract interface
31
- │ │ ├── mlx_backend.py # Apple Silicon Metal hardware-accelerated backend
32
- │ │ ├── cuda_backend.py # NVIDIA CUDA & AMD ROCm PyTorch backend
33
- │ │ ├── gguf_backend.py # GGUF quantized tensor & CPU fallback backend
34
- │ │ └── factory.py # Auto-detection backend factory
35
- │ ├── storage/
36
- │ │ ├── layout.py # Shard manifests and block metadata dataclasses
37
- │ │ ├── mmap_loader.py # Zero-copy memory-mapped safetensors tensor reader
38
- │ │ └── sharder.py # Partitioning & virtual byte-range index builder
39
- │ ├── models/
40
- │ │ ├── attention.py # Universal Self-Attention and Cross-Attention
41
- │ │ ├── rotary.py # 3D Spatio-Temporal Rotary Position Embedding (3D RoPE)
42
- │ │ └── dit_block.py # Universal DiT Block (adaLN, SwiGLU / MLP, Residuals)
43
- │ ├── adapters/
44
- │ │ ├── base.py # BaseModelAdapter abstract interface
45
- │ │ ├── wan_adapter.py # Alibaba Wan2.1 14B / 1.3B Video DiT adapter
46
- │ │ ├── flux_adapter.py # Black Forest Labs FLUX.1 12B image adapter
47
- │ │ ├── hunyuan_adapter.py # Tencent HunyuanVideo 13B adapter
48
- │ │ └── factory.py # Model architecture auto-resolution
49
- │ ├── pipeline/
50
- │ │ ├── scheduler.py # Flow Matching / Rectified Flow Euler ODE scheduler
51
- │ │ ├── offloader.py # 3-Stage Sequential Offloader (T5 -> DiT -> VAE)
52
- │ │ └── stream_engine.py # Denoising orchestrator and telemetry tracker
53
- │ └── server/
54
- │ ├── schemas.py # OpenAI / Sora compatible Pydantic schemas
55
- │ ├── ws_progress.py # WebSocket real-time progress broadcaster
56
- │ └── app.py # FastAPI server (/v1/videos/generations, /v1/images/generations)
57
- ├── tests/ # 15 Comprehensive Unit Tests (100% Passing)
58
- └── examples/
59
- ├── benchmark_streaming.py # Live 14B video generation benchmark on Metal GPU
60
- └── test_live_server.py # End-to-end integration test validating REST endpoints
61
- ```
62
-
63
- ---
64
-
65
- ## 📊 Verified Test Results (Apple Silicon Metal GPU)
66
-
67
- ### 1. Benchmark Telemetry (`examples/benchmark_streaming.py`)
68
- Tested with 16 simulated DiT blocks (2048 hidden dimension, 720p 25-frame video latents):
69
-
70
- | Metric | Monolithic Baseline | PhobosStream (MLX Metal) | Impact |
71
- | :--- | :--- | :--- | :--- |
72
- | **Peak VRAM / Unified RAM**| **28.4 GB (OOM Crash)**| **788.11 MB** | **>97% RAM Reduction!** |
73
- | **Stage 1 (Text Encoding)** | 11.2 GB persistent | **0.73 ms** (Instantly freed) | Memory reused for DiT |
74
- | **Stage 2 (DiT Denoising)** | Crashes on 16GB/24GB | **11.19 s / step** | Runs entirely in-budget |
75
- | **Stage 3 (VAE Decode)** | OOM with DiT loaded | **57.53 ms** | Reconstructed to RGB |
76
- | **Crash Rate** | 100% OOM on 16GB Mac | **0% (Rock Solid)** | Zero-VRAM guarantee |
77
-
78
- ### 2. Live HTTP & WebSocket API Validation (`examples/test_live_server.py`)
79
- - `GET /health`: Returned `200 OK` (backend: `mlx`, architecture: `wan2.1`).
80
- - `GET /v1/models`: Listed `wan2.1`, `flux-schnell`, `hunyuan-video`.
81
- - `POST /v1/images/generations`: Completed photorealistic image request in `0.04s`.
82
- - `POST /v1/videos/generations`: Completed video request in `0.08s` with `16.61 MB` peak RAM.
83
-
84
- ---
85
-
86
- ## ⚡ Quick Operational Commands
87
-
88
- ### 1. Activate Environment
89
- ```bash
90
- cd ~/Documents/phobos-stream
91
- source .venv/bin/activate
92
- ```
93
-
94
- ### 2. Run Test Suite
95
- ```bash
96
- pytest -v
97
- ```
98
-
99
- ### 3. Run Benchmark
100
- ```bash
101
- python examples/benchmark_streaming.py
102
- ```
103
-
104
- ### 4. Start the OpenAI / Sora-Compatible API Gateway
105
- ```bash
106
- phobos-stream serve --port 8088 --backend auto
107
- ```
108
-
109
- ### 5. Test Live Server Integration
110
- ```bash
111
- python examples/test_live_server.py
112
- ```
113
-
114
- ### 6. ComfyUI Integration Status
115
- - **Dedicated Repo:** [https://github.com/martianacademy/ComfyUI-PhobosStream](https://github.com/martianacademy/ComfyUI-PhobosStream)
116
- - **Official ComfyUI Registry PR:** [Comfy-Org/ComfyUI-Manager #3453](https://github.com/Comfy-Org/ComfyUI-Manager/pull/3453)
117
- - **Local Adapter Location:** `~/Documents/phobos-stream/ComfyUI-PhobosStream`
118
- - **Installed Symlink:** `~/ComfyUI/custom_nodes/ComfyUI-PhobosStream` (or installed standalone via ComfyUI-Manager)
119
- - **Nodes Registered (`PhobosStream` Category):**
120
- - `PhobosStageOffloadPipeline`: `🚀 Phobos Zero-VRAM 2K/4K & Video Pipeline`
121
- - `PhobosBlockStreamPatcher`: `🔌 PhobosStream Block-Streamer (Any MODEL)`
122
- - `PhobosStreamLoader`: `🌌 PhobosStream Model Loader (Zero-VRAM)`
123
- - `PhobosStreamSampler`: `⚡ PhobosStream Diffusion Sampler (Stage-Offload)`
124
- - `PhobosStreamVAEDecode`: `🎞️ PhobosStream Tiled VAE Decoder`
125
- - **Output Compatibility:** Emits standard `(Batch, H, W, 3)` `IMAGE` tensors compatible with standard ComfyUI `SaveImage` and `Video Combine` nodes.
126
-
127
- ---
128
-
129
- ## 🧭 Future Roadmap
130
-
131
- 1. **Metal I/O DMA Acceleration:**
132
- Direct SSD to GPU buffer transfer via `MTLIOCommandQueue` to bypass kernel page faults for an additional 1.5x–2x streaming boost.
133
- 2. **FlashAttention-3 / SageAttention Kernel:**
134
- Quantized FP8 attention for spatio-temporal video latents to double denoising frame rates.
135
- 3. **Multi-GPU / Hybrid Distributed Offload:**
136
- Streaming DiT blocks across hybrid setups (e.g. Mac Metal primary + remote RTX secondary).
File without changes
File without changes
File without changes