Rewrite addWeighted to use torch.mul iteratively.

This commit is contained in:
City 2023-04-30 20:01:52 +02:00
parent 099fb5184a
commit fff14743d0

View File

@ -71,16 +71,14 @@ class ConditioningAverage :
CATEGORY = "conditioning" CATEGORY = "conditioning"
def addWeighted(self, conditioning_from, conditioning_to, conditioning_from_strength): def addWeighted(self, conditioning_from, conditioning_to, conditioning_from_strength):
conditioning_to_strength = (1-conditioning_from_strength) out = []
conditioning_from_tensor = conditioning_from[0][0] for i in range(min(len(conditioning_from),len(conditioning_to))):
conditioning_to_tensor = conditioning_to[0][0] t0 = conditioning_from[i]
output = conditioning_from t1 = conditioning_to[i]
if conditioning_from_tensor.shape[0] > conditioning_to_tensor.shape[1]: tw = torch.mul(t0[0],(1-conditioning_from_strength)) + torch.mul(t1[0],conditioning_from_strength)
conditioning_to_tensor = torch.cat((conditioning_to_tensor, torch.zeros((1, conditioning_from_tensor.shape[1] - conditioning_to_tensor.shape[1], conditioning_from_tensor.shape[1].value))), dim=1) n = [tw, t0[1].copy()]
elif conditioning_to_tensor.shape[1] > conditioning_from_tensor.shape[1]: out.append(n)
conditioning_from_tensor = torch.cat((conditioning_from_tensor, torch.zeros((1, conditioning_to_tensor.shape[1] - conditioning_from_tensor.shape[1], conditioning_to_tensor.shape[1].value))), dim=1) return (out, )
output[0][0] = ((conditioning_from_tensor * conditioning_from_strength) + (conditioning_to_tensor * conditioning_to_strength))
return (output, )
class ConditioningSetArea: class ConditioningSetArea:
@classmethod @classmethod