mirror of
https://github.com/vladmandic/automatic
synced 2026-09-15 02:58:44 +02:00
[IPEX] Fix native windows setup
This commit is contained in:
@@ -287,6 +287,30 @@ def check_python():
|
||||
log.debug(f'Git {git_version.replace("git version", "").strip()}')
|
||||
|
||||
|
||||
# Intel hasn't released a corresponding torchvision wheel along with torch and
|
||||
# ipex wheels, so we have to install official pytorch torchvision as a W/A.
|
||||
# However, the latest torchvision explicitly requires torch version == 2.0.1,
|
||||
# which is incompatible with the Intel torch version 2.0.0a0. This will cause
|
||||
# intel torch to be uninstalled when pip scans the dependencies of torchvision.
|
||||
# This function will check the torch version and force installing Intel torch
|
||||
# 2.0.0a0 to avoid the underlying dll version error.
|
||||
# TODO remove this W/A when Intel releases torchvision wheel for windows.
|
||||
def fix_ipex_win_torch():
|
||||
if not args.use_ipex or not 'win' in sys.platform:
|
||||
return
|
||||
try:
|
||||
ipex_torch_ver = '2.0.0a0'
|
||||
installed_torch_ver = pkg_resources.get_distribution('torch').version
|
||||
if not installed_torch_ver.startswith(ipex_torch_ver):
|
||||
log.warning(f'Incompatible torch version {installed_torch_ver} for ipex windows, reinstalling to {ipex_torch_ver}')
|
||||
torch_command = os.environ.get('TORCH_COMMAND', 'torch==2.0.0a0 intel_extension_for_pytorch==2.0.110+gitba7f6c1 -f https://developer.intel.com/ipex-whl-stable-xpu')
|
||||
install(torch_command)
|
||||
import torch
|
||||
import intel_extension_for_pytorch as ipex
|
||||
except Exception as e:
|
||||
log.warning(e)
|
||||
|
||||
|
||||
# check torch version
|
||||
def check_torch():
|
||||
if args.quick:
|
||||
@@ -348,6 +372,7 @@ def check_torch():
|
||||
import torch
|
||||
log.info(f'Torch {torch.__version__}')
|
||||
if args.use_ipex and allow_ipex:
|
||||
fix_ipex_win_torch()
|
||||
import intel_extension_for_pytorch as ipex # pylint: disable=import-error, unused-import
|
||||
log.info(f'Torch backend: Intel IPEX {ipex.__version__}')
|
||||
if shutil.which('icpx') is not None:
|
||||
|
||||
@@ -184,6 +184,7 @@ if __name__ == "__main__":
|
||||
installer.log.warning(f'Setup complete with errors: {installer.errors}')
|
||||
installer.log.warning(f'See log file for more details: {installer.log_file}')
|
||||
installer.extensions_preload(parser) # adds additional args from extensions
|
||||
installer.fix_ipex_win_torch() # redo ipex win torch fix since extensions may scan the deps of torchvision
|
||||
args = installer.parse_args(parser)
|
||||
# installer.run_setup()
|
||||
# installer.log.debug(f"Args: {vars(args)}")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
import sys
|
||||
import contextlib
|
||||
import torch
|
||||
import intel_extension_for_pytorch as ipex
|
||||
@@ -81,7 +82,8 @@ def ipex_init():
|
||||
#Fix functions with ipex:
|
||||
torch.cuda.mem_get_info = lambda device=None: [(torch.xpu.get_device_properties(device).total_memory - torch.xpu.memory_allocated(device)), torch.xpu.get_device_properties(device).total_memory]
|
||||
torch._utils._get_available_device_type = lambda: "xpu" # pylint: disable=protected-access
|
||||
torch.xpu.empty_cache = torch.xpu.empty_cache if "WSL2" not in os.popen("uname -a").read() else lambda: None
|
||||
if 'linux' in sys.platform:
|
||||
torch.xpu.empty_cache = torch.xpu.empty_cache if "WSL2" not in os.popen("uname -a").read() else lambda: None
|
||||
torch.cuda.get_device_properties.major = 2023
|
||||
torch.cuda.get_device_properties.minor = 2
|
||||
torch.backends.cuda.sdp_kernel = return_null_context
|
||||
|
||||
Reference in New Issue
Block a user