poipiii
commited on
Commit
•
662dbef
1
Parent(s):
b00902f
test in latnent upcale
Browse files- pipeline.py +15 -7
pipeline.py
CHANGED
@@ -848,13 +848,13 @@ class StableDiffusionLongPromptWeightingPipeline(StableDiffusionPipeline):
|
|
848 |
print("after first step denoise latents")
|
849 |
# print(latents)
|
850 |
print(latents.shape)
|
851 |
-
|
852 |
latents, size=(int(height*resize_scale)//8, int(width*resize_scale)//8))
|
853 |
|
854 |
for i, t in enumerate(self.progress_bar(timesteps)):
|
855 |
# expand the latents if we are doing classifier free guidance
|
856 |
latent_model_input = torch.cat(
|
857 |
-
[
|
858 |
print("latent_model_input 2nd step")
|
859 |
# print(latent_model_input)
|
860 |
print(latent_model_input.shape)
|
@@ -864,6 +864,10 @@ class StableDiffusionLongPromptWeightingPipeline(StableDiffusionPipeline):
|
|
864 |
|
865 |
latent_model_input = self.scheduler.scale_model_input(
|
866 |
latent_model_input, t)
|
|
|
|
|
|
|
|
|
867 |
print("latent_model_input after scheduler")
|
868 |
# print(latent_model_input)
|
869 |
print(latent_model_input.shape)
|
@@ -879,26 +883,30 @@ class StableDiffusionLongPromptWeightingPipeline(StableDiffusionPipeline):
|
|
879 |
noise_pred = noise_pred_uncond + guidance_scale * \
|
880 |
(noise_pred_text - noise_pred_uncond)
|
881 |
|
|
|
882 |
# compute the previous noisy sample x_t -> x_t-1
|
883 |
-
|
884 |
-
noise_pred, t,
|
885 |
|
|
|
|
|
886 |
if mask is not None:
|
887 |
# masking
|
888 |
init_latents_proper = self.scheduler.add_noise(
|
889 |
init_latents_orig, noise, torch.tensor([t]))
|
890 |
-
|
|
|
891 |
|
892 |
# call the callback, if provided
|
893 |
if i % callback_steps == 0:
|
894 |
if callback is not None:
|
895 |
-
callback(i, t,
|
896 |
if is_cancelled_callback is not None and is_cancelled_callback():
|
897 |
return None
|
898 |
#do latent upscale here
|
899 |
|
900 |
# 9. Post-processing
|
901 |
-
image = self.decode_latents(
|
902 |
|
903 |
|
904 |
# 10. Run safety checker
|
|
|
848 |
print("after first step denoise latents")
|
849 |
# print(latents)
|
850 |
print(latents.shape)
|
851 |
+
upscale_latents = torch.nn.functional.interpolate(
|
852 |
latents, size=(int(height*resize_scale)//8, int(width*resize_scale)//8))
|
853 |
|
854 |
for i, t in enumerate(self.progress_bar(timesteps)):
|
855 |
# expand the latents if we are doing classifier free guidance
|
856 |
latent_model_input = torch.cat(
|
857 |
+
[upscale_latents] * 2) if do_classifier_free_guidance else upscale_latents
|
858 |
print("latent_model_input 2nd step")
|
859 |
# print(latent_model_input)
|
860 |
print(latent_model_input.shape)
|
|
|
864 |
|
865 |
latent_model_input = self.scheduler.scale_model_input(
|
866 |
latent_model_input, t)
|
867 |
+
|
868 |
+
|
869 |
+
|
870 |
+
|
871 |
print("latent_model_input after scheduler")
|
872 |
# print(latent_model_input)
|
873 |
print(latent_model_input.shape)
|
|
|
883 |
noise_pred = noise_pred_uncond + guidance_scale * \
|
884 |
(noise_pred_text - noise_pred_uncond)
|
885 |
|
886 |
+
print("compute the previous noisy sample")
|
887 |
# compute the previous noisy sample x_t -> x_t-1
|
888 |
+
upscale_latents = self.scheduler.step(
|
889 |
+
noise_pred, t, upscale_latents, **extra_step_kwargs).prev_sample
|
890 |
|
891 |
+
|
892 |
+
print("compute mask")
|
893 |
if mask is not None:
|
894 |
# masking
|
895 |
init_latents_proper = self.scheduler.add_noise(
|
896 |
init_latents_orig, noise, torch.tensor([t]))
|
897 |
+
upscale_latents = (init_latents_proper *
|
898 |
+
mask) + (latents * (1 - mask))
|
899 |
|
900 |
# call the callback, if provided
|
901 |
if i % callback_steps == 0:
|
902 |
if callback is not None:
|
903 |
+
callback(i, t, upscale_latents)
|
904 |
if is_cancelled_callback is not None and is_cancelled_callback():
|
905 |
return None
|
906 |
#do latent upscale here
|
907 |
|
908 |
# 9. Post-processing
|
909 |
+
image = self.decode_latents(upscale_latents)
|
910 |
|
911 |
|
912 |
# 10. Run safety checker
|