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(rocm): default MIOPEN_FIND_MODE=FAST at startup

Lincoln Steinb2521e90ce72
diff --git a/docs/src/content/docs/start-here/system-requirements.mdx b/docs/src/content/docs/start-here/system-requirements.mdx
index 18cd92e4df..7874158ecb 100644
--- a/docs/src/content/docs/start-here/system-requirements.mdx
+++ b/docs/src/content/docs/start-here/system-requirements.mdx
@@ -148,6 +148,13 @@ If, after restarting the app, this doesn't improve your performance, either rest
While the application does run on AMD GPUs, there are occasional bumps related to spotty torch support.
:::
+:::note[MIOpen kernel search]
+ Invoke starts with `MIOPEN_FIND_MODE=FAST` so that MIOpen (ROCm's convolution library) does not
+ spend minutes benchmarking kernels the first time each convolution shape runs - most noticeable on
+ the video VAEs, which run many distinct shapes. Export `MIOPEN_FIND_MODE` yourself to override it
+ (for example `MIOPEN_FIND_MODE=NORMAL` to let MIOpen re-tune its kernel database).
+:::
+
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 --git a/invokeai/app/run_app.py b/invokeai/app/run_app.py
index 56cfa63246..0f0f18fa8c 100644
--- a/invokeai/app/run_app.py
+++ b/invokeai/app/run_app.py
@@ -17,6 +17,21 @@ from typing import Any
# keeps their value.
os.environ.setdefault("TOKENIZERS_PARALLELISM", "false")
+# ROCm: run MIOpen's convolution-kernel search in FAST mode. The default mode benchmarks
+# every candidate kernel the first time a convolution shape is seen, which on a VAE-shaped
+# workload (many layers x spatial tiles x temporal chunks, separately per dtype) costs minutes
+# of "warm-up" per new shape set, and torch's MIOpen ``chooseAlgorithm`` falls back to a
+# *global* ``emptyCache`` whenever a candidate's workspace allocation fails - on multi-GPU
+# installs that convoys the peer device mid-step (see ``install_peer_aware_empty_cache``).
+# FAST looks the shape up in MIOpen's find-db and takes the first viable kernel otherwise;
+# with a warmed find-db the difference in kernel quality is negligible. MIOpen reads the
+# variable when it is first used, so, like the tokenizer flag, it is set at module level -
+# before torch is even imported - rather than inside ``run_app()``, so no early import can run
+# a convolution ahead of it. On
+# CUDA/CPU/MPS builds MIOpen is absent and the variable is inert. ``setdefault`` keeps an
+# explicitly exported value (e.g. ``MIOPEN_FIND_MODE=NORMAL`` to re-tune the find-db).
+os.environ.setdefault("MIOPEN_FIND_MODE", "FAST")
+
def get_app():
"""Import the app and event loop. We wrap this in a function to more explicitly control when it happens, because
diff --git a/tests/app/test_run_app_environment.py b/tests/app/test_run_app_environment.py
new file mode 100644
index 0000000000..6b08ab21d7
--- /dev/null
+++ b/tests/app/test_run_app_environment.py
@@ -0,0 +1,32 @@
+"""The console-script entry module pins process-wide environment defaults before any heavy import."""
+
+import importlib
+import os
+
+import pytest
+
+
+def reload_run_app(monkeypatch: pytest.MonkeyPatch):
+ """Re-execute ``invokeai.app.run_app``'s module body under a patched environment."""
+ import invokeai.app.run_app as run_app
+
+ def reload() -> None:
+ importlib.reload(run_app)
+
+ yield reload
+ importlib.reload(run_app)
+
+
[email protected]("name, default", [("MIOPEN_FIND_MODE", "FAST"), ("TOKENIZERS_PARALLELISM", "false")])
+def test_run_app_sets_environment_defaults(name: str, default: str, monkeypatch: pytest.MonkeyPatch, reload_run_app):
+ monkeypatch.delenv(name, raising=False)
+ reload_run_app()
+ assert os.environ[name] == default
+
+
[email protected]("name", ["MIOPEN_FIND_MODE", "TOKENIZERS_PARALLELISM"])
+def test_run_app_keeps_an_explicit_environment_value(name: str, monkeypatch: pytest.MonkeyPatch, reload_run_app):
+ monkeypatch.setenv(name, "user-choice")
+ reload_run_app()
+ assert os.environ[name] == "user-choice"