From dd649143c8d8fb34c7a1ad9d1182ab6417f681bb Mon Sep 17 00:00:00 2001 From: Haofan Wang Date: Wed, 11 Jan 2023 15:17:14 +0800 Subject: [PATCH 1/3] Update train_dreambooth_colossalai.py --- .../colossalai/train_dreambooth_colossalai.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/research_projects/colossalai/train_dreambooth_colossalai.py b/examples/research_projects/colossalai/train_dreambooth_colossalai.py index b37adf7124ca..10fa27eff532 100644 --- a/examples/research_projects/colossalai/train_dreambooth_colossalai.py +++ b/examples/research_projects/colossalai/train_dreambooth_colossalai.py @@ -365,10 +365,11 @@ def gemini_zero_dpp(model: torch.nn.Module, placememt_policy: str = "auto"): def main(args): - colossalai.launch_from_torch(config={}) - - if args.seed is not None: - gpc.set_seed(args.seed) + + if args.seed is None: + colossalai.launch_from_torch(config={}) + else: + colossalai.launch_from_torch(config={}, seed=args.seed) if args.with_prior_preservation: class_images_dir = Path(args.class_data_dir) From d4dfc39e4022d7b3b2c50d7b8b50b42455d27a72 Mon Sep 17 00:00:00 2001 From: haofanwang Date: Sat, 14 Jan 2023 07:46:18 +0800 Subject: [PATCH 2/3] make style --- .../colossalai/train_dreambooth_colossalai.py | 1 - .../textual_inversion/textual_inversion_bf16.py | 5 ++++- examples/textual_inversion/textual_inversion.py | 5 ++++- examples/textual_inversion/textual_inversion_flax.py | 5 ++++- src/diffusers/models/attention.py | 6 ++++-- src/diffusers/models/cross_attention.py | 6 ++++-- .../schedulers/scheduling_euler_ancestral_discrete.py | 8 +++++--- src/diffusers/schedulers/scheduling_euler_discrete.py | 8 +++++--- tests/test_scheduler.py | 6 ++++-- 9 files changed, 34 insertions(+), 16 deletions(-) diff --git a/examples/research_projects/colossalai/train_dreambooth_colossalai.py b/examples/research_projects/colossalai/train_dreambooth_colossalai.py index 10fa27eff532..e947aea03bce 100644 --- a/examples/research_projects/colossalai/train_dreambooth_colossalai.py +++ b/examples/research_projects/colossalai/train_dreambooth_colossalai.py @@ -365,7 +365,6 @@ def gemini_zero_dpp(model: torch.nn.Module, placememt_policy: str = "auto"): def main(args): - if args.seed is None: colossalai.launch_from_torch(config={}) else: diff --git a/examples/research_projects/intel_opts/textual_inversion/textual_inversion_bf16.py b/examples/research_projects/intel_opts/textual_inversion/textual_inversion_bf16.py index 4a7540aa161b..a9b663b2e68c 100644 --- a/examples/research_projects/intel_opts/textual_inversion/textual_inversion_bf16.py +++ b/examples/research_projects/intel_opts/textual_inversion/textual_inversion_bf16.py @@ -336,7 +336,10 @@ def __getitem__(self, i): if self.center_crop: crop = min(img.shape[0], img.shape[1]) - (h, w,) = ( + ( + h, + w, + ) = ( img.shape[0], img.shape[1], ) diff --git a/examples/textual_inversion/textual_inversion.py b/examples/textual_inversion/textual_inversion.py index a9f766ac79c0..11e145e63a3f 100644 --- a/examples/textual_inversion/textual_inversion.py +++ b/examples/textual_inversion/textual_inversion.py @@ -381,7 +381,10 @@ def __getitem__(self, i): if self.center_crop: crop = min(img.shape[0], img.shape[1]) - (h, w,) = ( + ( + h, + w, + ) = ( img.shape[0], img.shape[1], ) diff --git a/examples/textual_inversion/textual_inversion_flax.py b/examples/textual_inversion/textual_inversion_flax.py index 2fb961f9a3f9..1001126402ec 100644 --- a/examples/textual_inversion/textual_inversion_flax.py +++ b/examples/textual_inversion/textual_inversion_flax.py @@ -306,7 +306,10 @@ def __getitem__(self, i): if self.center_crop: crop = min(img.shape[0], img.shape[1]) - (h, w,) = ( + ( + h, + w, + ) = ( img.shape[0], img.shape[1], ) diff --git a/src/diffusers/models/attention.py b/src/diffusers/models/attention.py index ffe67987467b..85dcc800fd1e 100644 --- a/src/diffusers/models/attention.py +++ b/src/diffusers/models/attention.py @@ -90,8 +90,10 @@ def set_use_memory_efficient_attention_xformers(self, use_memory_efficient_atten if use_memory_efficient_attention_xformers: if not is_xformers_available(): raise ModuleNotFoundError( - "Refer to https://github.com/facebookresearch/xformers for more information on how to install" - " xformers", + ( + "Refer to https://github.com/facebookresearch/xformers for more information on how to install" + " xformers" + ), name="xformers", ) elif not torch.cuda.is_available(): diff --git a/src/diffusers/models/cross_attention.py b/src/diffusers/models/cross_attention.py index 98173cb8a406..5e3808dddffc 100644 --- a/src/diffusers/models/cross_attention.py +++ b/src/diffusers/models/cross_attention.py @@ -105,8 +105,10 @@ def set_use_memory_efficient_attention_xformers(self, use_memory_efficient_atten ) elif not is_xformers_available(): raise ModuleNotFoundError( - "Refer to https://github.com/facebookresearch/xformers for more information on how to install" - " xformers", + ( + "Refer to https://github.com/facebookresearch/xformers for more information on how to install" + " xformers" + ), name="xformers", ) elif not torch.cuda.is_available(): diff --git a/src/diffusers/schedulers/scheduling_euler_ancestral_discrete.py b/src/diffusers/schedulers/scheduling_euler_ancestral_discrete.py index 2db7bb67bcbd..9976235b75f6 100644 --- a/src/diffusers/schedulers/scheduling_euler_ancestral_discrete.py +++ b/src/diffusers/schedulers/scheduling_euler_ancestral_discrete.py @@ -189,9 +189,11 @@ def step( or isinstance(timestep, torch.LongTensor) ): raise ValueError( - "Passing integer indices (e.g. from `enumerate(timesteps)`) as timesteps to" - " `EulerDiscreteScheduler.step()` is not supported. Make sure to pass" - " one of the `scheduler.timesteps` as a timestep.", + ( + "Passing integer indices (e.g. from `enumerate(timesteps)`) as timesteps to" + " `EulerDiscreteScheduler.step()` is not supported. Make sure to pass" + " one of the `scheduler.timesteps` as a timestep." + ), ) if not self.is_scale_input_called: diff --git a/src/diffusers/schedulers/scheduling_euler_discrete.py b/src/diffusers/schedulers/scheduling_euler_discrete.py index f1e9100acfe2..10f277f7e090 100644 --- a/src/diffusers/schedulers/scheduling_euler_discrete.py +++ b/src/diffusers/schedulers/scheduling_euler_discrete.py @@ -198,9 +198,11 @@ def step( or isinstance(timestep, torch.LongTensor) ): raise ValueError( - "Passing integer indices (e.g. from `enumerate(timesteps)`) as timesteps to" - " `EulerDiscreteScheduler.step()` is not supported. Make sure to pass" - " one of the `scheduler.timesteps` as a timestep.", + ( + "Passing integer indices (e.g. from `enumerate(timesteps)`) as timesteps to" + " `EulerDiscreteScheduler.step()` is not supported. Make sure to pass" + " one of the `scheduler.timesteps` as a timestep." + ), ) if not self.is_scale_input_called: diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py index 34770222d529..69831dee1bed 100755 --- a/tests/test_scheduler.py +++ b/tests/test_scheduler.py @@ -537,8 +537,10 @@ def test_scheduler_public_api(self): ) self.assertTrue( hasattr(scheduler, "scale_model_input"), - f"{scheduler_class} does not implement a required class method `scale_model_input(sample," - " timestep)`", + ( + f"{scheduler_class} does not implement a required class method `scale_model_input(sample," + " timestep)`" + ), ) self.assertTrue( hasattr(scheduler, "step"), From 5c40eb39fe91215bb90600f273d0fd91bfb644a2 Mon Sep 17 00:00:00 2001 From: haofanwang Date: Mon, 16 Jan 2023 16:33:43 +0800 Subject: [PATCH 3/3] refact --- .../colossalai/train_dreambooth_colossalai.py | 1 - .../textual_inversion/textual_inversion_bf16.py | 5 ++++- examples/textual_inversion/textual_inversion.py | 5 ++++- examples/textual_inversion/textual_inversion_flax.py | 5 ++++- src/diffusers/models/attention.py | 6 ++++-- src/diffusers/models/cross_attention.py | 6 ++++-- .../schedulers/scheduling_euler_ancestral_discrete.py | 8 +++++--- src/diffusers/schedulers/scheduling_euler_discrete.py | 8 +++++--- tests/test_scheduler.py | 6 ++++-- 9 files changed, 34 insertions(+), 16 deletions(-) diff --git a/examples/research_projects/colossalai/train_dreambooth_colossalai.py b/examples/research_projects/colossalai/train_dreambooth_colossalai.py index 10fa27eff532..e947aea03bce 100644 --- a/examples/research_projects/colossalai/train_dreambooth_colossalai.py +++ b/examples/research_projects/colossalai/train_dreambooth_colossalai.py @@ -365,7 +365,6 @@ def gemini_zero_dpp(model: torch.nn.Module, placememt_policy: str = "auto"): def main(args): - if args.seed is None: colossalai.launch_from_torch(config={}) else: diff --git a/examples/research_projects/intel_opts/textual_inversion/textual_inversion_bf16.py b/examples/research_projects/intel_opts/textual_inversion/textual_inversion_bf16.py index 4a7540aa161b..a9b663b2e68c 100644 --- a/examples/research_projects/intel_opts/textual_inversion/textual_inversion_bf16.py +++ b/examples/research_projects/intel_opts/textual_inversion/textual_inversion_bf16.py @@ -336,7 +336,10 @@ def __getitem__(self, i): if self.center_crop: crop = min(img.shape[0], img.shape[1]) - (h, w,) = ( + ( + h, + w, + ) = ( img.shape[0], img.shape[1], ) diff --git a/examples/textual_inversion/textual_inversion.py b/examples/textual_inversion/textual_inversion.py index a9f766ac79c0..11e145e63a3f 100644 --- a/examples/textual_inversion/textual_inversion.py +++ b/examples/textual_inversion/textual_inversion.py @@ -381,7 +381,10 @@ def __getitem__(self, i): if self.center_crop: crop = min(img.shape[0], img.shape[1]) - (h, w,) = ( + ( + h, + w, + ) = ( img.shape[0], img.shape[1], ) diff --git a/examples/textual_inversion/textual_inversion_flax.py b/examples/textual_inversion/textual_inversion_flax.py index 2fb961f9a3f9..1001126402ec 100644 --- a/examples/textual_inversion/textual_inversion_flax.py +++ b/examples/textual_inversion/textual_inversion_flax.py @@ -306,7 +306,10 @@ def __getitem__(self, i): if self.center_crop: crop = min(img.shape[0], img.shape[1]) - (h, w,) = ( + ( + h, + w, + ) = ( img.shape[0], img.shape[1], ) diff --git a/src/diffusers/models/attention.py b/src/diffusers/models/attention.py index ffe67987467b..85dcc800fd1e 100644 --- a/src/diffusers/models/attention.py +++ b/src/diffusers/models/attention.py @@ -90,8 +90,10 @@ def set_use_memory_efficient_attention_xformers(self, use_memory_efficient_atten if use_memory_efficient_attention_xformers: if not is_xformers_available(): raise ModuleNotFoundError( - "Refer to https://github.com/facebookresearch/xformers for more information on how to install" - " xformers", + ( + "Refer to https://github.com/facebookresearch/xformers for more information on how to install" + " xformers" + ), name="xformers", ) elif not torch.cuda.is_available(): diff --git a/src/diffusers/models/cross_attention.py b/src/diffusers/models/cross_attention.py index 98173cb8a406..5e3808dddffc 100644 --- a/src/diffusers/models/cross_attention.py +++ b/src/diffusers/models/cross_attention.py @@ -105,8 +105,10 @@ def set_use_memory_efficient_attention_xformers(self, use_memory_efficient_atten ) elif not is_xformers_available(): raise ModuleNotFoundError( - "Refer to https://github.com/facebookresearch/xformers for more information on how to install" - " xformers", + ( + "Refer to https://github.com/facebookresearch/xformers for more information on how to install" + " xformers" + ), name="xformers", ) elif not torch.cuda.is_available(): diff --git a/src/diffusers/schedulers/scheduling_euler_ancestral_discrete.py b/src/diffusers/schedulers/scheduling_euler_ancestral_discrete.py index 2db7bb67bcbd..9976235b75f6 100644 --- a/src/diffusers/schedulers/scheduling_euler_ancestral_discrete.py +++ b/src/diffusers/schedulers/scheduling_euler_ancestral_discrete.py @@ -189,9 +189,11 @@ def step( or isinstance(timestep, torch.LongTensor) ): raise ValueError( - "Passing integer indices (e.g. from `enumerate(timesteps)`) as timesteps to" - " `EulerDiscreteScheduler.step()` is not supported. Make sure to pass" - " one of the `scheduler.timesteps` as a timestep.", + ( + "Passing integer indices (e.g. from `enumerate(timesteps)`) as timesteps to" + " `EulerDiscreteScheduler.step()` is not supported. Make sure to pass" + " one of the `scheduler.timesteps` as a timestep." + ), ) if not self.is_scale_input_called: diff --git a/src/diffusers/schedulers/scheduling_euler_discrete.py b/src/diffusers/schedulers/scheduling_euler_discrete.py index f1e9100acfe2..10f277f7e090 100644 --- a/src/diffusers/schedulers/scheduling_euler_discrete.py +++ b/src/diffusers/schedulers/scheduling_euler_discrete.py @@ -198,9 +198,11 @@ def step( or isinstance(timestep, torch.LongTensor) ): raise ValueError( - "Passing integer indices (e.g. from `enumerate(timesteps)`) as timesteps to" - " `EulerDiscreteScheduler.step()` is not supported. Make sure to pass" - " one of the `scheduler.timesteps` as a timestep.", + ( + "Passing integer indices (e.g. from `enumerate(timesteps)`) as timesteps to" + " `EulerDiscreteScheduler.step()` is not supported. Make sure to pass" + " one of the `scheduler.timesteps` as a timestep." + ), ) if not self.is_scale_input_called: diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py index 34770222d529..69831dee1bed 100755 --- a/tests/test_scheduler.py +++ b/tests/test_scheduler.py @@ -537,8 +537,10 @@ def test_scheduler_public_api(self): ) self.assertTrue( hasattr(scheduler, "scale_model_input"), - f"{scheduler_class} does not implement a required class method `scale_model_input(sample," - " timestep)`", + ( + f"{scheduler_class} does not implement a required class method `scale_model_input(sample," + " timestep)`" + ), ) self.assertTrue( hasattr(scheduler, "step"),