From 27f62999c94f72fd7825d8fba2886e0d6a3fbf67 Mon Sep 17 00:00:00 2001 From: Peter Baylies Date: Fri, 7 Oct 2022 18:43:55 -0400 Subject: [PATCH] * Fix for Perlin noise issue for cuda as well. --- ldm/util.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ldm/util.py b/ldm/util.py index 298c3141d6..95cad79523 100644 --- a/ldm/util.py +++ b/ldm/util.py @@ -223,15 +223,15 @@ def rand_perlin_2d(shape, res, device, fade = lambda t: 6*t**5 - 15*t**4 + 10*t* rand_val = torch.rand(res[0]+1, res[1]+1) angles = 2*math.pi*rand_val - gradients = torch.stack((torch.cos(angles), torch.sin(angles)), dim = -1) + gradients = torch.stack((torch.cos(angles), torch.sin(angles)), dim = -1).to(device) tile_grads = lambda slice1, slice2: gradients[slice1[0]:slice1[1], slice2[0]:slice2[1]].repeat_interleave(d[0], 0).repeat_interleave(d[1], 1) dot = lambda grad, shift: (torch.stack((grid[:shape[0],:shape[1],0] + shift[0], grid[:shape[0],:shape[1], 1] + shift[1] ), dim = -1) * grad[:shape[0], :shape[1]]).sum(dim = -1) - n00 = dot(tile_grads([0, -1], [0, -1]), [0, 0]) - n10 = dot(tile_grads([1, None], [0, -1]), [-1, 0]) - n01 = dot(tile_grads([0, -1],[1, None]), [0, -1]) - n11 = dot(tile_grads([1, None], [1, None]), [-1,-1]) + n00 = dot(tile_grads([0, -1], [0, -1]), [0, 0]).to(device) + n10 = dot(tile_grads([1, None], [0, -1]), [-1, 0]).to(device) + n01 = dot(tile_grads([0, -1],[1, None]), [0, -1]).to(device) + n11 = dot(tile_grads([1, None], [1, None]), [-1,-1]).to(device) t = fade(grid[:shape[0], :shape[1]]) - return math.sqrt(2) * torch.lerp(torch.lerp(n00, n10, t[..., 0]), torch.lerp(n01, n11, t[..., 0]), t[..., 1]) + return math.sqrt(2) * torch.lerp(torch.lerp(n00, n10, t[..., 0]), torch.lerp(n01, n11, t[..., 0]), t[..., 1]).to(device)