Better TF docstring types (#23477)

* Rework TF type hints to use | None instead of Optional[] for tf.Tensor

* Rework TF type hints to use | None instead of Optional[] for tf.Tensor

* Don't forget the imports

* Add the imports to tests too

* make fixup

* Refactor tests that depended on get_type_hints

* Better test refactor

* Fix an old hidden bug in the test_keras_fit input creation code

* Fix for the Deit tests
This commit is contained in:
Matt
2023-05-24 13:52:52 +01:00
committed by GitHub
parent 767e6b5314
commit f8b2574416
139 changed files with 2907 additions and 2621 deletions

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import AlbertConfig, is_tf_available

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import copy
import tempfile
import unittest

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import is_tf_available, is_torch_available

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import copy
import tempfile
import unittest

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import BertConfig, is_tf_available

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import BlenderbotConfig, BlenderbotTokenizer, is_tf_available

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import BlenderbotSmallConfig, BlenderbotSmallTokenizer, is_tf_available

View File

@@ -15,6 +15,8 @@
""" Testing suite for the TensorFlow Blip model. """
from __future__ import annotations
import inspect
import tempfile
import unittest

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
""" Testing suite for the TensorFlow Blip model. """
from __future__ import annotations
import unittest
import numpy as np

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import is_tf_available

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import is_tf_available

View File

@@ -15,6 +15,8 @@
""" Testing suite for the TensorFlow CLIP model. """
from __future__ import annotations
import inspect
import os
import tempfile

View File

@@ -12,6 +12,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import os
import tempfile
import unittest

View File

@@ -14,6 +14,8 @@
# limitations under the License.
""" Testing suite for the TensorFlow ConvNext model. """
from __future__ import annotations
import inspect
import unittest
from typing import List, Tuple

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import CTRLConfig, is_tf_available

View File

@@ -1,6 +1,8 @@
""" Testing suite for the Tensorflow CvT model. """
from __future__ import annotations
import inspect
import unittest
from math import floor

View File

@@ -14,6 +14,8 @@
# limitations under the License.
""" Testing suite for the TensorFlow Data2VecVision model. """
from __future__ import annotations
import collections.abc
import inspect
import unittest

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import DebertaConfig, is_tf_available

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import DebertaV2Config, is_tf_available

View File

@@ -15,6 +15,8 @@
""" Testing suite for the TensorFlow DeiT model. """
from __future__ import annotations
import inspect
import unittest
@@ -242,7 +244,7 @@ class TFDeiTModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase
inputs_dict = super()._prepare_for_class(inputs_dict, model_class, return_labels=return_labels)
if return_labels:
if model_class.__name__ == "DeiTForImageClassificationWithTeacher":
if "labels" in inputs_dict and "labels" not in inspect.signature(model_class.call).parameters:
del inputs_dict["labels"]
return inputs_dict

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import DistilBertConfig, is_tf_available

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import is_tf_available

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import ElectraConfig, is_tf_available

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import copy
import os
import tempfile

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import EsmConfig, is_tf_available

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import is_tf_available

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import FunnelConfig, is_tf_available

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import GPT2Config, is_tf_available

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import AutoTokenizer, GPTJConfig, is_tf_available

View File

@@ -15,6 +15,8 @@
""" Testing suite for the TensorFlow GroupViT model. """
from __future__ import annotations
import inspect
import os
import random

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import copy
import inspect
import math

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import unittest
import numpy as np

View File

@@ -14,6 +14,8 @@
# limitations under the License.
""" Testing suite for the TensorFlow LayoutLMv3 model. """
from __future__ import annotations
import copy
import inspect
import unittest

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import LEDConfig, is_tf_available

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import is_tf_available

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import os
import tempfile
import unittest

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import tempfile
import unittest
import warnings

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import tempfile
import unittest

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import MobileBertConfig, is_tf_available

View File

@@ -15,6 +15,8 @@
""" Testing suite for the TensorFlow MobileViT model. """
from __future__ import annotations
import inspect
import unittest

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import MPNetConfig, is_tf_available

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import is_tf_available

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import OpenAIGPTConfig, is_tf_available

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import unittest
import numpy as np

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import tempfile
import unittest

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
import json
import os
import shutil

View File

@@ -14,6 +14,8 @@
# limitations under the License.
""" Testing suite for the TensorFlow RegNet model. """
from __future__ import annotations
import inspect
import unittest
from typing import List, Tuple

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import RemBertConfig, is_tf_available

View File

@@ -15,6 +15,8 @@
""" Testing suite for the Tensorflow ResNet model. """
from __future__ import annotations
import inspect
import unittest

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import RobertaConfig, is_tf_available

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import RobertaPreLayerNormConfig, is_tf_available

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import RoFormerConfig, is_tf_available

View File

@@ -15,6 +15,8 @@
""" Testing suite for the TensorFlow SAM model. """
from __future__ import annotations
import inspect
import unittest

View File

@@ -14,6 +14,8 @@
# limitations under the License.
""" Testing suite for the TensorFlow SegFormer model. """
from __future__ import annotations
import inspect
import unittest
from typing import List, Tuple

View File

@@ -14,6 +14,8 @@
# limitations under the License.
""" Testing suite for the TensorFlow Speech2Text model. """
from __future__ import annotations
import inspect
import unittest

View File

@@ -15,6 +15,8 @@
""" Testing suite for the TF 2.0 Swin model. """
from __future__ import annotations
import inspect
import unittest

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import T5Config, is_tf_available

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import copy
import unittest

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import random
import unittest

View File

@@ -15,6 +15,8 @@
""" Testing suite for the TensorFlow VisionEncoderDecoder model. """
from __future__ import annotations
import copy
import os
import tempfile

View File

@@ -15,6 +15,8 @@
""" Testing suite for the PyTorch VisionTextDualEncoder model. """
from __future__ import annotations
import collections
import tempfile
import unittest

View File

@@ -15,6 +15,8 @@
""" Testing suite for the TensorFlow ViT model. """
from __future__ import annotations
import inspect
import unittest

View File

@@ -15,6 +15,8 @@
""" Testing suite for the TensorFlow ViTMAE model. """
from __future__ import annotations
import copy
import inspect
import json

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import copy
import glob
import inspect

View File

@@ -14,6 +14,8 @@
# limitations under the License.
""" Testing suite for the TensorFlow Whisper model. """
from __future__ import annotations
import inspect
import tempfile
import traceback

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import XGLMConfig, XGLMTokenizer, is_tf_available

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import is_tf_available

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import unittest
from transformers import is_tf_available

View File

@@ -14,6 +14,8 @@
# limitations under the License.
from __future__ import annotations
import inspect
import random
import unittest