mirror of
https://github.com/lucidrains/DALLE2-pytorch.git
synced 2026-02-21 16:14:27 +01:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
580274be79 | ||
|
|
848e8a480a |
@@ -1334,10 +1334,7 @@ class DiffusionPrior(nn.Module):
|
|||||||
|
|
||||||
# predict noise
|
# predict noise
|
||||||
|
|
||||||
if self.predict_x_start or self.predict_v:
|
pred_noise = self.noise_scheduler.predict_noise_from_start(image_embed, t = time_cond, x0 = x_start)
|
||||||
pred_noise = self.noise_scheduler.predict_noise_from_start(image_embed, t = time_cond, x0 = x_start)
|
|
||||||
else:
|
|
||||||
pred_noise = pred
|
|
||||||
|
|
||||||
if time_next < 0:
|
if time_next < 0:
|
||||||
image_embed = x_start
|
image_embed = x_start
|
||||||
@@ -2730,11 +2727,16 @@ class Decoder(nn.Module):
|
|||||||
if exists(unet_number):
|
if exists(unet_number):
|
||||||
unet = self.get_unet(unet_number)
|
unet = self.get_unet(unet_number)
|
||||||
|
|
||||||
|
# devices
|
||||||
|
|
||||||
|
cuda, cpu = torch.device('cuda'), torch.device('cpu')
|
||||||
|
|
||||||
self.cuda()
|
self.cuda()
|
||||||
|
|
||||||
devices = [module_device(unet) for unet in self.unets]
|
devices = [module_device(unet) for unet in self.unets]
|
||||||
self.unets.cpu()
|
|
||||||
unet.cuda()
|
self.unets.to(cpu)
|
||||||
|
unet.to(cuda)
|
||||||
|
|
||||||
yield
|
yield
|
||||||
|
|
||||||
@@ -2975,10 +2977,7 @@ class Decoder(nn.Module):
|
|||||||
|
|
||||||
# predict noise
|
# predict noise
|
||||||
|
|
||||||
if predict_x_start or predict_v:
|
pred_noise = noise_scheduler.predict_noise_from_start(img, t = time_cond, x0 = x_start)
|
||||||
pred_noise = noise_scheduler.predict_noise_from_start(img, t = time_cond, x0 = x_start)
|
|
||||||
else:
|
|
||||||
pred_noise = pred
|
|
||||||
|
|
||||||
c1 = eta * ((1 - alpha / alpha_next) * (1 - alpha_next) / (1 - alpha)).sqrt()
|
c1 = eta * ((1 - alpha / alpha_next) * (1 - alpha_next) / (1 - alpha)).sqrt()
|
||||||
c2 = ((1 - alpha_next) - torch.square(c1)).sqrt()
|
c2 = ((1 - alpha_next) - torch.square(c1)).sqrt()
|
||||||
@@ -3120,7 +3119,8 @@ class Decoder(nn.Module):
|
|||||||
distributed = False,
|
distributed = False,
|
||||||
inpaint_image = None,
|
inpaint_image = None,
|
||||||
inpaint_mask = None,
|
inpaint_mask = None,
|
||||||
inpaint_resample_times = 5
|
inpaint_resample_times = 5,
|
||||||
|
one_unet_in_gpu_at_time = True
|
||||||
):
|
):
|
||||||
assert self.unconditional or exists(image_embed), 'image embed must be present on sampling from decoder unless if trained unconditionally'
|
assert self.unconditional or exists(image_embed), 'image embed must be present on sampling from decoder unless if trained unconditionally'
|
||||||
|
|
||||||
@@ -3143,6 +3143,7 @@ class Decoder(nn.Module):
|
|||||||
assert image.shape[0] == batch_size, 'image must have batch size of {} if starting at unet number > 1'.format(batch_size)
|
assert image.shape[0] == batch_size, 'image must have batch size of {} if starting at unet number > 1'.format(batch_size)
|
||||||
prev_unet_output_size = self.image_sizes[start_at_unet_number - 2]
|
prev_unet_output_size = self.image_sizes[start_at_unet_number - 2]
|
||||||
img = resize_image_to(image, prev_unet_output_size, nearest = True)
|
img = resize_image_to(image, prev_unet_output_size, nearest = True)
|
||||||
|
|
||||||
is_cuda = next(self.parameters()).is_cuda
|
is_cuda = next(self.parameters()).is_cuda
|
||||||
|
|
||||||
num_unets = self.num_unets
|
num_unets = self.num_unets
|
||||||
@@ -3152,7 +3153,7 @@ class Decoder(nn.Module):
|
|||||||
if unet_number < start_at_unet_number:
|
if unet_number < start_at_unet_number:
|
||||||
continue # It's the easiest way to do it
|
continue # It's the easiest way to do it
|
||||||
|
|
||||||
context = self.one_unet_in_gpu(unet = unet) if is_cuda else null_context()
|
context = self.one_unet_in_gpu(unet = unet) if is_cuda and one_unet_in_gpu_at_time else null_context()
|
||||||
|
|
||||||
with context:
|
with context:
|
||||||
# prepare low resolution conditioning for upsamplers
|
# prepare low resolution conditioning for upsamplers
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
__version__ = '1.12.2'
|
__version__ = '1.12.4'
|
||||||
|
|||||||
Reference in New Issue
Block a user