-
Notifications
You must be signed in to change notification settings - Fork 6.1k
[Modular] More Updates for Custom Code Loading #11969
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?
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. |
I see, do you think maybe we should drop the concept difference between "inputs" and "intermediate inputs" algether? all inputs could be just "intermediates", and they can all be modified. https://huggingface.co/docs/diffusers/main/en/modular_diffusers/modular_diffusers_states Taking the example of If we do this for We need to be a little bit more mindful in modifying variables, and recommend to always use a new variable name, or not add to block_state, unless it's intended to replace e.g. if a downstream block needs to use a block like this would mean that it would not be able to access the raw image before the process def __call__(...):
...
block_state.image = process(block_state.image)
block_state.image_latent = prepare_latents(block_state.image)
... but, this might be fine (depends on if def __call__(...):
...
image = process(block_state.image)
block_state.image_latent = prepare_latents(block_state.image)
... On the other hand, the system would be more flexible, and also it simplifies a bit conceptually (I found it not easy to explain the difference between these two states) Let me know what you think! |
IMO this makes sense since we more or less put them into the same group when fetching the block state and they are accessed in the block in the same way. I can't think of any edge cases where this might lead to issues.
We could do this, but suppose you want to insert a custom block that manipulates an input value into a set of existing blocks. You would have to update all subsequent blocks to point to the intermediate input. def __call__(...):
...
image = process(block_state.image)
block_state.image_latent = prepare_latents(block_state.image)
... I think this works well as best practice if we want to leave the input unchanged. IMO the less restrictive we are the better since there isn't a very strong reason to keep the input types separated? |
@@ -322,7 +322,7 @@ class ModularPipelineBlocks(ConfigMixin, PushToHubMixin): | |||
</Tip> | |||
""" | |||
|
|||
config_name = "config.json" | |||
config_name = "modular_config.json" |
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.
For consistency with modular_model_index.json
. Also could be cases where a repo contains model weights/config file and a modular pipeline block to load the model. We can avoid conflicts with the configs this way.
Sounds good! let's do this then! I think it will simplify the code a lot. Basically now we'll just have |
Another thing is: should we remove the concept of single |
@yiyixuxu
Then you can review and refactor as you see fit? |
@DN6 sounds good! |
What does this PR do?
In order to support custom code for any block type, we have to invoke downloading/loading of custom code from the
ModularPipelineBlocks
object. This means some of the properties/methods defined in PipelineBlock, SequentialPipelineBlock etc have to be moved into theModularPipelineBlocks
class.Additionally, included a potential change to consolidate how the block state is created from inputs and intermediate inputs. The change is necessary to support the case where a pipeline input might be created in an intermediate step e.g. Using a segmentation model to create an inpainting mask. With the existing approach, simply setting the output of the mask creation step to the desired input value
mask_image
wouldn't allow downstream steps to access it in the block state, becauseget_block_state
runs over required inputs first, and errors out because it's missing. Propose changing this to checking for required values in both input and intermediates before erroring out. There could be edge cases here that I might be missing, but it seems safe to consolidate in this way.Code to test
Fixes # (issue)
Before submitting
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.