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

Use fp32 for router sim scores #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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