File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1129,13 +1129,18 @@ def unpin_memory(tensor):
11291129 if not is_device_cpu (tensor .device ):
11301130 return False
11311131
1132- if not tensor .is_pinned ():
1133- #NOTE: Cuda does detect when a tensor is already pinned and would
1134- #error below, but there are proven cases where this also queues an error
1135- #on the GPU async. So dont trust the CUDA API and guard here
1132+ ptr = tensor .data_ptr ()
1133+ size = tensor .numel () * tensor .element_size ()
1134+
1135+ size_stored = PINNED_MEMORY .get (ptr , None )
1136+ if size_stored is None :
1137+ logging .warning ("Tried to unpin tensor not pinned by ComfyUI" )
1138+ return False
1139+
1140+ if size != size_stored :
1141+ logging .warning ("Size of pinned tensor changed" )
11361142 return False
11371143
1138- ptr = tensor .data_ptr ()
11391144 if torch .cuda .cudart ().cudaHostUnregister (ptr ) == 0 :
11401145 TOTAL_PINNED_MEMORY -= PINNED_MEMORY .pop (ptr )
11411146 if len (PINNED_MEMORY ) == 0 :
You can’t perform that action at this time.
0 commit comments