DataParallel fix: multi gpu evaluation (#5926)

The DataParallel training was fixed in https://github.com/huggingface/transformers/pull/5733, this commit also fixes the evaluation. It's more convenient when the user enables both `do_train` and `do_eval`.
This commit is contained in:
Qingqing Cao
2020-07-20 17:54:08 -04:00
committed by GitHub
parent a20969170b
commit 8e0bcb56ec

View File

@@ -316,7 +316,8 @@ def evaluate(args, model, tokenizer, prefix=""):
inputs.update( inputs.update(
{"langs": (torch.ones(batch[0].shape, dtype=torch.int64) * args.lang_id).to(args.device)} {"langs": (torch.ones(batch[0].shape, dtype=torch.int64) * args.lang_id).to(args.device)}
) )
if isinstance(model, torch.nn.DataParallel):
inputs["return_tuple"] = True
outputs = model(**inputs) outputs = model(**inputs)
for i, feature_index in enumerate(feature_indices): for i, feature_index in enumerate(feature_indices):