Skip to content

Commit

Permalink
better parallelization
Browse files Browse the repository at this point in the history
  • Loading branch information
vansky committed Sep 10, 2019
1 parent 40e49b6 commit ab444ab
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,11 @@ def batchify(data, bsz):
# if args.cuda and (not args.single) and (torch.cuda.device_count() > 1):
# model.module.rnn.flatten_parameters()
# else:
if args.cuda and (not args.single) and (torch.cuda.device_count() > 1):
# Scatters minibatches (in dim=1) across available GPUs
model = nn.DataParallel(model, dim=1)
if isinstance(model, torch.nn.DataParallel):
model = model.module
elif args.cuda:
if (not args.single) and (torch.cuda.device_count() > 1):
# Scatters minibatches (in dim=1) across available GPUs
model = nn.DataParallel(model, dim=1)
model.rnn.flatten_parameters()

criterion = nn.CrossEntropyLoss()
Expand Down

0 comments on commit ab444ab

Please sign in to comment.