Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

Fix/tweak pinned memory accounting (#13221)

rattus8d723d2caa95
diff --git a/comfy/model_management.py b/comfy/model_management.py
index ce079cf2f..0eebf1ded 100644
--- a/comfy/model_management.py
+++ b/comfy/model_management.py
@@ -1326,9 +1326,9 @@ MAX_PINNED_MEMORY = -1
if not args.disable_pinned_memory:
if is_nvidia() or is_amd():
if WINDOWS:
- MAX_PINNED_MEMORY = get_total_memory(torch.device("cpu")) * 0.45 # Windows limit is apparently 50%
+ MAX_PINNED_MEMORY = get_total_memory(torch.device("cpu")) * 0.40 # Windows limit is apparently 50%
else:
- MAX_PINNED_MEMORY = get_total_memory(torch.device("cpu")) * 0.95
+ MAX_PINNED_MEMORY = get_total_memory(torch.device("cpu")) * 0.90
logging.info("Enabled pinned memory {}".format(MAX_PINNED_MEMORY // (1024 * 1024)))
PINNING_ALLOWED_TYPES = set(["Tensor", "Parameter", "QuantizedTensor"])
@@ -1403,8 +1403,6 @@ def unpin_memory(tensor):
if torch.cuda.cudart().cudaHostUnregister(ptr) == 0:
TOTAL_PINNED_MEMORY -= PINNED_MEMORY.pop(ptr)
- if len(PINNED_MEMORY) == 0:
- TOTAL_PINNED_MEMORY = 0
return True
else:
logging.warning("Unpin error.")