Skip to content

Commit

Permalink
fix scores mask
Browse files Browse the repository at this point in the history
  • Loading branch information
GeeeekExplorer authored Feb 14, 2025
1 parent 2f7b80e commit 1398800
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions inference/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,8 @@ def forward(self, x: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
else:
group_scores = scores.topk(2, dim=-1)[0].sum(dim=-1)
indices = group_scores.topk(self.topk_groups, dim=-1)[1]
mask = torch.zeros_like(scores[..., 0]).scatter_(1, indices, True)
scores = (scores * mask.unsqueeze(-1)).flatten(1)
mask = scores.new_ones(x.size(0), self.n_groups, dtype=bool).scatter_(1, indices, False)
scores = scores.masked_fill_(mask.unsqueeze(-1), float("-inf")).flatten(1)
indices = torch.topk(scores, self.topk, dim=-1)[1]
weights = original_scores.gather(1, indices)
if self.score_func == "sigmoid":
Expand Down

0 comments on commit 1398800

Please sign in to comment.