You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 7, 2025. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 7, 2025. It is now read-only.
NoiseSchedules cosine seems wrong and lead to division by 0 #489
I saw no issue reporting this, maybe I am using it wrong. 🤷♂️
I tried using DDPMScheduler(num_train_timesteps=1000, schedule="cosine") in the 2d_ddpm_compare_schedulers.ipynb and got nan filled images as result.
Indeed the alphas are clipped in the code snippet you linked, but that's not those values which are used in the scheduler.
From what I saw it is the step function of DDPMScheduler which does that.
In the beginning of the step function, some variables are defined:
The issue comes from the alpha_prod_t variable which is equal to 1 at timestep 0 because with cosine scheduler enable alphas_cumprod is defined like so :
So alpha_prod_t at time step 0 is always equal to 1 and so beta_prod_t = 1 - alpha_prod_t is equal to 0 and later in that step function values are divided by this same beta_prod_t (equal to 0 and thus leading to NaN results).
I will try what @srassman proposed and give you a feedback later 👍
ah yes nice spot - it seems like we should be making sure alpha cumprod is calculated from the clipped alphas before we return it from the cosine scheduler
I came across the same issue of receiving Nans with Cosine due to devision by zero.
I looked to see if there is an open issue about it and here it is.
Are there immediate plans to fix this? How do you suggest to handle it right now?
Note that the MONAI Generative Models repository will be soon archived because the code has been integrated in MONAI core (https://github.com/Project-MONAI). Could you check if using the latest version of the schedulers from MONAI core leads to the same error?
If so, we will look at it immediately.
Otherwise, please use that alternative repository.
Thanks. We will look into it.
Could you please open an issue in MONAI core describing the problem so that we can have a look at the problem from there and trace it?
Activity
marksgraham commentedon May 15, 2024
Hi there,
In the cosine schedule the alpha/beta are calculated with clipping, so beta_prod_t is not 0 when t=0 as far as i can see:
however there are documented problems with the cosine scheduler, see discussion here
@srassman reports better results if you try using leading timesteps here could you try that and see if it fixes it for you?
Leirbag-gabrieL commentedon May 16, 2024
Hi thanks for your quick response,
Indeed the alphas are clipped in the code snippet you linked, but that's not those values which are used in the scheduler.
From what I saw it is the
stepfunction ofDDPMSchedulerwhich does that.In the beginning of the
stepfunction, some variables are defined:The issue comes from the
alpha_prod_tvariable which is equal to 1 at timestep 0 because with cosine scheduler enablealphas_cumprodis defined like so :So
alpha_prod_tat time step 0 is always equal to 1 and sobeta_prod_t = 1 - alpha_prod_tis equal to 0 and later in thatstepfunction values are divided by this samebeta_prod_t(equal to 0 and thus leading to NaN results).I will try what @srassman proposed and give you a feedback later 👍
marksgraham commentedon May 20, 2024
ah yes nice spot - it seems like we should be making sure alpha cumprod is calculated from the clipped alphas before we return it from the cosine scheduler
OdedRotem314 commentedon Sep 22, 2024
Hi
I came across the same issue of receiving Nans with Cosine due to devision by zero.
I looked to see if there is an open issue about it and here it is.
Are there immediate plans to fix this? How do you suggest to handle it right now?
Thanks
oded
virginiafdez commentedon Sep 23, 2024
Dear Oded,
Note that the MONAI Generative Models repository will be soon archived because the code has been integrated in MONAI core (https://github.com/Project-MONAI). Could you check if using the latest version of the schedulers from MONAI core leads to the same error?
If so, we will look at it immediately.
Otherwise, please use that alternative repository.
Thank you very much!
Virginia
OdedRotem314 commentedon Sep 23, 2024
virginiafdez commentedon Sep 23, 2024
Dear Oded
Thanks. We will look into it.
Could you please open an issue in MONAI core describing the problem so that we can have a look at the problem from there and trace it?
Thanks!
Virginia