Skip to content

Commit

Permalink
Fix Trainer in DataParallel setting (#5685)
Browse files Browse the repository at this point in the history
* Fix Trainer in DataParallel setting

* Fix typo

Co-authored-by: Sam Shleifer <sshleifer@gmail.com>
  • Loading branch information
sgugger and sshleifer committed Jul 13, 2020
1 parent 0a19a49 commit ce374ba
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/transformers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,9 @@ def _training_step(

if self.args.past_index >= 0 and self._past is not None:
inputs["mems"] = self._past
# Our model outputs do not work with DataParallel, so forcing return tuple.
if self.args.n_gpu > 1:
inputs["return_tuple"] = True

outputs = model(**inputs)
loss = outputs[0] # model outputs are always tuple in transformers (see doc)
Expand Down Expand Up @@ -818,6 +821,9 @@ def _prediction_loop(
inputs[k] = v.to(self.args.device)
if self.args.past_index >= 0:
inputs["mems"] = past
# Our model outputs do not work with DataParallel, so forcing return tuple.
if self.args.n_gpu > 1:
inputs["return_tuple"] = True

with torch.no_grad():
outputs = model(**inputs)
Expand Down

0 comments on commit ce374ba

Please sign in to comment.