Spaces:
Running on Zero
Running on Zero
Temporary disable tqdm
Browse files397 unmodified lines398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448397 unmodified lines# 11. Denoising loopnum_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler.orderwith self.progress_bar(total=num_inference_steps) as progress_bar:for i, t in enumerate(timesteps):latent_model_input = (torch.cat([latents] * 2) if do_classifier_free_guidance else latents)latent_model_input = self.scheduler.scale_model_input(latent_model_input, t)if i <= start_merge_step:current_prompt_embeds = torch.cat([negative_prompt_embeds, prompt_embeds_text_only], dim=0)add_text_embeds = torch.cat([negative_pooled_prompt_embeds, pooled_prompt_embeds_text_only], dim=0)else:current_prompt_embeds = torch.cat([negative_prompt_embeds, prompt_embeds], dim=0)add_text_embeds = torch.cat([negative_pooled_prompt_embeds, pooled_prompt_embeds], dim=0)# predict the noise residualadded_cond_kwargs = {"text_embeds": add_text_embeds, "time_ids": add_time_ids}noise_pred = self.unet(latent_model_input,t,encoder_hidden_states=current_prompt_embeds,cross_attention_kwargs=cross_attention_kwargs,added_cond_kwargs=added_cond_kwargs,return_dict=False,)[0]# perform guidanceif do_classifier_free_guidance:noise_pred_uncond, noise_pred_text = noise_pred.chunk(2)noise_pred = noise_pred_uncond + guidance_scale * (noise_pred_text - noise_pred_uncond)if do_classifier_free_guidance and guidance_rescale > 0.0:# Based on 3.4. in https://arxiv.org/pdf/2305.08891.pdfnoise_pred = rescale_noise_cfg(noise_pred, noise_pred_text, guidance_rescale=guidance_rescale)# compute the previous noisy sample x_t -> x_t-1latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs, return_dict=False)[0]# call the callback, if providedif i == len(timesteps) - 1 or ((i + 1) > num_warmup_steps and (i + 1) % self.scheduler.order == 0):progress_bar.update()if callback is not None and i % callback_steps == 0:callback(i, t, latents)# make sure the VAE is in float32 mode, as it overflows in float16if self.vae.dtype == torch.float16 and self.vae.config.force_upcast:397 unmodified lines398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447397 unmodified lines# 11. Denoising loopnum_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler.orderfor i, t in enumerate(timesteps):latent_model_input = (torch.cat([latents] * 2) if do_classifier_free_guidance else latents)latent_model_input = self.scheduler.scale_model_input(latent_model_input, t)if i <= start_merge_step:current_prompt_embeds = torch.cat([negative_prompt_embeds, prompt_embeds_text_only], dim=0)add_text_embeds = torch.cat([negative_pooled_prompt_embeds, pooled_prompt_embeds_text_only], dim=0)else:current_prompt_embeds = torch.cat([negative_prompt_embeds, prompt_embeds], dim=0)add_text_embeds = torch.cat([negative_pooled_prompt_embeds, pooled_prompt_embeds], dim=0)# predict the noise residualadded_cond_kwargs = {"text_embeds": add_text_embeds, "time_ids": add_time_ids}noise_pred = self.unet(latent_model_input,t,encoder_hidden_states=current_prompt_embeds,cross_attention_kwargs=cross_attention_kwargs,added_cond_kwargs=added_cond_kwargs,return_dict=False,)[0]# perform guidanceif do_classifier_free_guidance:noise_pred_uncond, noise_pred_text = noise_pred.chunk(2)noise_pred = noise_pred_uncond + guidance_scale * (noise_pred_text - noise_pred_uncond)if do_classifier_free_guidance and guidance_rescale > 0.0:# Based on 3.4. in https://arxiv.org/pdf/2305.08891.pdfnoise_pred = rescale_noise_cfg(noise_pred, noise_pred_text, guidance_rescale=guidance_rescale)# compute the previous noisy sample x_t -> x_t-1latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs, return_dict=False)[0]# call the callback, if providedif i == len(timesteps) - 1 or ((i + 1) > num_warmup_steps and (i + 1) % self.scheduler.order == 0):if callback is not None and i % callback_steps == 0:callback(i, t, latents)# make sure the VAE is in float32 mode, as it overflows in float16if self.vae.dtype == torch.float16 and self.vae.config.force_upcast:
pipeline.py+43-44