Fix ONNX exports for Optimum compatible models (#31311)

* fixed models

* format with bumped ruff version on my local

* fix copies

* add tracing checks

* format

* Update src/transformers/utils/generic.py

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>

* format

* style fix

* Update modeling_mobilevit.py

* add docstring and change name

* Update __init__.py

* Update __init__.py

---------

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
This commit is contained in:
Merve Noyan
2024-06-27 12:46:36 +03:00
committed by GitHub
parent dc76e9fa7f
commit c9f191a0b7
10 changed files with 72 additions and 17 deletions

View File

@@ -15,7 +15,6 @@
"""PyTorch SAM model."""
import collections
import math
from dataclasses import dataclass
from typing import Dict, List, Optional, Tuple, Union
@@ -232,7 +231,7 @@ class SamAttention(nn.Module):
# SamAttention
_, _, _, c_per_head = query.shape
attn = query @ key.permute(0, 1, 3, 2) # batch_size * point_batch_size x N_heads x N_tokens x N_tokens
attn = attn / math.sqrt(c_per_head)
attn = attn / (c_per_head**0.5)
attn = torch.softmax(attn, dim=-1)
if attention_similarity is not None: