phobos-stream 0.2.0__tar.gz → 0.2.2__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.
- phobos_stream-0.2.2/.github/workflows/ci.yml +27 -0
- phobos_stream-0.2.2/HANDOFF.md +79 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/PKG-INFO +61 -22
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/README.md +54 -21
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/pyproject.toml +8 -1
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/__init__.py +1 -1
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/cli.py +70 -30
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/integrations/comfyui/comfy_runtime.py +4 -2
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/integrations/comfyui/nodes.py +7 -4
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/media/video_writer.py +33 -34
- phobos_stream-0.2.2/src/phobos_stream/pipelines/__init__.py +6 -0
- phobos_stream-0.2.2/src/phobos_stream/pipelines/hf_diffusers.py +372 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/server/app.py +68 -36
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/server/schemas.py +9 -5
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/streaming/__init__.py +5 -1
- phobos_stream-0.2.2/src/phobos_stream/streaming/block_discovery.py +160 -0
- phobos_stream-0.2.2/src/phobos_stream/streaming/budget_planner.py +175 -0
- phobos_stream-0.2.2/src/phobos_stream/streaming/torch_block_streamer.py +417 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/tests/test_real_streaming.py +86 -0
- phobos_stream-0.2.0/.github/workflows/ci.yml +0 -19
- phobos_stream-0.2.0/HANDOFF.md +0 -136
- phobos_stream-0.2.0/src/phobos_stream/pipelines/__init__.py +0 -8
- phobos_stream-0.2.0/src/phobos_stream/streaming/torch_block_streamer.py +0 -401
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/.github/workflows/publish-pypi.yml +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/.gitignore +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/LICENSE +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/assets/icon.png +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/examples/benchmark_streaming.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/examples/phobos_2k_comfyui_workflow.json +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/examples/test_live_server.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/scripts/benchmark_2k_phobos_vs_direct.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/scripts/benchmark_mlx_lm_optimizations.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/scripts/benchmark_real_phobos_optimization.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/scripts/generate_z_image_mlx_phobos.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/scripts/run_z_image_turbo.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/adapters/__init__.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/adapters/base.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/adapters/cogvideo_adapter.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/adapters/factory.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/adapters/flux_adapter.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/adapters/hunyuan_adapter.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/adapters/wan_adapter.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/backends/__init__.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/backends/base.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/backends/cuda_backend.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/backends/factory.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/backends/gguf_backend.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/backends/mlx_backend.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/integrations/__init__.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/integrations/comfyui/__init__.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/media/__init__.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/models/__init__.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/models/attention.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/models/dit_block.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/models/rotary.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/pipeline/__init__.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/pipeline/offloader.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/pipeline/scheduler.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/pipeline/stage_runner.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/pipeline/stream_engine.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/pipelines/mlx_zimage.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/pipelines/mlx_zimage_blocks.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/pipelines/mlx_zimage_vae.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/server/__init__.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/server/ws_progress.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/storage/__init__.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/storage/layout.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/storage/mmap_loader.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/storage/sharder.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/streaming/mlx_block_streamer.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/types.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/tests/test_adapters.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/tests/test_backends.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/tests/test_comfyui.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/tests/test_models.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/tests/test_pipeline.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/tests/test_server.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/tests/test_storage.py +0 -0
- {phobos_stream-0.2.0 → phobos_stream-0.2.2}/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.
|
|
3
|
+
Version: 0.2.2
|
|
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
|
|
@@ -32,26 +32,53 @@ Requires-Dist: torch>=2.4.0; extra == 'cuda'
|
|
|
32
32
|
Provides-Extra: dev
|
|
33
33
|
Requires-Dist: httpx>=0.27.0; extra == 'dev'
|
|
34
34
|
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
35
|
+
Provides-Extra: diffusers
|
|
36
|
+
Requires-Dist: accelerate>=1.2.0; extra == 'diffusers'
|
|
37
|
+
Requires-Dist: diffusers>=0.33.0; extra == 'diffusers'
|
|
38
|
+
Requires-Dist: ftfy>=6.2.0; extra == 'diffusers'
|
|
39
|
+
Requires-Dist: torch>=2.4.0; extra == 'diffusers'
|
|
40
|
+
Requires-Dist: transformers>=4.49.0; extra == 'diffusers'
|
|
35
41
|
Provides-Extra: gguf
|
|
36
42
|
Requires-Dist: gguf>=0.10.0; extra == 'gguf'
|
|
37
43
|
Description-Content-Type: text/markdown
|
|
38
44
|
|
|
39
|
-
# <img src="assets/icon.png" width="42" align="top" alt="PhobosStream Icon" /> PhobosStream
|
|
45
|
+
# <img src="https://raw.githubusercontent.com/martianacademy/phobos-stream/main/assets/icon.png" width="42" align="top" alt="PhobosStream Icon" /> PhobosStream
|
|
40
46
|
|
|
41
|
-
[](https://pypi.org/project/phobos-stream/)
|
|
48
|
+
[](https://registry.comfy.org/publishers/martianacademy/nodes/comfyui-phobosstream)
|
|
49
|
+
[](https://github.com/martianacademy/phobos-stream/actions/workflows/ci.yml)
|
|
42
50
|
[](https://www.python.org/)
|
|
43
|
-
[]()
|
|
51
|
+
[](https://github.com/martianacademy/phobos-stream/blob/main/LICENSE)
|
|
45
52
|
|
|
46
|
-
**PhobosStream** is a universal zero-VRAM diffusion streaming engine
|
|
53
|
+
**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
54
|
|
|
48
55
|
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
56
|
|
|
50
57
|
---
|
|
51
58
|
|
|
52
|
-
## 📊 Verified Empirical Benchmarks
|
|
59
|
+
## 📊 Verified Empirical Benchmarks
|
|
53
60
|
|
|
54
|
-
|
|
61
|
+
### A. NVIDIA CUDA GPU — 8.0 GiB Hardware VRAM Cap & 3-Tier `HYBRID_BUDGET` (Tesla T4)
|
|
62
|
+
|
|
63
|
+
*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`):*
|
|
64
|
+
|
|
65
|
+
| Pipeline Configuration | Enforced CUDA Cap | Peak CUDA VRAM | Result |
|
|
66
|
+
| :--- | :---: | :---: | :--- |
|
|
67
|
+
| **Standard Monolithic `WanPipeline.to("cuda")`** | `8,192.0 MB` (`8.0 GiB`) | `> 8,192 MB` (**OOM**) | ❌ Crashes (`CUDA out of memory`) |
|
|
68
|
+
| **`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!) |
|
|
69
|
+
|
|
70
|
+
*2. **3-Tier `TorchBlockStreamer` Benchmark on NVIDIA Tesla T4** (24-block 2.3 GB FP16 DiT, `4 steps`, double-buffered CUDA `record_stream` prefetch):*
|
|
71
|
+
|
|
72
|
+
| Streaming Mode | Block Residency (`GPU / CPU / NVMe`) | Peak CUDA VRAM | VRAM Saved | 4-Step Latency | Max Abs Diff vs Monolithic |
|
|
73
|
+
| :--- | :---: | :---: | :---: | :---: | :---: |
|
|
74
|
+
| **Monolithic FP16** | `24 / 0 / 0` | `4,610.0 MB` | `0.0%` | `1.024 s` | `0.0` (Reference) |
|
|
75
|
+
| **`cpu_offload` (Pinned + Async CUDA Stream)** | `0 / 24 / 0` | **`322.2 MB`** | **`93.0%`** | **`1.074 s`** *(only +4.9%!)* | **`0.0` (Bit-Exact)** |
|
|
76
|
+
| **`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)** |
|
|
77
|
+
| **`mmap_stream` (Zero-RAM `meta` + NVMe)** | `0 / 0 / 24` | **`226.1 MB`** | **`95.1%`** | `5.653 s` | **`0.0` (Bit-Exact)** |
|
|
78
|
+
|
|
79
|
+
### B. Apple Silicon Metal GPU — Real 19.5 GB Model Suite (`1024×1024`, 8 Steps)
|
|
80
|
+
|
|
81
|
+
*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):*
|
|
55
82
|
|
|
56
83
|
| Execution Mode | Peak Metal GPU Memory | VRAM Saved | Active Resident Weights | Denoising (`Per Step`) | Total Wall Time | Visual Quality |
|
|
57
84
|
| :--- | :---: | :---: | :---: | :---: | :---: | :--- |
|
|
@@ -96,24 +123,24 @@ flowchart TD
|
|
|
96
123
|
|
|
97
124
|
## ⚡ Quick Start
|
|
98
125
|
|
|
99
|
-
### 1.
|
|
126
|
+
### 1. Install from PyPI
|
|
100
127
|
|
|
101
128
|
```bash
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
uv venv --python 3.12
|
|
106
|
-
source .venv/bin/activate
|
|
107
|
-
uv pip install -e ".[dev]"
|
|
129
|
+
pip install phobos-stream
|
|
130
|
+
# With HuggingFace Diffusers (Wan2.1 / FLUX / SDXL) or GGUF extras:
|
|
131
|
+
pip install "phobos-stream[diffusers,gguf]"
|
|
108
132
|
```
|
|
109
133
|
|
|
110
|
-
|
|
111
|
-
|
|
134
|
+
Or install from source for development:
|
|
112
135
|
```bash
|
|
136
|
+
git clone https://github.com/martianacademy/phobos-stream.git
|
|
137
|
+
cd phobos-stream
|
|
138
|
+
uv venv --python 3.12 && source .venv/bin/activate
|
|
139
|
+
uv pip install -e ".[dev]"
|
|
113
140
|
pytest -v
|
|
114
141
|
```
|
|
115
142
|
|
|
116
|
-
###
|
|
143
|
+
### 2. Python API: Stream Any Real PyTorch DiT in 4 Lines
|
|
117
144
|
|
|
118
145
|
```python
|
|
119
146
|
import torch
|
|
@@ -131,17 +158,29 @@ with TorchBlockStreamer(
|
|
|
131
158
|
output = model(latents, timestep, context)
|
|
132
159
|
```
|
|
133
160
|
|
|
134
|
-
###
|
|
161
|
+
### 3. CLI & OpenAI / Sora-Compatible Video & Image API Gateway
|
|
135
162
|
|
|
136
163
|
```bash
|
|
137
|
-
|
|
164
|
+
# Launch standalone Diffusers video/image server under a strict 3-tier VRAM/RAM budget (runs Wan2.1 in ~4.3 GiB VRAM!):
|
|
165
|
+
phobos-stream serve --port 8088 \
|
|
166
|
+
--hf-model Wan-AI/Wan2.1-T2V-1.3B-Diffusers \
|
|
167
|
+
--stream-mode hybrid_budget \
|
|
168
|
+
--vram-budget-mb 3200
|
|
169
|
+
|
|
170
|
+
# Or index a local .safetensors checkpoint directory into a zero-copy virtual manifest:
|
|
171
|
+
phobos-stream shard --model-dir /path/to/models --architecture wan2.1
|
|
172
|
+
phobos-stream serve --port 8088 --manifest-path /path/to/models/shards/manifest.json --backend auto
|
|
138
173
|
```
|
|
139
174
|
|
|
140
175
|
---
|
|
141
176
|
|
|
142
177
|
## 🎨 ComfyUI Custom Node Extension (`ComfyUI-PhobosStream`)
|
|
143
178
|
|
|
144
|
-
**
|
|
179
|
+
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)):
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
comfy node install comfyui-phobosstream
|
|
183
|
+
```
|
|
145
184
|
|
|
146
185
|
* **`🚀 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
186
|
* **`🔌 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 +190,4 @@ phobos-stream serve --port 8088 --manifest-path shards/manifest.json --backend a
|
|
|
151
190
|
|
|
152
191
|
## 📜 License
|
|
153
192
|
|
|
154
|
-
MIT License — free for commercial and personal use.
|
|
193
|
+
[MIT License](https://github.com/martianacademy/phobos-stream/blob/main/LICENSE) — free for commercial and personal use.
|
|
@@ -1,19 +1,40 @@
|
|
|
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
|
-
[](https://pypi.org/project/phobos-stream/)
|
|
4
|
+
[](https://registry.comfy.org/publishers/martianacademy/nodes/comfyui-phobosstream)
|
|
5
|
+
[](https://github.com/martianacademy/phobos-stream/actions/workflows/ci.yml)
|
|
4
6
|
[](https://www.python.org/)
|
|
5
|
-
[]()
|
|
7
|
+
[](https://github.com/martianacademy/phobos-stream/blob/main/LICENSE)
|
|
7
8
|
|
|
8
|
-
**PhobosStream** is a universal zero-VRAM diffusion streaming engine
|
|
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
|
|
|
12
13
|
---
|
|
13
14
|
|
|
14
|
-
## 📊 Verified Empirical Benchmarks
|
|
15
|
+
## 📊 Verified Empirical Benchmarks
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
### A. NVIDIA CUDA GPU — 8.0 GiB Hardware VRAM Cap & 3-Tier `HYBRID_BUDGET` (Tesla T4)
|
|
18
|
+
|
|
19
|
+
*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`):*
|
|
20
|
+
|
|
21
|
+
| Pipeline Configuration | Enforced CUDA Cap | Peak CUDA VRAM | Result |
|
|
22
|
+
| :--- | :---: | :---: | :--- |
|
|
23
|
+
| **Standard Monolithic `WanPipeline.to("cuda")`** | `8,192.0 MB` (`8.0 GiB`) | `> 8,192 MB` (**OOM**) | ❌ Crashes (`CUDA out of memory`) |
|
|
24
|
+
| **`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!) |
|
|
25
|
+
|
|
26
|
+
*2. **3-Tier `TorchBlockStreamer` Benchmark on NVIDIA Tesla T4** (24-block 2.3 GB FP16 DiT, `4 steps`, double-buffered CUDA `record_stream` prefetch):*
|
|
27
|
+
|
|
28
|
+
| Streaming Mode | Block Residency (`GPU / CPU / NVMe`) | Peak CUDA VRAM | VRAM Saved | 4-Step Latency | Max Abs Diff vs Monolithic |
|
|
29
|
+
| :--- | :---: | :---: | :---: | :---: | :---: |
|
|
30
|
+
| **Monolithic FP16** | `24 / 0 / 0` | `4,610.0 MB` | `0.0%` | `1.024 s` | `0.0` (Reference) |
|
|
31
|
+
| **`cpu_offload` (Pinned + Async CUDA Stream)** | `0 / 24 / 0` | **`322.2 MB`** | **`93.0%`** | **`1.074 s`** *(only +4.9%!)* | **`0.0` (Bit-Exact)** |
|
|
32
|
+
| **`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)** |
|
|
33
|
+
| **`mmap_stream` (Zero-RAM `meta` + NVMe)** | `0 / 0 / 24` | **`226.1 MB`** | **`95.1%`** | `5.653 s` | **`0.0` (Bit-Exact)** |
|
|
34
|
+
|
|
35
|
+
### B. Apple Silicon Metal GPU — Real 19.5 GB Model Suite (`1024×1024`, 8 Steps)
|
|
36
|
+
|
|
37
|
+
*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):*
|
|
17
38
|
|
|
18
39
|
| Execution Mode | Peak Metal GPU Memory | VRAM Saved | Active Resident Weights | Denoising (`Per Step`) | Total Wall Time | Visual Quality |
|
|
19
40
|
| :--- | :---: | :---: | :---: | :---: | :---: | :--- |
|
|
@@ -58,24 +79,24 @@ flowchart TD
|
|
|
58
79
|
|
|
59
80
|
## ⚡ Quick Start
|
|
60
81
|
|
|
61
|
-
### 1.
|
|
82
|
+
### 1. Install from PyPI
|
|
62
83
|
|
|
63
84
|
```bash
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
uv venv --python 3.12
|
|
68
|
-
source .venv/bin/activate
|
|
69
|
-
uv pip install -e ".[dev]"
|
|
85
|
+
pip install phobos-stream
|
|
86
|
+
# With HuggingFace Diffusers (Wan2.1 / FLUX / SDXL) or GGUF extras:
|
|
87
|
+
pip install "phobos-stream[diffusers,gguf]"
|
|
70
88
|
```
|
|
71
89
|
|
|
72
|
-
|
|
73
|
-
|
|
90
|
+
Or install from source for development:
|
|
74
91
|
```bash
|
|
92
|
+
git clone https://github.com/martianacademy/phobos-stream.git
|
|
93
|
+
cd phobos-stream
|
|
94
|
+
uv venv --python 3.12 && source .venv/bin/activate
|
|
95
|
+
uv pip install -e ".[dev]"
|
|
75
96
|
pytest -v
|
|
76
97
|
```
|
|
77
98
|
|
|
78
|
-
###
|
|
99
|
+
### 2. Python API: Stream Any Real PyTorch DiT in 4 Lines
|
|
79
100
|
|
|
80
101
|
```python
|
|
81
102
|
import torch
|
|
@@ -93,17 +114,29 @@ with TorchBlockStreamer(
|
|
|
93
114
|
output = model(latents, timestep, context)
|
|
94
115
|
```
|
|
95
116
|
|
|
96
|
-
###
|
|
117
|
+
### 3. CLI & OpenAI / Sora-Compatible Video & Image API Gateway
|
|
97
118
|
|
|
98
119
|
```bash
|
|
99
|
-
|
|
120
|
+
# Launch standalone Diffusers video/image server under a strict 3-tier VRAM/RAM budget (runs Wan2.1 in ~4.3 GiB VRAM!):
|
|
121
|
+
phobos-stream serve --port 8088 \
|
|
122
|
+
--hf-model Wan-AI/Wan2.1-T2V-1.3B-Diffusers \
|
|
123
|
+
--stream-mode hybrid_budget \
|
|
124
|
+
--vram-budget-mb 3200
|
|
125
|
+
|
|
126
|
+
# Or index a local .safetensors checkpoint directory into a zero-copy virtual manifest:
|
|
127
|
+
phobos-stream shard --model-dir /path/to/models --architecture wan2.1
|
|
128
|
+
phobos-stream serve --port 8088 --manifest-path /path/to/models/shards/manifest.json --backend auto
|
|
100
129
|
```
|
|
101
130
|
|
|
102
131
|
---
|
|
103
132
|
|
|
104
133
|
## 🎨 ComfyUI Custom Node Extension (`ComfyUI-PhobosStream`)
|
|
105
134
|
|
|
106
|
-
**
|
|
135
|
+
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)):
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
comfy node install comfyui-phobosstream
|
|
139
|
+
```
|
|
107
140
|
|
|
108
141
|
* **`🚀 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
142
|
* **`🔌 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 +146,4 @@ phobos-stream serve --port 8088 --manifest-path shards/manifest.json --backend a
|
|
|
113
146
|
|
|
114
147
|
## 📜 License
|
|
115
148
|
|
|
116
|
-
MIT License — free for commercial and personal use.
|
|
149
|
+
[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.
|
|
7
|
+
version = "0.2.2"
|
|
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"
|
|
@@ -42,6 +42,13 @@ Issues = "https://github.com/martianacademy/phobos-stream/issues"
|
|
|
42
42
|
cuda = [
|
|
43
43
|
"torch>=2.4.0",
|
|
44
44
|
]
|
|
45
|
+
diffusers = [
|
|
46
|
+
"torch>=2.4.0",
|
|
47
|
+
"diffusers>=0.33.0",
|
|
48
|
+
"transformers>=4.49.0",
|
|
49
|
+
"accelerate>=1.2.0",
|
|
50
|
+
"ftfy>=6.2.0",
|
|
51
|
+
]
|
|
45
52
|
gguf = [
|
|
46
53
|
"gguf>=0.10.0",
|
|
47
54
|
]
|
|
@@ -7,9 +7,11 @@ import uvicorn
|
|
|
7
7
|
|
|
8
8
|
from phobos_stream.media import save_rgb_mp4, save_rgb_png
|
|
9
9
|
from phobos_stream.pipeline.stream_engine import PhobosStreamEngine
|
|
10
|
+
from phobos_stream.pipelines.hf_diffusers import HFDiffusersStreamEngine
|
|
10
11
|
from phobos_stream.server.app import create_app
|
|
11
12
|
from phobos_stream.storage.layout import ModelShardsManifest
|
|
12
13
|
from phobos_stream.storage.sharder import DiffusionSharder
|
|
14
|
+
from phobos_stream.streaming import BlockStreamMode
|
|
13
15
|
from phobos_stream.types import BackendType, GenerationConfig
|
|
14
16
|
|
|
15
17
|
|
|
@@ -22,21 +24,37 @@ def main() -> None:
|
|
|
22
24
|
@main.command()
|
|
23
25
|
@click.option("--host", default="0.0.0.0", help="Host interface to bind")
|
|
24
26
|
@click.option("--port", default=8088, type=int, help="Port to listen on")
|
|
27
|
+
@click.option("--hf-model", default=None, help="HuggingFace repo ID or local Diffusers path (e.g. Wan-AI/Wan2.1-T2V-1.3B-Diffusers)")
|
|
25
28
|
@click.option("--manifest-path", default=None, type=click.Path(exists=True), help="Path to manifest.json")
|
|
29
|
+
@click.option("--stream-mode", default="hybrid_budget", type=click.Choice(["hybrid_budget", "cpu_offload", "mmap_stream", "stage_only"]))
|
|
30
|
+
@click.option("--vram-budget-mb", default=None, type=float, help="Optional GPU VRAM budget in MB for hybrid block residency")
|
|
31
|
+
@click.option("--ram-budget-mb", default=None, type=float, help="Optional CPU RAM budget in MB for hybrid block residency")
|
|
26
32
|
@click.option("--backend", default="auto", type=click.Choice(["auto", "mlx", "cuda", "gguf", "cpu"]))
|
|
27
|
-
@click.option("--allow-synthetic", is_flag=True, default=False, help="Allow synthetic benchmark weights when no
|
|
33
|
+
@click.option("--allow-synthetic", is_flag=True, default=False, help="Allow synthetic benchmark weights when no model is set")
|
|
28
34
|
def serve(
|
|
29
35
|
host: str,
|
|
30
36
|
port: int,
|
|
37
|
+
hf_model: Optional[str],
|
|
31
38
|
manifest_path: Optional[str],
|
|
39
|
+
stream_mode: str,
|
|
40
|
+
vram_budget_mb: Optional[float],
|
|
41
|
+
ram_budget_mb: Optional[float],
|
|
32
42
|
backend: str,
|
|
33
43
|
allow_synthetic: bool,
|
|
34
44
|
) -> None:
|
|
35
45
|
"""Launch the OpenAI/Sora-compatible HTTP & WebSocket API Gateway."""
|
|
36
46
|
manifest = ModelShardsManifest.load(Path(manifest_path)) if manifest_path else None
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
47
|
+
app = create_app(
|
|
48
|
+
manifest=manifest,
|
|
49
|
+
backend_type=BackendType(backend),
|
|
50
|
+
allow_synthetic=allow_synthetic,
|
|
51
|
+
hf_model_id=hf_model,
|
|
52
|
+
stream_mode=BlockStreamMode(stream_mode),
|
|
53
|
+
vram_budget_mb=vram_budget_mb,
|
|
54
|
+
ram_budget_mb=ram_budget_mb,
|
|
55
|
+
)
|
|
56
|
+
target = hf_model or (manifest.model_name if manifest else "default")
|
|
57
|
+
click.echo(f"[*] Starting PhobosStream Gateway on http://{host}:{port} [Model: {target} | Mode: {stream_mode}]")
|
|
40
58
|
uvicorn.run(app, host=host, port=port)
|
|
41
59
|
|
|
42
60
|
|
|
@@ -50,8 +68,12 @@ def serve(
|
|
|
50
68
|
@click.option("--fps", default=24, type=int, help="Video frame rate when --video is set")
|
|
51
69
|
@click.option("--steps", default=20, type=int, help="Denoising steps")
|
|
52
70
|
@click.option("--guidance-scale", default=6.0, type=float, help="Classifier-free guidance scale")
|
|
71
|
+
@click.option("--hf-model", default=None, help="HuggingFace repo ID or local Diffusers path (e.g. Wan-AI/Wan2.1-T2V-1.3B-Diffusers)")
|
|
72
|
+
@click.option("--stream-mode", default="hybrid_budget", type=click.Choice(["hybrid_budget", "cpu_offload", "mmap_stream", "stage_only"]))
|
|
73
|
+
@click.option("--vram-budget-mb", default=None, type=float, help="Optional GPU VRAM budget in MB")
|
|
74
|
+
@click.option("--ram-budget-mb", default=None, type=float, help="Optional CPU RAM budget in MB")
|
|
53
75
|
@click.option("--manifest-path", default=None, type=click.Path(exists=True), help="Path to shard manifest.json")
|
|
54
|
-
@click.option("--allow-synthetic", is_flag=True, default=False, help="Explicitly run synthetic benchmark mode
|
|
76
|
+
@click.option("--allow-synthetic", is_flag=True, default=False, help="Explicitly run synthetic benchmark mode")
|
|
55
77
|
@click.option("--output", "-o", default="outputs/generated.mp4", help="Output file path (.mp4 or .png)")
|
|
56
78
|
@click.option("--backend", default="auto", type=click.Choice(["auto", "mlx", "cuda", "gguf", "cpu"]))
|
|
57
79
|
def generate(
|
|
@@ -64,31 +86,16 @@ def generate(
|
|
|
64
86
|
fps: int,
|
|
65
87
|
steps: int,
|
|
66
88
|
guidance_scale: float,
|
|
89
|
+
hf_model: Optional[str],
|
|
90
|
+
stream_mode: str,
|
|
91
|
+
vram_budget_mb: Optional[float],
|
|
92
|
+
ram_budget_mb: Optional[float],
|
|
67
93
|
manifest_path: Optional[str],
|
|
68
94
|
allow_synthetic: bool,
|
|
69
95
|
output: str,
|
|
70
96
|
backend: str,
|
|
71
97
|
) -> None:
|
|
72
98
|
"""Generate a video or image via zero-VRAM streaming and save to disk."""
|
|
73
|
-
if manifest_path:
|
|
74
|
-
manifest = ModelShardsManifest.load(Path(manifest_path))
|
|
75
|
-
if allow_synthetic:
|
|
76
|
-
manifest.allow_synthetic = True
|
|
77
|
-
elif allow_synthetic:
|
|
78
|
-
manifest = ModelShardsManifest(
|
|
79
|
-
model_name="wan2.1-synthetic-benchmark",
|
|
80
|
-
architecture="wan2.1",
|
|
81
|
-
num_blocks=4,
|
|
82
|
-
hidden_size=2048,
|
|
83
|
-
allow_synthetic=True,
|
|
84
|
-
)
|
|
85
|
-
else:
|
|
86
|
-
raise click.UsageError(
|
|
87
|
-
"Real generation requires `--manifest-path <path/to/manifest.json>` (or use ComfyUI / "
|
|
88
|
-
"`StageSequentialRunner`). Pass `--allow-synthetic` only for synthetic benchmarking."
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
engine = PhobosStreamEngine(manifest=manifest, backend_type=BackendType(backend))
|
|
92
99
|
config = GenerationConfig(
|
|
93
100
|
prompt=prompt,
|
|
94
101
|
negative_prompt=negative_prompt,
|
|
@@ -99,11 +106,44 @@ def generate(
|
|
|
99
106
|
steps=steps,
|
|
100
107
|
guidance_scale=guidance_scale,
|
|
101
108
|
)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
109
|
+
|
|
110
|
+
if hf_model:
|
|
111
|
+
runner = HFDiffusersStreamEngine(
|
|
112
|
+
model_id_or_path=hf_model,
|
|
113
|
+
device="cpu" if backend == "cpu" else "auto",
|
|
114
|
+
stream_mode=BlockStreamMode(stream_mode),
|
|
115
|
+
vram_budget_mb=vram_budget_mb,
|
|
116
|
+
ram_budget_mb=ram_budget_mb,
|
|
117
|
+
)
|
|
118
|
+
click.echo(f"[*] Generating {'Video' if video else 'Image'} via Real HF Pipeline [{hf_model}] ({stream_mode})...")
|
|
119
|
+
rgb_frames, metrics = runner.generate(
|
|
120
|
+
config,
|
|
121
|
+
progress_callback=lambda step, total, stage: click.echo(f"[{stage}] Step {step}/{total}"),
|
|
122
|
+
)
|
|
123
|
+
else:
|
|
124
|
+
if manifest_path:
|
|
125
|
+
manifest = ModelShardsManifest.load(Path(manifest_path))
|
|
126
|
+
if allow_synthetic:
|
|
127
|
+
manifest.allow_synthetic = True
|
|
128
|
+
elif allow_synthetic:
|
|
129
|
+
manifest = ModelShardsManifest(
|
|
130
|
+
model_name="wan2.1-synthetic-benchmark",
|
|
131
|
+
architecture="wan2.1",
|
|
132
|
+
num_blocks=4,
|
|
133
|
+
hidden_size=2048,
|
|
134
|
+
allow_synthetic=True,
|
|
135
|
+
)
|
|
136
|
+
else:
|
|
137
|
+
raise click.UsageError(
|
|
138
|
+
"Provide `--hf-model <repo_id>` (e.g. `Wan-AI/Wan2.1-T2V-1.3B-Diffusers`) or `--manifest-path`, "
|
|
139
|
+
"or pass `--allow-synthetic` for synthetic benchmarking."
|
|
140
|
+
)
|
|
141
|
+
engine = PhobosStreamEngine(manifest=manifest, backend_type=BackendType(backend))
|
|
142
|
+
click.echo(f"[*] Generating {'Video' if video else 'Image'} with PhobosStream...")
|
|
143
|
+
rgb_frames, metrics = engine.generate(
|
|
144
|
+
config,
|
|
145
|
+
progress_callback=lambda step, total, stage: click.echo(f"[{stage}] Step {step}/{total}"),
|
|
146
|
+
)
|
|
107
147
|
|
|
108
148
|
out_path = Path(output)
|
|
109
149
|
out_path.parent.mkdir(parents=True, exist_ok=True)
|
|
@@ -176,7 +216,7 @@ def benchmark(steps: int, blocks: int, backend: str) -> None:
|
|
|
176
216
|
click.echo(f"Total Latency: {metrics.total_time_sec:.3f} s")
|
|
177
217
|
click.echo(f"Denoising Latency: {metrics.denoising_time_sec:.3f} s ({metrics.denoising_time_sec / steps:.3f} s/step)")
|
|
178
218
|
click.echo(f"Peak VRAM/RAM: {metrics.peak_vram_mb:.2f} MB")
|
|
179
|
-
click.echo(f"I/O Throughput: {metrics.io_throughput_mb_s:.
|
|
219
|
+
click.echo(f"I/O Throughput: {metrics.io_throughput_mb_s:.1f} MB/s")
|
|
180
220
|
click.echo("=" * 60)
|
|
181
221
|
|
|
182
222
|
|
{phobos_stream-0.2.0 → phobos_stream-0.2.2}/src/phobos_stream/integrations/comfyui/comfy_runtime.py
RENAMED
|
@@ -197,8 +197,9 @@ def decode_comfy_vae_smart(
|
|
|
197
197
|
|
|
198
198
|
def attach_streamer_to_comfy_model(
|
|
199
199
|
comfy_model: Any,
|
|
200
|
-
block_stream_mode: str = "
|
|
200
|
+
block_stream_mode: str = "hybrid_budget",
|
|
201
201
|
unet_name: str = "",
|
|
202
|
+
vram_budget_mb: Optional[float] = None,
|
|
202
203
|
) -> Optional[TorchBlockStreamer]:
|
|
203
204
|
"""Attach `TorchBlockStreamer` onto a ComfyUI `ModelPatcher`'s underlying `diffusion_model`."""
|
|
204
205
|
mode = BlockStreamMode(block_stream_mode)
|
|
@@ -217,7 +218,7 @@ def attach_streamer_to_comfy_model(
|
|
|
217
218
|
diff_mod = comfy_model
|
|
218
219
|
|
|
219
220
|
st_paths: List[Path] = []
|
|
220
|
-
if mode
|
|
221
|
+
if mode in (BlockStreamMode.MMAP_STREAM, BlockStreamMode.HYBRID_BUDGET):
|
|
221
222
|
if unet_name and Path(unet_name).exists():
|
|
222
223
|
st_paths.append(Path(unet_name))
|
|
223
224
|
elif unet_name and COMFY_NATIVE_AVAILABLE and folder_paths is not None:
|
|
@@ -230,6 +231,7 @@ def attach_streamer_to_comfy_model(
|
|
|
230
231
|
compute_device="auto",
|
|
231
232
|
mode=mode,
|
|
232
233
|
safetensors_paths=st_paths,
|
|
234
|
+
vram_budget_mb=vram_budget_mb if (vram_budget_mb and vram_budget_mb > 0) else None,
|
|
233
235
|
)
|
|
234
236
|
streamer.attach()
|
|
235
237
|
return streamer
|