Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bert/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from torchtext.data.utils import get_tokenizer


device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
device = torch.device("cuda" if torch.cuda.is_available() else ("mps" if torch.backends.mps.is_available() else "cpu"))


class IMDBBertDataset(Dataset):
Expand Down Expand Up @@ -194,7 +194,7 @@ def _select_false_nsp_sentences(self, sentences: typing.List[str]):
return sentences[sentence_index], sentences[next_sentence_index]

def _preprocess_sentence(self, sentence: typing.List[str], should_mask: bool = True):
inverse_token_mask = None
inverse_token_mask = []
if should_mask:
sentence, inverse_token_mask = self._mask_sentence(sentence)
sentence, inverse_token_mask = self._pad_sentence([self.CLS] + sentence, [True] + inverse_token_mask)
Expand Down
2 changes: 1 addition & 1 deletion bert/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import torch.nn.functional as f


device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
device = torch.device("cuda" if torch.cuda.is_available() else ("mps" if torch.backends.mps.is_available() else "cpu"))


class JointEmbedding(nn.Module):
Expand Down
2 changes: 1 addition & 1 deletion bert/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from bert.dataset import IMDBBertDataset
from bert.model import BERT

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
device = torch.device("cuda" if torch.cuda.is_available() else ("mps" if torch.backends.mps.is_available() else "cpu"))


def percentage(batch_size: int, max_index: int, current_index: int):
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
timestamp = datetime.datetime.utcnow().timestamp()
LOG_DIR = BASE_DIR.joinpath(f'data/logs/bert_experiment_{timestamp}')

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
device = torch.device("cuda" if torch.cuda.is_available() else ("mps" if torch.backends.mps.is_available() else "cpu"))

if torch.cuda.is_available():
torch.cuda.empty_cache()
Expand Down