Skip to content

Commit a320824

Browse files
committed
better progress bar resuming
1 parent 62a83e1 commit a320824

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
'stylegan2_pytorch = stylegan2_pytorch.cli:main',
99
],
1010
},
11-
version = '1.0.1',
11+
version = '1.0.2',
1212
license='GPLv3+',
1313
description = 'StyleGan2 in Pytorch',
1414
author = 'Phil Wang',

stylegan2_pytorch/cli.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@ def timestamped_filename(prefix = 'generated-'):
2121
timestamp = now.strftime("%m-%d-%Y_%H-%M-%S")
2222
return f'{prefix}{timestamp}'
2323

24+
def set_seed(seed):
25+
torch.manual_seed(seed)
26+
torch.backends.cudnn.deterministic = True
27+
torch.backends.cudnn.benchmark = False
28+
np.random.seed(seed)
29+
random.seed(seed)
30+
2431
def run_training(rank, world_size, model_args, data, load_from, new, num_train_steps, name):
2532
is_main = rank == 0
2633
is_ddp = world_size > 1
2734

2835
if is_ddp:
29-
torch.manual_seed(0)
30-
torch.backends.cudnn.deterministic = True
31-
torch.backends.cudnn.benchmark = False
32-
np.random.seed(0)
33-
random.seed(0)
34-
36+
set_seed(seed)
3537
os.environ['MASTER_ADDR'] = 'localhost'
3638
os.environ['MASTER_PORT'] = '12355'
3739
dist.init_process_group('nccl', rank=rank, world_size=world_size)
@@ -53,7 +55,7 @@ def run_training(rank, world_size, model_args, data, load_from, new, num_train_s
5355

5456
model.set_data_src(data)
5557

56-
for _ in tqdm(range(num_train_steps - model.steps), mininterval=10., desc=f'{name}<{data}>'):
58+
for _ in tqdm(range(num_train_steps - model.steps), initial = model.steps, total = num_train_steps, mininterval=10., desc=f'{name}<{data}>'):
5759
retry_call(model.train, tries=3, exceptions=NanException)
5860
if is_main and _ % 50 == 0:
5961
model.print_log()

0 commit comments

Comments
 (0)