Make cast_to a nop if weight is already good.

This commit is contained in:
comfyanonymous 2024-08-20 00:50:39 -04:00
parent 1b3eee672c
commit 538cb068bc

View File

@ -21,6 +21,8 @@ import comfy.model_management
def cast_to(weight, dtype=None, device=None, non_blocking=False):
if (dtype is None or weight.dtype == dtype) and (device is None or weight.device == device):
return weight
r = torch.empty_like(weight, dtype=dtype, device=device)
r.copy_(weight, non_blocking=non_blocking)
return r