OpenVINO fix cache loading

This commit is contained in:
Disty0
2024-01-05 22:43:15 +03:00
parent c4d419b715
commit 3b14e1e70e
3 changed files with 12 additions and 1 deletions
+1
View File
@@ -78,6 +78,7 @@ And it also includes fixes for all reported issues so far
enable *Compress Model weights with NNCF* from *Compute Settings* and set a 4-bit NNCF mode
4-bit and 8-bit with OpenVINO is CPU only for now
- reduce system memory usage after compile
- fix cache loading with multiple models
- **Fixes**
- ipadapter: allow changing of model/image on-the-fly
- ipadapter: fix fallback of cross-attention on unload
+8 -1
View File
@@ -342,6 +342,11 @@ def partition_graph(gm: GraphModule, use_python_fusion_cache: bool, model_hash_s
return gm
def generate_subgraph_str(tensor):
if hasattr(tensor, "weight"):
shared.compiled_model_state.model_str = shared.compiled_model_state.model_str + str(tensor.weight)
return tensor
@register_backend
@fake_tensor_unsupported
def openvino_fx(subgraph, example_inputs):
@@ -351,7 +356,9 @@ def openvino_fx(subgraph, example_inputs):
if not shared.opts.openvino_disable_model_caching:
os.environ.setdefault('OPENVINO_TORCH_MODEL_CACHING', "1")
# Create a hash to be used for caching
model_hash_str = sha256(subgraph.code.encode('utf-8')).hexdigest()
shared.compiled_model_state.model_str = ""
subgraph.apply(generate_subgraph_str)
model_hash_str = sha256(shared.compiled_model_state.model_str.encode('utf-8')).hexdigest()
if (shared.compiled_model_state.cn_model != [] and shared.compiled_model_state.partition_id == 0):
model_hash_str = model_hash_str + str(shared.compiled_model_state.cn_model)
+3
View File
@@ -8,6 +8,7 @@ from installer import setup_logging
#Used by OpenVINO, can be used with TensorRT or Olive
class CompiledModelState:
def __init__(self):
self.model_str = ""
self.first_pass = True
self.first_pass_refiner = True
self.first_pass_vae = True
@@ -76,6 +77,8 @@ def optimize_openvino():
shared.compiled_model_state.lora_model = []
shared.compiled_model_state.compiled_cache.clear()
shared.compiled_model_state.partitioned_modules.clear()
shared.compiled_model_state.partition_id = 0
shared.compiled_model_state.model_str = ""
shared.compiled_model_state.first_pass = True if not shared.opts.cuda_compile_precompile else False
shared.compiled_model_state.first_pass_vae = True if not shared.opts.cuda_compile_precompile else False
shared.compiled_model_state.first_pass_refiner = True if not shared.opts.cuda_compile_precompile else False