From 538cb068bc10c8eec3fc2884f0b79c71a3c0b75a Mon Sep 17 00:00:00 2001 From: comfyanonymous Date: Tue, 20 Aug 2024 00:50:39 -0400 Subject: [PATCH] Make cast_to a nop if weight is already good. --- comfy/ops.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/comfy/ops.py b/comfy/ops.py index ce13291..418d59e 100644 --- a/comfy/ops.py +++ b/comfy/ops.py @@ -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