From a697e40650221df09fa1f9c418cc6c44040bc96c Mon Sep 17 00:00:00 2001 From: Muhammad Rehan Aslam <19831661+ranareehanaslam@users.noreply.github.com> Date: Sun, 3 Mar 2024 17:15:24 +0500 Subject: [PATCH 1/4] Update trt.py --- scripts/trt.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/trt.py b/scripts/trt.py index b9f16aa..15f8c42 100644 --- a/scripts/trt.py +++ b/scripts/trt.py @@ -158,7 +158,7 @@ def get_profile_idx(self, p, model_name: str, model_type: ModelType) -> (int, in ) # TODO: max_embedding, just ignore? if len(valid_models) == 0: gr.Error( - f"""No valid profile found for ({model_name}) LOWRES. Please go to the TensorRT tab and generate an engine with the necessary profile. + f"""No valid profile found for ({model_name}) LOWRES. Please go to the TensorRT tab and generate an engine with the necessary profile. If using hires.fix, you need an engine for both the base and upscaled resolutions. Otherwise, use the default (torch) U-Net.""" ) return None, None @@ -177,7 +177,7 @@ def get_profile_idx(self, p, model_name: str, model_type: ModelType) -> (int, in ) # TODO: max_embedding if len(valid_models_hr) == 0: gr.Error( - f"""No valid profile found for ({model_name}) HIRES. Please go to the TensorRT tab and generate an engine with the necessary profile. + f"""No valid profile found for ({model_name}) HIRES. Please go to the TensorRT tab and generate an engine with the necessary profile. If using hires.fix, you need an engine for both the base and upscaled resolutions. Otherwise, use the default (torch) U-Net.""" ) merged_idx = [i for i, id in enumerate(idx) if id in idx_hr] @@ -247,7 +247,7 @@ def process(self, p, *args): if not sd_unet_option.model_name == p.sd_model_name: gr.Error( - """Selected torch model ({}) does not match the selected TensorRT U-Net ({}). + """Selected torch model ({}) does not match the selected TensorRT U-Net ({}). Please ensure that both models are the same or select Automatic from the SD UNet dropdown.""".format( p.sd_model_name, sd_unet_option.model_name ) @@ -299,7 +299,7 @@ def process_batch(self, p, *args, **kwargs): if self.torch_unet: return super().process_batch(p, *args, **kwargs) - if self.idx != sd_unet.current_unet.profile_idx: + if sd_unet.current_unet is not None and self.idx != sd_unet.current_unet.profile_idx: sd_unet.current_unet.profile_idx = self.idx sd_unet.current_unet.switch_engine() From d3f8627869ef9340e93e5fa793bac08be10a5880 Mon Sep 17 00:00:00 2001 From: Muhammad Rehan Aslam <19831661+ranareehanaslam@users.noreply.github.com> Date: Sun, 3 Mar 2024 17:16:27 +0500 Subject: [PATCH 2/4] Update ui_trt.py --- ui_trt.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui_trt.py b/ui_trt.py index 4f19847..6075084 100644 --- a/ui_trt.py +++ b/ui_trt.py @@ -268,7 +268,10 @@ def get_lora_checkpoints(): if os.path.exists(config_file): with open(config_file, "r") as f: config = json.load(f) - version = SDVersion.from_str(config["sd version"]) + try: + version = SDVersion.from_str(config["sd version"]) + except: + version = SDVersion.Unknown else: version = SDVersion.Unknown From d6900585b9c2bce00e9ced24c455a2f17f448b2e Mon Sep 17 00:00:00 2001 From: Muhammad Rehan Aslam <19831661+ranareehanaslam@users.noreply.github.com> Date: Sun, 3 Mar 2024 17:17:55 +0500 Subject: [PATCH 3/4] The key changes made in the updated installation script The key changes made in the updated installation script~: 1. **Refactoring and Simplification**: The updated script has been refactored for better readability and maintainability. Functions like `get_installed_version` and `install_package` are introduced to reduce code repetition and make the script more modular. 2. **Version Checks and Updates**: - The `tensorrt` package version has been updated from `9.0.1.post11.dev4` to `9.3.0.post12.dev1`. This change indicates a significant version update, possibly including new features, bug fixes, and performance improvements. - The CUDA Deep Neural Network library (`nvidia-cudnn-cu11`) dependency has been replaced with `nvidia-cudnn-cu12` in the updated script, suggesting a move to support newer CUDA versions (`cu12` instead of `cu11`). However, there seems to be a discrepancy in the version handling (`8.9.7.29` vs. `8.9.6.50`) that might be a typo or an intentional downgrade for compatibility reasons. 3. **Improved Package Management**: - The updated script includes more sophisticated logic for managing package installations, including handling uninstallation of previous versions if needed, before installing a new version. This is especially evident in the handling of the `tensorrt` and `nvidia-cudnn-cu12` packages. - The addition of `no_cache_dir=True` to all `install_package` calls to ensure the latest versions are fetched and to avoid potential conflicts with cached packages. 4. **Simplified Dependency Handling**: - The dependencies for ONNX Graph Surgeon and Polygraphy are handled more straightforwardly in the updated script, with specific versions for dependent packages like `protobuf`. 5. **Error Handling and Robustness**: The introduction of the `get_installed_version` function allows for more robust error handling by checking if a package is installed and obtaining its version before attempting to install or uninstall. This reduces the risk of errors during the installation process. --- install.py | 87 +++++++++++++++++++++--------------------------------- 1 file changed, 33 insertions(+), 54 deletions(-) diff --git a/install.py b/install.py index b02753d..3b81cad 100644 --- a/install.py +++ b/install.py @@ -1,67 +1,46 @@ import launch -import sys -from importlib_metadata import version - -python = sys.executable +import pkg_resources + +def get_installed_version(package_name): + try: + return pkg_resources.get_distribution(package_name).version + except pkg_resources.DistributionNotFound: + return None + +def install_package(package_name, version_spec=None, uninstall_first=False, extra_index_url=None, no_cache_dir=False): + package_install_cmd = f"{package_name}{'==' + version_spec if version_spec else ''}" + if extra_index_url: + package_install_cmd += f" --extra-index-url {extra_index_url}" + if no_cache_dir: + package_install_cmd += " --no-cache-dir" + + if uninstall_first and launch.is_installed(package_name): + launch.run(["python", "-m", "pip", "uninstall", "-y", package_name], f"removing {package_name}") + + launch.run_pip(f"install {package_install_cmd}", package_name, live=True) def install(): - if launch.is_installed("tensorrt"): - if not version("tensorrt") == "9.0.1.post11.dev4": - launch.run( - ["python", "-m", "pip", "uninstall", "-y", "tensorrt"], - "removing old version of tensorrt", - ) - - if not launch.is_installed("tensorrt"): - print("TensorRT is not installed! Installing...") - launch.run_pip( - "install nvidia-cudnn-cu11==8.9.4.25 --no-cache-dir", "nvidia-cudnn-cu11" - ) - launch.run_pip( - "install --pre --extra-index-url https://pypi.nvidia.com tensorrt==9.0.1.post11.dev4 --no-cache-dir", - "tensorrt", - live=True, - ) - launch.run( - ["python", "-m", "pip", "uninstall", "-y", "nvidia-cudnn-cu11"], - "removing nvidia-cudnn-cu11", - ) + # TensorRT installation or upgrade + tensorrt_version = get_installed_version("tensorrt") + if not tensorrt_version or tensorrt_version != "9.3.0.post12.dev1": + # nvidia-cudnn-cu11 installation + if launch.is_installed("nvidia-cudnn-cu12") and get_installed_version("nvidia-cudnn-cu11") != "8.9.7.29": + install_package("nvidia-cudnn-cu12", "8.9.6.50", uninstall_first=True, no_cache_dir=True) + install_package("tensorrt", "9.3.0.post12.dev1", uninstall_first=True, extra_index_url="https://pypi.nvidia.com", no_cache_dir=True) - if launch.is_installed("nvidia-cudnn-cu11"): - if version("nvidia-cudnn-cu11") == "8.9.4.25": - launch.run( - ["python", "-m", "pip", "uninstall", "-y", "nvidia-cudnn-cu11"], - "removing nvidia-cudnn-cu11", - ) - # Polygraphy + # Polygraphy installation if not launch.is_installed("polygraphy"): - print("Polygraphy is not installed! Installing...") - launch.run_pip( - "install polygraphy --extra-index-url https://pypi.ngc.nvidia.com", - "polygraphy", - live=True, - ) + install_package("polygraphy", extra_index_url="https://pypi.ngc.nvidia.com", no_cache_dir=True) - # ONNX GS + # ONNX Graph Surgeon installation if not launch.is_installed("onnx_graphsurgeon"): - print("GS is not installed! Installing...") - launch.run_pip("install protobuf==3.20.2", "protobuf", live=True) - launch.run_pip( - "install onnx-graphsurgeon --extra-index-url https://pypi.ngc.nvidia.com", - "onnx-graphsurgeon", - live=True, - ) + install_package("protobuf", "3.20.3", no_cache_dir=True) + install_package("onnx-graphsurgeon", extra_index_url="https://pypi.ngc.nvidia.com", no_cache_dir=True) - # OPTIMUM + # Optimum installation if not launch.is_installed("optimum"): - print("Optimum is not installed! Installing...") - launch.run_pip( - "install optimum", - "optimum", - live=True, - ) - + install_package("optimum", no_cache_dir=True) install() From c7aeef4e79785100d5e359032d7b96b09af67445 Mon Sep 17 00:00:00 2001 From: Muhammad Rehan Aslam <19831661+ranareehanaslam@users.noreply.github.com> Date: Wed, 20 Mar 2024 20:22:00 +0500 Subject: [PATCH 4/4] Update install.py --- install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.py b/install.py index 3b81cad..16e6091 100644 --- a/install.py +++ b/install.py @@ -25,7 +25,7 @@ def install(): tensorrt_version = get_installed_version("tensorrt") if not tensorrt_version or tensorrt_version != "9.3.0.post12.dev1": # nvidia-cudnn-cu11 installation - if launch.is_installed("nvidia-cudnn-cu12") and get_installed_version("nvidia-cudnn-cu11") != "8.9.7.29": + if launch.is_installed("nvidia-cudnn-cu12") and get_installed_version("nvidia-cudnn-cu12") != "8.9.6.50": install_package("nvidia-cudnn-cu12", "8.9.6.50", uninstall_first=True, no_cache_dir=True) install_package("tensorrt", "9.3.0.post12.dev1", uninstall_first=True, extra_index_url="https://pypi.nvidia.com", no_cache_dir=True)