mirror of
https://github.com/vladmandic/automatic
synced 2026-09-08 13:58:43 +02:00
Temp fix for OpenVINO PyTorch
This commit is contained in:
+26
-3
@@ -431,9 +431,32 @@ def check_torch():
|
||||
ipex_pip = 'https://github.com/Nuullll/intel-extension-for-pytorch/releases/download/v2.0.110%2Bxpu-master%2Bdll-bundle/intel_extension_for_pytorch-2.0.110+gitc6ea20b-cp310-cp310-win_amd64.whl'
|
||||
torch_command = os.environ.get('TORCH_COMMAND', f'{pytorch_pip} {torchvision_pip} {ipex_pip}')
|
||||
elif allow_openvino and args.use_openvino:
|
||||
#Remove this after 2.1.0 releases
|
||||
log.info('Using OpenVINO')
|
||||
torch_command = os.environ.get('TORCH_COMMAND', '--pre torch==2.1.0.dev20230820+cpu torchvision==0.16.0.dev20230820+cpu -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html')
|
||||
if "linux" in sys.platform:
|
||||
if sys.version_info[1] == 11:
|
||||
pytorch_pip = 'https://github.com/Disty0/automatic/releases/download/openvino_pre_release_pytorch/torch-2.1.0.dev20230820+cpu-cp311-cp311-linux_x86_64.whl'
|
||||
torchvision_pip = 'https://github.com/Disty0/automatic/releases/download/openvino_pre_release_pytorch/torchvision-0.16.0.dev20230820+cpu-cp311-cp311-linux_x86_64.whl'
|
||||
elif sys.version_info[1] == 10:
|
||||
pytorch_pip = 'https://github.com/Disty0/automatic/releases/download/openvino_pre_release_pytorch/torch-2.1.0.dev20230820+cpu-cp310-cp310-linux_x86_64.whl'
|
||||
torchvision_pip = 'https://github.com/Disty0/automatic/releases/download/openvino_pre_release_pytorch/torchvision-0.16.0.dev20230820+cpu-cp310-cp310-linux_x86_64.whl'
|
||||
elif sys.version_info[1] == 8:
|
||||
pytorch_pip = 'https://github.com/Disty0/automatic/releases/download/openvino_pre_release_pytorch/torch-2.1.0.dev20230820+cpu-cp38-cp38-linux_x86_64.whl'
|
||||
torchvision_pip = 'https://github.com/Disty0/automatic/releases/download/openvino_pre_release_pytorch/torchvision-0.16.0.dev20230820+cpu-cp38-cp38-linux_x86_64.whl'
|
||||
else:
|
||||
log.error('Unsupported Pyhton version')
|
||||
else:
|
||||
if sys.version_info[1] == 11:
|
||||
pytorch_pip = 'https://github.com/Disty0/automatic/releases/download/openvino_pre_release_pytorch/torch-2.1.0.dev20230820+cpu-cp311-cp311-win_amd64.whl'
|
||||
torchvision_pip = 'https://github.com/Disty0/automatic/releases/download/openvino_pre_release_pytorch/torchvision-0.16.0.dev20230820+cpu-cp311-cp311-win_amd64.whl'
|
||||
elif sys.version_info[1] == 10:
|
||||
pytorch_pip = 'https://github.com/Disty0/automatic/releases/download/openvino_pre_release_pytorch/torch-2.1.0.dev20230820+cpu-cp310-cp310-win_amd64.whl'
|
||||
torchvision_pip = 'https://github.com/Disty0/automatic/releases/download/openvino_pre_release_pytorch/torchvision-0.16.0.dev20230820+cpu-cp310-cp310-win_amd64.whl'
|
||||
elif sys.version_info[1] == 8:
|
||||
pytorch_pip = 'https://github.com/Disty0/automatic/releases/download/openvino_pre_release_pytorch/torch-2.1.0.dev20230820+cpu-cp38-cp38-win_amd64.whl'
|
||||
torchvision_pip = 'https://github.com/Disty0/automatic/releases/download/openvino_pre_release_pytorch/torchvision-0.16.0.dev20230820+cpu-cp38-cp38-win_amd64.whl'
|
||||
else:
|
||||
log.error('Unsupported Pyhton version')
|
||||
torch_command = os.environ.get('TORCH_COMMAND', f'{pytorch_pip} {torchvision_pip}')
|
||||
else:
|
||||
machine = platform.machine()
|
||||
if sys.platform == 'darwin':
|
||||
@@ -505,7 +528,7 @@ def check_torch():
|
||||
if opts.get('cuda_compile_backend', '') == 'hidet':
|
||||
install('hidet', 'hidet')
|
||||
if args.use_openvino or opts.get('cuda_compile_backend', '') == 'openvino_fx':
|
||||
install('openvino==2023.1.0', 'openvino')
|
||||
install('openvino==2023.2.0.dev20230922', 'openvino')
|
||||
os.environ.setdefault('PYTORCH_TRACING_MODE', 'TORCHFX')
|
||||
os.environ.setdefault('NEOReadDebugKeys', '1')
|
||||
os.environ.setdefault('ClDeviceGlobalMemSizeAvailablePercent', '100')
|
||||
|
||||
@@ -8,6 +8,7 @@ from openvino.runtime import Core, Type, PartialShape, serialize
|
||||
from torch._dynamo.backends.common import fake_tensor_unsupported
|
||||
from torch._dynamo.backends.registry import register_backend
|
||||
from torch.fx.experimental.proxy_tensor import make_fx
|
||||
from torch.fx import GraphModule
|
||||
from torch.utils._pytree import tree_flatten
|
||||
from types import MappingProxyType
|
||||
from hashlib import sha256
|
||||
@@ -132,7 +133,7 @@ def cached_model_name(model_hash_str, device, args, cache_root, reversed = False
|
||||
|
||||
return file_name
|
||||
|
||||
def check_fully_supported(self, graph_module):
|
||||
def check_fully_supported(self, graph_module: GraphModule) -> bool:
|
||||
num_fused = 0
|
||||
for node in graph_module.graph.nodes:
|
||||
if node.op == "call_module" and "fused_" in node.name:
|
||||
@@ -178,7 +179,7 @@ def openvino_clear_caches():
|
||||
compiled_cache.clear()
|
||||
partitioned_modules.clear()
|
||||
|
||||
def openvino_compile(gm, *args, model_hash_str: str = None, file_name=""):
|
||||
def openvino_compile(gm: GraphModule, *args, model_hash_str: str = None, file_name=""):
|
||||
core = Core()
|
||||
|
||||
device = get_device()
|
||||
@@ -259,7 +260,7 @@ def openvino_compile_cached_model(cached_model_path, *example_inputs):
|
||||
|
||||
return compiled_model
|
||||
|
||||
def openvino_execute(gm, *args, executor_parameters=None, partition_id, file_name=""):
|
||||
def openvino_execute(gm: GraphModule, *args, executor_parameters=None, partition_id, file_name=""):
|
||||
executor_parameters = executor_parameters or DEFAULT_OPENVINO_PYTHON_CONFIG
|
||||
|
||||
use_cache = executor_parameters.get(
|
||||
@@ -292,7 +293,7 @@ def openvino_execute(gm, *args, executor_parameters=None, partition_id, file_nam
|
||||
return results1[0]
|
||||
return results1
|
||||
|
||||
def openvino_execute_partitioned(gm, *args, executor_parameters=None, file_name=""):
|
||||
def openvino_execute_partitioned(gm: GraphModule, *args, executor_parameters=None, file_name=""):
|
||||
executor_parameters = executor_parameters or DEFAULT_OPENVINO_PYTHON_CONFIG
|
||||
|
||||
global partitioned_modules
|
||||
@@ -316,7 +317,7 @@ def openvino_execute_partitioned(gm, *args, executor_parameters=None, file_name=
|
||||
|
||||
return partitioned_modules[signature](*args)
|
||||
|
||||
def partition_graph(gm, use_python_fusion_cache: bool, model_hash_str: str = None, file_name=""):
|
||||
def partition_graph(gm: GraphModule, use_python_fusion_cache: bool, model_hash_str: str = None, file_name=""):
|
||||
global max_openvino_partitions
|
||||
for node in gm.graph.nodes:
|
||||
if node.op == "call_module" and "fused_" in node.name:
|
||||
|
||||
Reference in New Issue
Block a user