Ryukijano commited on
Commit
1b66a10
·
verified ·
1 Parent(s): 7c212f5

Update custom_pipeline.py

Browse files
Files changed (1) hide show
  1. 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
- noise_pred = self.transformer(
142
- hidden_states=latents,
143
- timestep=timestep / 1000,
144
- guidance=guidance,
145
- pooled_projections=pooled_prompt_embeds,
146
- encoder_hidden_states=prompt_embeds,
147
- txt_ids=text_ids,
148
- img_ids=latent_image_ids,
149
- joint_attention_kwargs=self.joint_attention_kwargs,
150
- return_dict=False,
151
- )[0]
152
-
153
- # Yield intermediate result
154
- latents = self.scheduler.step(noise_pred, t, latents, return_dict=False)[0]
155
- torch.cuda.empty_cache()
 
 
 
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)