Skip to content

Commit

Permalink
Update forward signature test for vision models (#27681)
Browse files Browse the repository at this point in the history
* Update forward signature

* Empty-Commit
  • Loading branch information
NielsRogge authored Nov 27, 2023
1 parent 1d7f406 commit 59499bb
Show file tree
Hide file tree
Showing 48 changed files with 1 addition and 612 deletions.
13 changes: 0 additions & 13 deletions tests/models/beit/test_modeling_beit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
""" Testing suite for the PyTorch BEiT model. """


import inspect
import unittest

from datasets import load_dataset
Expand Down Expand Up @@ -236,18 +235,6 @@ def test_model_common_attributes(self):
x = model.get_output_embeddings()
self.assertTrue(x is None or isinstance(x, nn.Linear))

def test_forward_signature(self):
config, _ = self.model_tester.prepare_config_and_inputs_for_common()

for model_class in self.all_model_classes:
model = model_class(config)
signature = inspect.signature(model.forward)
# signature.parameters is an OrderedDict => so arg_names order is deterministic
arg_names = [*signature.parameters.keys()]

expected_arg_names = ["pixel_values"]
self.assertListEqual(arg_names[:1], expected_arg_names)

def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_model(*config_and_inputs)
Expand Down
13 changes: 0 additions & 13 deletions tests/models/bit/test_modeling_bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
""" Testing suite for the PyTorch Bit model. """


import inspect
import unittest

from transformers import BitConfig
Expand Down Expand Up @@ -202,18 +201,6 @@ def test_inputs_embeds(self):
def test_model_common_attributes(self):
pass

def test_forward_signature(self):
config, _ = self.model_tester.prepare_config_and_inputs_for_common()

for model_class in self.all_model_classes:
model = model_class(config)
signature = inspect.signature(model.forward)
# signature.parameters is an OrderedDict => so arg_names order is deterministic
arg_names = [*signature.parameters.keys()]

expected_arg_names = ["pixel_values"]
self.assertListEqual(arg_names[:1], expected_arg_names)

def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_model(*config_and_inputs)
Expand Down
13 changes: 0 additions & 13 deletions tests/models/convnext/test_modeling_convnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
""" Testing suite for the PyTorch ConvNext model. """


import inspect
import unittest

from transformers import ConvNextConfig
Expand Down Expand Up @@ -212,18 +211,6 @@ def test_model_common_attributes(self):
def test_feed_forward_chunking(self):
pass

def test_forward_signature(self):
config, _ = self.model_tester.prepare_config_and_inputs_for_common()

for model_class in self.all_model_classes:
model = model_class(config)
signature = inspect.signature(model.forward)
# signature.parameters is an OrderedDict => so arg_names order is deterministic
arg_names = [*signature.parameters.keys()]

expected_arg_names = ["pixel_values"]
self.assertListEqual(arg_names[:1], expected_arg_names)

def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_model(*config_and_inputs)
Expand Down
13 changes: 0 additions & 13 deletions tests/models/convnextv2/test_modeling_convnextv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
""" Testing suite for the PyTorch ConvNextV2 model. """


import inspect
import unittest

from transformers import ConvNextV2Config
Expand Down Expand Up @@ -265,18 +264,6 @@ def test_training_gradient_checkpointing(self):
loss = model(**inputs).loss
loss.backward()

def test_forward_signature(self):
config, _ = self.model_tester.prepare_config_and_inputs_for_common()

for model_class in self.all_model_classes:
model = model_class(config)
signature = inspect.signature(model.forward)
# signature.parameters is an OrderedDict => so arg_names order is deterministic
arg_names = [*signature.parameters.keys()]

expected_arg_names = ["pixel_values"]
self.assertListEqual(arg_names[:1], expected_arg_names)

def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_model(*config_and_inputs)
Expand Down
13 changes: 0 additions & 13 deletions tests/models/cvt/test_modeling_cvt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
""" Testing suite for the PyTorch CvT model. """


import inspect
import unittest
from math import floor

Expand Down Expand Up @@ -191,18 +190,6 @@ def test_inputs_embeds(self):
def test_model_common_attributes(self):
pass

def test_forward_signature(self):
config, _ = self.model_tester.prepare_config_and_inputs_for_common()

for model_class in self.all_model_classes:
model = model_class(config)
signature = inspect.signature(model.forward)
# signature.parameters is an OrderedDict => so arg_names order is deterministic
arg_names = [*signature.parameters.keys()]

expected_arg_names = ["pixel_values"]
self.assertListEqual(arg_names[:1], expected_arg_names)

def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_model(*config_and_inputs)
Expand Down
13 changes: 0 additions & 13 deletions tests/models/data2vec/test_modeling_data2vec_vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
""" Testing suite for the PyTorch Data2VecVision model. """


import inspect
import unittest

from transformers import Data2VecVisionConfig
Expand Down Expand Up @@ -220,18 +219,6 @@ def test_model_common_attributes(self):
x = model.get_output_embeddings()
self.assertTrue(x is None or isinstance(x, nn.Linear))

def test_forward_signature(self):
config, _ = self.model_tester.prepare_config_and_inputs_for_common()

for model_class in self.all_model_classes:
model = model_class(config)
signature = inspect.signature(model.forward)
# signature.parameters is an OrderedDict => so arg_names order is deterministic
arg_names = [*signature.parameters.keys()]

expected_arg_names = ["pixel_values"]
self.assertListEqual(arg_names[:1], expected_arg_names)

def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_model(*config_and_inputs)
Expand Down
13 changes: 0 additions & 13 deletions tests/models/deit/test_modeling_deit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
""" Testing suite for the PyTorch DeiT model. """


import inspect
import unittest
import warnings

Expand Down Expand Up @@ -238,18 +237,6 @@ def test_model_common_attributes(self):
x = model.get_output_embeddings()
self.assertTrue(x is None or isinstance(x, nn.Linear))

def test_forward_signature(self):
config, _ = self.model_tester.prepare_config_and_inputs_for_common()

for model_class in self.all_model_classes:
model = model_class(config)
signature = inspect.signature(model.forward)
# signature.parameters is an OrderedDict => so arg_names order is deterministic
arg_names = [*signature.parameters.keys()]

expected_arg_names = ["pixel_values"]
self.assertListEqual(arg_names[:1], expected_arg_names)

def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_model(*config_and_inputs)
Expand Down
13 changes: 0 additions & 13 deletions tests/models/dinat/test_modeling_dinat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
""" Testing suite for the PyTorch Dinat model. """

import collections
import inspect
import unittest

from transformers import DinatConfig
Expand Down Expand Up @@ -264,18 +263,6 @@ def test_model_common_attributes(self):
x = model.get_output_embeddings()
self.assertTrue(x is None or isinstance(x, nn.Linear))

def test_forward_signature(self):
config, _ = self.model_tester.prepare_config_and_inputs_for_common()

for model_class in self.all_model_classes:
model = model_class(config)
signature = inspect.signature(model.forward)
# signature.parameters is an OrderedDict => so arg_names order is deterministic
arg_names = [*signature.parameters.keys()]

expected_arg_names = ["pixel_values"]
self.assertListEqual(arg_names[:1], expected_arg_names)

def test_attention_outputs(self):
self.skipTest("Dinat's attention operation is handled entirely by NATTEN.")

Expand Down
13 changes: 0 additions & 13 deletions tests/models/dinov2/test_modeling_dinov2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
""" Testing suite for the PyTorch Dinov2 model. """


import inspect
import unittest

from transformers import Dinov2Config
Expand Down Expand Up @@ -265,18 +264,6 @@ def test_model_common_attributes(self):
x = model.get_output_embeddings()
self.assertTrue(x is None or isinstance(x, nn.Linear))

def test_forward_signature(self):
config, _ = self.model_tester.prepare_config_and_inputs_for_common()

for model_class in self.all_model_classes:
model = model_class(config)
signature = inspect.signature(model.forward)
# signature.parameters is an OrderedDict => so arg_names order is deterministic
arg_names = [*signature.parameters.keys()]

expected_arg_names = ["pixel_values"]
self.assertListEqual(arg_names[:1], expected_arg_names)

def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_model(*config_and_inputs)
Expand Down
13 changes: 0 additions & 13 deletions tests/models/donut/test_modeling_donut_swin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
""" Testing suite for the PyTorch Donut Swin model. """

import collections
import inspect
import unittest

from transformers import DonutSwinConfig
Expand Down Expand Up @@ -186,18 +185,6 @@ def test_model_common_attributes(self):
x = model.get_output_embeddings()
self.assertTrue(x is None or isinstance(x, nn.Linear))

def test_forward_signature(self):
config, _ = self.model_tester.prepare_config_and_inputs_for_common()

for model_class in self.all_model_classes:
model = model_class(config)
signature = inspect.signature(model.forward)
# signature.parameters is an OrderedDict => so arg_names order is deterministic
arg_names = [*signature.parameters.keys()]

expected_arg_names = ["pixel_values"]
self.assertListEqual(arg_names[:1], expected_arg_names)

def test_attention_outputs(self):
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
config.return_dict = True
Expand Down
13 changes: 0 additions & 13 deletions tests/models/dpt/test_modeling_dpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
""" Testing suite for the PyTorch DPT model. """


import inspect
import unittest

from transformers import DPTConfig
Expand Down Expand Up @@ -195,18 +194,6 @@ def test_model_common_attributes(self):
x = model.get_output_embeddings()
self.assertTrue(x is None or isinstance(x, nn.Linear))

def test_forward_signature(self):
config, _ = self.model_tester.prepare_config_and_inputs_for_common()

for model_class in self.all_model_classes:
model = model_class(config)
signature = inspect.signature(model.forward)
# signature.parameters is an OrderedDict => so arg_names order is deterministic
arg_names = [*signature.parameters.keys()]

expected_arg_names = ["pixel_values"]
self.assertListEqual(arg_names[:1], expected_arg_names)

def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_model(*config_and_inputs)
Expand Down
13 changes: 0 additions & 13 deletions tests/models/dpt/test_modeling_dpt_auto_backbone.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
""" Testing suite for the PyTorch DPT model. """


import inspect
import unittest

from transformers import Dinov2Config, DPTConfig
Expand Down Expand Up @@ -154,18 +153,6 @@ def test_config(self):
def test_inputs_embeds(self):
pass

def test_forward_signature(self):
config, _ = self.model_tester.prepare_config_and_inputs_for_common()

for model_class in self.all_model_classes:
model = model_class(config)
signature = inspect.signature(model.forward)
# signature.parameters is an OrderedDict => so arg_names order is deterministic
arg_names = [*signature.parameters.keys()]

expected_arg_names = ["pixel_values"]
self.assertListEqual(arg_names[:1], expected_arg_names)

def test_for_depth_estimation(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_for_depth_estimation(*config_and_inputs)
Expand Down
13 changes: 0 additions & 13 deletions tests/models/dpt/test_modeling_dpt_hybrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
""" Testing suite for the PyTorch DPT model. """


import inspect
import unittest

from transformers import DPTConfig
Expand Down Expand Up @@ -209,18 +208,6 @@ def test_model_common_attributes(self):
x = model.get_output_embeddings()
self.assertTrue(x is None or isinstance(x, nn.Linear))

def test_forward_signature(self):
config, _ = self.model_tester.prepare_config_and_inputs_for_common()

for model_class in self.all_model_classes:
model = model_class(config)
signature = inspect.signature(model.forward)
# signature.parameters is an OrderedDict => so arg_names order is deterministic
arg_names = [*signature.parameters.keys()]

expected_arg_names = ["pixel_values"]
self.assertListEqual(arg_names[:1], expected_arg_names)

def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_model(*config_and_inputs)
Expand Down
13 changes: 0 additions & 13 deletions tests/models/efficientformer/test_modeling_efficientformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
""" Testing suite for the PyTorch EfficientFormer model. """


import inspect
import unittest
import warnings
from typing import List
Expand Down Expand Up @@ -223,18 +222,6 @@ def test_inputs_embeds(self):
def test_model_common_attributes(self):
pass

def test_forward_signature(self):
config, _ = self.model_tester.prepare_config_and_inputs_for_common()

for model_class in self.all_model_classes:
model = model_class(config)
signature = inspect.signature(model.forward)
# signature.parameters is an OrderedDict => so arg_names order is deterministic
arg_names = [*signature.parameters.keys()]

expected_arg_names = ["pixel_values"]
self.assertListEqual(arg_names[:1], expected_arg_names)

def test_hidden_states_output(self):
def check_hidden_states_output(inputs_dict, config, model_class):
model = model_class(config)
Expand Down
Loading

0 comments on commit 59499bb

Please sign in to comment.