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

[tests] use torch_device instead of auto for model testing #29531

Merged
merged 5 commits into from Mar 8, 2024

Conversation

faaany
Copy link
Contributor

@faaany faaany commented Mar 8, 2024

What does this PR do?

When running test cases under the models folder on XPU, I found that many model tests fail at the same test test_model_parallel_beam_search, e.g.

FAILED tests/models/bigbird_pegasus/test_modeling_bigbird_pegasus.py::BigBirdPegasusModelTest::test_model_parallel_beam_search - RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and xpu:0! (when che

This is because device_map="auto" is used. As elaborated in this PR, the device_map="auto" mechanism is still not mature on XPU, causing model to be loaded on CPU, rather than on XPU.

If there is no particular reason for using auto, I would suggest using torch_device instead auto, because torch_device is more specific than auto and we don't have the need to use auto, e.g. large model inference, in our tests anyway. WDYT? @ArthurZucker

@amyeroberts
Copy link
Collaborator

Hi @faaany - thanks for opening this PR! Using device_map="auto" is necessary for this test - it's checking that beam search works when the model is split across devices. If it doesn't work with XPU, then you can add a skip with unittest e.g.

if "xpu" in torch_device:
    return unittest.skip("device_map='auto' does not work with XPU devices")

@faaany
Copy link
Contributor Author

faaany commented Mar 8, 2024

Hi @amyeroberts , thanks so much for reviewing this PR! I updated my patch and used torch_device=="xpu" instead of 'xpu' in torch_device, hope this is fine for you. And yes, I will remove this skip once auto works on XPU.

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

Thanks for handling!

Just a small nit

tests/generation/test_utils.py Outdated Show resolved Hide resolved
Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
@faaany
Copy link
Contributor Author

faaany commented Mar 8, 2024

Thanks for handling!

Just a small nit

done, thx!

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

Thanks!

@amyeroberts amyeroberts merged commit 1ea3ad1 into huggingface:main Mar 8, 2024
17 checks passed
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.

None yet

2 participants