Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5573830
Update dependencies and TensorRT installation
cursoragent Sep 23, 2025
822e1c6
Update dependencies and TensorRT installation
cursoragent Sep 23, 2025
04c7c6f
Update dependencies and TensorRT installation script
cursoragent Sep 23, 2025
42de821
Refactor: Remove hardcoded torch dependencies and add validation
cursoragent Sep 23, 2025
52acc8f
Checkpoint before follow-up message
cursoragent Sep 23, 2025
8fe9e8f
Refactor torch validation and pin cuda-python
cursoragent Sep 23, 2025
23a340c
Update dependencies and CUDA version detection
cursoragent Sep 23, 2025
02cf5d3
Refactor CUDA version check and dependency installation
cursoragent Sep 23, 2025
3e268be
Refactor TensorRT installation for CUDA 12
cursoragent Sep 23, 2025
5d54cf3
Undo uncalled for wrapper change
victorges Sep 23, 2025
49d2942
Cleanup setup
victorges Sep 23, 2025
af0df82
Cleanup install tensorrt
victorges Sep 23, 2025
1788ae6
Consistent CLMI behvaior
victorges Sep 23, 2025
16549ab
Simplify tensiorrt installs
victorges Sep 23, 2025
efc6b71
Add versionless torch
victorges Sep 23, 2025
d2f437b
Make controlnet and ipadapter extras
victorges Sep 23, 2025
1d49a24
Do not check cuda version on wheel
victorges Sep 23, 2025
a001f4c
Fix utils not being a module
victorges Sep 23, 2025
4fff579
Fix cuda-python install
victorges Sep 23, 2025
39e818a
Fix cuda constraint constraint
victorges Sep 24, 2025
b725e8b
Buffer allocation test -fix.
BuffMcBigHuge Sep 24, 2025
f8a25ce
Merge remote-tracking branch 'origin/cursor/update-requirements-and-i…
victorges Sep 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion demo/realtime-img2img/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ fastapi==0.115.0
uvicorn[standard]==0.32.0
Pillow==10.5.0
compel==2.0.2
controlnet-aux==0.0.7
xformers; sys_platform != 'darwin' or platform_machine != 'arm64'
markdown2
PyYAML
Expand Down
85 changes: 70 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,77 @@
import os
import re
import sys

from setuptools import find_packages, setup

# Copied from pip_utils.py to avoid import
def _check_torch_installed():
try:
import torch
import torchvision
except Exception:
msg = (
"Missing required pre-installed packages: torch, torchvision\n"
"Install the PyTorch CUDA wheels from the appropriate index first, e.g.:\n"
" pip install --index-url https://download.pytorch.org/whl/cu12x torch torchvision\n"
"Replace the index URL and versions to match your CUDA runtime."
)
raise RuntimeError(msg)

if not torch.version.cuda:
raise RuntimeError("Detected CPU-only PyTorch. Install CUDA-enabled torch/vision/audio before installing this package.")


def get_cuda_constraint():
cuda_version = os.environ.get("STREAMDIFFUSION_CUDA_VERSION") or \
os.environ.get("CUDA_VERSION")

if not cuda_version:
try:
import torch
cuda_version = torch.version.cuda
except Exception:
# might not be available during wheel build, so we have to ignore
pass

if not cuda_version:
return ">=11,<13"

parts = cuda_version.split(".")
if len(parts) < 2:
raise RuntimeError(f"Invalid CUDA version: {cuda_version}")
return f"~={parts[0]}.{parts[1]}"


if any(cmd in sys.argv for cmd in ("install", "develop")):
_check_torch_installed()

_deps = [
f"cuda-python{get_cuda_constraint()}",
"xformers==0.0.30",
"diffusers==0.35.0",
"transformers==4.56.0",
"accelerate==1.10.0",
"huggingface_hub==0.35.0",
"Pillow==11.0.0",
"fire==0.6.0",
"omegaconf==2.3.0",
"onnx==1.18.0",
"onnxruntime==1.22.0",
"onnxruntime-gpu==1.22.0",
"protobuf==4.25.3",
"colored==2.2.4",
"pywin32==306;sys_platform == 'win32'",
"onnx-graphsurgeon==0.5.8",
"controlnet-aux==0.0.10",
"diffusers-ipadapter @ git+https://github.com/livepeer/Diffusers_IPAdapter.git@405f87da42932e30bd55ee8dca3ce502d7834a99",
"mediapipe==0.10.21",
"insightface==0.7.3",
# We can't really pin torch version as it depends on CUDA, but we check if it's pre-installed above
"torch",
"xformers",
"diffusers>=0.31.0",
"transformers",
"accelerate",
"fire",
"omegaconf",
"cuda-python==12.9.0",
"onnx>=1.15.0",
"onnxruntime>=1.16.3",
"protobuf>=3.20.2",
"colored",
"pywin32;sys_platform == 'win32'"
]

deps = {b: a for a, b in (re.findall(r"^(([^!=<>~]+)(?:[!=<>~].*)?$)", x)[0] for x in _deps)}
deps = {b: a for a, b in (re.findall(r"^(([^!=<>~ @]+)(?:[!=<>~ @].*)?$)", x)[0] for x in _deps)}


def deps_list(*pkgs):
Expand All @@ -30,7 +81,9 @@ def deps_list(*pkgs):
extras = {}
extras["xformers"] = deps_list("xformers")
extras["torch"] = deps_list("torch", "accelerate")
extras["tensorrt"] = deps_list("protobuf", "cuda-python", "onnx", "onnxruntime", "colored")
extras["tensorrt"] = deps_list("protobuf", "cuda-python", "onnx", "onnxruntime", "onnxruntime-gpu", "colored")
extras["controlnet"] = deps_list("onnx-graphsurgeon", "controlnet-aux")
extras["ipadapter"] = deps_list("diffusers-ipadapter", "mediapipe", "insightface")

extras["dev"] = extras["xformers"] + extras["torch"] + extras["tensorrt"]

Expand All @@ -40,9 +93,11 @@ def deps_list(*pkgs):
deps["diffusers"],
deps["transformers"],
deps["accelerate"],
"diffusers-ipadapter @ git+https://github.com/livepeer/Diffusers_IPAdapter.git@405f87da42932e30bd55ee8dca3ce502d7834a99",
deps["huggingface_hub"],
deps["Pillow"],
]


setup(
name="streamdiffusion",
version="0.1.1",
Expand Down
5 changes: 5 additions & 0 deletions src/streamdiffusion/acceleration/tensorrt/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ def activate(self, reuse_device_memory=None):
self.context = self.engine.create_execution_context()

def allocate_buffers(self, shape_dict=None, device="cuda"):
# Ensure an execution context exists before allocating buffers
if self.context is None:
if self.engine is None:
raise RuntimeError("TensorRT engine is not loaded; call load() before allocate_buffers().")
self.activate()
# Check if we can reuse existing buffers (OPTIMIZATION)
if self._can_reuse_buffers(shape_dict, device):
return
Expand Down
37 changes: 36 additions & 1 deletion src/streamdiffusion/pip_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import subprocess
import sys
from typing import Dict, Optional
from typing import Dict, Literal, Optional

from packaging.version import Version

Expand All @@ -12,6 +12,41 @@
index_url = os.environ.get("INDEX_URL", "")


def _check_torch_installed():
try:
import torch
import torchvision
except Exception:
msg = (
"Missing required pre-installed packages: torch, torchvision\n"
"Install the PyTorch CUDA wheels from the appropriate index first, e.g.:\n"
" pip install --index-url https://download.pytorch.org/whl/cu12x torch torchvision\n"
"Replace the index URL and versions to match your CUDA runtime."
)
raise RuntimeError(msg)

if not torch.version.cuda:
raise RuntimeError("Detected CPU-only PyTorch. Install CUDA-enabled torch/vision/audio before installing this package.")


def get_cuda_version() -> str:
_check_torch_installed()

import torch
return torch.version.cuda


def get_cuda_major() -> Optional[Literal["11", "12"]]:
version = get_cuda_version()
if not version:
return None

major = version.split(".")[0]
if major not in ("11", "12"):
return None
return major


def version(package: str) -> Optional[Version]:
try:
return Version(importlib.import_module(package).__version__)
Expand Down
47 changes: 19 additions & 28 deletions src/streamdiffusion/tools/install-tensorrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,43 @@
import fire
from packaging.version import Version

from ..pip_utils import is_installed, run_pip, version
from ..pip_utils import is_installed, run_pip, version, get_cuda_major
import platform


def get_cuda_version_from_torch() -> Optional[Literal["11", "12"]]:
try:
import torch
except ImportError:
return None
def install(cu: Optional[Literal["11", "12"]] = get_cuda_major()):
if cu not in ("11", "12"):
raise RuntimeError("CUDA major version not detected. Pass --cu 11 or --cu 12 explicitly.")

return torch.version.cuda.split(".")[0]


def install(cu: Optional[Literal["11", "12"]] = get_cuda_version_from_torch()):
if cu is None or cu not in ["11", "12"]:
print("Could not detect CUDA version. Please specify manually.")
return
print("Installing TensorRT requirements...")

if is_installed("tensorrt"):
if version("tensorrt") < Version("9.0.0"):
run_pip("uninstall -y tensorrt")

cudnn_name = f"nvidia-cudnn-cu{cu}==8.9.4.25"
min_trt_version = Version("10.12.0") if cu == "12" else Version("9.0.0")
trt_version = version("tensorrt")
if trt_version and trt_version < min_trt_version:
run_pip("uninstall -y tensorrt")

if not is_installed("tensorrt"):
run_pip(f"install {cudnn_name} --no-cache-dir")
run_pip(
"install --pre --extra-index-url https://pypi.nvidia.com tensorrt==9.0.1.post11.dev4 --no-cache-dir"
)
cudnn_package, trt_package = (
("nvidia-cudnn-cu12==9.7.1.26", "tensorrt==10.12.0.36")
if cu == "12" else
("nvidia-cudnn-cu11==8.9.7.29", "tensorrt==9.0.1.post11.dev4")
)
if not is_installed(trt_package):
run_pip(f"install {cudnn_package} --no-cache-dir")
run_pip(f"install --extra-index-url https://pypi.nvidia.com {trt_package} --no-cache-dir")

if not is_installed("polygraphy"):
run_pip(
"install polygraphy==0.47.1 --extra-index-url https://pypi.ngc.nvidia.com"
"install polygraphy==0.49.24 --extra-index-url https://pypi.ngc.nvidia.com"
)
if not is_installed("onnx_graphsurgeon"):
run_pip(
"install onnx-graphsurgeon==0.3.26 --extra-index-url https://pypi.ngc.nvidia.com"
"install onnx-graphsurgeon==0.5.8 --extra-index-url https://pypi.ngc.nvidia.com"
)
if platform.system() == 'Windows' and not is_installed("pywin32"):
run_pip(
"install pywin32"
"install pywin32==306"
)

pass


if __name__ == "__main__":
fire.Fire(install)
Empty file.