Skip to content

Commit 16571d3

Browse files
comfyanonymouszhangp365
authored andcommitted
Enable pinned memory by default on Nvidia. (comfyanonymous#10656)
Removed the --fast pinned_memory flag. You can use --disable-pinned-memory to disable it. Please report if it causes any issues.
1 parent 7a518ab commit 16571d3

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

comfy/cli_args.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,11 @@ class PerformanceFeature(enum.Enum):
145145
Fp8MatrixMultiplication = "fp8_matrix_mult"
146146
CublasOps = "cublas_ops"
147147
AutoTune = "autotune"
148-
PinnedMem = "pinned_memory"
149148

150149
parser.add_argument("--fast", nargs="*", type=PerformanceFeature, help="Enable some untested and potentially quality deteriorating optimizations. This is used to test new features so using it might crash your comfyui. --fast with no arguments enables everything. You can pass a list specific optimizations if you only want to enable specific ones. Current valid optimizations: {}".format(" ".join(map(lambda c: c.value, PerformanceFeature))))
151150

151+
parser.add_argument("--disable-pinned-memory", action="store_true", help="Disable pinned memory use.")
152+
152153
parser.add_argument("--mmap-torch-files", action="store_true", help="Use mmap when loading ckpt/pt files.")
153154
parser.add_argument("--disable-mmap", action="store_true", help="Don't use mmap when loading safetensors.")
154155

comfy/model_management.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,22 +1118,21 @@ def cast_to_device(tensor, device, dtype, copy=False):
11181118

11191119
PINNED_MEMORY = {}
11201120
TOTAL_PINNED_MEMORY = 0
1121-
if PerformanceFeature.PinnedMem in args.fast:
1122-
if WINDOWS:
1123-
MAX_PINNED_MEMORY = get_total_memory(torch.device("cpu")) * 0.45 # Windows limit is apparently 50%
1124-
else:
1125-
MAX_PINNED_MEMORY = get_total_memory(torch.device("cpu")) * 0.95
1126-
else:
1127-
MAX_PINNED_MEMORY = -1
1121+
MAX_PINNED_MEMORY = -1
1122+
if not args.disable_pinned_memory:
1123+
if is_nvidia():
1124+
if WINDOWS:
1125+
MAX_PINNED_MEMORY = get_total_memory(torch.device("cpu")) * 0.45 # Windows limit is apparently 50%
1126+
else:
1127+
MAX_PINNED_MEMORY = get_total_memory(torch.device("cpu")) * 0.95
1128+
logging.info("Enabled pinned memory {}".format(MAX_PINNED_MEMORY // (1024 * 1024)))
1129+
11281130

11291131
def pin_memory(tensor):
11301132
global TOTAL_PINNED_MEMORY
11311133
if MAX_PINNED_MEMORY <= 0:
11321134
return False
11331135

1134-
if not is_nvidia():
1135-
return False
1136-
11371136
if not is_device_cpu(tensor.device):
11381137
return False
11391138

@@ -1154,9 +1153,6 @@ def unpin_memory(tensor):
11541153
if MAX_PINNED_MEMORY <= 0:
11551154
return False
11561155

1157-
if not is_nvidia():
1158-
return False
1159-
11601156
if not is_device_cpu(tensor.device):
11611157
return False
11621158

0 commit comments

Comments
 (0)