phobos-stream 0.2.1__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.
Files changed (77) hide show
  1. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/PKG-INFO +40 -10
  2. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/README.md +33 -9
  3. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/pyproject.toml +8 -1
  4. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/__init__.py +1 -1
  5. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/cli.py +70 -30
  6. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/integrations/comfyui/comfy_runtime.py +4 -2
  7. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/integrations/comfyui/nodes.py +7 -4
  8. phobos_stream-0.2.2/src/phobos_stream/pipelines/__init__.py +6 -0
  9. phobos_stream-0.2.2/src/phobos_stream/pipelines/hf_diffusers.py +372 -0
  10. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/server/app.py +68 -36
  11. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/server/schemas.py +9 -5
  12. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/streaming/__init__.py +5 -1
  13. phobos_stream-0.2.2/src/phobos_stream/streaming/block_discovery.py +160 -0
  14. phobos_stream-0.2.2/src/phobos_stream/streaming/budget_planner.py +175 -0
  15. phobos_stream-0.2.2/src/phobos_stream/streaming/torch_block_streamer.py +417 -0
  16. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/tests/test_real_streaming.py +86 -0
  17. phobos_stream-0.2.1/src/phobos_stream/pipelines/__init__.py +0 -8
  18. phobos_stream-0.2.1/src/phobos_stream/streaming/torch_block_streamer.py +0 -401
  19. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/.github/workflows/ci.yml +0 -0
  20. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/.github/workflows/publish-pypi.yml +0 -0
  21. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/.gitignore +0 -0
  22. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/HANDOFF.md +0 -0
  23. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/LICENSE +0 -0
  24. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/assets/icon.png +0 -0
  25. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/examples/benchmark_streaming.py +0 -0
  26. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/examples/phobos_2k_comfyui_workflow.json +0 -0
  27. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/examples/test_live_server.py +0 -0
  28. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/scripts/benchmark_2k_phobos_vs_direct.py +0 -0
  29. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/scripts/benchmark_mlx_lm_optimizations.py +0 -0
  30. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/scripts/benchmark_real_phobos_optimization.py +0 -0
  31. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/scripts/generate_z_image_mlx_phobos.py +0 -0
  32. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/scripts/run_z_image_turbo.py +0 -0
  33. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/adapters/__init__.py +0 -0
  34. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/adapters/base.py +0 -0
  35. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/adapters/cogvideo_adapter.py +0 -0
  36. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/adapters/factory.py +0 -0
  37. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/adapters/flux_adapter.py +0 -0
  38. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/adapters/hunyuan_adapter.py +0 -0
  39. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/adapters/wan_adapter.py +0 -0
  40. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/backends/__init__.py +0 -0
  41. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/backends/base.py +0 -0
  42. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/backends/cuda_backend.py +0 -0
  43. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/backends/factory.py +0 -0
  44. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/backends/gguf_backend.py +0 -0
  45. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/backends/mlx_backend.py +0 -0
  46. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/integrations/__init__.py +0 -0
  47. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/integrations/comfyui/__init__.py +0 -0
  48. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/media/__init__.py +0 -0
  49. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/media/video_writer.py +0 -0
  50. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/models/__init__.py +0 -0
  51. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/models/attention.py +0 -0
  52. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/models/dit_block.py +0 -0
  53. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/models/rotary.py +0 -0
  54. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/pipeline/__init__.py +0 -0
  55. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/pipeline/offloader.py +0 -0
  56. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/pipeline/scheduler.py +0 -0
  57. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/pipeline/stage_runner.py +0 -0
  58. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/pipeline/stream_engine.py +0 -0
  59. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/pipelines/mlx_zimage.py +0 -0
  60. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/pipelines/mlx_zimage_blocks.py +0 -0
  61. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/pipelines/mlx_zimage_vae.py +0 -0
  62. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/server/__init__.py +0 -0
  63. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/server/ws_progress.py +0 -0
  64. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/storage/__init__.py +0 -0
  65. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/storage/layout.py +0 -0
  66. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/storage/mmap_loader.py +0 -0
  67. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/storage/sharder.py +0 -0
  68. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/streaming/mlx_block_streamer.py +0 -0
  69. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/src/phobos_stream/types.py +0 -0
  70. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/tests/test_adapters.py +0 -0
  71. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/tests/test_backends.py +0 -0
  72. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/tests/test_comfyui.py +0 -0
  73. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/tests/test_models.py +0 -0
  74. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/tests/test_pipeline.py +0 -0
  75. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/tests/test_server.py +0 -0
  76. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/tests/test_storage.py +0 -0
  77. {phobos_stream-0.2.1 → phobos_stream-0.2.2}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: phobos-stream
3
- Version: 0.2.1
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,6 +32,12 @@ 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
@@ -39,7 +45,7 @@ Description-Content-Type: text/markdown
39
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
47
  [![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)
48
+ [![Comfy Registry](https://img.shields.io/badge/Comfy_Registry-v0.2.4-EE6A3E)](https://registry.comfy.org/publishers/martianacademy/nodes/comfyui-phobosstream)
43
49
  [![CI Tests](https://github.com/martianacademy/phobos-stream/actions/workflows/ci.yml/badge.svg)](https://github.com/martianacademy/phobos-stream/actions/workflows/ci.yml)
44
50
  [![Python 3.10+](https://img.shields.io/badge/Python-3.10%2B-brightgreen.svg)](https://www.python.org/)
45
51
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/martianacademy/phobos-stream/blob/main/LICENSE)
@@ -50,9 +56,29 @@ By combining **3-Stage Sequential Offloading** (`Text Encoder -> DiT -> Tiled VA
50
56
 
51
57
  ---
52
58
 
53
- ## 📊 Verified Empirical Benchmarks (Real 19.5 GB Model Suite)
59
+ ## 📊 Verified Empirical Benchmarks
54
60
 
55
- *Measured end-to-end on Apple Silicon Metal GPU 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) at `1024 × 1024`, `8 steps`, `seed=42`:*
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):*
56
82
 
57
83
  | Execution Mode | Peak Metal GPU Memory | VRAM Saved | Active Resident Weights | Denoising (`Per Step`) | Total Wall Time | Visual Quality |
58
84
  | :--- | :---: | :---: | :---: | :---: | :---: | :--- |
@@ -101,8 +127,8 @@ flowchart TD
101
127
 
102
128
  ```bash
103
129
  pip install phobos-stream
104
- # With PyTorch CUDA/MPS or GGUF extras:
105
- pip install "phobos-stream[cuda,gguf]"
130
+ # With HuggingFace Diffusers (Wan2.1 / FLUX / SDXL) or GGUF extras:
131
+ pip install "phobos-stream[diffusers,gguf]"
106
132
  ```
107
133
 
108
134
  Or install from source for development:
@@ -132,13 +158,17 @@ with TorchBlockStreamer(
132
158
  output = model(latents, timestep, context)
133
159
  ```
134
160
 
135
- ### 3. CLI & OpenAI / Sora-Compatible API Gateway
161
+ ### 3. CLI & OpenAI / Sora-Compatible Video & Image API Gateway
136
162
 
137
163
  ```bash
138
- # Index a .safetensors checkpoint directory into a zero-copy virtual manifest:
139
- phobos-stream shard --model-dir /path/to/models --architecture wan2.1
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
140
169
 
141
- # Launch REST & WebSocket API server (/v1/images/generations, /v1/videos/generations):
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
142
172
  phobos-stream serve --port 8088 --manifest-path /path/to/models/shards/manifest.json --backend auto
143
173
  ```
144
174
 
@@ -1,7 +1,7 @@
1
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
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)
4
+ [![Comfy Registry](https://img.shields.io/badge/Comfy_Registry-v0.2.4-EE6A3E)](https://registry.comfy.org/publishers/martianacademy/nodes/comfyui-phobosstream)
5
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)
6
6
  [![Python 3.10+](https://img.shields.io/badge/Python-3.10%2B-brightgreen.svg)](https://www.python.org/)
7
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/martianacademy/phobos-stream/blob/main/LICENSE)
@@ -12,9 +12,29 @@ By combining **3-Stage Sequential Offloading** (`Text Encoder -> DiT -> Tiled VA
12
12
 
13
13
  ---
14
14
 
15
- ## 📊 Verified Empirical Benchmarks (Real 19.5 GB Model Suite)
15
+ ## 📊 Verified Empirical Benchmarks
16
16
 
17
- *Measured end-to-end on Apple Silicon Metal GPU 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) at `1024 × 1024`, `8 steps`, `seed=42`:*
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):*
18
38
 
19
39
  | Execution Mode | Peak Metal GPU Memory | VRAM Saved | Active Resident Weights | Denoising (`Per Step`) | Total Wall Time | Visual Quality |
20
40
  | :--- | :---: | :---: | :---: | :---: | :---: | :--- |
@@ -63,8 +83,8 @@ flowchart TD
63
83
 
64
84
  ```bash
65
85
  pip install phobos-stream
66
- # With PyTorch CUDA/MPS or GGUF extras:
67
- pip install "phobos-stream[cuda,gguf]"
86
+ # With HuggingFace Diffusers (Wan2.1 / FLUX / SDXL) or GGUF extras:
87
+ pip install "phobos-stream[diffusers,gguf]"
68
88
  ```
69
89
 
70
90
  Or install from source for development:
@@ -94,13 +114,17 @@ with TorchBlockStreamer(
94
114
  output = model(latents, timestep, context)
95
115
  ```
96
116
 
97
- ### 3. CLI & OpenAI / Sora-Compatible API Gateway
117
+ ### 3. CLI & OpenAI / Sora-Compatible Video & Image API Gateway
98
118
 
99
119
  ```bash
100
- # Index a .safetensors checkpoint directory into a zero-copy virtual manifest:
101
- phobos-stream shard --model-dir /path/to/models --architecture wan2.1
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
102
125
 
103
- # Launch REST & WebSocket API server (/v1/images/generations, /v1/videos/generations):
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
104
128
  phobos-stream serve --port 8088 --manifest-path /path/to/models/shards/manifest.json --backend auto
105
129
  ```
106
130
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "phobos-stream"
7
- version = "0.2.1"
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
  ]
@@ -3,7 +3,7 @@
3
3
  Supports Apple Silicon (MLX), NVIDIA CUDA, AMD ROCm, Vulkan, and GGUF quantization.
4
4
  """
5
5
 
6
- __version__ = "0.1.0"
6
+ __version__ = "0.2.2"
7
7
  __author__ = "Martian Academy"
8
8
 
9
9
  from phobos_stream.types import (
@@ -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 manifest is set")
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
- backend_type = BackendType(backend)
38
- app = create_app(manifest=manifest, backend_type=backend_type, allow_synthetic=allow_synthetic)
39
- click.echo(f"[*] Starting PhobosStream Gateway on http://{host}:{port} [Backend: {backend}]")
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 without real weights")
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
- click.echo(f"[*] Generating {'Video' if video else 'Image'} with PhobosStream...")
103
- rgb_frames, metrics = engine.generate(
104
- config,
105
- progress_callback=lambda step, total, stage: click.echo(f"[{stage}] Step {step}/{total}"),
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:.2f} 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
 
@@ -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 = "cpu_offload",
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 == BlockStreamMode.MMAP_STREAM:
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
@@ -59,7 +59,7 @@ class PhobosStreamLoaderNode:
59
59
  "clip_type": (CLIP_TYPE_CHOICES, {"default": "lumina2"}),
60
60
  "vae_name": (vae_list, {"default": vae_list[0]}),
61
61
  "aura_shift": ("FLOAT", {"default": 3.0, "min": 0.0, "max": 12.0, "step": 0.1}),
62
- "block_stream_mode": (["stage_only", "cpu_offload", "mmap_stream"], {"default": "stage_only"}),
62
+ "block_stream_mode": (["stage_only", "hybrid_budget", "cpu_offload", "mmap_stream"], {"default": "stage_only"}),
63
63
  "use_comfy_stage_offload": ("BOOLEAN", {"default": True}),
64
64
  "allow_synthetic": ("BOOLEAN", {"default": False}),
65
65
  },
@@ -133,9 +133,10 @@ class PhobosBlockStreamPatcherNode:
133
133
  return {
134
134
  "required": {
135
135
  "model": ("MODEL",),
136
- "mode": (["cpu_offload", "mmap_stream"], {"default": "cpu_offload"}),
136
+ "mode": (["hybrid_budget", "cpu_offload", "mmap_stream"], {"default": "hybrid_budget"}),
137
137
  },
138
138
  "optional": {
139
+ "vram_budget_mb": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 65536.0, "step": 256.0}),
139
140
  "safetensors_path": ("STRING", {"default": ""}),
140
141
  },
141
142
  }
@@ -148,7 +149,8 @@ class PhobosBlockStreamPatcherNode:
148
149
  def patch_model(
149
150
  self,
150
151
  model: Any,
151
- mode: str = "cpu_offload",
152
+ mode: str = "hybrid_budget",
153
+ vram_budget_mb: float = 0.0,
152
154
  safetensors_path: str = "",
153
155
  ) -> Tuple[Any]:
154
156
  patched = model.clone() if hasattr(model, "clone") else model
@@ -156,6 +158,7 @@ class PhobosBlockStreamPatcherNode:
156
158
  comfy_model=patched,
157
159
  block_stream_mode=mode,
158
160
  unet_name=safetensors_path.strip(),
161
+ vram_budget_mb=vram_budget_mb if vram_budget_mb > 0 else None,
159
162
  )
160
163
  setattr(patched, "_phobos_block_streamer", streamer)
161
164
  return (patched,)
@@ -373,7 +376,7 @@ class PhobosStageOffloadPipelineNode:
373
376
  "num_frames": ("INT", {"default": 1, "min": 1, "max": 241, "step": 1}),
374
377
  "clip_name2": (clip2_list, {"default": "none"}),
375
378
  "weight_dtype": (["default", "fp8_e4m3fn", "fp8_e4m3fn_fast", "fp8_e5m2"], {"default": "default"}),
376
- "block_stream_mode": (["stage_only", "cpu_offload", "mmap_stream"], {"default": "stage_only"}),
379
+ "block_stream_mode": (["stage_only", "hybrid_budget", "cpu_offload", "mmap_stream"], {"default": "stage_only"}),
377
380
  "use_tiled_vae": ("BOOLEAN", {"default": True}),
378
381
  },
379
382
  }
@@ -0,0 +1,6 @@
1
+ """Production model pipelines with 3-stage offloading and hybrid/mmap block streaming."""
2
+
3
+ from phobos_stream.pipelines.hf_diffusers import HFDiffusersStreamEngine
4
+ from phobos_stream.pipelines.mlx_zimage import MLXGenerationResult, generate_zimage_mlx
5
+
6
+ __all__ = ["HFDiffusersStreamEngine", "MLXGenerationResult", "generate_zimage_mlx"]