Skip to content

Commit

Permalink
Scope out autocast in extended atten mask gen (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
ANSHUMAN87 authored Jul 10, 2023
1 parent 32f8555 commit dbefacd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion optimum/habana/transformers/models/albert/modeling_albert.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def gaudi_albert_forward(
# torch.finfo must take the dtype of encoder_extended_attention_mask
extended_attention_mask = extended_attention_mask.to(dtype=self.dtype) # bf16 compatibility
extended_attention_mask = 1.0 - extended_attention_mask
extended_attention_mask = extended_attention_mask * torch.finfo(extended_attention_mask.dtype).min
with torch.autocast(enabled=False, device_type="hpu"):
extended_attention_mask = extended_attention_mask * torch.finfo(extended_attention_mask.dtype).min
head_mask = self.get_head_mask(head_mask, self.config.num_hidden_layers)

embedding_output = self.embeddings(
Expand Down
3 changes: 2 additions & 1 deletion optimum/habana/transformers/models/modeling_all_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def gaudi_get_extended_attention_mask(
# torch.finfo must take the dtype of encoder_extended_attention_mask
extended_attention_mask = extended_attention_mask.to(dtype=dtype) # bf16 compatibility
extended_attention_mask = 1.0 - extended_attention_mask
extended_attention_mask = extended_attention_mask * torch.finfo(extended_attention_mask.dtype).min
with torch.autocast(enabled=False, device_type="hpu"):
extended_attention_mask = extended_attention_mask * torch.finfo(extended_attention_mask.dtype).min

return extended_attention_mask

Expand Down

0 comments on commit dbefacd

Please sign in to comment.