Skip to content

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.

Remove dead If activation compiler

JPPhoto104282976598
diff --git a/docs/src/content/docs/contributing/loop-nodes.md b/docs/src/content/docs/contributing/loop-nodes.md
index af4f398f47..aa580cd65d 100644
--- a/docs/src/content/docs/contributing/loop-nodes.md
+++ b/docs/src/content/docs/contributing/loop-nodes.md
@@ -157,8 +157,8 @@ valid. A loaded terminal legacy state may retain its empty in-memory ledger for
`IfInvocation` now declares the same seam for branch activation: it emits one frame-scoped activation token for the
selected branch, and the graph state validates and persists it after invocation. For a fresh generic `If`, the dedicated
-`_IfActivationController` owns opaque, frame-local activation dependencies; the legacy `_IfActivationCompiler`
-remains only as a compatibility lowering helper for old snapshots. Fresh materialization prepares the condition boundary,
+`_IfActivationController` is the sole runtime dependency owner for opaque, frame-local activation dependencies. Legacy
+skipped-state projection remains only for old snapshots. Fresh materialization prepares the condition boundary,
resolves the activation token, and attaches only the selected branch input; unselected branch nodes remain unprepared.
The generic and compatibility adapters consume the same decisions and append-only execution edges; no type-specific
branch scheduler prunes edges or propagates skips. Legacy skipped-state metadata remains only for snapshots that already
diff --git a/invokeai/app/services/shared/README.md b/invokeai/app/services/shared/README.md
index b1eaa6df34..77ef06958d 100644
--- a/invokeai/app/services/shared/README.md
+++ b/invokeai/app/services/shared/README.md
@@ -9,8 +9,8 @@ iterator patterns, tracks readiness via indegree (the number of incoming edges t
executes nodes from class-grouped ready queues. In normal execution, runtime expansion happens in a separate execution graph
instead of mutating the source graph. Ordinary static DAGs and legacy-shaped `If` graphs use the opaque `ExecutionPlan`
and deterministic `ExecutionScheduler` in `execution_engine/scheduler.py`. For a fresh generic `If`, the dedicated
-`_IfActivationController` owns fresh `If` admission and produces opaque, frame-local activation dependencies; the legacy
-`_IfActivationCompiler` remains only as a compatibility lowering helper for old snapshots. Fresh `If` materialization
+`_IfActivationController` is the sole runtime dependency owner for `If` admission and produces opaque, frame-local
+activation dependencies. Legacy skipped-state projection remains only for old snapshots. Fresh `If` materialization
prepares the condition boundary first, resolves the activation token, and attaches only the selected branch input.
Unselected branch nodes are never prepared, skipped, or added to fresh execution history. Both scheduler adapters
consume the controller's decisions without pruning execution edges or calling a type-specific branch scheduler.
@@ -237,8 +237,8 @@ rehydration, every activation token is bound to a currently prepared owner and i
declared port, value, canonical token id, mapping key, and known frame fields must match. Unknown extra frame metadata
remains forward-compatible.
For a fresh generic `If`, `_IfActivationController` puts opaque, frame-local activation-dependency records on each
-branch-local plan node. The controller derives branch membership from the current author graph, but the schedulers no
-longer call the legacy compiler. Fresh materialization prepares the condition boundary, resolves the activation token,
+branch-local plan node. The controller is the sole runtime dependency owner; the schedulers no longer call a legacy
+compiler. Fresh materialization prepares the condition boundary, resolves the activation token,
and attaches only the selected branch input; rejected branch sources remain unprepared. `_GenericGraphSchedulerAdapter`
consumes those records through the opaque plan: its readiness
callback accepts a node only when the required private `ActivationGate` runtime state is resolved and a matching
@@ -406,9 +406,9 @@ Workflow-call note:
ready work. It owns iterator expansion, collector grouping, prepared-parent selection, and creation of execution-graph
edges. When matching prepared parents for a downstream exec node, skipped prepared exec nodes are ignored and cannot
be selected as live inputs.
-- `_IfActivationController` Owns fresh runtime admission and compiles opaque, frame-local activation dependency
- records for prepared nodes. `_IfActivationCompiler` remains the compatibility-only lowering helper for legacy
- callers. Fresh admission leaves rejected branch sources unprepared; legacy discarded projections remain loadable.
+- `_IfActivationController` Owns all runtime `If` admission and compiles opaque, frame-local activation dependency
+ records for prepared nodes. Fresh admission leaves rejected branch sources unprepared; legacy skipped-state
+ projections remain loadable.
Branch-membership analysis remains internal to the controller.
- `_GenericGraphSchedulerAdapter` Projects the generic `ExecutionPlan`/`ExecutionScheduler` into the existing state
fields for ordinary static DAGs and legacy-shaped `If` graphs; the generic scheduler owns opaque readiness,
diff --git a/invokeai/app/services/shared/graph.py b/invokeai/app/services/shared/graph.py
index a196c772d2..7bd47cfefc 100644
--- a/invokeai/app/services/shared/graph.py
+++ b/invokeai/app/services/shared/graph.py
@@ -332,83 +332,6 @@ class _PreparedExecRegistry:
self._on_iteration_path_change(exec_node_id)
-class _IfActivationCompiler:
- """Lower legacy-shaped ``If`` inputs into opaque activation requirements.
-
- This compiler is deliberately separate from both schedulers. The generic
- scheduler consumes the resulting dependency records and never consults
- the compatibility branch scheduler; the latter remains available only to
- resume execution graphs produced by the legacy lowering path.
- """
-
- def __init__(self, state: "GraphExecutionState") -> None:
- self._state = state
-
- def get_branch_exclusive_sources(self, if_node_id: str) -> dict[str, set[str]]:
- cached = self._state._if_branch_exclusive_sources.get(if_node_id)
- if cached is not None:
- return cached
-
- source_graph = self._state._get_source_graph_flat()
- branch_sources: dict[str, set[str]] = {}
- for branch_field in ("true_input", "false_input"):
- direct_inputs = {
- edge.source.node_id for edge in self._state.graph._get_input_edges(if_node_id, branch_field)
- }
- expanded = set(direct_inputs)
- for node_id in list(expanded):
- expanded.update(nx.ancestors(source_graph, node_id))
-
- exclusive_sources = set(expanded)
- changed = True
- while changed:
- changed = False
- for node_id in list(exclusive_sources):
- output_edges = self._state.graph._get_output_edges(node_id)
- stays_in_branch = all(
- edge.destination.node_id in exclusive_sources
- or (edge.destination.node_id == if_node_id and edge.destination.field == branch_field)
- for edge in output_edges
- )
- if not stays_in_branch:
- exclusive_sources.remove(node_id)
- changed = True
- branch_sources[branch_field] = exclusive_sources
-
- self._state._tx_set_mapping(self._state._if_branch_exclusive_sources, if_node_id, branch_sources)
- return branch_sources
-
- def get_activation_dependencies(self, exec_node_id: str) -> tuple[ActivationDependency, ...]:
- """Compile opaque branch requirements for one prepared execution node."""
-
- source_node_id = self._state._prepared_registry().get_source_node_id(exec_node_id)
- if not any(isinstance(node, IfInvocation) for node in self._state.graph.nodes.values()):
- return ()
-
- iteration_path = self._state._get_iteration_path(exec_node_id)
- dependencies: list[ActivationDependency] = []
- for source_if_id, source_if_node in self._state.graph.nodes.items():
- if not isinstance(source_if_node, IfInvocation):
- continue
- branches = self.get_branch_exclusive_sources(source_if_id)
- matching_fields = tuple(
- branch_field
- for branch_field in ("true_input", "false_input")
- if source_node_id in branches[branch_field]
- )
- # A shared ancestor is live regardless of branch selection.
- if len(matching_fields) != 1:
- continue
- dependencies.append(
- ActivationDependency(
- owner_id=source_if_id,
- branch=matching_fields[0],
- frame=iteration_path,
- )
- )
- return tuple(dependencies)
-
-
class _IfActivationController:
"""Own activation admission for concrete execution nodes.
@@ -534,20 +457,6 @@ class _IfActivationController:
return True
-def _get_if_branch_exclusive_sources(state: "GraphExecutionState", if_node_id: str) -> dict[str, set[str]]:
- """Compatibility entry point for legacy ``If`` topology lowering."""
-
- return state._if_activation_compiler().get_branch_exclusive_sources(if_node_id)
-
-
-def _get_if_activation_dependencies(
- state: "GraphExecutionState", exec_node_id: str
-) -> tuple[ActivationDependency, ...]:
- """Compatibility entry point for callers that still request If dependencies."""
-
- return state._if_activation_compiler().get_activation_dependencies(exec_node_id)
-
-
class _ExecutionMaterializer:
"""Expands source-graph nodes into concrete execution-graph nodes for the current runtime state.
@@ -4601,12 +4510,10 @@ class GraphExecutionState(BaseModel):
# Optional priority; others follow in name order
ready_order: list[str] = Field(default_factory=list)
indegree: dict[str, int] = Field(default_factory=dict, description="Remaining unmet input count for exec nodes")
- _if_branch_exclusive_sources: dict[str, dict[str, set[str]]] = PrivateAttr(default_factory=dict)
_resolved_if_exec_branches: dict[str, str] = PrivateAttr(default_factory=dict)
_pending_if_exec_nodes: set[str] = PrivateAttr(default_factory=set)
_prepared_exec_metadata: dict[str, _PreparedExecNodeMetadata] = PrivateAttr(default_factory=dict)
_prepared_exec_registry: Optional[_PreparedExecRegistry] = PrivateAttr(default=None)
- _if_activation_compiler_instance: Optional[_IfActivationCompiler] = PrivateAttr(default=None)
_if_activation_controller_instance: Optional[_IfActivationController] = PrivateAttr(default=None)
_execution_materializer: Optional[_ExecutionMaterializer] = PrivateAttr(default=None)
_execution_scheduler: Optional[_ExecutionScheduler | _GenericGraphSchedulerAdapter] = PrivateAttr(default=None)
@@ -4722,11 +4629,9 @@ class GraphExecutionState(BaseModel):
self._execution_materializer = None
self._execution_scheduler = None
self._generic_graph_scheduler = None
- self._if_activation_compiler_instance = None
self._if_activation_controller_instance = None
self._pending_if_exec_nodes = set()
self._execution_runtime = None
- self._if_branch_exclusive_sources = {}
self._source_graph_flat = None
self._execution_graph_flat = None
self._completed_source_ids_cache = None
@@ -4752,11 +4657,6 @@ class GraphExecutionState(BaseModel):
)
return self._prepared_exec_registry
- def _if_activation_compiler(self) -> _IfActivationCompiler:
- if self._if_activation_compiler_instance is None:
- self._if_activation_compiler_instance = _IfActivationCompiler(self)
- return self._if_activation_compiler_instance
-
def _if_activation_controller(self) -> _IfActivationController:
if self._if_activation_controller_instance is None:
self._if_activation_controller_instance = _IfActivationController(self)
@@ -6865,12 +6765,10 @@ class GraphExecutionState(BaseModel):
self._ready_queues = {}
self._ready_node_ids = set()
self._active_class = None
- self._if_branch_exclusive_sources = {}
self._resolved_if_exec_branches = {}
self._pending_if_exec_nodes = set()
self._prepared_exec_metadata = {}
self._prepared_exec_registry = None
- self._if_activation_compiler_instance = None
self._execution_materializer = None
self._execution_scheduler = None
self._generic_graph_scheduler = None
diff --git a/tests/app/services/shared/test_execution_engine_differential.py b/tests/app/services/shared/test_execution_engine_differential.py
index 853b731e54..13bf6bf18e 100644
--- a/tests/app/services/shared/test_execution_engine_differential.py
+++ b/tests/app/services/shared/test_execution_engine_differential.py
@@ -34,7 +34,6 @@ from invokeai.app.services.shared.graph import (
IterateInvocation,
_ExecutionScheduler,
_GenericGraphSchedulerAdapter,
- _IfActivationCompiler,
)
from invokeai.app.services.shared.invocation_context import InvocationContextData, build_invocation_context
from tests.test_nodes import (
@@ -2091,13 +2090,9 @@ def test_generic_legacy_shaped_if_does_not_prune_or_skip_during_resolution(
state = GraphExecutionState(graph=graph)
deleted_edges: list[Edge] = []
- def fail_topology(*_: object, **__: object) -> dict[str, set[str]]:
- raise AssertionError("generic If execution consulted legacy branch topology")
-
def record_deleted_edge(self: GraphExecutionState, edge: Edge) -> None:
deleted_edges.append(edge)
- monkeypatch.setattr(graph_module, "_get_if_branch_exclusive_sources", fail_topology)
monkeypatch.setattr(GraphExecutionState, "_tx_delete_execution_edge", record_deleted_edge)
trace, state = _run_graph(state)
@@ -2110,22 +2105,11 @@ def test_generic_legacy_shaped_if_does_not_prune_or_skip_during_resolution(
@pytest.mark.parametrize("force_compatibility_scheduler", [False, True])
-def test_if_readiness_does_not_delegate_to_legacy_activation_compiler(
+def test_if_readiness_preserves_both_schedulers(
force_compatibility_scheduler: bool,
- monkeypatch: pytest.MonkeyPatch,
) -> None:
graph = _nested_if_graph()
- def fail_compiler(*_: object, **__: object) -> tuple[object, ...]:
- raise AssertionError("If readiness used compiler-derived branch topology")
-
- def fail_topology(*_: object, **__: object) -> dict[str, set[str]]:
- raise AssertionError("If readiness used the legacy topology entry point")
-
- monkeypatch.setattr(_IfActivationCompiler, "get_activation_dependencies", fail_compiler)
- monkeypatch.setattr(_IfActivationCompiler, "get_branch_exclusive_sources", fail_topology)
- monkeypatch.setattr(graph_module, "_get_if_branch_exclusive_sources", fail_topology)
-
trace, state = _run_graph(
GraphExecutionState(graph=graph),
force_compatibility_scheduler=force_compatibility_scheduler,
@@ -2138,15 +2122,7 @@ def test_if_readiness_does_not_delegate_to_legacy_activation_compiler(
@pytest.mark.parametrize("force_compatibility_scheduler", [False, True])
def test_flat_if_admission_is_demand_driven_and_token_authoritative(
force_compatibility_scheduler: bool,
- monkeypatch: pytest.MonkeyPatch,
) -> None:
- def fail_legacy_path(*_: object, **__: object) -> None:
- raise AssertionError("fresh If execution used a legacy branch projection")
-
- monkeypatch.setattr(_IfActivationCompiler, "get_activation_dependencies", fail_legacy_path)
- monkeypatch.setattr(_IfActivationCompiler, "get_branch_exclusive_sources", fail_legacy_path)
- monkeypatch.setattr(graph_module, "_get_if_branch_exclusive_sources", fail_legacy_path)
-
trace, state = _run_graph(
GraphExecutionState(graph=_flat_if_graph()),
force_compatibility_scheduler=force_compatibility_scheduler,
@@ -2249,8 +2225,8 @@ def test_fresh_generic_nested_if_preserves_state_without_legacy_branch_projectio
graph.get_node("outer_condition").value = outer_condition
graph.get_node("inner_condition").value = inner_condition
- def fail_legacy_path(*_: object, **__: object) -> None:
- raise AssertionError("fresh generic If execution used a legacy branch projection")
+ def fail_edge_deletion(*_: object, **__: object) -> None:
+ raise AssertionError("fresh generic If execution deleted an execution edge")
generic_retired_nodes: list[str] = []
original_discard = _GenericGraphSchedulerAdapter._retire_unselected_node
@@ -2259,9 +2235,8 @@ def test_fresh_generic_nested_if_preserves_state_without_legacy_branch_projectio
generic_retired_nodes.append(exec_node_id)
original_discard(adapter, exec_node_id)
- monkeypatch.setattr(graph_module, "_get_if_branch_exclusive_sources", fail_legacy_path)
monkeypatch.setattr(_GenericGraphSchedulerAdapter, "_retire_unselected_node", record_generic_discard)
- monkeypatch.setattr(GraphExecutionState, "_tx_delete_execution_edge", fail_legacy_path)
+ monkeypatch.setattr(GraphExecutionState, "_tx_delete_execution_edge", fail_edge_deletion)
trace, state = _run_graph(GraphExecutionState(graph=graph))