From 10091375849e916499b4cf7d80bdf099a661d0f4 Mon Sep 17 00:00:00 2001 From: Pierre Chapuis Date: Tue, 16 Jan 2024 15:15:52 +0100 Subject: [PATCH 1/3] fix invalid default value for --half in help --- scripts/conversion/convert_diffusers_unet.py | 2 +- scripts/conversion/convert_transformers_clip_image_model.py | 2 +- scripts/conversion/convert_transformers_clip_text_model.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/conversion/convert_diffusers_unet.py b/scripts/conversion/convert_diffusers_unet.py index e3b118f4f..7fbeedae8 100644 --- a/scripts/conversion/convert_diffusers_unet.py +++ b/scripts/conversion/convert_diffusers_unet.py @@ -81,7 +81,7 @@ def main() -> None: " source path." ), ) - parser.add_argument("--half", action="store_true", help="Convert to half precision. Default: True") + parser.add_argument("--half", action="store_true", help="Convert to half precision.") parser.add_argument( "--verbose", action="store_true", diff --git a/scripts/conversion/convert_transformers_clip_image_model.py b/scripts/conversion/convert_transformers_clip_image_model.py index 552dcf32f..431b0f2ba 100644 --- a/scripts/conversion/convert_transformers_clip_image_model.py +++ b/scripts/conversion/convert_transformers_clip_image_model.py @@ -119,7 +119,7 @@ def main() -> None: " source path." ), ) - parser.add_argument("--half", action="store_true", help="Convert to half precision. Default: True") + parser.add_argument("--half", action="store_true", help="Convert to half precision.") parser.add_argument( "--verbose", action="store_true", diff --git a/scripts/conversion/convert_transformers_clip_text_model.py b/scripts/conversion/convert_transformers_clip_text_model.py index e987952bd..400eed074 100644 --- a/scripts/conversion/convert_transformers_clip_text_model.py +++ b/scripts/conversion/convert_transformers_clip_text_model.py @@ -100,7 +100,7 @@ def main() -> None: " source path." ), ) - parser.add_argument("--half", action="store_true", help="Convert to half precision. Default: True") + parser.add_argument("--half", action="store_true", help="Convert to half precision.") parser.add_argument( "--verbose", action="store_true", From e1cc958a22f6ee6925bf892dacb5f14ac465e92d Mon Sep 17 00:00:00 2001 From: Pierre Chapuis Date: Tue, 16 Jan 2024 15:16:33 +0100 Subject: [PATCH 2/3] add a way to specify the subfolder of the unet (no subfolder -> pass an empty string) --- scripts/conversion/convert_diffusers_unet.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/conversion/convert_diffusers_unet.py b/scripts/conversion/convert_diffusers_unet.py index 7fbeedae8..516c1e543 100644 --- a/scripts/conversion/convert_diffusers_unet.py +++ b/scripts/conversion/convert_diffusers_unet.py @@ -12,6 +12,7 @@ class Args(argparse.Namespace): source_path: str output_path: str | None + subfolder: str half: bool verbose: bool @@ -20,7 +21,7 @@ def setup_converter(args: Args) -> ModelConverter: # low_cpu_mem_usage=False stops some annoying console messages us to `pip install accelerate` source: nn.Module = UNet2DConditionModel.from_pretrained( # type: ignore pretrained_model_name_or_path=args.source_path, - subfolder="unet", + subfolder=args.subfolder, low_cpu_mem_usage=False, ) source_in_channels: int = source.config.in_channels # type: ignore @@ -81,6 +82,7 @@ def main() -> None: " source path." ), ) + parser.add_argument("--subfolder", type=str, default="unet", help="Subfolder. Default: unet.") parser.add_argument("--half", action="store_true", help="Convert to half precision.") parser.add_argument( "--verbose", From 37381d162b63a0f4a06d6800d31314921af3ba58 Mon Sep 17 00:00:00 2001 From: Pierre Chapuis Date: Tue, 16 Jan 2024 18:40:43 +0100 Subject: [PATCH 3/3] unet conversion: add option to skip init check --- scripts/conversion/convert_diffusers_unet.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/conversion/convert_diffusers_unet.py b/scripts/conversion/convert_diffusers_unet.py index 516c1e543..c762dee82 100644 --- a/scripts/conversion/convert_diffusers_unet.py +++ b/scripts/conversion/convert_diffusers_unet.py @@ -15,6 +15,7 @@ class Args(argparse.Namespace): subfolder: str half: bool verbose: bool + skip_init_check: bool def setup_converter(args: Args) -> ModelConverter: @@ -49,7 +50,13 @@ def setup_converter(args: Args) -> ModelConverter: "keyword": {"added_cond_kwargs": added_cond_kwargs} if source_has_time_ids else {}, } - converter = ModelConverter(source_model=source, target_model=target, skip_output_check=True, verbose=args.verbose) + converter = ModelConverter( + source_model=source, + target_model=target, + skip_init_check=args.skip_init_check, + skip_output_check=True, + verbose=args.verbose, + ) if not converter.run( source_args=source_args, target_args=target_args, @@ -83,6 +90,11 @@ def main() -> None: ), ) parser.add_argument("--subfolder", type=str, default="unet", help="Subfolder. Default: unet.") + parser.add_argument( + "--skip-init-check", + action="store_true", + help="Skip check that source and target have the same layers count.", + ) parser.add_argument("--half", action="store_true", help="Convert to half precision.") parser.add_argument( "--verbose",