MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / compute_snr

Function compute_snr

diffusers/examples/controlnet/train_controlnet_flax.py:836–848  ·  view source on GitHub ↗

Computes SNR as per https://github.com/TiankaiHang/Min-SNR-Diffusion-Training/blob/521b624bd70c67cee4bdf49225915f5945a872e3/guided_diffusion/gaussian_diffusion.py#L847-L849

(timesteps)

Source from the content-addressed store, hash-verified

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

Callers 1

compute_lossFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected