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: replace torch.device("cuda") with torch.device("cuda:0") in devices initialization #3184

Merged
merged 1 commit into from
Sep 8, 2022
Merged

fix: replace torch.device("cuda") with torch.device("cuda:0") in devices initialization #3184

merged 1 commit into from
Sep 8, 2022

Conversation

vblagoje
Copy link
Member

@vblagoje vblagoje commented Sep 8, 2022

Related Issues

Proposed Changes:

As version 4.21.2 in their pipelines, HF transformers only accept indexed Cuda devices. Therefore, we needed to replace instances of torch.device("cuda") with torch.device("cuda:0") in devices initialization util function.

How did you test it?

A fix is trivial; I tried a small unit test in an interpreter but didn't add any additional unit tests

Notes for the reviewer

Think of a potential scenario where the proposed fix breaks.

@vblagoje vblagoje requested a review from a team as a code owner September 8, 2022 08:35
@vblagoje vblagoje requested review from masci and sjrl and removed request for a team September 8, 2022 08:35
@vblagoje
Copy link
Member Author

vblagoje commented Sep 8, 2022

wdyt @sjrl ? This is what I had in mind ☝️

@@ -96,6 +96,12 @@ def initialize_device_settings(
n_gpu = 1
# Initializes the distributed backend which will take care of sychronizing nodes/GPUs
torch.distributed.init_process_group(backend="nccl")

# HF transformers v4.21.2 pipeline object doesn't accept torch.device("cuda"), it has to be indexed cuda device
Copy link
Contributor

Choose a reason for hiding this comment

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

small typo add "an" to "to be an indexed ..."

@@ -96,6 +96,12 @@ def initialize_device_settings(
n_gpu = 1
# Initializes the distributed backend which will take care of sychronizing nodes/GPUs
torch.distributed.init_process_group(backend="nccl")

# HF transformers v4.21.2 pipeline object doesn't accept torch.device("cuda"), it has to be indexed cuda device
# TODO eventually remove once the limitation is fixed in HF transformers
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make this TODO an issue, so we can keep track in GitHub?

Copy link
Contributor

@sjrl sjrl left a comment

Choose a reason for hiding this comment

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

Looks good! Just two small comments.

@vblagoje
Copy link
Member Author

vblagoje commented Sep 8, 2022

Corrected comment and opened #3185

@vblagoje vblagoje merged commit e0d73f3 into deepset-ai:main Sep 8, 2022
@masci masci changed the title Replace torch.device("cuda") with torch.device("cuda:0") in devices initialization fix: replace torch.device("cuda") with torch.device("cuda:0") in devices initialization Sep 21, 2022
@vblagoje vblagoje deleted the fix_initialize_device branch October 24, 2022 08:21
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.

Incorrect device specified when using HF transformer pipeline object
2 participants