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.

fix(vae): keep the build-wide constant when no VAE device is named

Alexander Eichhornf8d7dfb7f35a
diff --git a/invokeai/backend/util/vae_working_memory.py b/invokeai/backend/util/vae_working_memory.py
index 48b594596f..9c0daa81bb 100644
--- a/invokeai/backend/util/vae_working_memory.py
+++ b/invokeai/backend/util/vae_working_memory.py
@@ -795,8 +795,10 @@ def estimate_vae_working_memory_qwen_image(
# W7900's, which is the card that needs them; what the spread means is that the reservation carries
# cross-card conservatism, so it must not double as the up-front tiling decision -- see
# `qwen_image_untiled_decode_peak_bytes`, which prices that decision from the measured curve instead.
- device = device if device is not None else TorchDevice.choose_torch_device()
- is_rocm = device.type == "cuda" and torch.version.hip is not None
+ # A named device answers for that device -- a `cpu_only` VAE is not on MIOpen even on a ROCm build. Without one
+ # the answer stays the build-wide one these constants were always selected by, so callers that pass no device
+ # (and tests that pin none) keep the figure they had.
+ is_rocm = torch.version.hip is not None and (device is None or device.type == "cuda")
if operation == "decode":
scaling_constant = 5500 if is_rocm else 2900
else: # encode
diff --git a/tests/backend/util/test_rocm_sdpa_head_dim_guard.py b/tests/backend/util/test_rocm_sdpa_head_dim_guard.py
index 79c3e92015..662dd13e8e 100644
--- a/tests/backend/util/test_rocm_sdpa_head_dim_guard.py
+++ b/tests/backend/util/test_rocm_sdpa_head_dim_guard.py
@@ -486,9 +486,13 @@ class TestClassicVaeEstimators:
@pytest.fixture(autouse=True)
def _rocm_cuda(self, monkeypatch):
+ """The guard's ROCm switch and the convolution backend are separate questions, and this class is about the
+ first: the assertions below carry the cuDNN linear term, so pin `torch.version.hip` (which selects MIOpen's
+ larger constants) away from it while the attention side stays on ROCm."""
import invokeai.backend.util.vae_working_memory as vwm
monkeypatch.setattr(attention, "_IS_ROCM", True)
+ monkeypatch.setattr(torch.version, "hip", None)
monkeypatch.setattr(vwm.TorchDevice, "choose_torch_device", classmethod(lambda cls: torch.device("cuda", 0)))
@staticmethod
diff --git a/tests/backend/util/test_vae_pretile.py b/tests/backend/util/test_vae_pretile.py
index 76fd578fff..79e208b833 100644
--- a/tests/backend/util/test_vae_pretile.py
+++ b/tests/backend/util/test_vae_pretile.py
@@ -73,6 +73,7 @@ def test_the_pretile_gate_uses_the_memory_the_device_will_keep_resident(monkeypa
assert should_pretile_vae_decode(torch.device("cuda", 0), estimate) is True
+
def test_the_gate_counts_memory_this_process_can_still_release(monkeypatch):
"""Windows halves the budget once the process passes about 12 of 16 GiB, i.e. below what it already holds. The
cache evicts models for the reservation, so the ceiling is the budget plus this process's own allocations --