Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in run_*.py scripts: double wrap into DataParallel during eval #3842

Merged
merged 1 commit into from
Apr 20, 2020

Conversation

and-kul
Copy link
Contributor

@and-kul and-kul commented Apr 17, 2020

This bug is present in several scripts in examples:

  • examples/run_language_modeling.py
  • examples/run_multiple_choice.py
  • examples/run_xnli.py
  • examples/ner/run_ner.py
  • examples/mm-imdb/run_mmimdb.py
  • examples/hans/test_hans.py

The problem is exactly the same as it was in #1801 and in #1504:

During the evaluation, we are trying to wrap the model into DataParallel second time (we did it already during training). As a result we have:

"RuntimeError: module must have its parameters and buffers on device cuda:0 (device_ids[0]) but found one of them on device: cuda:1" (ids of devices may differ)

The fix is straightforward:
Before:

# multi-gpu eval
if args.n_gpu > 1:
    model = torch.nn.DataParallel(model)

After:

# multi-gpu eval
if args.n_gpu > 1 and not isinstance(model, torch.nn.DataParallel):
    model = torch.nn.DataParallel(model)

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for taking time to look at all the scripts affected @and-kul!

@LysandreJik LysandreJik requested a review from julien-c April 17, 2020 15:00
@julien-c
Copy link
Member

Merging this, though it will be rendered obsolete (for a subset of the script initially) by #3800

@julien-c julien-c merged commit b1ff0b2 into huggingface:master Apr 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants