[Modular] implement requirements validation for custom blocks#12196
[Modular] implement requirements validation for custom blocks#12196
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. |
|
@DN6 a gentle ping :) |
|
Gentle ping @DN6 |
|
ummm, should requirements be defined at the pipeline level instead of the block level? the person who put together the pipeline should be responsible and have the final say over the final components, e.g requirements and modular_model_index.json etc, no? |
|
I think implementing it at both the block and pipeline levels could be nice. What I am thinking:
WDYT about this approach? 👀 |
|
for blocks, maybe define requirements within the block definition similar to inputs/outputs? class GeminiPromptExpander:
_requirements = {
"google-generativeai": ">=0.8.0",
"pillow": ">=10.0.0"
}
class FluxTransformer:
_requirements = {
"transformers": ">=4.44.0",
"sentencepiece": ">=0.2.0"
}When we combine them: pipe = SequentialPipelineBlocks.from_blocks_dict({
"prompt_expander": GeminiPromptExpander,
"transformer": FluxTransformer
})
print(pipe._requirements)
# Output:
# {
# "prompt_expander": {"google-generativeai": ">=0.8.0", "pillow": ">=10.0.0"},
# "transformer": {"transformers": ">=4.44.0", "sentencepiece": ">=0.2.0"}
# }This should be just meta data thought, it just helps generate the final requirements.txt, but the pipeline author still need to manually write the requirement file and test it |
|
@yiyixuxu yes that makes sense. I will apply those changes in the PR. |
|
@yiyixuxu I have implemented what we discussed above. Individual from diffusers.modular_pipelines import SequentialPipelineBlocks
class GeminiPromptExpander:
_requirements = {
"google-generativeai": ">=0.8.0",
"pillow": ">=10.0.0"
}
class FluxTransformer:
_requirements = {
"transformers": ">=4.44.0",
"sentencepiece": ">=0.2.0"
}
pipe = SequentialPipelineBlocks.from_blocks_dict({
"prompt_expander": GeminiPromptExpander,
"transformer": FluxTransformer
})
print(pipe._requirements)
pipe.save_pretrained(".")LMK. |
|
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. Please note that issues that do not follow the contributing guidelines are likely to be ignored. |
|
Also cc: @stevhliu. Could you help with the docs for this? |
DN6
left a comment
There was a problem hiding this comment.
All good with saving requirements to the config file.
But since requirements are metadata, I don't think we need to run extensive normalization and validation. We already warn users of missing packages when trying to load custom code.
diffusers/src/diffusers/utils/dynamic_modules_utils.py
Lines 153 to 156 in 35086ac
Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
|
@DN6 I have updated the |
What does this PR do?
As discussed with Dhruv.
When implementing custom blocks (which we all believe will grow big :)), it can be useful for the block author and the users to have some kind of dependencies and their versions specified. This PR implements that feature.
Sample output: https://huggingface.co/diffusers-internal-dev/gemini-prompt-expander/blob/main/modular_config.json.