ovi054 commited on
Commit
8105df3
·
verified ·
1 Parent(s): 995bef5

Update live_preview_helpers.py

Browse files
Files changed (1) hide show
  1. live_preview_helpers.py +23 -26
live_preview_helpers.py CHANGED
@@ -131,34 +131,31 @@ def flux_pipe_call_that_returns_an_iterable_of_images(
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
- # FIX: The `para_attn` library requires wrapping the inference loop in a `cache_scope`
135
- # context manager. This manager is attached to the pipeline (`self`) by `apply_cache_on_pipe`.
136
- with self.cache_scope(0, num_inference_steps):
137
- for i, t in enumerate(timesteps):
138
- if self.interrupt:
139
- continue
140
 
141
- timestep = t.expand(latents.shape[0]).to(latents.dtype)
142
 
143
- noise_pred = self.transformer(
144
- hidden_states=latents,
145
- timestep=timestep / 1000,
146
- guidance=guidance,
147
- pooled_projections=pooled_prompt_embeds,
148
- encoder_hidden_states=prompt_embeds,
149
- txt_ids=text_ids,
150
- img_ids=latent_image_ids,
151
- joint_attention_kwargs=self.joint_attention_kwargs,
152
- return_dict=False,
153
- )[0]
154
- # Yield intermediate result
155
- latents_for_image = self._unpack_latents(latents, height, width, self.vae_scale_factor)
156
- latents_for_image = (latents_for_image / self.vae.config.scaling_factor) + self.vae.config.shift_factor
157
- image = self.vae.decode(latents_for_image, return_dict=False)[0]
158
- yield self.image_processor.postprocess(image, output_type=output_type)[0]
159
-
160
- latents = self.scheduler.step(noise_pred, t, latents, return_dict=False)[0]
161
- torch.cuda.empty_cache()
162
 
163
  # Final image using good_vae
164
  latents = self._unpack_latents(latents, height, width, 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)