Spaces:
Running
on
Zero
Running
on
Zero
Update custom_pipeline.py
Browse files- custom_pipeline.py +19 -15
custom_pipeline.py
CHANGED
@@ -66,6 +66,7 @@ class FluxWithCFGPipeline(FluxPipeline):
|
|
66 |
return_dict: bool = True,
|
67 |
joint_attention_kwargs: Optional[Dict[str, Any]] = None,
|
68 |
max_sequence_length: int = 300,
|
|
|
69 |
):
|
70 |
"""Generates images and yields intermediate results during the denoising process."""
|
71 |
height = height or self.default_sample_size * self.vae_scale_factor
|
@@ -138,21 +139,24 @@ class FluxWithCFGPipeline(FluxPipeline):
|
|
138 |
|
139 |
timestep = t.expand(latents.shape[0]).to(latents.dtype)
|
140 |
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
|
|
|
|
|
|
156 |
|
157 |
# Final image
|
158 |
return self._decode_latents_to_image(latents, height, width, output_type)
|
|
|
66 |
return_dict: bool = True,
|
67 |
joint_attention_kwargs: Optional[Dict[str, Any]] = None,
|
68 |
max_sequence_length: int = 300,
|
69 |
+
generate_with_graph = None
|
70 |
):
|
71 |
"""Generates images and yields intermediate results during the denoising process."""
|
72 |
height = height or self.default_sample_size * self.vae_scale_factor
|
|
|
139 |
|
140 |
timestep = t.expand(latents.shape[0]).to(latents.dtype)
|
141 |
|
142 |
+
if generate_with_graph:
|
143 |
+
return generate_with_graph(latents, prompt_embeds, pooled_prompt_embeds, text_ids, latent_image_ids, timestep)
|
144 |
+
else:
|
145 |
+
noise_pred = self.transformer(
|
146 |
+
hidden_states=latents,
|
147 |
+
timestep=timestep / 1000,
|
148 |
+
guidance=guidance,
|
149 |
+
pooled_projections=pooled_prompt_embeds,
|
150 |
+
encoder_hidden_states=prompt_embeds,
|
151 |
+
txt_ids=text_ids,
|
152 |
+
img_ids=latent_image_ids,
|
153 |
+
joint_attention_kwargs=self.joint_attention_kwargs,
|
154 |
+
return_dict=False,
|
155 |
+
)[0]
|
156 |
+
|
157 |
+
# Yield intermediate result
|
158 |
+
latents = self.scheduler.step(noise_pred, t, latents, return_dict=False)[0]
|
159 |
+
torch.cuda.empty_cache()
|
160 |
|
161 |
# Final image
|
162 |
return self._decode_latents_to_image(latents, height, width, output_type)
|