-
Notifications
You must be signed in to change notification settings - Fork 254
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
base: main
Are you sure you want to change the base?
Conversation
@@ -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' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()): |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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
.
No description provided.