Skip to content

Commit 8e77d6d

Browse files
add model caching
1 parent e7afec3 commit 8e77d6d

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

node_openvino.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import torch
22
import openvino as ov
33
import openvino.frontend.pytorch.torchdynamo.execute as ov_ex
4-
4+
import os
55
from comfy_api.torch_helpers import set_torch_compile_wrapper
66

77

@@ -10,11 +10,12 @@ class TorchCompileModelOpenVINO:
1010
def INPUT_TYPES(s):
1111
core = ov.Core()
1212
available_devices = core.available_devices
13-
13+
model_cache_option = ["OFF", "ON"]
1414
return {
1515
"required": {
1616
"model": ("MODEL",),
1717
"device": (available_devices,),
18+
"model_cache": (model_cache_option,),
1819
},
1920
}
2021

@@ -24,21 +25,32 @@ def INPUT_TYPES(s):
2425
CATEGORY = "OpenVINO"
2526
EXPERIMENTAL = True
2627

27-
def patch(self, model, device):
28-
options = {"device": device}
28+
def patch(self, model, device, model_cache):
29+
model_cache_option = {"OFF": False, "ON": True}
30+
cache_path = os.path.join(os.getcwd(), "openvino_model_cache")
31+
options = {
32+
"device": device,
33+
"model_caching": model_cache_option[model_cache],
34+
"cache_dir": cache_path,
35+
}
2936
torch._dynamo.reset()
3037
ov_ex.compiled_cache.clear()
3138
ov_ex.req_cache.clear()
3239
ov_ex.partitioned_modules.clear()
3340
m = model.clone()
34-
set_torch_compile_wrapper(m,
35-
backend="openvino",
36-
options=options,
37-
)
41+
42+
if model_cache_option[model_cache]:
43+
print(f"Using the model cache from {cache_path}.")
44+
45+
set_torch_compile_wrapper(
46+
m,
47+
backend="openvino",
48+
options=options,
49+
)
3850
return (m,)
3951

4052

4153
# The node ID in NODE_CLASS_MAPPINGS should be globally unique across ComfyUI ecosystem
4254
NODE_CLASS_MAPPINGS = {
4355
"OpenVINO_TorchCompileModel": TorchCompileModelOpenVINO,
44-
}
56+
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "comfyui-openvino"
33
description = "OpenVINO node is designed for optimizing the performance of model inference in ComfyUI by leveraging Intel OpenVINO toolkits. It can support running model on Intel CPU, GPU and NPU device."
4-
version = "1.0.2"
4+
version = "1.0.3"
55
license = {file = "LICENSE"}
66

77
[project.urls]

0 commit comments

Comments
 (0)