Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
Fix compatibility scheduling for a nested If graph with a literal outer condition.
JPPhoto498cc8ccf703
diff --git a/invokeai/app/services/shared/graph_if_runtime.py b/invokeai/app/services/shared/graph_if_runtime.pyindex bcec70767d..0496f0d4bf 100644--- a/invokeai/app/services/shared/graph_if_runtime.py+++ b/invokeai/app/services/shared/graph_if_runtime.py@@ -6,7 +6,7 @@ from invokeai.app.invocations.logic import IfInvocationfrom invokeai.app.services.shared.execution_engine.primitives import ActivationGatefrom invokeai.app.services.shared.execution_engine.scheduler import ActivationDependencyfrom invokeai.app.services.shared.graph_models import Edge, ExecutionToken-from invokeai.app.services.shared.graph_validation import IterateInvocation+from invokeai.app.services.shared.graph_validation import ForInvocation, IterateInvocation, nxif TYPE_CHECKING:from invokeai.app.services.shared.graph import GraphExecutionState@@ -91,9 +91,14 @@ def _get_if_iteration_paths(paths: set[tuple[int, ...]] = set()has_selected_edges = False+ has_unresolved_selected_source = Falsefor condition_path, selected_field in condition_selections:selected_edges = state.graph._get_input_edges(node_id, selected_field)has_selected_edges = has_selected_edges or bool(selected_edges)+ has_unresolved_selected_source = has_unresolved_selected_source or any(+ edge.source.node_id not in state.source_prepared_mapping and edge.source.node_id not in state.executed+ for edge in selected_edges+ )if selected_edges:branch_paths = set().union(*(@@ -119,7 +124,17 @@ def _get_if_iteration_paths(paths.add(branch_path)if not paths:- return [] if has_selected_edges else [()]+ if not has_selected_edges:+ return [()]+ if not condition_edges and has_unresolved_selected_source:+ iterator_graph = state._iterator_graph(state._get_source_graph_flat())+ has_iterator_ancestor = any(+ isinstance(state.graph.get_node(ancestor_id), (ForInvocation, IterateInvocation))+ for ancestor_id in nx.ancestors(iterator_graph, node_id)+ )+ if not has_iterator_ancestor:+ return [()]+ return []return sorted(path for path in paths if not any(path != other and other[: len(path)] == path for other in paths))diff --git a/tests/test_graph_execution_state.py b/tests/test_graph_execution_state.pyindex fec0436673..c2fab0de9f 100644--- a/tests/test_graph_execution_state.py+++ b/tests/test_graph_execution_state.py@@ -3019,6 +3019,43 @@ def test_graph_static_nested_ifs_ignore_unselected_loop_branch_context():assert state.is_complete()+def test_nested_if_literal_condition_activates_selected_branch():+ """A literal outer If must activate the branch containing an inner If.++ The inner condition is only needed by the outer If's selected branch.+ Waiting for that condition to be prepared before activating the outer+ branch causes the compatibility scheduler to return None prematurely.+ """+ graph = Graph()+ graph.add_node(BooleanInvocation(id="inner_condition", value=False))+ graph.add_node(AddInvocation(id="inner_true", a=100, b=0))+ graph.add_node(AddInvocation(id="inner_false", a=2, b=3))+ graph.add_node(IfInvocation(id="inner_if"))+ graph.add_node(AddInvocation(id="outer_true", a=10, b=20))+ graph.add_node(IfInvocation(id="outer_if", condition=False))+ graph.add_node(AddInvocation(id="sink", b=1))++ graph.add_edge(create_edge("inner_condition", "value", "inner_if", "condition"))+ graph.add_edge(create_edge("inner_true", "value", "inner_if", "true_input"))+ graph.add_edge(create_edge("inner_false", "value", "inner_if", "false_input"))+ graph.add_edge(create_edge("inner_if", "value", "outer_if", "false_input"))+ graph.add_edge(create_edge("outer_true", "value", "outer_if", "true_input"))+ graph.add_edge(create_edge("outer_if", "value", "sink", "a"))++ state = GraphExecutionState(graph=graph)+ assert not state._can_use_fresh_flat_if_activation()++ executed_source_ids = execute_all_nodes(state)++ assert state.is_complete(), (+ "Scheduler returned no ready node with unfinished source nodes: "+ f"{sorted(set(graph.nodes) - state._completed_source_ids())}"+ )+ assert {"inner_if", "outer_if", "sink"} <= set(executed_source_ids)+ sink_exec_id = next(iter(state.source_prepared_mapping["sink"]))+ assert state.results[sink_exec_id].value == 6++def test_graph_for_final_state_materializes_after_last_direct_return():graph = Graph()graph.add_node(ForInvocation(id="for", collection=["alpha", "beta"]))