Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a way to specify the subfolder of the unet #185

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions scripts/conversion/convert_diffusers_unet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
class Args(argparse.Namespace):
source_path: str
output_path: str | None
subfolder: str
half: bool
verbose: bool
skip_init_check: bool


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
Expand Down Expand Up @@ -48,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,
Expand Down Expand Up @@ -81,7 +89,13 @@ def main() -> None:
" source path."
),
)
parser.add_argument("--half", action="store_true", help="Convert to half precision. Default: True")
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",
action="store_true",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion scripts/conversion/convert_transformers_clip_text_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down