|
16 | 16 | import threading |
17 | 17 | from pathlib import Path |
18 | 18 | from tqdm import tqdm |
| 19 | +import time |
| 20 | + |
19 | 21 | logging.basicConfig(format='%(message)s', level=logging.INFO, stream=sys.stdout) |
20 | 22 |
|
21 | 23 | sys.path.extend([os.path.join(os.path.dirname(os.path.realpath(__file__)), "openvino_common")]) |
22 | 24 | sys.path.extend([os.path.join(os.path.dirname(os.path.realpath(__file__)), "..","tools")]) |
23 | 25 | from models_ov import (stable_diffusion_engine_genai) |
24 | | - |
| 26 | +from gimpopenvino.install_utils import * |
25 | 27 |
|
26 | 28 |
|
27 | 29 | # This dictionary is used to populate the drop-down model selection list. |
|
299 | 301 |
|
300 | 302 | access_token = None |
301 | 303 |
|
302 | | -# Enum for NPU Arch |
303 | | -class NPUArchitecture(Enum): |
304 | | - ARCH_3700 = "3700" # Keem Bay |
305 | | - ARCH_3720 = "3720" # Meteor Lake and Arrow Lake |
306 | | - ARCH_4000 = "4000" # Lunar Lake |
307 | | - ARCH_NEXT = "FFFF" # Next Lake |
308 | | - |
309 | 304 | NPU_THRESHOLD = 43000 |
310 | 305 |
|
311 | 306 | def does_filename_match_patterns(filename, patterns): |
@@ -371,34 +366,9 @@ def download_file_with_progress(url, local_filename, callback, total_bytes_downl |
371 | 366 | if callback(total_bytes_downloaded, total_file_list_size): |
372 | 367 | return downloaded_size |
373 | 368 |
|
| 369 | + time.sleep(0.5) # give large files a chance to sync in their target directory. |
374 | 370 | return downloaded_size |
375 | 371 |
|
376 | | -def get_npu_architecture(core): |
377 | | - """ |
378 | | - Retrieves the NPU architecture using the OpenVINO core. |
379 | | -
|
380 | | - Args: |
381 | | - core (ov.Core): The OpenVINO core instance. |
382 | | -
|
383 | | - Returns: |
384 | | - NPUArchitecture: The detected architecture, or None if not found. |
385 | | - """ |
386 | | - try: |
387 | | - available_devices = core.get_available_devices() |
388 | | - if 'NPU' in available_devices: |
389 | | - architecture = core.get_property('NPU', 'DEVICE_ARCHITECTURE') |
390 | | - for arch in NPUArchitecture: |
391 | | - if arch.value in architecture: |
392 | | - return arch |
393 | | - if core.get_property("NPU", "DEVICE_GOPS")[ov.Type.i8] > 0: |
394 | | - return NPUArchitecture.ARCH_NEXT |
395 | | - else: |
396 | | - return NPUArchitecture.ARCH_3700 |
397 | | - return None |
398 | | - except Exception as e: |
399 | | - logging.error(f"Error retrieving NPU architecture: {str(e)}") |
400 | | - return None |
401 | | - |
402 | 372 | def get_npu_driver_version(core): |
403 | 373 | try: |
404 | 374 | available_devices = core.get_available_devices() |
@@ -428,7 +398,7 @@ def __init__(self, weight_path): |
428 | 398 | self._npu_driver_version = get_npu_driver_version(self._core) |
429 | 399 | self._weight_path = weight_path |
430 | 400 | self._install_location = os.path.join(self._weight_path, "stable-diffusion-ov") |
431 | | - self._npu_is_available = True if self._npu_arch is not NPUArchitecture.ARCH_3700 and self._npu_arch is not None else False |
| 401 | + self._npu_is_available = True if self._npu_arch is not NPUArchitecture.ARCH_3700 and self._npu_arch is not NPUArchitecture.ARCH_NONE else False |
432 | 402 | self.show_hf_download_tqdm = False |
433 | 403 |
|
434 | 404 | self.hf_api = HfApi() |
@@ -536,7 +506,7 @@ def is_model_installed(self, model_id): |
536 | 506 | print(f"{model_id} installation folder exists, but it is missing {required_bin_path}") |
537 | 507 | return False |
538 | 508 |
|
539 | | - print("model_id",model_id) |
| 509 | + #print("model_id",model_id) |
540 | 510 | if "sd_3.0_med" in model_id or "sd_3.5_med" in model_id: |
541 | 511 | install_subdir = g_supported_model_map[model_id]["install_subdir"] |
542 | 512 | full_install_path = os.path.join(self._weight_path, *install_subdir) |
@@ -885,12 +855,10 @@ def _download_model(self, model_id): |
885 | 855 | else: |
886 | 856 | os.makedirs(full_install_path) |
887 | 857 |
|
888 | | - print("Inpainting optimun-cli full install path",full_install_path) |
| 858 | + #print("optimun-cli full install path",full_install_path) |
889 | 859 | import subprocess |
890 | 860 |
|
891 | | - |
892 | | - ppath = sys.executable |
893 | | - optimum_ex = ppath.replace("python.exe","optimum-cli.exe") |
| 861 | + optimum_ex = sys.executable.replace("python", "optimum-cli").replace("optimum-cli3", "optimum-cli") |
894 | 862 |
|
895 | 863 | output_file = Path(os.path.join(full_install_path, "export_output.log")) |
896 | 864 | if(model_id != "sd_15_inpainting"): |
@@ -933,6 +901,8 @@ def _download_model(self, model_id): |
933 | 901 | if os.path.isdir(download_folder): |
934 | 902 | shutil.rmtree(download_folder, ignore_errors=True) |
935 | 903 |
|
| 904 | + |
| 905 | + |
936 | 906 | # To cache these models upfront as it takes a lot of time to load. |
937 | 907 | if "sdxl_turbo" in model_id: |
938 | 908 | model_name="sdxl_turbo_square" |
|
0 commit comments