Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lenglaender committed Jan 7, 2025
1 parent dee1023 commit 31248b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/adapters/models/deberta/modeling_deberta.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,15 @@ def forward(

if rel_att is not None:
# >>> START AH Changes <<<
rel_att_padded = torch.zeros_like(attention_scores)
rel_att_padded[:, :, :, -rel_att.size(-1) :] = rel_att
# rel_att is set to 0 by default, i.e. rel_att is always not None (don't know why HuggingFace does this).
# Hence, we must check whether rel_att is a tensor and if so, pad it with zeros to be able to add it to attention_scores.
if isinstance(rel_att, torch.Tensor):
rel_att_padded = torch.zeros_like(attention_scores)
rel_att_padded[:, :, :, -rel_att.size(-1) :] = rel_att
attention_scores = attention_scores + rel_att_padded
else:
attention_scores = attention_scores + rel_att
# >>> END AH Changes <<<
attention_scores = attention_scores + rel_att_padded

# bxhxlxd
if self.head_logits_proj is not None:
Expand Down
12 changes: 11 additions & 1 deletion src/adapters/models/deberta_v2/modeling_deberta_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,17 @@ def forward(
# >>> END AH Changes <<<

if rel_att is not None:
attention_scores = attention_scores + rel_att
# >>> START AH Changes <<<
# rel_att is set to 0 by default, i.e. rel_att is always not None (don't know why HuggingFace does this).
# Hence, we must check whether rel_att is a tensor and if so, pad it with zeros to be able to add it to attention_scores.
if isinstance(rel_att, torch.Tensor):
rel_att_padded = torch.zeros_like(attention_scores)
rel_att_padded[:, :, -rel_att.size(2) :] = rel_att
attention_scores = attention_scores + rel_att_padded
else:
attention_scores = attention_scores + rel_att
# >>> END AH Changes <<<

attention_scores = attention_scores
attention_scores = attention_scores.view(
-1, self.num_attention_heads, attention_scores.size(-2), attention_scores.size(-1)
Expand Down

0 comments on commit 31248b4

Please sign in to comment.