Skip to content

Commit

Permalink
fix bugs when training with single device
Browse files Browse the repository at this point in the history
  • Loading branch information
tqch committed Sep 14, 2022
1 parent a0e0d39 commit 9765b3a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion train.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def logger(msg, **kwargs):
if dist.get_rank() == 0:
if dist.is_initialized() and dist.get_rank() == 0:
print(msg, **kwargs)


Expand Down Expand Up @@ -72,6 +72,7 @@ def main(args):
model = DDP(_model, device_ids=[rank, ])
train_device = torch.device(f"cuda:{rank}")
else:
rank = 0
model = _model.to(train_device)

optimizer = Adam(model.parameters(), lr=lr, betas=(beta1, beta2))
Expand Down

0 comments on commit 9765b3a

Please sign in to comment.