Uh oh!
There was an error while loading. Please reload this page.
[Modular] implement requirements validation for custom blocks - #12196
Conversation
HuggingFaceDocBuilderDev
commented
Aug 20, 2025
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. |
sayakpaul
commented
Aug 29, 2025
@DN6 a gentle ping :) |
sayakpaul
commented
Sep 12, 2025
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? |
sayakpaul
commented
Oct 22, 2025
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? classGeminiPromptExpander:
_requirements= {
"google-generativeai": ">=0.8.0",
"pillow": ">=10.0.0"
}
classFluxTransformer:
_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 |
sayakpaul
commented
Oct 22, 2025
@yiyixuxu yes that makes sense. I will apply those changes in the PR. |
sayakpaul
commented
Oct 27, 2025
@yiyixuxu I have implemented what we discussed above. Individual fromdiffusers.modular_pipelinesimportSequentialPipelineBlocksclassGeminiPromptExpander:
_requirements= {
"google-generativeai": ">=0.8.0",
"pillow": ">=10.0.0"
}
classFluxTransformer:
_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. |
Uh oh!
There was an error while loading. Please reload this page.
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. |
sayakpaul
commented
Feb 16, 2026
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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
sayakpaul
commented
Feb 17, 2026
@DN6 I have updated the |
yiyixuxu
left a comment
There was a problem hiding this comment.
thanks for working on this!
| ) | ||
| @property | ||
| def _requirements(self) -> dict[str, str]: |
There was a problem hiding this comment.
should we add the same _requirements property to ConditionalPipelineBlocks & others?
right now, unless it's all SequentialPipelineBlocks, the nested requirements get lost, no?
block_a (conditional) ---------------------> block_b -block_a.1 -block_a.2
block_a's subblock requirement will be lost
the algo might be a bit aggresive for conditional blocks (we'd collect from all branches even though the user may only want to run one), but since this is warn-only I think that's fine
In practice, I think we'd recommend people override _requirements directly on their final block class rather than relying on the auto-accumulation, but good to have a default and have this meta data
Uh oh!
There was an error while loading. Please reload this page.
…gface#12196) * feat: implement requirements validation for custom blocks. * up * unify. * up * add tests * Apply suggestions from code review Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com> * reviewer feedback. * [docs] validation for custom blocks (huggingface#13156) validation * move to tmp_path fixture. * propagate to conditional and loopsequential blocks. * up * remove collected tests --------- Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com> Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
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.