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: don't run global empty_cache on no-op make_rooms

Lincoln Stein199ade5a97d8
diff --git a/invokeai/backend/model_manager/load/model_cache/model_cache.py b/invokeai/backend/model_manager/load/model_cache/model_cache.py
index c7fd502a20..e737c8b7af 100644
--- a/invokeai/backend/model_manager/load/model_cache/model_cache.py
+++ b/invokeai/backend/model_manager/load/model_cache/model_cache.py
@@ -1747,7 +1747,16 @@ class ModelCache:
self._sync_current_stats()
- TorchDevice.empty_cache()
+ # Only pay for empty_cache() when this make_room actually dropped something. It is a
+ # GLOBAL operation: it takes every device's caching-allocator mutex and hipFree/cudaFrees
+ # their cached blocks, and freeing on a device with a long kernel in flight blocks until
+ # that kernel completes — with the mutex held, so even a peer worker's ordinary tensor
+ # deallocations stall until the step boundary (observed via py-spy on a dual-GPU ROCm
+ # box: a no-op make_room during one worker's model load froze the other worker's denoise
+ # step for its full duration). make_room runs on every put(), and most of those evict
+ # nothing, so the unconditional call turned every submodel load into a cross-GPU stall.
+ if models_cleared > 0:
+ TorchDevice.empty_cache()
self._logger.debug(f"Dropped {models_cleared} models to free {ram_bytes_freed / MB:.2f}MB of RAM.")
self._log_cache_state(title="After dropping models:")
return CacheClearResult(models_cleared=models_cleared, bytes_freed=ram_bytes_freed)