From c0e8b07dba9ea1accca4cd30acdd838887b10bef Mon Sep 17 00:00:00 2001 From: strint Date: Thu, 15 Feb 2024 08:53:07 +0000 Subject: [PATCH 1/6] add debug --- src/onediff/infer_compiler/import_tools/importer.py | 2 ++ .../infer_compiler/transform/builtin_transform.py | 13 +++++++++---- src/onediff/infer_compiler/transform/manager.py | 3 ++- src/onediff/infer_compiler/with_oneflow_compile.py | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/onediff/infer_compiler/import_tools/importer.py b/src/onediff/infer_compiler/import_tools/importer.py index 1344e2168..84799cf45 100644 --- a/src/onediff/infer_compiler/import_tools/importer.py +++ b/src/onediff/infer_compiler/import_tools/importer.py @@ -7,6 +7,7 @@ from pathlib import Path from importlib.metadata import requires from .format_utils import MockEntityNameFormatter +from ..utils.log_utils import logger __all__ = ["import_module_from_path", "LazyMocker", "is_need_mock"] @@ -19,6 +20,7 @@ def is_need_mock(cls) -> bool: return True pkgs = requires(main_pkg) except Exception as e: + logger.warning(f"Error when checking need mock of package {main_pkg}: {e}") return True if pkgs: for pkg in pkgs: diff --git a/src/onediff/infer_compiler/transform/builtin_transform.py b/src/onediff/infer_compiler/transform/builtin_transform.py index dee3b0ec1..089f86fc5 100644 --- a/src/onediff/infer_compiler/transform/builtin_transform.py +++ b/src/onediff/infer_compiler/transform/builtin_transform.py @@ -35,7 +35,10 @@ def wrapper(first_param, *args, **kwargs): nonlocal _warning_set before = first_param.__class__.__name__ - result = dispatcher(first_param, *args, **kwargs) + try: + result = dispatcher(first_param, *args, **kwargs) + except Exception as e: + raise NotImplementedError(f"Transform failed of {type(first_param)}: {e}") after = result.__class__.__name__ description = f"{before} transformed to {after}" @@ -176,7 +179,7 @@ def init(self): return of_obj except Exception as e: logger.warning(f"Unsupported type: {type(obj)} {e=}") - # raise NotImplementedError(f"Unsupported type: {obj}") + raise NotImplementedError(f"Unsupported type: {obj}") return obj @@ -214,7 +217,8 @@ def proxy_getattr(self, attr): try: return super().__getattribute__(attr) - except: + except Exception as e: + logger.warning(f"{type(self)} getattr {attr} failed: {e}") if attr in self._modules: return self._modules[attr] if attr in self._parameters: @@ -442,7 +446,8 @@ def _(mod: types.BuiltinFunctionType, verbose=False): try: if getattr(torch.nn.functional, mod.__name__) == mod: mod_name = "oneflow.nn.functional" - except: + except Exception as e: + logger.warning(f"warning when get {mod.__name__} in torch.nn.functional: {e}") mod_name = mod.__module__.replace("torch", "oneflow") if mod_name is not None: m = importlib.import_module(mod_name) diff --git a/src/onediff/infer_compiler/transform/manager.py b/src/onediff/infer_compiler/transform/manager.py index 9afa2dfe3..aa07efe51 100644 --- a/src/onediff/infer_compiler/transform/manager.py +++ b/src/onediff/infer_compiler/transform/manager.py @@ -125,5 +125,6 @@ def transform_package(self, package_name): "huggingface_hub.inference._text_generation" ) -except ImportError: +except Exception as e: + logger.warning(f"Pydantic related warning: {e}.") pass diff --git a/src/onediff/infer_compiler/with_oneflow_compile.py b/src/onediff/infer_compiler/with_oneflow_compile.py index 5a5c06bb8..77ede585b 100644 --- a/src/onediff/infer_compiler/with_oneflow_compile.py +++ b/src/onediff/infer_compiler/with_oneflow_compile.py @@ -33,7 +33,7 @@ def oneflow_module(self): logger.debug(f"Convert {type(self._torch_module)} ...") self._oneflow_module = torch2oflow(self._torch_module) - logger.debug(f"Convert {id(self._torch_module)=} done!") + logger.debug(f"Convert {type(self._torch_module)} done!") return self._oneflow_module @oneflow_module.deleter From 9c56dff81b94c2ac9fe16b28f74989e9b9034965 Mon Sep 17 00:00:00 2001 From: strint Date: Thu, 15 Feb 2024 08:54:18 +0000 Subject: [PATCH 2/6] format --- src/onediff/infer_compiler/transform/builtin_transform.py | 4 +++- src/onediff/infer_compiler/utils/log_utils.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/onediff/infer_compiler/transform/builtin_transform.py b/src/onediff/infer_compiler/transform/builtin_transform.py index 089f86fc5..70511a008 100644 --- a/src/onediff/infer_compiler/transform/builtin_transform.py +++ b/src/onediff/infer_compiler/transform/builtin_transform.py @@ -447,7 +447,9 @@ def _(mod: types.BuiltinFunctionType, verbose=False): if getattr(torch.nn.functional, mod.__name__) == mod: mod_name = "oneflow.nn.functional" except Exception as e: - logger.warning(f"warning when get {mod.__name__} in torch.nn.functional: {e}") + logger.warning( + f"warning when get {mod.__name__} in torch.nn.functional: {e}" + ) mod_name = mod.__module__.replace("torch", "oneflow") if mod_name is not None: m = importlib.import_module(mod_name) diff --git a/src/onediff/infer_compiler/utils/log_utils.py b/src/onediff/infer_compiler/utils/log_utils.py index 9e9892209..0f1feef71 100644 --- a/src/onediff/infer_compiler/utils/log_utils.py +++ b/src/onediff/infer_compiler/utils/log_utils.py @@ -37,7 +37,8 @@ def configure_logging(self, name, level, log_dir=None, file_name=None): # Create a console formatter and add it to a console handler console_formatter = ColorFormatter( - fmt="%(levelname)s [%(asctime)s] %(filename)s:%(lineno)d - %(message)s", datefmt="%Y-%m-%d %H:%M:%S" + fmt="%(levelname)s [%(asctime)s] %(filename)s:%(lineno)d - %(message)s", + datefmt="%Y-%m-%d %H:%M:%S", ) console_handler = logging.StreamHandler() console_handler.setFormatter(console_formatter) From e18d33f3700531150e646a5afc6b6b8887ac6a52 Mon Sep 17 00:00:00 2001 From: strint Date: Thu, 15 Feb 2024 08:56:01 +0000 Subject: [PATCH 3/6] rm useless --- src/onediff/infer_compiler/transform/builtin_transform.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/onediff/infer_compiler/transform/builtin_transform.py b/src/onediff/infer_compiler/transform/builtin_transform.py index 70511a008..b54f9e7c0 100644 --- a/src/onediff/infer_compiler/transform/builtin_transform.py +++ b/src/onediff/infer_compiler/transform/builtin_transform.py @@ -179,7 +179,6 @@ def init(self): return of_obj except Exception as e: logger.warning(f"Unsupported type: {type(obj)} {e=}") - raise NotImplementedError(f"Unsupported type: {obj}") return obj From 4afa646ed083be6c0c77a9f64f89095ac3c30bb1 Mon Sep 17 00:00:00 2001 From: strint Date: Thu, 15 Feb 2024 10:17:40 +0000 Subject: [PATCH 4/6] mv error to info --- src/onediff/infer_compiler/import_tools/importer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/onediff/infer_compiler/import_tools/importer.py b/src/onediff/infer_compiler/import_tools/importer.py index 84799cf45..69d9be081 100644 --- a/src/onediff/infer_compiler/import_tools/importer.py +++ b/src/onediff/infer_compiler/import_tools/importer.py @@ -20,7 +20,7 @@ def is_need_mock(cls) -> bool: return True pkgs = requires(main_pkg) except Exception as e: - logger.warning(f"Error when checking need mock of package {main_pkg}: {e}") + logger.info(f"Error when checking need mock of package {main_pkg}: {e}") return True if pkgs: for pkg in pkgs: From 6179ea743fa3c3898c3138cb652243b7db1b9dfe Mon Sep 17 00:00:00 2001 From: strint Date: Thu, 15 Feb 2024 11:10:34 +0000 Subject: [PATCH 5/6] back to 0.25 --- onediff_diffusers_extensions/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onediff_diffusers_extensions/setup.py b/onediff_diffusers_extensions/setup.py index e1350cd69..3c68b0107 100644 --- a/onediff_diffusers_extensions/setup.py +++ b/onediff_diffusers_extensions/setup.py @@ -12,7 +12,7 @@ python_requires=">=3.7.0", install_requires=[ "transformers>=4.27.1", - "diffusers>=0.24.0,<=0.26.2", + "diffusers>=0.24.0,<=0.25.1", "accelerate", "torch", "onefx", From b855147a25f1658df73b6154026b97ec6f9861bb Mon Sep 17 00:00:00 2001 From: strint Date: Thu, 15 Feb 2024 11:16:36 +0000 Subject: [PATCH 6/6] format --- .../examples/text_to_image_deep_cache_sd.py | 4 +-- .../examples/text_to_image_sdxl_turbo.py | 5 +--- .../deep_cache/models/unet_2d_blocks.py | 28 +++++++++++++++---- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/onediff_diffusers_extensions/examples/text_to_image_deep_cache_sd.py b/onediff_diffusers_extensions/examples/text_to_image_deep_cache_sd.py index 23b9aab09..651d98085 100644 --- a/onediff_diffusers_extensions/examples/text_to_image_deep_cache_sd.py +++ b/onediff_diffusers_extensions/examples/text_to_image_deep_cache_sd.py @@ -13,9 +13,7 @@ from onediffx.deep_cache import StableDiffusionPipeline parser = argparse.ArgumentParser() -parser.add_argument( - "--base", type=str, default="runwayml/stable-diffusion-v1-5" -) +parser.add_argument("--base", type=str, default="runwayml/stable-diffusion-v1-5") parser.add_argument("--variant", type=str, default="fp16") parser.add_argument( "--prompt", diff --git a/onediff_diffusers_extensions/examples/text_to_image_sdxl_turbo.py b/onediff_diffusers_extensions/examples/text_to_image_sdxl_turbo.py index d37a335d1..5486491d7 100644 --- a/onediff_diffusers_extensions/examples/text_to_image_sdxl_turbo.py +++ b/onediff_diffusers_extensions/examples/text_to_image_sdxl_turbo.py @@ -36,10 +36,7 @@ # SDXL turbo base: AutoPipelineForText2Image base = AutoPipelineForText2Image.from_pretrained( - args.base, - torch_dtype=torch.float16, - variant=args.variant, - use_safetensors=True, + args.base, torch_dtype=torch.float16, variant=args.variant, use_safetensors=True, ) base.to("cuda") diff --git a/onediff_diffusers_extensions/onediffx/deep_cache/models/unet_2d_blocks.py b/onediff_diffusers_extensions/onediffx/deep_cache/models/unet_2d_blocks.py index bc709fe0a..55db38320 100644 --- a/onediff_diffusers_extensions/onediffx/deep_cache/models/unet_2d_blocks.py +++ b/onediff_diffusers_extensions/onediffx/deep_cache/models/unet_2d_blocks.py @@ -568,12 +568,23 @@ def __init__( if kernel_size is None: kernel_size = 4 conv = nn.ConvTranspose2d( - channels, self.out_channels, kernel_size=kernel_size, stride=2, padding=padding, bias=bias + channels, + self.out_channels, + kernel_size=kernel_size, + stride=2, + padding=padding, + bias=bias, ) elif use_conv: if kernel_size is None: kernel_size = 3 - conv = conv_cls(self.channels, self.out_channels, kernel_size=kernel_size, padding=padding, bias=bias) + conv = conv_cls( + self.channels, + self.out_channels, + kernel_size=kernel_size, + padding=padding, + bias=bias, + ) # TODO(Suraj, Patrick) - clean up after weight dicts are correctly renamed if name == "conv": @@ -590,7 +601,9 @@ def forward( assert hidden_states.shape[1] == self.channels if self.norm is not None: - hidden_states = self.norm(hidden_states.permute(0, 2, 3, 1)).permute(0, 3, 1, 2) + hidden_states = self.norm(hidden_states.permute(0, 2, 3, 1)).permute( + 0, 3, 1, 2 + ) if self.use_conv_transpose: return self.conv(hidden_states) @@ -610,7 +623,9 @@ def forward( # size and do not make use of `scale_factor=2` if self.interpolate: if output_size is None: - hidden_states = F.interpolate(hidden_states, scale_factor=2.0, mode="nearest") + hidden_states = F.interpolate( + hidden_states, scale_factor=2.0, mode="nearest" + ) else: # Rewritten for the switching of uncommon resolutions. # hidden_states = F.interpolate(hidden_states, size=output_size, mode="nearest") @@ -630,7 +645,10 @@ def forward( else: hidden_states = self.conv(hidden_states) else: - if isinstance(self.Conv2d_0, LoRACompatibleConv) and not USE_PEFT_BACKEND: + if ( + isinstance(self.Conv2d_0, LoRACompatibleConv) + and not USE_PEFT_BACKEND + ): hidden_states = self.Conv2d_0(hidden_states, scale) else: hidden_states = self.Conv2d_0(hidden_states)