Computes SNR as per https://github.com/TiankaiHang/Min-SNR-Diffusion-Training/blob/521b624bd70c67cee4bdf49225915f5945a872e3/guided_diffusion/gaussian_diffusion.py#L847-L849
(timesteps)
| 834 | train_rngs = jax.random.split(train_rngs, jax.local_device_count()) |
| 835 | |
| 836 | def compute_snr(timesteps): |
| 837 | """ |
| 838 | Computes SNR as per https://github.com/TiankaiHang/Min-SNR-Diffusion-Training/blob/521b624bd70c67cee4bdf49225915f5945a872e3/guided_diffusion/gaussian_diffusion.py#L847-L849 |
| 839 | """ |
| 840 | alphas_cumprod = noise_scheduler_state.common.alphas_cumprod |
| 841 | sqrt_alphas_cumprod = alphas_cumprod**0.5 |
| 842 | sqrt_one_minus_alphas_cumprod = (1.0 - alphas_cumprod) ** 0.5 |
| 843 | |
| 844 | alpha = sqrt_alphas_cumprod[timesteps] |
| 845 | sigma = sqrt_one_minus_alphas_cumprod[timesteps] |
| 846 | # Compute SNR. |
| 847 | snr = (alpha / sigma) ** 2 |
| 848 | return snr |
| 849 | |
| 850 | def train_step(state, unet_params, text_encoder_params, vae_params, batch, train_rng): |
| 851 | # reshape batch, add grad_step_dim if gradient_accumulation_steps > 1 |