Support passthrough/skipping nodes #2805
Merged
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.
Fixes #373.
I had to change a lot of stuff, because passthrough affects not only how chains are executed, but also the type state and visuals of the chain.
The UI
I changed the disable toggle to be an icon that opens a popover. It now only displays the current state of the node (enabled, disabled, skipped) and has a tooltip explaining the current state.
When a node is skipped, all inputs that are not mapped to outputs will be faded out. This makes it easy to see that those inputs do not have an effect anymore. This is consistent with how disabling a node makes the whole node transparent.
How inputs are mapped to outputs
To skip a node, we need to know how to rewire inputs to outputs. This is done is 2 ways:
This allows us to correct the automatic mapping if it doesn't work for a particular node (which should be very rare). The manual mapping is done with
Output().as_passthrough_of(input_id)
.I added a new
shape_as=input_id
property toImageOutput
. This new property has 3 functions: (1) it will set the output type to the shape of the given input image, (2) it will make this output a passthrough for the input, and (3) it will be used to check the shape of the returned image (not implemented yet). This means that we already have quite a few nodes that manually set the mapping, which is good.The automatic method works almost exactly as proposed by @theflyingzamboni in #373. The only differences are that I handle a few more edge cases and that I always pick the first input (regardless of whether if there are other possible mappings). See the
PassthroughMap
class for details.How passthrough is implemented
I implemented passthrough as a frontend optimization. So the backend has no concept of passthrough except for manual mappings. It's implemented alongside the other optimizations (e.g. removing disabled nodes) and works by simply rewiring edges.
From
To
The optimization for removing unused nodes without side effects will then take care of removing skipped nodes. Since we only remove one level of skipped nodes per optimization, I changed the optimizer to perform multiple passes. This will correctly remove chains of skipped nodes.