[LatentFlow] Simplifying Complex Pipelines with a Functional API #6508
Replies: 4 comments 5 replies
-
ComfyUI like node system but with code? I'm all for using this in my workflows ❤️ Very nice approach that provides far more control to power users without the need for copying large amounts of code to customize a pipeline to your needs (which is what most of us do I think). I have been wanting to work on something similar for a while too, but more related to different denosing backends (attend-and-excite, self-attention-guidance, sd-safe, etc.), something like: pipe.set_denoise_backend(DenoisingBackend.SAG) It would also make it easier to add newer features like FreeU or FreeInit or StyleAligned or whatever accessible across all pipelines/tasks because State() can handle it all behind the scenes. From the user end, it would be as simple as adding an additional line (as you demonstrate above, I personally prefer the style of sklearn-like composite pipelines, but using the proposed syntax would make me feel 10x smarter instantly 😆 Great share! |
Beta Was this translation helpful? Give feedback.
-
Thank you for initiating this discussion.
One of the reasons why we don't want to introduce too many abstractions. We manage the copy mechanism by using "# Copied from ..." statements. The Other popular features are enabled with Also note that we support pipeline chaining seamlessly: https://huggingface.co/docs/diffusers/main/en/using-diffusers/img2img#chained-image-to-image-pipelines. We also expose more explicit control over the most important components inside a pipeline via a callback mechanism: https://huggingface.co/docs/diffusers/main/en/using-diffusers/callback. |
Beta Was this translation helpful? Give feedback.
-
Hello everybody! I've just added support for ComfyUI nodes in my import sys
sys.path.insert(0, f'/path/to/latentflow/src')
sys.path.insert(0, f'/path/to/ComfyUI')
import latentflow as lf
import nodes
import torch
state = lf.State({})
(lf.ComfyNode(nodes.CheckpointLoaderSimple, ckpt_name='revanimated.safetensors').apply()
| lf.Set(state, "checkpoint")
| lf.ComfyNode(nodes.EmptyLatentImage, width=512, height=512, batch_size=1)
| lf.ComfyNode(
nodes.KSampler,
model=state['checkpoint']['MODEL'],
positive=lf.ComfyNode(nodes.CLIPTextEncode, text="a cat", clip=state["checkpoint"]["CLIP"]).apply(),
negative=lf.ComfyNode(nodes.CLIPTextEncode, text="", clip=state["checkpoint"]["CLIP"]).apply(),
)
| lf.ComfyNode(nodes.VAEDecode, vae=state['checkpoint']["VAE"])
| lf.Apply(lambda x: lf.Video('HWC', torch.stack([x['IMAGE']])))
| lf.VideoShow()
)
I would greatly appreciate your feedback. While it's in the early stages and lacks documentation, I've been extensively working with it for my own purposes. |
Beta Was this translation helpful? Give feedback.
-
Great work here @tumurzakov! I love how you have gone about the design. If there's a tweet or announcement, we would love to share it! |
Beta Was this translation helpful? Give feedback.
-
Hi everyone,
I've been delving into numerous pipelines in the Diffusers repository, and I've noticed a recurring pattern among them. Names like StableDiffusionPipeline, StableDiffusionInpaintPipeline, StableDiffusionControlNetPipeline, and even StableDiffusionDeathStarPipeline all seem to share the same code, repeatedly copy-pasted throughout these files.
In my exploration of AnimateDiff, I've encountered intricate challenges, particularly with multiple nested loops: FreeInit > Denoising Loop > WalkPrompt > RegionPrompt. The complexity of these nested structures has left me somewhat overwhelmed.
To address this, I've attempted to create a functional-style API for the Stable Diffusion pipeline. Below is an example of what I've come up with:
LatentFlow
|
is pipe (like unix pipe)>
write value in state (like in unix too)-
bypass for pipe<
bypass for write>>
go to next statementI'd love to hear your thoughts on this API. Additionally, if you have any ideas on how it could be further improved or refined, please feel free to share them.
Looking forward to your insights and feedback.
Beta Was this translation helpful? Give feedback.
All reactions