Skip to content

Commit

Permalink
Fix float out of range in owlvit and owlv2 when using FP16 or lower p…
Browse files Browse the repository at this point in the history
…recision (#31657)
  • Loading branch information
aliencaocao authored Jun 27, 2024
1 parent 75a6319 commit e44b878
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/transformers/models/owlv2/modeling_owlv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ def forward(
if query_mask.ndim > 1:
query_mask = torch.unsqueeze(query_mask, dim=-2)

pred_logits = torch.where(query_mask == 0, -1e6, pred_logits)
pred_logits = torch.where(query_mask == 0, torch.finfo(pred_logits.dtype).min, pred_logits)
pred_logits = pred_logits.to(torch.float32)

return (pred_logits, image_class_embeds)
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/models/owlvit/modeling_owlvit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ def forward(
if query_mask.ndim > 1:
query_mask = torch.unsqueeze(query_mask, dim=-2)

pred_logits = torch.where(query_mask == 0, -1e6, pred_logits)
pred_logits = torch.where(query_mask == 0, torch.finfo(pred_logits.dtype).min, pred_logits)
pred_logits = pred_logits.to(torch.float32)

return (pred_logits, image_class_embeds)
Expand Down

0 comments on commit e44b878

Please sign in to comment.