-
Notifications
You must be signed in to change notification settings - Fork 6.1k
The Modular Diffusers #9672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
The Modular Diffusers #9672
Conversation
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Very cool! |
… completely yet (look into later)
hi this is very interesting! I'm making a Python pipeline flow visual scripting tool, that can auto-convert functions to visual nodes for fast and modular UI blocks demo. Itself is a pip package: https://pypi.org/project/nozyio/ I wanted to integrate diffusers with my flow nodes UI project but found its not very modular. But this PR may change that! Looking forward to see how this evolves. github: https://github.com/oozzy77/nozyio happy to connect! |
@oozzy77 thanks! |
Hi super willing to join slack channel with you! What’s the workspace
channel I should join?or you can invite me ***@***.***
…On Thu, Oct 31, 2024 at 4:59 AM YiYi Xu ***@***.***> wrote:
@oozzy77 <https://github.com/oozzy77> thanks!
do you want to join a slack channel with me? if you want to experiment
building something with this PR I'm eager to hear your feedback and iterate
base on that
—
Reply to this email directly, view it on GitHub
<#9672 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BMBK3ZHNSKN56N262LBH3WLZ6FCBNAVCNFSM6AAAAABP5SYMXOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINBYGM3DQMBYGE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@oozzy77 I sent an invite! |
…into modular-diffusers
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DN6 @sayakpaul
I merged in this part of code without reviewing it (I need the save_pretrained()
code and it works fine)
can you let me know if you want to keep it in here when we merge this PR or remove &convert it into a new PR
|
||
GuiderType = Union[ | ||
AdaptiveProjectedGuidance, | ||
AutoGuidance, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@a-r-r-o-w can we make sure PAG has its own class before we merge?
@@ -154,33 +159,87 @@ def check_imports(filename): | |||
return get_relative_imports(filename) | |||
|
|||
|
|||
def get_class_in_module(class_name, module_path, pretrained_model_name_or_path=None): | |||
def _raise_timeout_error(signum, frame): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DN6 is there a test we can run for remote code? want to make sure we don't break anything here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no test yet. Can add one.
Super comprehensive and nice set of guides! 👏 Here is my feedback:
The docs would look something like this: - local: getting_started
title: Getting started
- local: modular_diffusers_states
title: Pipeline and block states
- local: pipeline_block
title: PipelineBlock
- local: sequential_pipeline_blocks
title: SequentialPipelineBlocks
- local: loop_sequential_pipeline_blocks
title: LoopSequentialPipelineBlocks
- local: auto_pipeline_blocks
title: AutoPipelineBlocks
- local: modular_pipeline
title: ModularPipeline |
@stevhliu So I think we can aim for something like this for the merge, what do you think? - local: modular_diffusers_states
title: Pipeline and block states
- local: pipeline_block
title: PipelineBlock
- local: sequential_pipeline_blocks
title: SequentialPipelineBlocks
- local: loop_sequential_pipeline_blocks
title: LoopSequentialPipelineBlocks
- local: auto_pipeline_blocks
title: AutoPipelineBlocks
- local: modular_pipeline
title: ModularPipeline
- local: end_to_end_guide
title: An End-to-End Example (from building custom pipeline to UI node deployment) # look for better names lol |
Sounds good to me, let me know how I can help! |
|
||
<Tip> | ||
|
||
💡 We recommend using `ModularPipeline` with Component Manager by passing a `components_manager`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would just have the description of the ComponentManager
before the code example.
|
||
```py | ||
>>> components = ComponentsManager() | ||
>>> pipeline = blocks.init_pipeline(modular_repo_id, components_manager=components) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if no component manager is set?
from diffusers import ComponentsManager | ||
# Set up component manager and turn on the offloading | ||
components = ComponentsManager() | ||
components.enable_auto_cpu_offload(device="cuda") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would auto offloading work here? No components have been loaded into it yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah it works, once the strategy is on it's on, you can add/remove models
(currently I just reset it everytime a model is added/removed, so basically all the models get moved to cpu and start over; but we can certainly do it more efficiently if there is a demand for that)
* update * fix * update
* update * update * register to config pag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for leading the charge here, @yiyixuxu! 15k LoC changes might seem a lot but I do believe that it's for the greater good!
My comments are mostly in the docs because I think even for reviewers, that should be the entrypoint to understanding the different moving parts involed in the modular design.
Additionally, I also reviewed the changes made to the existing core modules and all of them are okay to me.
Apart from that, I am quite interested to grow the offloading part in components manager as I believe that will be crucial for the UI-based workflows!
|
||
**Important**: It is important to always check the docstring because arguments can be different from standard pipelines that you're familar with. For example, in Modular Diffusers we standardized controlnet image input as `control_image`, but regular pipelines have inconsistencies over the names, e.g. controlnet text-to-image uses `image` while SDXL controlnet img2img uses `control_image`. | ||
|
||
**Note**: The `output` list might be longer than you expected - it includes everything in the intermediate state that you can choose to return. Most of the time, you'll just want `output="images"` or `output="latents"`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could show an example output?
```py | ||
t2i_pipeline.doc | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it need to be here?
|
||
**Components Manager**: Create one manager and pass it to `init_pipeline` along with a collection name. All models loaded by that pipeline will be added to the manager under that collection. | ||
|
||
**Auto Offloading**: All components are placed on CPU and only moved to device right before their forward pass. The manager monitors device memory and may move components off-device to make space for new ones. Unlike `DiffusionPipeline.enable_model_cpu_offload()`, this works across all components in the manager and all your workflows. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the component manager deserves its own section / page where we go deep into offloading, etc., and remove it from there.
I am also following what is meant by
Unlike
DiffusionPipeline.enable_model_cpu_offload()
, this works across all components in the manager and all your workflows.
If we do enable_model_cpu_offload()
it works on all the model-components of the underlying pipeline, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it works across pipelines, say like you have 10 pipelines share 15 models, it works across these 15 models
for model_name, pipeline in task_mapping.items(): | ||
if pipeline.__name__ == pipeline_class_name: | ||
return model_name | ||
def _get_model(pipeline_class_name): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am guessing this is just refactoring?
* update * make style
Co-authored-by: Sayak Paul <[email protected]>
TO-DOs before merge
guider
on its ownPipelineBlock
; and how to assembleSequentialPipelineBlocks
andAutoPipelineBlocks
TO-DOs
ConfigMixin
ModularPipelineBlocks.from_pretrained
needs to work with official blocksModularLoader
intoModularPipeline
Documentations