hunk.code_window:             # don't attend to padding symbols
               if utils.item(key_padding_mask.max()) > 0:
                   attn_weights = attn_weights.view(bsz, self.num_heads, tgt_len, src_len)
                   attn_weights = attn_weights.masked_fill(
                       key_padding_mask.unsqueeze(1).unsqueeze(2),
                       -math.inf,
                   )
                   attn_weights = attn_weights.view(bsz * self.num_heads, tgt_len, src_len)
           attn_weights = F.softmax(attn_weights, dim=-1)
           attn_weights = F.dropout(attn_weights, p=self.dropout, training=self.training)
           attn = torch.bmm(attn_weights, v)
           assert list(attn.size()) == [bsz * self.num_heads, tgt_len, self.head_dim]
  
hunk.labels: keep replace replace replace replace replace replace replace keep keep keep keep keep
hunk.after_edit:             attn_weights = attn_weights.view(bsz, self.num_heads, tgt_len, src_len)
               attn_weights = attn_weights.masked_fill(
                   key_padding_mask.unsqueeze(1).unsqueeze(2),
                   -math.inf,
               )
               attn_weights = attn_weights.view(bsz * self.num_heads, tgt_len, src_len)
  
hunk.file_path: fairseq/modules/multihead_attention.py
hunk.type: replace
file: # Copyright (c) 2017-present, Facebook, Inc.
  # All rights reserved.
  #
  # This source code is licensed under the license found in the LICENSE file in
  # the root directory of this source tree. An additional grant of patent rights
  # can be found in the PATENTS file in the same directory.
  
  import torch
  
  
  class GradMultiply(torch.autograd.Function):
      @staticmethod
      def forward(ctx, x, scale):
          ctx.scale = scale
          res = x.new(x)
          ctx.mark_shared_storage((x, res))
          return res
  
      @staticmethod
      def backward(ctx, grad):
          return grad * ctx.scale, None
  