Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit580274b

Browse files
committed
use .to(device) to avoid copy, within one_unet_in_gpu context
1 parent848e8a4 commit580274b

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

‎dalle2_pytorch/dalle2_pytorch.py‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,11 +2727,16 @@ def one_unet_in_gpu(self, unet_number = None, unet = None):
27272727
ifexists(unet_number):
27282728
unet=self.get_unet(unet_number)
27292729

2730+
# devices
2731+
2732+
cuda,cpu=torch.device('cuda'),torch.device('cpu')
2733+
27302734
self.cuda()
27312735

27322736
devices= [module_device(unet)forunetinself.unets]
2733-
self.unets.cpu()
2734-
unet.cuda()
2737+
2738+
self.unets.to(cpu)
2739+
unet.to(cuda)
27352740

27362741
yield
27372742

@@ -3114,7 +3119,8 @@ def sample(
31143119
distributed=False,
31153120
inpaint_image=None,
31163121
inpaint_mask=None,
3117-
inpaint_resample_times=5
3122+
inpaint_resample_times=5,
3123+
one_unet_in_gpu_at_time=True
31183124
):
31193125
assertself.unconditionalorexists(image_embed),'image embed must be present on sampling from decoder unless if trained unconditionally'
31203126

@@ -3137,6 +3143,7 @@ def sample(
31373143
assertimage.shape[0]==batch_size,'image must have batch size of {} if starting at unet number > 1'.format(batch_size)
31383144
prev_unet_output_size=self.image_sizes[start_at_unet_number-2]
31393145
img=resize_image_to(image,prev_unet_output_size,nearest=True)
3146+
31403147
is_cuda=next(self.parameters()).is_cuda
31413148

31423149
num_unets=self.num_unets
@@ -3146,7 +3153,7 @@ def sample(
31463153
ifunet_number<start_at_unet_number:
31473154
continue# It's the easiest way to do it
31483155

3149-
context=self.one_unet_in_gpu(unet=unet)ifis_cudaelsenull_context()
3156+
context=self.one_unet_in_gpu(unet=unet)ifis_cudaandone_unet_in_gpu_at_timeelsenull_context()
31503157

31513158
withcontext:
31523159
# prepare low resolution conditioning for upsamplers

‎dalle2_pytorch/version.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__='1.12.3'
1+
__version__='1.12.4'

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp