Skip to content

Commit

Permalink
Make sure random_tokens is on correct device (#96)
Browse files Browse the repository at this point in the history
Make sure random_tokens is on correct device
  • Loading branch information
aced125 committed Aug 23, 2021
1 parent c85682e commit 7c516af
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions alphafold2_pytorch/mlm.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def noise(self, seq, mask):

random_replace_token_prob_mask = get_mask_subset_with_prob(mlm_mask, (1 - self.keep_token_same_prob) * self.random_replace_token_prob)

random_tokens = torch.randint(1, constants.NUM_AMINO_ACIDS, seq.shape)
random_tokens = torch.randint(1, constants.NUM_AMINO_ACIDS, seq.shape).to(seq.device)

for token_id in self.exclude_token_ids:
random_replace_token_prob_mask = random_replace_token_prob_mask & (random_tokens != token_id) # make sure you never substitute a token with an excluded token type (pad, start, end)
Expand All @@ -89,4 +89,4 @@ def forward(self, seq_embed, original_seq, mask):
seq_labels = original_seq[mask]

loss = F.cross_entropy(seq_logits, seq_labels, reduction = 'mean')
return loss
return loss

0 comments on commit 7c516af

Please sign in to comment.