mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 01:04:32 +02:00
Upate OpenVINO to PyTorch 2.6 and fix mismatched shapes error on too many resolution changes
This commit is contained in:
@@ -3,10 +3,10 @@ import sys
|
||||
import torch
|
||||
import nncf
|
||||
|
||||
from openvino.frontend import FrontEndManager
|
||||
from openvino.frontend.pytorch.fx_decoder import TorchFXPythonDecoder
|
||||
from openvino.frontend.pytorch.torchdynamo.partition import Partitioner
|
||||
from openvino.runtime import Core, Type, PartialShape, serialize
|
||||
from openvino.frontend.pytorch.fx_decoder import TorchFXPythonDecoder
|
||||
from openvino.frontend import FrontEndManager
|
||||
from openvino import Core, Type, PartialShape, serialize
|
||||
from openvino.properties import hint as ov_hints
|
||||
|
||||
from torch._dynamo.backends.common import fake_tensor_unsupported
|
||||
@@ -23,6 +23,11 @@ import functools
|
||||
from modules import shared, devices, sd_models
|
||||
|
||||
|
||||
torch._dynamo.eval_frame.check_if_dynamo_supported = lambda: True # pylint: disable=protected-access
|
||||
if hasattr(torch._dynamo.config, "inline_inbuilt_nn_modules"):
|
||||
torch._dynamo.config.inline_inbuilt_nn_modules = False # pylint: disable=protected-access
|
||||
|
||||
|
||||
DEFAULT_OPENVINO_PYTHON_CONFIG = MappingProxyType(
|
||||
{
|
||||
"use_python_fusion_cache": True,
|
||||
@@ -114,9 +119,9 @@ def cached_model_name(model_hash_str, device, args, cache_root, reversed = False
|
||||
for input_data in args:
|
||||
if isinstance(input_data, torch.SymInt):
|
||||
if reversed:
|
||||
inputs_str = "_" + "torch.SymInt1" + inputs_str
|
||||
inputs_str = "_" + "torch.SymInt[]" + inputs_str
|
||||
else:
|
||||
inputs_str += "_" + "torch.SymInt1"
|
||||
inputs_str += "_" + "torch.SymInt[]"
|
||||
elif isinstance(input_data, int):
|
||||
pass
|
||||
else:
|
||||
@@ -176,7 +181,7 @@ def openvino_compile(gm: GraphModule, *example_inputs, model_hash_str: str = Non
|
||||
for input_data in example_inputs:
|
||||
if isinstance(input_data, torch.SymInt):
|
||||
input_types.append(torch.SymInt)
|
||||
input_shapes.append(torch.Size([1]))
|
||||
input_shapes.append(torch.Size([]))
|
||||
elif isinstance(input_data, int):
|
||||
pass
|
||||
else:
|
||||
@@ -426,9 +431,8 @@ def get_subgraph_type(tensor):
|
||||
return tensor
|
||||
|
||||
|
||||
@register_backend
|
||||
@fake_tensor_unsupported
|
||||
def openvino_fx(subgraph, example_inputs):
|
||||
def openvino_fx(subgraph, example_inputs, options=None):
|
||||
global dont_use_4bit_nncf
|
||||
global dont_use_nncf
|
||||
global dont_use_quant
|
||||
@@ -528,6 +532,8 @@ def openvino_fx(subgraph, example_inputs):
|
||||
for node in model.graph.nodes:
|
||||
if node.target == torch.ops.aten.mul_.Tensor:
|
||||
node.target = torch.ops.aten.mul.Tensor
|
||||
elif node.target == torch.ops.aten._unsafe_index.Tensor:
|
||||
node.target = torch.ops.aten.index.Tensor
|
||||
with devices.inference_context():
|
||||
model.eval()
|
||||
partitioner = Partitioner(options=None)
|
||||
@@ -543,3 +549,7 @@ def openvino_fx(subgraph, example_inputs):
|
||||
res = execute(compiled_model, *args, executor="openvino", executor_parameters=executor_parameters, file_name=maybe_fs_cached_name)
|
||||
return res
|
||||
return _call
|
||||
|
||||
|
||||
if "openvino_fx" not in torch.compiler.list_backends():
|
||||
register_backend(compiler_fn=openvino_fx, name="openvino_fx")
|
||||
|
||||
Reference in New Issue
Block a user