From baf1e9f1fe6976e4be876457ea22e4c66fb9f962 Mon Sep 17 00:00:00 2001 From: drhead <1313496+drhead@users.noreply.github.com> Date: Sun, 25 May 2025 12:49:49 -0400 Subject: [PATCH] copy conds to device before repeating --- comfy/conds.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/comfy/conds.py b/comfy/conds.py index 58d705028..691dc1fbc 100644 --- a/comfy/conds.py +++ b/comfy/conds.py @@ -11,17 +11,13 @@ class CONDRegular: def _copy_with(self, cond): return self.__class__(cond) - def _pin_memory(self, cond): - if cond.device == torch.device('cpu'): - return cond.pin_memory() - else: - return cond + def _pin_cond(self, device): + if self.cond.device == torch.device('cpu') and device_supports_non_blocking(device): + self.cond = self.cond.pin_memory(device) def process_cond(self, batch_size, device, **kwargs): - if device_supports_non_blocking(device): - return self._copy_with(comfy.utils.repeat_to_batch_size(self._pin_memory(self.cond), batch_size).to(device, non_blocking=True)) - else: - return self._copy_with(comfy.utils.repeat_to_batch_size(self.cond, batch_size).to(device)) + self._pin_cond(device) + return self._copy_with(comfy.utils.repeat_to_batch_size(self.cond.to(device, non_blocking=device_supports_non_blocking(device)), batch_size)) def can_concat(self, other): if self.cond.shape != other.cond.shape: