From 9c50c8c26ae6d34dbdf9067013130b6114d6372f Mon Sep 17 00:00:00 2001 From: tin2tin Date: Fri, 1 Dec 2023 14:24:56 +0100 Subject: [PATCH] Make Torch import for device safe. --- __init__.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/__init__.py b/__init__.py index d4a0415..cec5ad4 100644 --- a/__init__.py +++ b/__init__.py @@ -26,16 +26,19 @@ import string from os.path import dirname, realpath, isdir, join, basename import shutil from datetime import date -import torch +try: + exec("import torch") + if torch.cuda.is_available(): + gfx_device = "cuda" + elif torch.backends.mps.is_available(): + gfx_device = "mps" + else: + gfx_device = "cpu" +except ModuleNotFoundError: + print("Pallaidium dependencies needs to be installed and then Blender needs to be restarted.") os_platform = platform.system() # 'Linux', 'Darwin', 'Java', 'Windows' -if torch.cuda.is_available(): - gfx_device = "cuda" -elif torch.backends.mps.is_available(): - gfx_device = "mps" -else: - gfx_device = "cpu" def show_system_console(show):