mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-06-19 06:19:38 +08:00
implement touch accounting
Implement accounting of touching mmapped tensors.
This commit is contained in:
parent
34647e8345
commit
6b7f170b3e
@ -1227,6 +1227,9 @@ def cast_to_gathered(tensors, r, non_blocking=False, stream=None):
|
||||
continue
|
||||
if comfy.memory_management.read_tensor_file_slice_into(tensor, dest_view):
|
||||
continue
|
||||
storage = tensor.untyped_storage()
|
||||
if hasattr(storage, "_comfy_tensor_mmap_touched"):
|
||||
storage._comfy_tensor_mmap_touched = True
|
||||
dest_view.copy_(tensor, non_blocking=non_blocking)
|
||||
|
||||
|
||||
|
||||
@ -104,9 +104,11 @@ def load_safetensors(ckpt):
|
||||
#We are working with read-only RAM by design
|
||||
warnings.filterwarnings("ignore", message="The given buffer is not writable")
|
||||
tensor = torch.frombuffer(mv[start:end], dtype=_TYPES[info["dtype"]]).view(info["shape"])
|
||||
setattr(tensor.untyped_storage(),
|
||||
storage = tensor.untyped_storage()
|
||||
setattr(storage,
|
||||
"_comfy_tensor_file_slice",
|
||||
comfy.memory_management.TensorFileSlice(f, threading.get_ident(), data_base_offset + start, end - start))
|
||||
setattr(storage, "_comfy_tensor_mmap_touched", False)
|
||||
sd[name] = tensor
|
||||
|
||||
return sd, header.get("__metadata__", {}),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user