Spaces:
Running
on
Zero
Running
on
Zero
Update live_preview_helpers.py
Browse files- live_preview_helpers.py +23 -32
live_preview_helpers.py
CHANGED
|
@@ -60,7 +60,6 @@ def flux_pipe_call_that_returns_an_iterable_of_images(
|
|
| 60 |
joint_attention_kwargs: Optional[Dict[str, Any]] = None,
|
| 61 |
max_sequence_length: int = 512,
|
| 62 |
good_vae: Optional[Any] = None,
|
| 63 |
-
cache_scope: Optional[Any] = None,
|
| 64 |
):
|
| 65 |
height = height or self.default_sample_size * self.vae_scale_factor
|
| 66 |
width = width or self.default_sample_size * self.vae_scale_factor
|
|
@@ -132,39 +131,31 @@ def flux_pipe_call_that_returns_an_iterable_of_images(
|
|
| 132 |
guidance = torch.full([1], guidance_scale, device=device, dtype=torch.float32).expand(latents.shape[0]) if self.transformer.config.guidance_embeds else None
|
| 133 |
|
| 134 |
# 6. Denoising loop
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
if self.interrupt:
|
| 139 |
-
continue
|
| 140 |
|
| 141 |
-
|
| 142 |
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
if cache_scope:
|
| 164 |
-
with cache_scope:
|
| 165 |
-
yield from denoise_loop_generator()
|
| 166 |
-
else:
|
| 167 |
-
yield from denoise_loop_generator()
|
| 168 |
|
| 169 |
# Final image using good_vae
|
| 170 |
latents = self._unpack_latents(latents, height, width, self.vae_scale_factor)
|
|
|
|
| 60 |
joint_attention_kwargs: Optional[Dict[str, Any]] = None,
|
| 61 |
max_sequence_length: int = 512,
|
| 62 |
good_vae: Optional[Any] = None,
|
|
|
|
| 63 |
):
|
| 64 |
height = height or self.default_sample_size * self.vae_scale_factor
|
| 65 |
width = width or self.default_sample_size * self.vae_scale_factor
|
|
|
|
| 131 |
guidance = torch.full([1], guidance_scale, device=device, dtype=torch.float32).expand(latents.shape[0]) if self.transformer.config.guidance_embeds else None
|
| 132 |
|
| 133 |
# 6. Denoising loop
|
| 134 |
+
for i, t in enumerate(timesteps):
|
| 135 |
+
if self.interrupt:
|
| 136 |
+
continue
|
|
|
|
|
|
|
| 137 |
|
| 138 |
+
timestep = t.expand(latents.shape[0]).to(latents.dtype)
|
| 139 |
|
| 140 |
+
noise_pred = self.transformer(
|
| 141 |
+
hidden_states=latents,
|
| 142 |
+
timestep=timestep / 1000,
|
| 143 |
+
guidance=guidance,
|
| 144 |
+
pooled_projections=pooled_prompt_embeds,
|
| 145 |
+
encoder_hidden_states=prompt_embeds,
|
| 146 |
+
txt_ids=text_ids,
|
| 147 |
+
img_ids=latent_image_ids,
|
| 148 |
+
joint_attention_kwargs=self.joint_attention_kwargs,
|
| 149 |
+
return_dict=False,
|
| 150 |
+
)[0]
|
| 151 |
+
# Yield intermediate result
|
| 152 |
+
latents_for_image = self._unpack_latents(latents, height, width, self.vae_scale_factor)
|
| 153 |
+
latents_for_image = (latents_for_image / self.vae.config.scaling_factor) + self.vae.config.shift_factor
|
| 154 |
+
image = self.vae.decode(latents_for_image, return_dict=False)[0]
|
| 155 |
+
yield self.image_processor.postprocess(image, output_type=output_type)[0]
|
| 156 |
+
|
| 157 |
+
latents = self.scheduler.step(noise_pred, t, latents, return_dict=False)[0]
|
| 158 |
+
torch.cuda.empty_cache()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
# Final image using good_vae
|
| 161 |
latents = self._unpack_latents(latents, height, width, self.vae_scale_factor)
|