mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-03-11 00:00:01 +00:00
Compare commits
3 Commits
temp_pr
...
prs/dynami
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8423394577 | ||
|
|
f7aebddcf6 | ||
|
|
89dc4a8df8 |
@@ -1213,8 +1213,12 @@ def cast_to(weight, dtype=None, device=None, non_blocking=False, copy=False, str
|
|||||||
|
|
||||||
signature = comfy_aimdo.model_vbar.vbar_fault(weight._v)
|
signature = comfy_aimdo.model_vbar.vbar_fault(weight._v)
|
||||||
if signature is not None:
|
if signature is not None:
|
||||||
v_tensor = comfy.memory_management.interpret_gathered_like(cast_geometry, weight._v_tensor)[0]
|
if comfy_aimdo.model_vbar.vbar_signature_compare(signature, weight._v_signature):
|
||||||
if not comfy_aimdo.model_vbar.vbar_signature_compare(signature, weight._v_signature):
|
v_tensor = weight._v_tensor
|
||||||
|
else:
|
||||||
|
raw_tensor = comfy_aimdo.torch.aimdo_to_tensor(weight._v, device)
|
||||||
|
v_tensor = comfy.memory_management.interpret_gathered_like(cast_geometry, raw_tensor)[0]
|
||||||
|
weight._v_tensor = v_tensor
|
||||||
weight._v_signature = signature
|
weight._v_signature = signature
|
||||||
#Send it over
|
#Send it over
|
||||||
v_tensor.copy_(weight, non_blocking=non_blocking)
|
v_tensor.copy_(weight, non_blocking=non_blocking)
|
||||||
|
|||||||
@@ -1542,7 +1542,6 @@ class ModelPatcherDynamic(ModelPatcher):
|
|||||||
|
|
||||||
if vbar is not None and not hasattr(m, "_v"):
|
if vbar is not None and not hasattr(m, "_v"):
|
||||||
m._v = vbar.alloc(v_weight_size)
|
m._v = vbar.alloc(v_weight_size)
|
||||||
m._v_tensor = comfy_aimdo.torch.aimdo_to_tensor(m._v, device_to)
|
|
||||||
allocated_size += v_weight_size
|
allocated_size += v_weight_size
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -1557,7 +1556,6 @@ class ModelPatcherDynamic(ModelPatcher):
|
|||||||
weight_size = geometry.numel() * geometry.element_size()
|
weight_size = geometry.numel() * geometry.element_size()
|
||||||
if vbar is not None and not hasattr(weight, "_v"):
|
if vbar is not None and not hasattr(weight, "_v"):
|
||||||
weight._v = vbar.alloc(weight_size)
|
weight._v = vbar.alloc(weight_size)
|
||||||
weight._v_tensor = comfy_aimdo.torch.aimdo_to_tensor(weight._v, device_to)
|
|
||||||
weight._model_dtype = model_dtype
|
weight._model_dtype = model_dtype
|
||||||
allocated_size += weight_size
|
allocated_size += weight_size
|
||||||
vbar.set_watermark_limit(allocated_size)
|
vbar.set_watermark_limit(allocated_size)
|
||||||
|
|||||||
21
comfy/ops.py
21
comfy/ops.py
@@ -83,14 +83,18 @@ def cast_to_input(weight, input, non_blocking=False, copy=True):
|
|||||||
def cast_bias_weight_with_vbar(s, dtype, device, bias_dtype, non_blocking, compute_dtype):
|
def cast_bias_weight_with_vbar(s, dtype, device, bias_dtype, non_blocking, compute_dtype):
|
||||||
offload_stream = None
|
offload_stream = None
|
||||||
xfer_dest = None
|
xfer_dest = None
|
||||||
cast_geometry = comfy.memory_management.tensors_to_geometries([ s.weight, s.bias ])
|
|
||||||
|
|
||||||
signature = comfy_aimdo.model_vbar.vbar_fault(s._v)
|
signature = comfy_aimdo.model_vbar.vbar_fault(s._v)
|
||||||
if signature is not None:
|
|
||||||
xfer_dest = s._v_tensor
|
|
||||||
resident = comfy_aimdo.model_vbar.vbar_signature_compare(signature, s._v_signature)
|
resident = comfy_aimdo.model_vbar.vbar_signature_compare(signature, s._v_signature)
|
||||||
|
if signature is not None:
|
||||||
|
if resident:
|
||||||
|
weight = s._v_weight
|
||||||
|
bias = s._v_bias
|
||||||
|
else:
|
||||||
|
xfer_dest = comfy_aimdo.torch.aimdo_to_tensor(s._v, device)
|
||||||
|
|
||||||
if not resident:
|
if not resident:
|
||||||
|
cast_geometry = comfy.memory_management.tensors_to_geometries([ s.weight, s.bias ])
|
||||||
cast_dest = None
|
cast_dest = None
|
||||||
|
|
||||||
xfer_source = [ s.weight, s.bias ]
|
xfer_source = [ s.weight, s.bias ]
|
||||||
@@ -140,9 +144,13 @@ def cast_bias_weight_with_vbar(s, dtype, device, bias_dtype, non_blocking, compu
|
|||||||
post_cast.copy_(pre_cast)
|
post_cast.copy_(pre_cast)
|
||||||
xfer_dest = cast_dest
|
xfer_dest = cast_dest
|
||||||
|
|
||||||
params = comfy.memory_management.interpret_gathered_like(cast_geometry, xfer_dest)
|
params = comfy.memory_management.interpret_gathered_like(cast_geometry, xfer_dest)
|
||||||
weight = params[0]
|
weight = params[0]
|
||||||
bias = params[1]
|
bias = params[1]
|
||||||
|
if signature is not None:
|
||||||
|
s._v_weight = weight
|
||||||
|
s._v_bias = bias
|
||||||
|
s._v_signature=signature
|
||||||
|
|
||||||
def post_cast(s, param_key, x, dtype, resident, update_weight):
|
def post_cast(s, param_key, x, dtype, resident, update_weight):
|
||||||
lowvram_fn = getattr(s, param_key + "_lowvram_function", None)
|
lowvram_fn = getattr(s, param_key + "_lowvram_function", None)
|
||||||
@@ -182,7 +190,6 @@ def cast_bias_weight_with_vbar(s, dtype, device, bias_dtype, non_blocking, compu
|
|||||||
weight = post_cast(s, "weight", weight, dtype, resident, update_weight)
|
weight = post_cast(s, "weight", weight, dtype, resident, update_weight)
|
||||||
if s.bias is not None:
|
if s.bias is not None:
|
||||||
bias = post_cast(s, "bias", bias, bias_dtype, resident, update_weight)
|
bias = post_cast(s, "bias", bias, bias_dtype, resident, update_weight)
|
||||||
s._v_signature=signature
|
|
||||||
|
|
||||||
#FIXME: weird offload return protocol
|
#FIXME: weird offload return protocol
|
||||||
return weight, bias, (offload_stream, device if signature is not None else None, None)
|
return weight, bias, (offload_stream, device if signature is not None else None, None)
|
||||||
|
|||||||
Reference in New Issue
Block a user