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.

Merge remote-tracking branch 'origin/main' into execution-engine-refactoring

JPPhotodf7c2d750fcd
diff --cc tests/app/services/shared/test_for_scheduler_performance.py
index 5515fc3057,1fe48825d6..fb2961515a
--- a/tests/app/services/shared/test_for_scheduler_performance.py
+++ b/tests/app/services/shared/test_for_scheduler_performance.py
@@@ -1,8 -1,12 +1,13 @@@
- """Regression coverage for scheduler overhead with trivial loop bodies."""
+ """Scheduler behavior and overhead for trivial loop bodies.
+
+ `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. 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.
+ """
import time
+from collections.abc import Callable
- from statistics import median
from unittest.mock import Mock
import pytest
@@@ -13,7 -17,7 +18,7 @@@ from invokeai.app.services.shared.grap
from tests.test_nodes import AnyTypeTestInvocation, create_edge, create_loop_linkage
- def _run_trivial_loop(loop_type: str, count: int, *, clock: Callable[[], float] = time.perf_counter) -> float:
-def _run_trivial_loop(loop_type: str, count: int) -> float:
++def _run_trivial_loop(loop_type: str, count: int, *, clock: Callable[[], float] = time.process_time) -> float:
graph = Graph()
graph.add_node(RangeInvocation(id="range", start=0, stop=count))
graph.add_node(ForInvocation(id="loop") if loop_type == "for" else IterateInvocation(id="loop"))
@@@ -41,22 -45,20 +46,31 @@@ def test_loop_scheduler_overhead_is_lin
timings = {count: [] for count in (300, 1200)}
for _ in range(3):
for count in (1200, 300):
- timings[count].append(_run_trivial_loop(loop_type, count, clock=time.process_time) / count)
- per_node = {count: median(samples) for count, samples in timings.items()}
- # Linear scheduling keeps per-item cost flat; the quadratic regression roughly doubled it per doubling.
- assert per_node[1200] < per_node[300] * 1.5, f"{loop_type}: {per_node}"
+ # CPU time, so a worker losing the core to a sibling does not read as scheduler cost.
+ # Both sizes take hundreds of milliseconds, well clear of the ~15ms clock granularity
+ # that made this measurement unusable when the loops were cheaper.
+ timings[count].append(_run_trivial_loop(loop_type, count) / count)
+ # Best-of-N is the noise-tolerant estimator for a lower bound: shared CI hosts inflate any
+ # single sample (a GC pause or a scheduler hiccup), and the median of three still fell over
+ # a tight threshold on macOS.
+ per_node = {count: min(samples) for count, samples in timings.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_for_loop_scheduler_overhead_is_linear_with_wall_clock() -> None:
+ """Use wall clock for the For guard so Windows' coarse process clock cannot quantize the baseline."""
+ timings: dict[int, list[float]] = {count: [] for count in (300, 1200)}
+ for _ in range(5):
+ for count in (1200, 300):
+ timings[count].append(_run_trivial_loop("for", count) / count)
+ per_node = {count: min(samples) for count, samples in timings.items()}
+ assert per_node[1200] < per_node[300] * 1.5, f"for: {per_node}"
+
+
+ @pytest.mark.slow
@pytest.mark.parametrize("loop_type", ["for", "iterate"])
def test_trivial_loop_scheduler_overhead(loop_type: str) -> None:
elapsed = _run_trivial_loop(loop_type, 600)