Skip to content
Open
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
14 changes: 11 additions & 3 deletions dpr_scale/task/citadel_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import torch
from pytorch_lightning.strategies import DDPShardedStrategy, DDPStrategy
from dpr_scale.task.dpr_task import DenseRetrieverTask
from torch.cuda.amp import autocast


class MultiVecRetrieverTask(DenseRetrieverTask):
def __init__(
Expand Down Expand Up @@ -144,9 +146,15 @@ def sim_score(self, query_repr, context_repr, mask=None, pairwise=False):
if mask is not None:
scores[mask] = float("-inf")
else:
scores = torch.matmul(
query_repr, torch.transpose(context_repr, 0, 1)
) # num_q x num_ctx
if self.trainer.precision == 16:
with autocast(enabled=False):
scores = torch.matmul(
query_repr, torch.transpose(context_repr, 0, 1)
) # num_q x num_ctx
else:
scores = torch.matmul(
query_repr, torch.transpose(context_repr, 0, 1)
) # num_q x num_ctx
if mask is not None:
# mask is size num_ctx
scores[mask.repeat(scores.size(0), 1)] = float("-inf")
Expand Down