From 0b9f8ccd696b3dc55a0e5fa0c7e98de707a0b174 Mon Sep 17 00:00:00 2001 From: Roger Date: Sun, 20 Oct 2024 19:00:01 +0530 Subject: [PATCH 1/3] Additions to docstrings in training_utils.py --- src/diffusers/training_utils.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/diffusers/training_utils.py b/src/diffusers/training_utils.py index 9c898ad141ee..ca77504d9bab 100644 --- a/src/diffusers/training_utils.py +++ b/src/diffusers/training_utils.py @@ -43,6 +43,9 @@ def set_seed(seed: int): Args: seed (`int`): The seed to set. + + Returns: + `None` """ random.seed(seed) np.random.seed(seed) @@ -56,8 +59,21 @@ def set_seed(seed: int): def compute_snr(noise_scheduler, timesteps): """ - Computes SNR as per - https://github.com/TiankaiHang/Min-SNR-Diffusion-Training/blob/521b624bd70c67cee4bdf49225915f5945a872e3/guided_diffusion/gaussian_diffusion.py#L847-L849 + Computes SNR as per https://github.com/TiankaiHang/Min-SNR-Diffusion-Training/blob/521b624bd70c67cee4bdf49225915f5945a872e3/guided_diffusion/gaussian_diffusion.py#L847-L849 + for the given timesteps using the provided noise scheduler. + + Args: + noise_scheduler (`NoiseScheduler`): + An object containing the noise schedule parameters, specifically `alphas_cumprod`, which is used + to compute the SNR values. + timesteps (`torch.Tensor`): + A tensor of timesteps for which the SNR is computed. The device and shape of this tensor is used + to adjust and expand the calculated values. + + Returns: + `torch.Tensor`: + A tensor containing the computed SNR values for each timestep. + """ alphas_cumprod = noise_scheduler.alphas_cumprod sqrt_alphas_cumprod = alphas_cumprod**0.5 From 4a1c7d4c4bbc502578770f9c42e47c4975ea0c18 Mon Sep 17 00:00:00 2001 From: Roger Date: Sun, 20 Oct 2024 19:09:49 +0530 Subject: [PATCH 2/3] Additions to docstrings in training_utils.py continued. --- src/diffusers/training_utils.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/diffusers/training_utils.py b/src/diffusers/training_utils.py index ca77504d9bab..f8531c6e0fcb 100644 --- a/src/diffusers/training_utils.py +++ b/src/diffusers/training_utils.py @@ -67,13 +67,10 @@ def compute_snr(noise_scheduler, timesteps): An object containing the noise schedule parameters, specifically `alphas_cumprod`, which is used to compute the SNR values. timesteps (`torch.Tensor`): - A tensor of timesteps for which the SNR is computed. The device and shape of this tensor is used - to adjust and expand the calculated values. + A tensor of timesteps for which the SNR is computed. Returns: - `torch.Tensor`: - A tensor containing the computed SNR values for each timestep. - + `torch.Tensor`: A tensor containing the computed SNR values for each timestep. """ alphas_cumprod = noise_scheduler.alphas_cumprod sqrt_alphas_cumprod = alphas_cumprod**0.5 From 220e27feb78551319466c09009f56878053e5ede Mon Sep 17 00:00:00 2001 From: Roger Date: Tue, 22 Oct 2024 07:34:24 +0530 Subject: [PATCH 3/3] Changes after running make style. --- src/diffusers/training_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/diffusers/training_utils.py b/src/diffusers/training_utils.py index f8531c6e0fcb..11cc32795d2e 100644 --- a/src/diffusers/training_utils.py +++ b/src/diffusers/training_utils.py @@ -59,7 +59,7 @@ def set_seed(seed: int): def compute_snr(noise_scheduler, timesteps): """ - Computes SNR as per https://github.com/TiankaiHang/Min-SNR-Diffusion-Training/blob/521b624bd70c67cee4bdf49225915f5945a872e3/guided_diffusion/gaussian_diffusion.py#L847-L849 + Computes SNR as per https://github.com/TiankaiHang/Min-SNR-Diffusion-Training/blob/521b624bd70c67cee4bdf49225915f5945a872e3/guided_diffusion/gaussian_diffusion.py#L847-L849 for the given timesteps using the provided noise scheduler. Args: @@ -67,10 +67,10 @@ def compute_snr(noise_scheduler, timesteps): An object containing the noise schedule parameters, specifically `alphas_cumprod`, which is used to compute the SNR values. timesteps (`torch.Tensor`): - A tensor of timesteps for which the SNR is computed. + A tensor of timesteps for which the SNR is computed. Returns: - `torch.Tensor`: A tensor containing the computed SNR values for each timestep. + `torch.Tensor`: A tensor containing the computed SNR values for each timestep. """ alphas_cumprod = noise_scheduler.alphas_cumprod sqrt_alphas_cumprod = alphas_cumprod**0.5