Unverified Commit bcd61fd3 authored by timdalxx's avatar timdalxx Committed by GitHub
Browse files

[docs] add docstrings in `pipline_stable_diffusion.py` (#9590)



* fix the issue on flux dreambooth lora training

* update : origin main code

* docs: update pipeline_stable_diffusion docstring

* docs: update pipeline_stable_diffusion docstring

* Update src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py
Co-authored-by: default avatarSteven Liu <59462357+stevhliu@users.noreply.github.com>

* fix: style

* fix: style

* fix: copies

* make fix-copies

* remove extra newline

---------
Co-authored-by: default avatarSteven Liu <59462357+stevhliu@users.noreply.github.com>
Co-authored-by: default avatarAryan <aryan@huggingface.co>
Co-authored-by: default avatarSayak Paul <spsayakpaul@gmail.com>
parent d27ecc59
...@@ -113,9 +113,21 @@ EXAMPLE_DOC_STRING = """ ...@@ -113,9 +113,21 @@ EXAMPLE_DOC_STRING = """
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.rescale_noise_cfg # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.rescale_noise_cfg
def rescale_noise_cfg(noise_cfg, noise_pred_text, guidance_rescale=0.0): def rescale_noise_cfg(noise_cfg, noise_pred_text, guidance_rescale=0.0):
""" r"""
Rescale `noise_cfg` according to `guidance_rescale`. Based on findings of [Common Diffusion Noise Schedules and Rescales `noise_cfg` tensor based on `guidance_rescale` to improve image quality and fix overexposure. Based on
Sample Steps are Flawed](https://arxiv.org/pdf/2305.08891.pdf). See Section 3.4 Section 3.4 from [Common Diffusion Noise Schedules and Sample Steps are
Flawed](https://arxiv.org/pdf/2305.08891.pdf).
Args:
noise_cfg (`torch.Tensor`):
The predicted noise tensor for the guided diffusion process.
noise_pred_text (`torch.Tensor`):
The predicted noise tensor for the text-guided diffusion process.
guidance_rescale (`float`, *optional*, defaults to 0.0):
A rescale factor applied to the noise predictions.
Returns:
noise_cfg (`torch.Tensor`): The rescaled noise prediction tensor.
""" """
std_text = noise_pred_text.std(dim=list(range(1, noise_pred_text.ndim)), keepdim=True) std_text = noise_pred_text.std(dim=list(range(1, noise_pred_text.ndim)), keepdim=True)
std_cfg = noise_cfg.std(dim=list(range(1, noise_cfg.ndim)), keepdim=True) std_cfg = noise_cfg.std(dim=list(range(1, noise_cfg.ndim)), keepdim=True)
...@@ -135,7 +147,7 @@ def retrieve_timesteps( ...@@ -135,7 +147,7 @@ def retrieve_timesteps(
sigmas: Optional[List[float]] = None, sigmas: Optional[List[float]] = None,
**kwargs, **kwargs,
): ):
""" r"""
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`. custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
......
...@@ -119,7 +119,7 @@ def retrieve_timesteps( ...@@ -119,7 +119,7 @@ def retrieve_timesteps(
sigmas: Optional[List[float]] = None, sigmas: Optional[List[float]] = None,
**kwargs, **kwargs,
): ):
""" r"""
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`. custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
......
...@@ -131,7 +131,7 @@ def retrieve_timesteps( ...@@ -131,7 +131,7 @@ def retrieve_timesteps(
sigmas: Optional[List[float]] = None, sigmas: Optional[List[float]] = None,
**kwargs, **kwargs,
): ):
""" r"""
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`. custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
......
...@@ -53,7 +53,7 @@ def retrieve_timesteps( ...@@ -53,7 +53,7 @@ def retrieve_timesteps(
sigmas: Optional[List[float]] = None, sigmas: Optional[List[float]] = None,
**kwargs, **kwargs,
): ):
""" r"""
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`. custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
......
...@@ -86,7 +86,7 @@ def retrieve_timesteps( ...@@ -86,7 +86,7 @@ def retrieve_timesteps(
sigmas: Optional[List[float]] = None, sigmas: Optional[List[float]] = None,
**kwargs, **kwargs,
): ):
""" r"""
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`. custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
......
...@@ -93,7 +93,7 @@ def retrieve_timesteps( ...@@ -93,7 +93,7 @@ def retrieve_timesteps(
sigmas: Optional[List[float]] = None, sigmas: Optional[List[float]] = None,
**kwargs, **kwargs,
): ):
""" r"""
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`. custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
......
...@@ -88,7 +88,7 @@ def retrieve_timesteps( ...@@ -88,7 +88,7 @@ def retrieve_timesteps(
sigmas: Optional[List[float]] = None, sigmas: Optional[List[float]] = None,
**kwargs, **kwargs,
): ):
""" r"""
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`. custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
......
...@@ -94,7 +94,7 @@ def retrieve_timesteps( ...@@ -94,7 +94,7 @@ def retrieve_timesteps(
sigmas: Optional[List[float]] = None, sigmas: Optional[List[float]] = None,
**kwargs, **kwargs,
): ):
""" r"""
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`. custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
......
...@@ -57,7 +57,7 @@ def retrieve_timesteps( ...@@ -57,7 +57,7 @@ def retrieve_timesteps(
sigmas: Optional[List[float]] = None, sigmas: Optional[List[float]] = None,
**kwargs, **kwargs,
): ):
""" r"""
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`. custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
......
...@@ -101,7 +101,7 @@ def retrieve_timesteps( ...@@ -101,7 +101,7 @@ def retrieve_timesteps(
sigmas: Optional[List[float]] = None, sigmas: Optional[List[float]] = None,
**kwargs, **kwargs,
): ):
""" r"""
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`. custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
......
...@@ -137,9 +137,21 @@ EXAMPLE_DOC_STRING = """ ...@@ -137,9 +137,21 @@ EXAMPLE_DOC_STRING = """
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.rescale_noise_cfg # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.rescale_noise_cfg
def rescale_noise_cfg(noise_cfg, noise_pred_text, guidance_rescale=0.0): def rescale_noise_cfg(noise_cfg, noise_pred_text, guidance_rescale=0.0):
""" r"""
Rescale `noise_cfg` according to `guidance_rescale`. Based on findings of [Common Diffusion Noise Schedules and Rescales `noise_cfg` tensor based on `guidance_rescale` to improve image quality and fix overexposure. Based on
Sample Steps are Flawed](https://arxiv.org/pdf/2305.08891.pdf). See Section 3.4 Section 3.4 from [Common Diffusion Noise Schedules and Sample Steps are
Flawed](https://arxiv.org/pdf/2305.08891.pdf).
Args:
noise_cfg (`torch.Tensor`):
The predicted noise tensor for the guided diffusion process.
noise_pred_text (`torch.Tensor`):
The predicted noise tensor for the text-guided diffusion process.
guidance_rescale (`float`, *optional*, defaults to 0.0):
A rescale factor applied to the noise predictions.
Returns:
noise_cfg (`torch.Tensor`): The rescaled noise prediction tensor.
""" """
std_text = noise_pred_text.std(dim=list(range(1, noise_pred_text.ndim)), keepdim=True) std_text = noise_pred_text.std(dim=list(range(1, noise_pred_text.ndim)), keepdim=True)
std_cfg = noise_cfg.std(dim=list(range(1, noise_cfg.ndim)), keepdim=True) std_cfg = noise_cfg.std(dim=list(range(1, noise_cfg.ndim)), keepdim=True)
......
...@@ -122,7 +122,7 @@ def retrieve_timesteps( ...@@ -122,7 +122,7 @@ def retrieve_timesteps(
sigmas: Optional[List[float]] = None, sigmas: Optional[List[float]] = None,
**kwargs, **kwargs,
): ):
""" r"""
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`. custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
......
...@@ -141,9 +141,21 @@ def get_resize_crop_region_for_grid(src, tgt_size): ...@@ -141,9 +141,21 @@ def get_resize_crop_region_for_grid(src, tgt_size):
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.rescale_noise_cfg # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.rescale_noise_cfg
def rescale_noise_cfg(noise_cfg, noise_pred_text, guidance_rescale=0.0): def rescale_noise_cfg(noise_cfg, noise_pred_text, guidance_rescale=0.0):
""" r"""
Rescale `noise_cfg` according to `guidance_rescale`. Based on findings of [Common Diffusion Noise Schedules and Rescales `noise_cfg` tensor based on `guidance_rescale` to improve image quality and fix overexposure. Based on
Sample Steps are Flawed](https://arxiv.org/pdf/2305.08891.pdf). See Section 3.4 Section 3.4 from [Common Diffusion Noise Schedules and Sample Steps are
Flawed](https://arxiv.org/pdf/2305.08891.pdf).
Args:
noise_cfg (`torch.Tensor`):
The predicted noise tensor for the guided diffusion process.
noise_pred_text (`torch.Tensor`):
The predicted noise tensor for the text-guided diffusion process.
guidance_rescale (`float`, *optional*, defaults to 0.0):
A rescale factor applied to the noise predictions.
Returns:
noise_cfg (`torch.Tensor`): The rescaled noise prediction tensor.
""" """
std_text = noise_pred_text.std(dim=list(range(1, noise_pred_text.ndim)), keepdim=True) std_text = noise_pred_text.std(dim=list(range(1, noise_pred_text.ndim)), keepdim=True)
std_cfg = noise_cfg.std(dim=list(range(1, noise_cfg.ndim)), keepdim=True) std_cfg = noise_cfg.std(dim=list(range(1, noise_cfg.ndim)), keepdim=True)
......
...@@ -83,7 +83,7 @@ def retrieve_timesteps( ...@@ -83,7 +83,7 @@ def retrieve_timesteps(
sigmas: Optional[List[float]] = None, sigmas: Optional[List[float]] = None,
**kwargs, **kwargs,
): ):
""" r"""
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`. custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
......
...@@ -108,7 +108,7 @@ def retrieve_timesteps( ...@@ -108,7 +108,7 @@ def retrieve_timesteps(
sigmas: Optional[List[float]] = None, sigmas: Optional[List[float]] = None,
**kwargs, **kwargs,
): ):
""" r"""
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`. custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
......
...@@ -65,9 +65,21 @@ EXAMPLE_DOC_STRING = """ ...@@ -65,9 +65,21 @@ EXAMPLE_DOC_STRING = """
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.rescale_noise_cfg # Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.rescale_noise_cfg
def rescale_noise_cfg(noise_cfg, noise_pred_text, guidance_rescale=0.0): def rescale_noise_cfg(noise_cfg, noise_pred_text, guidance_rescale=0.0):
""" r"""
Rescale `noise_cfg` according to `guidance_rescale`. Based on findings of [Common Diffusion Noise Schedules and Rescales `noise_cfg` tensor based on `guidance_rescale` to improve image quality and fix overexposure. Based on
Sample Steps are Flawed](https://arxiv.org/pdf/2305.08891.pdf). See Section 3.4 Section 3.4 from [Common Diffusion Noise Schedules and Sample Steps are
Flawed](https://arxiv.org/pdf/2305.08891.pdf).
Args:
noise_cfg (`torch.Tensor`):
The predicted noise tensor for the guided diffusion process.
noise_pred_text (`torch.Tensor`):
The predicted noise tensor for the text-guided diffusion process.
guidance_rescale (`float`, *optional*, defaults to 0.0):
A rescale factor applied to the noise predictions.
Returns:
noise_cfg (`torch.Tensor`): The rescaled noise prediction tensor.
""" """
std_text = noise_pred_text.std(dim=list(range(1, noise_pred_text.ndim)), keepdim=True) std_text = noise_pred_text.std(dim=list(range(1, noise_pred_text.ndim)), keepdim=True)
std_cfg = noise_cfg.std(dim=list(range(1, noise_cfg.ndim)), keepdim=True) std_cfg = noise_cfg.std(dim=list(range(1, noise_cfg.ndim)), keepdim=True)
...@@ -87,7 +99,7 @@ def retrieve_timesteps( ...@@ -87,7 +99,7 @@ def retrieve_timesteps(
sigmas: Optional[List[float]] = None, sigmas: Optional[List[float]] = None,
**kwargs, **kwargs,
): ):
""" r"""
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`. custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
......
...@@ -127,7 +127,7 @@ def retrieve_timesteps( ...@@ -127,7 +127,7 @@ def retrieve_timesteps(
sigmas: Optional[List[float]] = None, sigmas: Optional[List[float]] = None,
**kwargs, **kwargs,
): ):
""" r"""
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`. custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
......
...@@ -86,7 +86,7 @@ def retrieve_timesteps( ...@@ -86,7 +86,7 @@ def retrieve_timesteps(
sigmas: Optional[List[float]] = None, sigmas: Optional[List[float]] = None,
**kwargs, **kwargs,
): ):
""" r"""
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`. custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
......
...@@ -106,7 +106,7 @@ def retrieve_timesteps( ...@@ -106,7 +106,7 @@ def retrieve_timesteps(
sigmas: Optional[List[float]] = None, sigmas: Optional[List[float]] = None,
**kwargs, **kwargs,
): ):
""" r"""
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`. custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
......
...@@ -118,7 +118,7 @@ def retrieve_timesteps( ...@@ -118,7 +118,7 @@ def retrieve_timesteps(
sigmas: Optional[List[float]] = None, sigmas: Optional[List[float]] = None,
**kwargs, **kwargs,
): ):
""" r"""
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`. custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.
......
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