From ab00f5d3e1780e10ebe146daa554dd39096d29a3 Mon Sep 17 00:00:00 2001 From: anton-l Date: Tue, 19 Jul 2022 15:13:22 +0200 Subject: [PATCH 1/4] Update model names for CompVis and google --- tests/test_modeling_utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_modeling_utils.py b/tests/test_modeling_utils.py index e8c87f73c9..b593ebe09b 100755 --- a/tests/test_modeling_utils.py +++ b/tests/test_modeling_utils.py @@ -969,7 +969,7 @@ class PipelineTesterMixin(unittest.TestCase): @slow def test_ddim_lsun(self): - model_id = "google/ddpm-lsun-bedroom-ema" + model_id = "google/ddpm-ema-bedroom-256" unet = UNetUnconditionalModel.from_pretrained(model_id) scheduler = DDIMScheduler.from_config(model_id) @@ -1028,7 +1028,7 @@ class PipelineTesterMixin(unittest.TestCase): @slow def test_ldm_text2img(self): - ldm = LatentDiffusionPipeline.from_pretrained("CompVis/latent-diffusion-text2im-large") + ldm = LatentDiffusionPipeline.from_pretrained("CompVis/ldm-text2im-large") prompt = "A painting of a squirrel eating a burger" generator = torch.manual_seed(0) @@ -1042,7 +1042,7 @@ class PipelineTesterMixin(unittest.TestCase): @slow def test_ldm_text2img_fast(self): - ldm = LatentDiffusionPipeline.from_pretrained("CompVis/latent-diffusion-text2im-large") + ldm = LatentDiffusionPipeline.from_pretrained("CompVis/ldm-text2im-large") prompt = "A painting of a squirrel eating a burger" generator = torch.manual_seed(0) @@ -1121,7 +1121,7 @@ class PipelineTesterMixin(unittest.TestCase): @slow def test_ldm_uncond(self): - ldm = LatentDiffusionUncondPipeline.from_pretrained("CompVis/latent-diffusion-celeba-256") + ldm = LatentDiffusionUncondPipeline.from_pretrained("CompVis/ldm-celebahq-256") generator = torch.manual_seed(0) image = ldm(generator=generator, num_inference_steps=5)["sample"] From e3c982ee29e90c68f655dbf8ff6a2a566801285b Mon Sep 17 00:00:00 2001 From: anton-l Date: Tue, 19 Jul 2022 16:41:13 +0200 Subject: [PATCH 2/4] Quick hacks for push_to_hub from notebooks --- src/diffusers/hub_utils.py | 40 +++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/diffusers/hub_utils.py b/src/diffusers/hub_utils.py index 8e22108318..c9a8271541 100644 --- a/src/diffusers/hub_utils.py +++ b/src/diffusers/hub_utils.py @@ -50,15 +50,16 @@ def init_git_repo(args, at_init: bool = False): Whether this function is called before any training or not. If `self.args.overwrite_output_dir` is `True` and `at_init` is `True`, the path to the repo (which is `self.args.output_dir`) might be wiped out. """ - if args.local_rank not in [-1, 0]: + if not hasattr(args, "local_rank") or args.local_rank not in [-1, 0]: return - use_auth_token = True if args.hub_token is None else args.hub_token - if args.hub_model_id is None: + hub_token = args.hub_token if hasattr(args, "hub_token") else None + use_auth_token = True if hub_token is None else hub_token + if not hasattr(args, "hub_model_id") or args.hub_model_id is None: repo_name = Path(args.output_dir).absolute().name else: repo_name = args.hub_model_id if "/" not in repo_name: - repo_name = get_full_repo_name(repo_name, token=args.hub_token) + repo_name = get_full_repo_name(repo_name, token=hub_token) try: repo = Repository( @@ -122,7 +123,7 @@ def push_to_hub( pipeline.save_pretrained(output_dir) # Only push from one node. - if args.local_rank not in [-1, 0]: + if not hasattr(args, "local_rank") or args.local_rank not in [-1, 0]: return # Cancel any async push in progress if blocking=True. The commits will all be pushed together. @@ -146,10 +147,11 @@ def push_to_hub( def create_model_card(args, model_name): - if args.local_rank not in [-1, 0]: + if hasattr(args, "local_rank") and args.local_rank not in [-1, 0]: return - repo_name = get_full_repo_name(model_name, token=args.hub_token) + hub_token = args.hub_token if hasattr(args, "hub_token") else None + repo_name = get_full_repo_name(model_name, token=hub_token) model_card = ModelCard.from_template( card_data=CardData( # Card metadata object that will be converted to YAML block @@ -163,20 +165,22 @@ def create_model_card(args, model_name): template_path=MODEL_CARD_TEMPLATE_PATH, model_name=model_name, repo_name=repo_name, - dataset_name=args.dataset, + dataset_name=args.dataset if hasattr(args, "dataset") else None, learning_rate=args.learning_rate, train_batch_size=args.train_batch_size, eval_batch_size=args.eval_batch_size, - gradient_accumulation_steps=args.gradient_accumulation_steps, - adam_beta1=args.adam_beta1, - adam_beta2=args.adam_beta2, - adam_weight_decay=args.adam_weight_decay, - adam_epsilon=args.adam_epsilon, - lr_scheduler=args.lr_scheduler, - lr_warmup_steps=args.lr_warmup_steps, - ema_inv_gamma=args.ema_inv_gamma, - ema_power=args.ema_power, - ema_max_decay=args.ema_max_decay, + gradient_accumulation_steps=args.gradient_accumulation_steps + if hasattr(args, "gradient_accumulation_steps") + else None, + adam_beta1=args.adam_beta1 if hasattr(args, "adam_beta1") else None, + adam_beta2=args.adam_beta2 if hasattr(args, "adam_beta2") else None, + adam_weight_decay=args.adam_weight_decay if hasattr(args, "adam_weight_decay") else None, + adam_epsilon=args.adam_epsilon if hasattr(args, "adam_weight_decay") else None, + lr_scheduler=args.lr_scheduler if hasattr(args, "lr_scheduler") else None, + lr_warmup_steps=args.lr_warmup_steps if hasattr(args, "lr_warmup_steps") else None, + ema_inv_gamma=args.ema_inv_gamma if hasattr(args, "ema_inv_gamma") else None, + ema_power=args.ema_power if hasattr(args, "ema_power") else None, + ema_max_decay=args.ema_max_decay if hasattr(args, "ema_max_decay") else None, mixed_precision=args.mixed_precision, ) From 0e5a99bb5ac274949d33bc58e378a18b84e7c60e Mon Sep 17 00:00:00 2001 From: anton-l Date: Tue, 19 Jul 2022 16:52:39 +0200 Subject: [PATCH 3/4] Quick hacks for push_to_hub from notebooks - follow-up --- src/diffusers/hub_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/diffusers/hub_utils.py b/src/diffusers/hub_utils.py index c9a8271541..4aa6180ca8 100644 --- a/src/diffusers/hub_utils.py +++ b/src/diffusers/hub_utils.py @@ -50,7 +50,7 @@ def init_git_repo(args, at_init: bool = False): Whether this function is called before any training or not. If `self.args.overwrite_output_dir` is `True` and `at_init` is `True`, the path to the repo (which is `self.args.output_dir`) might be wiped out. """ - if not hasattr(args, "local_rank") or args.local_rank not in [-1, 0]: + if hasattr(args, "local_rank") and args.local_rank not in [-1, 0]: return hub_token = args.hub_token if hasattr(args, "hub_token") else None use_auth_token = True if hub_token is None else hub_token @@ -112,7 +112,7 @@ def push_to_hub( commit and an object to track the progress of the commit if `blocking=True` """ - if args.hub_model_id is None: + if not hasattr(args, "hub_model_id") or args.hub_model_id is None: model_name = Path(args.output_dir).name else: model_name = args.hub_model_id.split("/")[-1] @@ -123,7 +123,7 @@ def push_to_hub( pipeline.save_pretrained(output_dir) # Only push from one node. - if not hasattr(args, "local_rank") or args.local_rank not in [-1, 0]: + if hasattr(args, "local_rank") and args.local_rank not in [-1, 0]: return # Cancel any async push in progress if blocking=True. The commits will all be pushed together. From 0ea78f0d3b37d473853ad3277237477bdb63966d Mon Sep 17 00:00:00 2001 From: anton-l Date: Tue, 19 Jul 2022 17:01:16 +0200 Subject: [PATCH 4/4] Include MANIFEST.in to package the modelcard template --- MANIFEST.in | 1 + 1 file changed, 1 insertion(+) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000000..8ff3cbc118 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include diffusers/utils/model_card_template.md \ No newline at end of file