Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce GPU usage by emptying cache #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,23 +380,26 @@ def train(args, loader, generator, discriminator, g_optim, d_optim, g_ema, devic

if args.ckpt is not None:
print('load model:', args.ckpt)

ckpt = torch.load(args.ckpt)

try:
ckpt_name = os.path.basename(args.ckpt)
args.start_iter = int(os.path.splitext(ckpt_name)[0])

except ValueError:
pass

generator.load_state_dict(ckpt['g'])
discriminator.load_state_dict(ckpt['d'])
g_ema.load_state_dict(ckpt['g_ema'])

g_optim.load_state_dict(ckpt['g_optim'])
d_optim.load_state_dict(ckpt['d_optim'])

del ckpt
torch.cuda.empty_cache()

if args.distributed:
generator = nn.parallel.DistributedDataParallel(
generator,
Expand Down