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
Merge remote-tracking branch 'origin/main' into feat/rocm-windows-memory
Alexander Eichhorn2a1b4e30d48a
diff --cc docs/src/content/docs/start-here/system-requirements.mdxindex 6a62a5efe6,ede60e15bb..e4c1c4e112--- a/docs/src/content/docs/start-here/system-requirements.mdx+++ b/docs/src/content/docs/start-here/system-requirements.mdx@@@ -159,20 -159,21 +159,29 @@@ If, after restarting the app, this doesOn ROCm builds Invoke routes attention whose head dimension exceeds 256 to PyTorch's math kernel.The fused kernels return wrong output there on torch 2.13 / ROCm 7.2 (measured on a W7900), whichshowed up as black or noisy images from the image VAEs - their mid-block attention is one 512-wide- head. The math kernel materializes the attention matrix, so large untiled VAE decodes reserve- more VRAM (about 4 GB at 1024px, 21 GB at 1536px) and may push other models out of the cache;- tiled decoding keeps that bounded. Export `INVOKE_ROCM_FUSED_SDPA_MAX_HEAD_DIM` to raise the- threshold on a build whose fused kernels are known to be correct.+ head. The math kernel builds the whole attention matrix (about 4 GB for a 1024px VAE decode, 21 GB+ at 1536px), so Invoke computes it in pieces of at most 1 GB. The result can differ from a single+ math call in the last bit of a bf16 value, and each such call is roughly 10% slower. Export+ `INVOKE_ROCM_FUSED_SDPA_MAX_HEAD_DIM` to raise the threshold on a build whose fused kernels are+ known to be correct.+:::++:::note[Attention without a fused kernel]+ Where PyTorch has no fused attention kernel for a call, it runs on the math kernel as well, and+ Invoke computes that in pieces of at most 1 GB too. That is what makes large models and+ resolutions usable on such builds: Z-Image at 1024px would otherwise build 8 GB of attention+ scores per call, Krea-2 almost 13 GB.:::+ :::note[Idle process pegging one CPU core]+ After GPU work, ROCm's HSA runtime can leave its internal `AsyncEventsLoop` thread busy-spinning+ on one CPU core indefinitely instead of blocking - a livelock in `libhsa-runtime64.so`, not an+ Invoke bug (see [ROCm/ROCm#6522] and [ROCm/TheRock#7051]). It inflates `rocm-smi`'s GPU-busy%+ reading too, so it can look like a stuck generation when the queue is actually idle. If you see+ this, export `HSA_TOOLS_DISABLE_REGISTER=1` before launching Invoke; unset it only if you need+ `rocprof`/ROCTracer-based kernel profiling, which this disables.+ :::+Run `rocm-smi` on your system's command line verify that drivers and ROCm are installed. If this command fails, or doesn't report versions, you will need to install them.Go to the [ROCm Documentation] and carefully follow the instructions for your system to get everything installed.diff --cc tests/app/invocations/test_z_image_tiled_decode.pyindex de36fd1ffa,e29c074ff1..8e29b7795f--- a/tests/app/invocations/test_z_image_tiled_decode.py+++ b/tests/app/invocations/test_z_image_tiled_decode.py@@@ -23,36 -23,20 +23,44 @@@ def _mock_flux_vae(element_size_bytes:class TestFluxWorkingMemoryEstimate:@pytest.fixture(autouse=True)- def _cudnn_column(self, monkeypatch):- """These pin the cuDNN-column arithmetic; on a ROCm machine the session device would select MIOpen's."""+ def _fused_non_rocm_build(self, monkeypatch):- """`estimate_vae_working_memory_flux` takes no device: it resolves one itself and prices the- mid-block score matrix for it. On a ROCm rig that resolves to `cuda`, where the head-dim- guard charges 4.25GiB for the 1024px case below -- which the expected value here clears by- 1%, so these exact-value assertions turn build-dependent the moment either constant moves.- Pin the fused, non-HIP regime they are written for; `TestClassicVaeEstimators` in++ """`estimate_vae_working_memory_flux` resolves a device when the caller passes none, and prices the mid-block++ score matrix for it. On a ROCm rig that resolves to `cuda`, where the head-dim guard charges 4.25GiB for the++ 1024px case below -- which the expected value here clears by 1%, so these exact-value assertions turn++ build-dependent the moment either constant moves. Pin the fused, non-HIP regime they are written for, which++ is also the cuDNN column of `_FLUX_VAE_SCALING_CONSTANTS`; `TestClassicVaeEstimators` in+ `tests/backend/util/test_rocm_sdpa_head_dim_guard.py` owns the ROCm side of this estimator.+ """+ import invokeai.backend.util.attention as attentionimport invokeai.backend.util.vae_working_memory as vwm+ monkeypatch.setattr(attention, "_IS_ROCM", False)monkeypatch.setattr(vwm.TorchDevice, "choose_torch_device", classmethod(lambda cls: torch.device("cpu")))+ @pytest.mark.parametrize(+ ("hip", "operation", "constant"),+ [(None, "decode", 2200), (None, "encode", 1100), ("7.14.0", "decode", 3600), ("7.14.0", "encode", 2750)],+ ids=["cudnn-decode", "cudnn-encode", "miopen-decode", "miopen-encode"],+ )+ def test_the_convolution_backend_of_the_vaes_device_picks_the_constant(self, monkeypatch, hip, operation, constant):+ """MIOpen's workspaces are larger than cuDNN's: measured 3451 decode / 2688 encode on an RX 9060 XT, the same+ as the FLUX.2 VAE. A HIP build reports its GPU as "cuda", so the torch build decides, for the VAE's device."""+ import invokeai.backend.util.vae_working_memory as vwm++ monkeypatch.setattr(torch.version, "hip", hip)+ monkeypatch.setattr(vwm, "_vae_mid_block_score_matrix_bytes", lambda *args, **kwargs: 0)+ tensor = torch.zeros(1, 16, 64, 64) if operation == "decode" else torch.zeros(1, 3, 512, 512)++ estimate = estimate_vae_working_memory_flux(+ operation=operation, image_tensor=tensor, vae=_mock_flux_vae(), device=torch.device("cuda", 0)+ )+ on_cpu = estimate_vae_working_memory_flux(+ operation=operation, image_tensor=tensor, vae=_mock_flux_vae(), device=torch.device("cpu")+ )++ assert estimate == 512 * 512 * 2 * constant+ assert on_cpu == 512 * 512 * 2 * (2200 if operation == "decode" else 1100), "a cpu_only VAE runs on cuDNN terms"+def test_the_default_reproduces_the_untiled_estimate(self):"""Regression guard for the six call sites that pass no tile_size at all."""latents = torch.zeros(1, 16, 128, 128)