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

Upgrade Transformers to v4.47.x #776

Merged
merged 6 commits into from
Jan 8, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
fix
lenglaender committed Jan 7, 2025
commit 31248b47b164d26b25cfe9a20b93929f687e4e75
11 changes: 8 additions & 3 deletions src/adapters/models/deberta/modeling_deberta.py
Original file line number Diff line number Diff line change
@@ -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:
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
@@ -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)