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

Making BERT_pytorch work with MPS backend #1434

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kulinseth
Copy link
Contributor

No description provided.

@@ -86,7 +86,7 @@ def __init__(self, test, device, batch_size=None, jit=False, extra_args=[]):
'--vocab_path', f'{root}/data/vocab.small',
'--output_path', 'bert.model',
]) # Avoid reading sys.argv here
args.with_cuda = self.device == 'cuda'
args.with_cuda = self.device == 'cuda' or self.device == 'mps'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Piggybacking on the cuda flag as i didn't want to create additional changes in the function signature.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest we remove the with_cuda flag and replace it with device and pass in self.device.

@@ -35,8 +35,12 @@ def __init__(self, bert: BERT, vocab_size: int,
"""

# Setup cuda device for BERT training, argument -c, --cuda should be true
cuda_condition = torch.cuda.is_available() and with_cuda
self.device = torch.device("cuda:0" if cuda_condition else "cpu")
if (with_cuda and torch.cuda.is_available()):
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, we can make it easier by using self.device = device

@@ -86,7 +86,7 @@ def __init__(self, test, device, batch_size=None, jit=False, extra_args=[]):
'--vocab_path', f'{root}/data/vocab.small',
'--output_path', 'bert.model',
]) # Avoid reading sys.argv here
args.with_cuda = self.device == 'cuda'
args.with_cuda = self.device == 'cuda' or self.device == 'mps'
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest we remove the with_cuda flag and replace it with device and pass in self.device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants