Repository navigation
[modular] fill a missing input from the first block that reads it, keep a passed None #15135
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
Open
yiyixuxu
wants to merge
3
commits into
main
Choose a base branch
from
conditional-runtime-defaults
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+78
−12
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -588,13 +588,12 @@ def get_block_state(self, state: PipelineState) -> dict: | |
| # Check inputs | ||
| for input_param in state_inputs: | ||
| if input_param.name: | ||
| value = state.get(input_param.name) | ||
| if value is None: | ||
| # if the value is None (not passed, or passed as None), the first block that reads it sets the | ||
| # default at call time. For sequential blocks the default is already resolved at compile time | ||
| # (first declaring block wins, see _get_inputs), but for conditional blocks the selected branch | ||
| # is only known at runtime: disagreeing branch defaults merge to None (see combine_inputs) and | ||
| # the block that actually runs applies its own declared default here | ||
| if input_param.name in state.values: | ||
| # a value in the state, None included, is what the user passed or an earlier block set | ||
| value = state.get(input_param.name) | ||
| else: | ||
| # the first block that reads an input fills in its own default; `set_block_state` records it so | ||
| # the blocks after it read the same value | ||
| value = input_param.default | ||
| if input_param.required and value is None: | ||
| raise ValueError(f"Required input '{input_param.name}' is missing") | ||
|
|
@@ -624,9 +623,10 @@ def set_block_state(self, state: PipelineState, block_state: BlockState): | |
| for input_param in self.inputs: | ||
| if input_param.name and hasattr(block_state, input_param.name): | ||
| param = getattr(block_state, input_param.name) | ||
| # Only add if the value is different from what's in the state | ||
| # Only add if the value is different from what's in the state, or the state did not hold it yet (the | ||
| # default this block filled in, see `get_block_state`) | ||
|
Comment on lines
+626
to
+627
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we also supplement this with an example? Just makes reading the code a bit easier. |
||
| current_value = state.get(input_param.name) | ||
| if current_value is not param: # Using identity comparison to check if object was modified | ||
| if input_param.name not in state.values or current_value is not param: # identity: object modified? | ||
| state.set(input_param.name, param, input_param.kwargs_type) | ||
|
|
||
| elif input_param.kwargs_type: | ||
|
|
@@ -3006,6 +3006,9 @@ def __call__(self, state: PipelineState = None, output: str | list[str] = None, | |
|
|
||
| # Add inputs to state, using defaults if not provided in the kwargs or the state | ||
| # if same input already in the state, will override it if provided in the kwargs | ||
| # a None passed by the user is stored as None. A None default is not prefilled: the first block that reads | ||
| # the input fills in its own default and records it, see `get_block_state` and `set_block_state`. That is how | ||
| # a conditional branch gets its own default (`defaults_by_block`) | ||
| for expected_input_param in self._blocks.inputs: | ||
| name = expected_input_param.name | ||
| default = expected_input_param.default | ||
|
|
@@ -3016,7 +3019,7 @@ def __call__(self, state: PipelineState = None, output: str | list[str] = None, | |
| kwargs_dict = passed_kwargs.pop(kwargs_type) | ||
| for k, v in kwargs_dict.items(): | ||
| state.set(k, v, kwargs_type) | ||
| elif name is not None and name not in state.values: | ||
| elif name is not None and name not in state.values and default is not None: | ||
| state.set(name, default, kwargs_type) | ||
|
|
||
| # Warn about unexpected inputs | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Ah!