mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-04-13 15:03:33 +00:00
Merge e14b8dfec5
into 22ad513c72
This commit is contained in:
commit
5afbcc9309
@ -498,12 +498,20 @@ class ModelPatcher:
|
||||
key = k[0]
|
||||
if len(k) > 2:
|
||||
function = k[2]
|
||||
|
||||
org_key=key.replace("diffusion_model", "diffusion_model._orig_mod")
|
||||
if key in model_sd:
|
||||
p.add(k)
|
||||
current_patches = self.patches.get(key, [])
|
||||
current_patches.append((strength_patch, patches[k], strength_model, offset, function))
|
||||
self.patches[key] = current_patches
|
||||
self.patches[org_key] = current_patches
|
||||
elif org_key in model_sd:
|
||||
if key in self.patches:
|
||||
self.patches.pop(key)
|
||||
p.add(k)
|
||||
current_patches = self.patches.get(org_key, [])
|
||||
current_patches.append((strength_patch, patches[k], strength_model, offset, function))
|
||||
self.patches[org_key] = current_patches
|
||||
|
||||
self.patches_uuid = uuid.uuid4()
|
||||
return list(p)
|
||||
|
@ -1,22 +1,65 @@
|
||||
import torch
|
||||
import importlib
|
||||
|
||||
|
||||
class TorchCompileModel:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {"required": { "model": ("MODEL",),
|
||||
"backend": (["inductor", "cudagraphs"],),
|
||||
}}
|
||||
if importlib.util.find_spec("openvino") is not None:
|
||||
import openvino as ov
|
||||
|
||||
core = ov.Core()
|
||||
available_devices = core.available_devices
|
||||
else:
|
||||
available_devices = []
|
||||
|
||||
return {
|
||||
"required": {
|
||||
"model": ("MODEL",),
|
||||
"backend": (["inductor", "cudagraphs", "openvino"],),
|
||||
},
|
||||
"optional": {
|
||||
"openvino_device": (available_devices,),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("MODEL",)
|
||||
FUNCTION = "patch"
|
||||
|
||||
CATEGORY = "_for_testing"
|
||||
EXPERIMENTAL = True
|
||||
|
||||
def patch(self, model, backend):
|
||||
def patch(self, model, backend, openvino_device):
|
||||
print(model.__class__.__name__)
|
||||
if backend == "openvino":
|
||||
options = {"device": openvino_device}
|
||||
try:
|
||||
import openvino.torch
|
||||
except ImportError:
|
||||
raise ImportError(
|
||||
"Could not import openvino python package. "
|
||||
"Please install it with `pip install openvino`."
|
||||
)
|
||||
import openvino.frontend.pytorch.torchdynamo.execute as ov_ex
|
||||
|
||||
torch._dynamo.reset()
|
||||
ov_ex.compiled_cache.clear()
|
||||
ov_ex.req_cache.clear()
|
||||
ov_ex.partitioned_modules.clear()
|
||||
else:
|
||||
options = None
|
||||
m = model.clone()
|
||||
m.add_object_patch("diffusion_model", torch.compile(model=m.get_model_object("diffusion_model"), backend=backend))
|
||||
m.add_object_patch(
|
||||
"diffusion_model",
|
||||
torch.compile(
|
||||
model=m.get_model_object("diffusion_model"),
|
||||
backend=backend,
|
||||
options=options,
|
||||
),
|
||||
)
|
||||
return (m,)
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"TorchCompileModel": TorchCompileModel,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user