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
test(execution): replace scheduler timing gate with counters
JPPhoto43657725a8e5
diff --git a/tests/app/services/shared/test_for_scheduler_performance.py b/tests/app/services/shared/test_for_scheduler_performance.pyindex e7792d5077..c2de4d3706 100644--- a/tests/app/services/shared/test_for_scheduler_performance.py+++ b/tests/app/services/shared/test_for_scheduler_performance.py@@ -1,15 +1,8 @@"""Scheduler behavior and overhead for trivial loop bodies.-The required scheduler-scaling regression test counts entries traversed in the growing scheduler-ledgers. The linear-overhead check measures CPU time across repeated runs, rather than relying on a-single wall-clock sample. Optional absolute-time benchmarks remain marked `slow`. The-completion-state tests are not benchmarks.-`test_loop_scheduler_overhead_is_linear` measures CPU time, not wall clock: it compares per-item-cost at two sizes, and CPU time is not inflated when xdist workers share the runner's cores. It can-be *deflated* by them, though -- Windows charges CPU in whole 15.625ms quanta at the clock interrupt-and a contended worker misses some -- so the comparison sums its repeats rather than picking one of-them. The absolute budget below it is machine-dependent and stays `slow`, as does the sibling-`test_graph_execution_performance.py`. The completion-state tests are not benchmarks at all.+The scheduler-scaling regression tests count visits to growing scheduler ledgers, so+they remain stable under shared CI load. Optional absolute-time benchmarks remain marked `slow`.+The completion-state tests are not benchmarks."""import time@@ -43,7 +36,7 @@ class _MappingTraversalCounter:class _CountingMapping(dict[str, object]):- """Count mapping-entry traversal without constraining the scheduler algorithm."""+ """Count mapping accesses and iteration without constraining the scheduler algorithm."""def __init__(self, values: dict[str, object], counter: _MappingTraversalCounter, mapping_name: str) -> None:super().__init__()@@ -84,6 +77,20 @@ class _CountingMapping(dict[str, object]):return super().get(key, default)+class _CountingSet(set[str]):+ """Count visits to prepared execution IDs without constraining set operations."""++ def __init__(self, values: set[str], counter: _MappingTraversalCounter, mapping_name: str) -> None:+ super().__init__(values)+ self._counter = counter+ self._mapping_name = mapping_name++ def __iter__(self): # type: ignore[override]+ for value in super().__iter__():+ self._counter.record(self._mapping_name)+ yield value++def _run_trivial_loop(loop_type: str,count: int,@@ -150,7 +157,7 @@ def _run_trivial_loop(("for", True, True),],)-def test_loop_scheduler_does_not_rescan_growing_state(+def test_loop_scheduler_mapping_visits_scale_linearly(loop_type: str, include_if: bool, external_condition: bool) -> None:visits: dict[int, int] = {}@@ -168,41 +175,41 @@ def test_loop_scheduler_does_not_rescan_growing_state(visits_by_mapping[count] = counter.visits_by_mapping# A small constant number of full mapping passes is acceptable. A pass per iteration is not:- # it visits growing scheduler state quadratically. For covers durable effect history; Iterate covers- # result synchronization in the generic scheduler.+ # it visits growing scheduler state quadratically. For covers durable effect history; Iterate+ # covers result synchronization in the generic scheduler.assert all(visits[count] <= count * 128 for count in visits), (f"mapping visits for {loop_type}, include_if={include_if}, external_condition={external_condition}: "f"{visits}; by mapping: {visits_by_mapping}")+ # Four times as many iterations should not make per-iteration mapping work grow substantially.+ # Per-mapping ratios catch an occasional full scan even when unrelated constant-time lookups+ # mask it in the aggregate. The counters are deterministic; unlike a timing ratio, they cannot+ # fail because the test worker was descheduled or contended.+ mappings = visits_by_mapping[300].keys() | visits_by_mapping[1200].keys()+ for mapping in mappings:+ small_per_node = visits_by_mapping[300].get(mapping, 0) / 300+ large_per_node = visits_by_mapping[1200].get(mapping, 0) / 1200+ assert large_per_node < small_per_node * 1.75, (+ f"{mapping} operations per node for {loop_type}, include_if={include_if}, "+ f"external_condition={external_condition}: "+ f"{small_per_node} at 300 vs {large_per_node} at 1200; all visits: {visits_by_mapping}"+ )-_REPEATS = 3--[email protected]("loop_type", ["iterate", "for"])-def test_loop_scheduler_overhead_is_linear(loop_type: str) -> None:- totals = dict.fromkeys((300, 1200), 0.0)- for _ in range(_REPEATS):- for count in (1200, 300):- # CPU time, so a worker losing the core to a sibling does not read as scheduler cost.- totals[count] += _run_trivial_loop(loop_type, count)-- # One estimate per size over all the repeats, rather than best-of-N over them. `min` assumes the- # noise only ever inflates a sample, and on a contended Windows runner it does not: CPU time is- # charged in whole 15.625ms quanta at the clock interrupt, and a worker sharing four vCPUs under- # `-n logical` misses some of them, so a reading can come back *short*. It came back at exactly- # 0.0 for a 300-item run that the 1200 reading beside it puts at ~250ms -- sixteen quanta, which- # no rounding can turn into zero -- and `min` took that for the fastest run, leaving the- # threshold at `0.0 * 2.5`.- # From there the assertion could not be satisfied by any scheduler. Summing absorbs a short- # reading instead of selecting it, and averages an inflated one instead of being blind to it.- for count, total in totals.items():- assert total, f"{loop_type}: the CPU clock did not advance across any {count}-item run ({totals})"- per_node = {count: total / (_REPEATS * count) for count, total in totals.items()}-- # Linear scheduling keeps per-item cost flat. The quadratic regression scaled per-item cost with- # the item count - about 4x between 300 and 1200 - so 2.5x leaves noise headroom on both sides.- assert per_node[1200] < per_node[300] * 2.5, f"{loop_type}: {per_node}"+def test_prepared_execution_count_scans_each_source_once() -> None:+ counter = _MappingTraversalCounter()+ state = GraphExecutionState(graph=Graph())+ state.source_prepared_mapping = _CountingMapping(+ {+ "source": _CountingSet({"exec-1", "exec-2", "exec-3"}, counter, "prepared_node_ids"),+ },+ counter,+ "source_prepared_mapping",+ ) # type: ignore[assignment]++ assert state._count_unexecuted_prepared("source") == 3+ assert state._count_unexecuted_prepared("source") == 3+ assert counter.visits_by_mapping == {"source_prepared_mapping": 1, "prepared_node_ids": 3}@pytest.mark.slow