Skip to content

Commit

Permalink
[add] deep-cache test (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccssu authored Mar 27, 2024
1 parent 358990f commit 2679a87
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ jobs:
run_comfy_test "workflows/sdxl-unet-speedup-graph-saver.json" 200
run_comfy_test "workflows/sdxl-control-lora-speedup.json" 200
run_comfy_test "/share_nfs/hf_models/comfyui_resources/workflows/deep-cache.json" 600
run_comfy_test "/share_nfs/hf_models/comfyui_resources/workflows/deep-cache-with-lora.json" 800
# run_comfy_test "workflows/text-to-video-speedup.json" 5000
- name: Show ComfyUI Log
Expand Down
34 changes: 5 additions & 29 deletions onediff_comfy_nodes/_compare_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ def INPUT_TYPES(s):
"required": {
"images1": ("IMAGE",),
"images2": ("IMAGE",),
"rtol": ("STRING", {"default": "1e-4"}),
"atol": ("STRING", {"default": "1e-4"}),
"ssim_threshold": ("STRING", {"default": "0.9"}),
"raise_if_diff": (["enable", "disable"],),
"image_id": ("STRING", {"default": "ComfyUI"}),
},
Expand All @@ -129,8 +128,7 @@ def save_images(
self,
images1,
images2,
rtol: str,
atol: str,
ssim_threshold: float,
raise_if_diff: str,
image_id="ComfyUI",
prompt=None,
Expand Down Expand Up @@ -180,31 +178,9 @@ def save_images(
)

if raise_if_diff == "enable":
default_rtol = 1e-4
default_atol = 1e-4
try:
rtol = float(rtol)
except ValueError:
print(
"\033[91m"
+ f"rtol = {rtol} is not a float, use default value rtol={default_rtol}"
+ "\033[0m"
)
rtol = default_rtol
try:
atol = float(atol)
except ValueError:
print(
"\033[91m"
+ f"atol = {atol} is not a float, use default value atol={default_atol}"
+ "\033[0m"
)
atol = default_atol

if not torch.allclose(image1, image2, rtol=rtol, atol=atol):
raise RuntimeError(
f"The diff between image1 and image2 is beyond the scope of rtol={rtol}, atol={atol}, max diff is {max_diff}"
)
assert ssim > float(ssim_threshold), (
f"Image diff is too large, ssim is {ssim}, "
)

return {"ui": {"images": results}}

Expand Down
3 changes: 3 additions & 0 deletions onediff_comfy_nodes/utils/model_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def __init__(
self.current_device = self.offload_device
else:
self.current_device = current_device

self.model_lowvram = False

def clone(self):
n = OneFlowSpeedUpModelPatcher(
Expand All @@ -80,6 +82,7 @@ def clone(self):
n.object_patches = self.object_patches.copy()
n.model_options = copy.deepcopy(self.model_options)
n.model_keys = self.model_keys
self.model_lowvram = False
return n

def add_patches(self, patches, strength_patch=1.0, strength_model=1.0):
Expand Down
7 changes: 5 additions & 2 deletions src/onediff/infer_compiler/import_tools/dyn_mock_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ def proxy_func(*args, **kwargs):
def _update_module(full_names, main_pkg_enable_context):
with main_pkg_enable_context():
original_results = inspect_modules_and_attributes(full_names)

updated_results = inspect_modules_and_attributes(full_names)

torch_path = os.path.dirname(torch.__file__)

for module_key, (module_path, module_code) in updated_results.items():
org_module_path, org_module_code = original_results.get(
module_key, (module_path, module_code)
Expand Down Expand Up @@ -182,9 +183,11 @@ def __getattr__(self, name: str):
obj_entity = self._get_module(name)
org_delete_list = deepcopy(_importer.delete_list)


try:
# Update obj_entity inplace
_update_module([fullname] + org_delete_list, self._main_pkg_enable)
if not _importer.enable:
_update_module([fullname] + org_delete_list, self._main_pkg_enable)
except Exception as e:
logger.warning(f'Failed to update obj_entity in place. Exception: {e}')

Expand Down

0 comments on commit 2679a87

Please sign in to comment.