required
and optional
inputs are evaluated before a node can be run. Sometimes, however, an
input won’t necessarily be used and evaluating it would result in unnecessary processing. Here are some examples
of nodes where lazy evaluation may be beneficial:
ModelMergeSimple
node where the ratio is either 0.0
(in which case the first model doesn’t need to be loaded)
or 1.0
(in which case the second model doesn’t need to be loaded).0.0
or entirely 1.0
.INPUT_TYPES
check_lazy_status
(note: not a class method) that will be called prior to evaluation to determine if any more inputs are necessary.0.0
, we don’t need to evaluate any part of the tree leading up to the second image. If the entire mask is 1.0
, we can skip evaluating the first image.
INPUT_TYPES
lazy: True
key-value pair to the input’s options dictionary.
image1
and image2
are both marked as lazy inputs, but mask
will always be evaluated.
check_lazy_status
check_lazy_status
method is called if there are one or more lazy inputs that are not yet available. This method receives the same arguments as the standard execution function. All available inputs are passed in with their final values while unavailable lazy inputs have a value of None
.
The responsibility of the check_lazy_status
function is to return a list of the names of any lazy inputs that are needed to proceed. If all lazy inputs are available, the function should return an empty list.
Note that check_lazy_status
may be called multiple times. (For example, you might find after evaluating one lazy input that you need to evaluate another.)
OUTPUT
node that doesn’t implement lazy evaluation itself. If it’s an output node that you developed yourself, you should just add lazy evaluation as follows:
enabled
that defaults to True
lazy
inputsenabled
is True
comfy_execution.graph.ExecutionBlocker
. This special object can be returned as an output from any socket. Any nodes which receive an ExecutionBlocker
as input will skip execution and return that ExecutionBlocker
for any outputs.
ExecutionBlocker
None
into the constructor to silently block execution. This is useful for cases where blocking execution is part of a successful run — like disabling an output.VAE
output when loading a model that doesn’t contain VAEs.