import torch import gc class Iter_ConditioningSwitch: @classmethod def INPUT_TYPES(s): return { "required": { "output_index": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}), "input_count": ("INT", {"default": 2, "min": 1, "max": 64}), "use_last_input": ("BOOLEAN", {"default": True}), }, } RETURN_TYPES = ("CONDITIONING",) FUNCTION = "switch_conditioning" CATEGORY = "CustomNodes/Iterators" def switch_conditioning(self, output_index, input_count, use_last_input, **kwargs): target_idx = output_index % input_count res = None for i in range(target_idx, -1, -1): val = kwargs.get(f"cond_{i}") if val is not None or not use_last_input: res = val break #gc.collect() #torch.cuda.empty_cache() return (res,) class Iter_CLIPSwitch: @classmethod def INPUT_TYPES(s): return { "required": { "output_index": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}), "input_count": ("INT", {"default": 2, "min": 1, "max": 64}), "use_last_input": ("BOOLEAN", {"default": True}), }, } RETURN_TYPES = ("CLIP",) FUNCTION = "switch_clip" CATEGORY = "CustomNodes/Iterators" def switch_clip(self, output_index, input_count, use_last_input, **kwargs): target_idx = output_index % input_count res = None for i in range(target_idx, -1, -1): val = kwargs.get(f"clip_{i}") if val is not None or not use_last_input: res = val break #gc.collect() #torch.cuda.empty_cache() return (res,)