Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion comfy/model_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,13 +1098,14 @@ def cast_to_device(tensor, device, dtype, copy=False):
MAX_PINNED_MEMORY = get_total_memory(torch.device("cpu")) * 0.95
logging.info("Enabled pinned memory {}".format(MAX_PINNED_MEMORY // (1024 * 1024)))

PINNING_ALLOWED_TYPES = set(["Parameter", "QuantizedTensor"])

def pin_memory(tensor):
global TOTAL_PINNED_MEMORY
if MAX_PINNED_MEMORY <= 0:
return False

if type(tensor) is not torch.nn.parameter.Parameter:
if type(tensor).__name__ not in PINNING_ALLOWED_TYPES:
return False

if not is_device_cpu(tensor.device):
Expand All @@ -1124,6 +1125,9 @@ def pin_memory(tensor):
return False

ptr = tensor.data_ptr()
if ptr == 0:
return False

if torch.cuda.cudart().cudaHostRegister(ptr, size, 1) == 0:
PINNED_MEMORY[ptr] = size
TOTAL_PINNED_MEMORY += size
Expand Down
8 changes: 8 additions & 0 deletions comfy/quant_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,14 @@ def dequant_arg(arg):
new_kwargs = dequant_arg(kwargs)
return func(*new_args, **new_kwargs)

def data_ptr(self):
return self._qdata.data_ptr()

def is_pinned(self):
return self._qdata.is_pinned()

def is_contiguous(self):
return self._qdata.is_contiguous()

# ==============================================================================
# Generic Utilities (Layout-Agnostic Operations)
Expand Down