"examples/quantize.py" did not exist on "331ff953dff4e547ccc999cbd3c6e3215c372def"
Unverified Commit a2ecce26 authored by Tolga Cangöz's avatar Tolga Cangöz Committed by GitHub
Browse files

Fix Copying Mechanism typo/bug (#8232)

* Fix copying mechanism typos

* fix copying mecha

* Revert, since they are in TODO

* Fix copying mechanism
parent 9e00b727
...@@ -758,7 +758,7 @@ class TokenEmbeddingsHandler: ...@@ -758,7 +758,7 @@ class TokenEmbeddingsHandler:
idx += 1 idx += 1
# copied from train_dreambooth_lora_sdxl_advanced.py # Copied from train_dreambooth_lora_sdxl_advanced.py
def save_embeddings(self, file_path: str): def save_embeddings(self, file_path: str):
assert self.train_ids is not None, "Initialize new tokens before saving embeddings." assert self.train_ids is not None, "Initialize new tokens before saving embeddings."
tensors = {} tensors = {}
......
...@@ -1524,35 +1524,35 @@ class LLMGroundedDiffusionPipeline( ...@@ -1524,35 +1524,35 @@ class LLMGroundedDiffusionPipeline(
assert emb.shape == (w.shape[0], embedding_dim) assert emb.shape == (w.shape[0], embedding_dim)
return emb return emb
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.guidance_scale
@property @property
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.guidance_scale
def guidance_scale(self): def guidance_scale(self):
return self._guidance_scale return self._guidance_scale
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.guidance_rescale
@property @property
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.guidance_rescale
def guidance_rescale(self): def guidance_rescale(self):
return self._guidance_rescale return self._guidance_rescale
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.clip_skip
@property @property
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.clip_skip
def clip_skip(self): def clip_skip(self):
return self._clip_skip return self._clip_skip
# here `guidance_scale` is defined analog to the guidance weight `w` of equation (2) # here `guidance_scale` is defined analog to the guidance weight `w` of equation (2)
# of the Imagen paper: https://arxiv.org/pdf/2205.11487.pdf . `guidance_scale = 1` # of the Imagen paper: https://arxiv.org/pdf/2205.11487.pdf . `guidance_scale = 1`
# corresponds to doing no classifier free guidance. # corresponds to doing no classifier free guidance.
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.do_classifier_free_guidance
@property @property
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.do_classifier_free_guidance
def do_classifier_free_guidance(self): def do_classifier_free_guidance(self):
return self._guidance_scale > 1 and self.unet.config.time_cond_proj_dim is None return self._guidance_scale > 1 and self.unet.config.time_cond_proj_dim is None
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.cross_attention_kwargs
@property @property
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.cross_attention_kwargs
def cross_attention_kwargs(self): def cross_attention_kwargs(self):
return self._cross_attention_kwargs return self._cross_attention_kwargs
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.num_timesteps
@property @property
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.num_timesteps
def num_timesteps(self): def num_timesteps(self):
return self._num_timesteps return self._num_timesteps
...@@ -851,8 +851,8 @@ class UNetControlNetXSModel(ModelMixin, ConfigMixin): ...@@ -851,8 +851,8 @@ class UNetControlNetXSModel(ModelMixin, ConfigMixin):
if hasattr(module, "gradient_checkpointing"): if hasattr(module, "gradient_checkpointing"):
module.gradient_checkpointing = value module.gradient_checkpointing = value
# copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel
@property @property
# Copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.attn_processors
def attn_processors(self) -> Dict[str, AttentionProcessor]: def attn_processors(self) -> Dict[str, AttentionProcessor]:
r""" r"""
Returns: Returns:
...@@ -911,7 +911,7 @@ class UNetControlNetXSModel(ModelMixin, ConfigMixin): ...@@ -911,7 +911,7 @@ class UNetControlNetXSModel(ModelMixin, ConfigMixin):
for name, module in self.named_children(): for name, module in self.named_children():
fn_recursive_attn_processor(name, module, processor) fn_recursive_attn_processor(name, module, processor)
# copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.set_default_attn_processor # Copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.set_default_attn_processor
def set_default_attn_processor(self): def set_default_attn_processor(self):
""" """
Disables custom attention processors and sets the default attention implementation. Disables custom attention processors and sets the default attention implementation.
...@@ -927,7 +927,7 @@ class UNetControlNetXSModel(ModelMixin, ConfigMixin): ...@@ -927,7 +927,7 @@ class UNetControlNetXSModel(ModelMixin, ConfigMixin):
self.set_attn_processor(processor) self.set_attn_processor(processor)
# copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.enable_freeu # Copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.enable_freeu
def enable_freeu(self, s1: float, s2: float, b1: float, b2: float): def enable_freeu(self, s1: float, s2: float, b1: float, b2: float):
r"""Enables the FreeU mechanism from https://arxiv.org/abs/2309.11497. r"""Enables the FreeU mechanism from https://arxiv.org/abs/2309.11497.
...@@ -952,7 +952,7 @@ class UNetControlNetXSModel(ModelMixin, ConfigMixin): ...@@ -952,7 +952,7 @@ class UNetControlNetXSModel(ModelMixin, ConfigMixin):
setattr(upsample_block, "b1", b1) setattr(upsample_block, "b1", b1)
setattr(upsample_block, "b2", b2) setattr(upsample_block, "b2", b2)
# copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.disable_freeu # Copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.disable_freeu
def disable_freeu(self): def disable_freeu(self):
"""Disables the FreeU mechanism.""" """Disables the FreeU mechanism."""
freeu_keys = {"s1", "s2", "b1", "b2"} freeu_keys = {"s1", "s2", "b1", "b2"}
...@@ -961,7 +961,7 @@ class UNetControlNetXSModel(ModelMixin, ConfigMixin): ...@@ -961,7 +961,7 @@ class UNetControlNetXSModel(ModelMixin, ConfigMixin):
if hasattr(upsample_block, k) or getattr(upsample_block, k, None) is not None: if hasattr(upsample_block, k) or getattr(upsample_block, k, None) is not None:
setattr(upsample_block, k, None) setattr(upsample_block, k, None)
# copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.fuse_qkv_projections # Copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.fuse_qkv_projections
def fuse_qkv_projections(self): def fuse_qkv_projections(self):
""" """
Enables fused QKV projections. For self-attention modules, all projection matrices (i.e., query, key, value) Enables fused QKV projections. For self-attention modules, all projection matrices (i.e., query, key, value)
...@@ -985,7 +985,7 @@ class UNetControlNetXSModel(ModelMixin, ConfigMixin): ...@@ -985,7 +985,7 @@ class UNetControlNetXSModel(ModelMixin, ConfigMixin):
if isinstance(module, Attention): if isinstance(module, Attention):
module.fuse_projections(fuse=True) module.fuse_projections(fuse=True)
# copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.unfuse_qkv_projections # Copied from diffusers.models.unets.unet_2d_condition.UNet2DConditionModel.unfuse_qkv_projections
def unfuse_qkv_projections(self): def unfuse_qkv_projections(self):
"""Disables the fused QKV projection if enabled. """Disables the fused QKV projection if enabled.
......
...@@ -17,7 +17,7 @@ class IFWatermarker(ModelMixin, ConfigMixin): ...@@ -17,7 +17,7 @@ class IFWatermarker(ModelMixin, ConfigMixin):
self.watermark_image_as_pil = None self.watermark_image_as_pil = None
def apply_watermark(self, images: List[PIL.Image.Image], sample_size=None): def apply_watermark(self, images: List[PIL.Image.Image], sample_size=None):
# copied from https://github.com/deep-floyd/IF/blob/b77482e36ca2031cb94dbca1001fc1e6400bf4ab/deepfloyd_if/modules/base.py#L287 # Copied from https://github.com/deep-floyd/IF/blob/b77482e36ca2031cb94dbca1001fc1e6400bf4ab/deepfloyd_if/modules/base.py#L287
h = images[0].height h = images[0].height
w = images[0].width w = images[0].width
......
...@@ -370,7 +370,7 @@ class DPMSolverSDEScheduler(SchedulerMixin, ConfigMixin): ...@@ -370,7 +370,7 @@ class DPMSolverSDEScheduler(SchedulerMixin, ConfigMixin):
timesteps = np.array([self._sigma_to_t(sigma, log_sigmas) for sigma in sig_proposed]) timesteps = np.array([self._sigma_to_t(sigma, log_sigmas) for sigma in sig_proposed])
return timesteps return timesteps
# copied from diffusers.schedulers.scheduling_euler_discrete._sigma_to_t # Copied from diffusers.schedulers.scheduling_euler_discrete.EulerDiscreteScheduler._sigma_to_t
def _sigma_to_t(self, sigma, log_sigmas): def _sigma_to_t(self, sigma, log_sigmas):
# get log sigma # get log sigma
log_sigma = np.log(np.maximum(sigma, 1e-10)) log_sigma = np.log(np.maximum(sigma, 1e-10))
...@@ -394,7 +394,7 @@ class DPMSolverSDEScheduler(SchedulerMixin, ConfigMixin): ...@@ -394,7 +394,7 @@ class DPMSolverSDEScheduler(SchedulerMixin, ConfigMixin):
t = t.reshape(sigma.shape) t = t.reshape(sigma.shape)
return t return t
# copied from diffusers.schedulers.scheduling_euler_discrete._convert_to_karras # copied from diffusers.schedulers.scheduling_euler_discrete.EulerDiscreteScheduler._convert_to_karras
def _convert_to_karras(self, in_sigmas: torch.Tensor) -> torch.Tensor: def _convert_to_karras(self, in_sigmas: torch.Tensor) -> torch.Tensor:
"""Constructs the noise schedule of Karras et al. (2022).""" """Constructs the noise schedule of Karras et al. (2022)."""
......
...@@ -324,7 +324,7 @@ class LMSDiscreteScheduler(SchedulerMixin, ConfigMixin): ...@@ -324,7 +324,7 @@ class LMSDiscreteScheduler(SchedulerMixin, ConfigMixin):
else: else:
self._step_index = self._begin_index self._step_index = self._begin_index
# copied from diffusers.schedulers.scheduling_euler_discrete._sigma_to_t # Copied from diffusers.schedulers.scheduling_euler_discrete.EulerDiscreteScheduler._sigma_to_t
def _sigma_to_t(self, sigma, log_sigmas): def _sigma_to_t(self, sigma, log_sigmas):
# get log sigma # get log sigma
log_sigma = np.log(np.maximum(sigma, 1e-10)) log_sigma = np.log(np.maximum(sigma, 1e-10))
...@@ -348,7 +348,7 @@ class LMSDiscreteScheduler(SchedulerMixin, ConfigMixin): ...@@ -348,7 +348,7 @@ class LMSDiscreteScheduler(SchedulerMixin, ConfigMixin):
t = t.reshape(sigma.shape) t = t.reshape(sigma.shape)
return t return t
# copied from diffusers.schedulers.scheduling_euler_discrete._convert_to_karras # copied from diffusers.schedulers.scheduling_euler_discrete.EulerDiscreteScheduler._convert_to_karras
def _convert_to_karras(self, in_sigmas: torch.Tensor) -> torch.Tensor: def _convert_to_karras(self, in_sigmas: torch.Tensor) -> torch.Tensor:
"""Constructs the noise schedule of Karras et al. (2022).""" """Constructs the noise schedule of Karras et al. (2022)."""
......
...@@ -156,7 +156,7 @@ class PeftLoraLoaderMixinTests: ...@@ -156,7 +156,7 @@ class PeftLoraLoaderMixinTests:
return noise, input_ids, pipeline_inputs return noise, input_ids, pipeline_inputs
# copied from: https://colab.research.google.com/gist/sayakpaul/df2ef6e1ae6d8c10a49d859883b10860/scratchpad.ipynb # Copied from: https://colab.research.google.com/gist/sayakpaul/df2ef6e1ae6d8c10a49d859883b10860/scratchpad.ipynb
def get_dummy_tokens(self): def get_dummy_tokens(self):
max_seq_length = 77 max_seq_length = 77
......
...@@ -294,7 +294,7 @@ class StableDiffusionXLControlNetPipelineFastTests( ...@@ -294,7 +294,7 @@ class StableDiffusionXLControlNetPipelineFastTests(
# ensure the results are not equal # ensure the results are not equal
assert np.abs(image_slice_1.flatten() - image_slice_3.flatten()).max() > 1e-4 assert np.abs(image_slice_1.flatten() - image_slice_3.flatten()).max() > 1e-4
# copied from test_stable_diffusion_xl.py # Copied from test_stable_diffusion_xl.py
def test_stable_diffusion_xl_prompt_embeds(self): def test_stable_diffusion_xl_prompt_embeds(self):
components = self.get_dummy_components() components = self.get_dummy_components()
sd_pipe = self.pipeline_class(**components) sd_pipe = self.pipeline_class(**components)
...@@ -375,7 +375,7 @@ class StableDiffusionXLControlNetPipelineFastTests( ...@@ -375,7 +375,7 @@ class StableDiffusionXLControlNetPipelineFastTests(
assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2 assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
# copied from test_stable_diffusion_xl.py:test_stable_diffusion_two_xl_mixture_of_denoiser_fast # Copied from test_stable_diffusion_xl.py:test_stable_diffusion_two_xl_mixture_of_denoiser_fast
# with `StableDiffusionXLControlNetPipeline` instead of `StableDiffusionXLPipeline` # with `StableDiffusionXLControlNetPipeline` instead of `StableDiffusionXLPipeline`
def test_controlnet_sdxl_two_mixture_of_denoiser_fast(self): def test_controlnet_sdxl_two_mixture_of_denoiser_fast(self):
components = self.get_dummy_components() components = self.get_dummy_components()
......
...@@ -322,7 +322,7 @@ class ControlNetPipelineSDXLImg2ImgFastTests( ...@@ -322,7 +322,7 @@ class ControlNetPipelineSDXLImg2ImgFastTests(
# ensure the results are not equal # ensure the results are not equal
assert np.abs(image_slice_1.flatten() - image_slice_3.flatten()).max() > 1e-4 assert np.abs(image_slice_1.flatten() - image_slice_3.flatten()).max() > 1e-4
# copied from test_stable_diffusion_xl.py # Copied from test_stable_diffusion_xl.py
def test_stable_diffusion_xl_prompt_embeds(self): def test_stable_diffusion_xl_prompt_embeds(self):
components = self.get_dummy_components() components = self.get_dummy_components()
sd_pipe = self.pipeline_class(**components) sd_pipe = self.pipeline_class(**components)
......
...@@ -151,7 +151,7 @@ class StableDiffusionXLControlNetXSPipelineFastTests( ...@@ -151,7 +151,7 @@ class StableDiffusionXLControlNetXSPipelineFastTests(
} }
return components return components
# copied from test_controlnet_sdxl.py # Copied from test_controlnet_sdxl.py
def get_dummy_inputs(self, device, seed=0): def get_dummy_inputs(self, device, seed=0):
if str(device).startswith("mps"): if str(device).startswith("mps"):
generator = torch.manual_seed(seed) generator = torch.manual_seed(seed)
...@@ -176,24 +176,24 @@ class StableDiffusionXLControlNetXSPipelineFastTests( ...@@ -176,24 +176,24 @@ class StableDiffusionXLControlNetXSPipelineFastTests(
return inputs return inputs
# copied from test_controlnet_sdxl.py # Copied from test_controlnet_sdxl.py
def test_attention_slicing_forward_pass(self): def test_attention_slicing_forward_pass(self):
return self._test_attention_slicing_forward_pass(expected_max_diff=2e-3) return self._test_attention_slicing_forward_pass(expected_max_diff=2e-3)
# copied from test_controlnet_sdxl.py
@unittest.skipIf( @unittest.skipIf(
torch_device != "cuda" or not is_xformers_available(), torch_device != "cuda" or not is_xformers_available(),
reason="XFormers attention is only available with CUDA and `xformers` installed", reason="XFormers attention is only available with CUDA and `xformers` installed",
) )
# Copied from test_controlnet_sdxl.py
def test_xformers_attention_forwardGenerator_pass(self): def test_xformers_attention_forwardGenerator_pass(self):
self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=2e-3) self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=2e-3)
# copied from test_controlnet_sdxl.py # Copied from test_controlnet_sdxl.py
def test_inference_batch_single_identical(self): def test_inference_batch_single_identical(self):
self._test_inference_batch_single_identical(expected_max_diff=2e-3) self._test_inference_batch_single_identical(expected_max_diff=2e-3)
# copied from test_controlnet_sdxl.py
@require_torch_gpu @require_torch_gpu
# Copied from test_controlnet_sdxl.py
def test_stable_diffusion_xl_offloads(self): def test_stable_diffusion_xl_offloads(self):
pipes = [] pipes = []
components = self.get_dummy_components() components = self.get_dummy_components()
...@@ -222,7 +222,7 @@ class StableDiffusionXLControlNetXSPipelineFastTests( ...@@ -222,7 +222,7 @@ class StableDiffusionXLControlNetXSPipelineFastTests(
assert np.abs(image_slices[0] - image_slices[1]).max() < 1e-3 assert np.abs(image_slices[0] - image_slices[1]).max() < 1e-3
assert np.abs(image_slices[0] - image_slices[2]).max() < 1e-3 assert np.abs(image_slices[0] - image_slices[2]).max() < 1e-3
# copied from test_controlnet_sdxl.py # Copied from test_controlnet_sdxl.py
def test_stable_diffusion_xl_multi_prompts(self): def test_stable_diffusion_xl_multi_prompts(self):
components = self.get_dummy_components() components = self.get_dummy_components()
sd_pipe = self.pipeline_class(**components).to(torch_device) sd_pipe = self.pipeline_class(**components).to(torch_device)
...@@ -276,7 +276,7 @@ class StableDiffusionXLControlNetXSPipelineFastTests( ...@@ -276,7 +276,7 @@ class StableDiffusionXLControlNetXSPipelineFastTests(
# ensure the results are not equal # ensure the results are not equal
assert np.abs(image_slice_1.flatten() - image_slice_3.flatten()).max() > 1e-4 assert np.abs(image_slice_1.flatten() - image_slice_3.flatten()).max() > 1e-4
# copied from test_stable_diffusion_xl.py # Copied from test_stable_diffusion_xl.py
def test_stable_diffusion_xl_prompt_embeds(self): def test_stable_diffusion_xl_prompt_embeds(self):
components = self.get_dummy_components() components = self.get_dummy_components()
sd_pipe = self.pipeline_class(**components) sd_pipe = self.pipeline_class(**components)
...@@ -315,11 +315,11 @@ class StableDiffusionXLControlNetXSPipelineFastTests( ...@@ -315,11 +315,11 @@ class StableDiffusionXLControlNetXSPipelineFastTests(
# make sure that it's equal # make sure that it's equal
assert np.abs(image_slice_1.flatten() - image_slice_2.flatten()).max() < 1.1e-4 assert np.abs(image_slice_1.flatten() - image_slice_2.flatten()).max() < 1.1e-4
# copied from test_stable_diffusion_xl.py # Copied from test_stable_diffusion_xl.py
def test_save_load_optional_components(self): def test_save_load_optional_components(self):
self._test_save_load_optional_components() self._test_save_load_optional_components()
# copied from test_controlnetxs.py # Copied from test_controlnetxs.py
def test_to_dtype(self): def test_to_dtype(self):
components = self.get_dummy_components() components = self.get_dummy_components()
pipe = self.pipeline_class(**components) pipe = self.pipeline_class(**components)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment