[tests] remove pt_tf equivalence tests (#36253)
This commit is contained in:
@@ -24,7 +24,7 @@ import numpy as np
|
||||
import requests
|
||||
|
||||
from transformers import GroupViTConfig, GroupViTTextConfig, GroupViTVisionConfig
|
||||
from transformers.testing_utils import is_flaky, is_pt_tf_cross_test, require_torch, require_vision, slow, torch_device
|
||||
from transformers.testing_utils import is_flaky, require_torch, require_vision, slow, torch_device
|
||||
from transformers.utils import is_torch_available, is_vision_available
|
||||
|
||||
from ...test_configuration_common import ConfigTester
|
||||
@@ -166,18 +166,6 @@ class GroupViTVisionModelTest(ModelTesterMixin, unittest.TestCase):
|
||||
def test_batching_equivalence(self):
|
||||
super().test_batching_equivalence()
|
||||
|
||||
@is_pt_tf_cross_test
|
||||
def test_pt_tf_model_equivalence(self):
|
||||
import tensorflow as tf
|
||||
|
||||
seed = 338
|
||||
random.seed(seed)
|
||||
np.random.seed(seed)
|
||||
torch.manual_seed(seed)
|
||||
torch.cuda.manual_seed_all(seed)
|
||||
tf.random.set_seed(seed)
|
||||
return super().test_pt_tf_model_equivalence()
|
||||
|
||||
def test_model_get_set_embeddings(self):
|
||||
config, _ = self.model_tester.prepare_config_and_inputs_for_common()
|
||||
|
||||
@@ -595,22 +583,6 @@ class GroupViTModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase
|
||||
def test_model_get_set_embeddings(self):
|
||||
pass
|
||||
|
||||
# overwritten from parent as this equivalent test needs a specific `seed` and hard to get a good one!
|
||||
def check_pt_tf_outputs(self, tf_outputs, pt_outputs, model_class, tol=2e-5, name="outputs", attributes=None):
|
||||
super().check_pt_tf_outputs(tf_outputs, pt_outputs, model_class, tol=tol, name=name, attributes=attributes)
|
||||
|
||||
@is_pt_tf_cross_test
|
||||
def test_pt_tf_model_equivalence(self):
|
||||
import tensorflow as tf
|
||||
|
||||
seed = 163
|
||||
random.seed(seed)
|
||||
np.random.seed(seed)
|
||||
torch.manual_seed(seed)
|
||||
torch.cuda.manual_seed_all(seed)
|
||||
tf.random.set_seed(seed)
|
||||
return super().test_pt_tf_model_equivalence()
|
||||
|
||||
# override as the `logit_scale` parameter initilization is different for GROUPVIT
|
||||
def test_initialization(self):
|
||||
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
|
||||
|
||||
@@ -23,12 +23,10 @@ import tempfile
|
||||
import unittest
|
||||
from importlib import import_module
|
||||
|
||||
import numpy as np
|
||||
import requests
|
||||
|
||||
from transformers import GroupViTConfig, GroupViTTextConfig, GroupViTVisionConfig
|
||||
from transformers.testing_utils import (
|
||||
is_pt_tf_cross_test,
|
||||
require_tensorflow_probability,
|
||||
require_tf,
|
||||
require_vision,
|
||||
@@ -149,10 +147,6 @@ class TFGroupViTVisionModelTest(TFModelTesterMixin, unittest.TestCase):
|
||||
test_head_masking = False
|
||||
test_onnx = False
|
||||
|
||||
def check_pt_tf_outputs(self, tf_outputs, pt_outputs, model_class, tol=1e-4, name="outputs", attributes=None):
|
||||
# We override with a slightly higher tol value, as this model tends to diverge a bit more
|
||||
super().check_pt_tf_outputs(tf_outputs, pt_outputs, model_class, tol, name, attributes)
|
||||
|
||||
def setUp(self):
|
||||
self.model_tester = TFGroupViTVisionModelTester(self)
|
||||
self.config_tester = ConfigTester(
|
||||
@@ -291,25 +285,6 @@ class TFGroupViTVisionModelTest(TFModelTesterMixin, unittest.TestCase):
|
||||
|
||||
check_hidden_states_output(inputs_dict, config, model_class)
|
||||
|
||||
@is_pt_tf_cross_test
|
||||
def test_pt_tf_model_equivalence(self):
|
||||
# `GroupViT` computes some indices using argmax, uses them as
|
||||
# one-hot encoding for further computation. The problem is
|
||||
# while PT/TF have very small difference in `y_soft` (~ 1e-9),
|
||||
# the argmax could be totally different, if there are at least
|
||||
# 2 indices with almost identical values. This leads to very
|
||||
# large difference in the outputs. We need specific seeds to
|
||||
# avoid almost identical values happening in `y_soft`.
|
||||
import torch
|
||||
|
||||
seed = 338
|
||||
random.seed(seed)
|
||||
np.random.seed(seed)
|
||||
torch.manual_seed(seed)
|
||||
torch.cuda.manual_seed_all(seed)
|
||||
tf.random.set_seed(seed)
|
||||
return super().test_pt_tf_model_equivalence()
|
||||
|
||||
@slow
|
||||
def test_model_from_pretrained(self):
|
||||
model_name = "nvidia/groupvit-gcc-yfcc"
|
||||
@@ -462,10 +437,6 @@ class TFGroupViTTextModelTest(TFModelTesterMixin, unittest.TestCase):
|
||||
test_head_masking = False
|
||||
test_onnx = False
|
||||
|
||||
def check_pt_tf_outputs(self, tf_outputs, pt_outputs, model_class, tol=1e-4, name="outputs", attributes=None):
|
||||
# We override with a slightly higher tol value, as this model tends to diverge a bit more
|
||||
super().check_pt_tf_outputs(tf_outputs, pt_outputs, model_class, tol, name, attributes)
|
||||
|
||||
def setUp(self):
|
||||
self.model_tester = TFGroupViTTextModelTester(self)
|
||||
self.config_tester = ConfigTester(self, config_class=GroupViTTextConfig, hidden_size=37)
|
||||
@@ -588,10 +559,6 @@ class TFGroupViTModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.Test
|
||||
test_attention_outputs = False
|
||||
test_onnx = False
|
||||
|
||||
def check_pt_tf_outputs(self, tf_outputs, pt_outputs, model_class, tol=1e-4, name="outputs", attributes=None):
|
||||
# We override with a slightly higher tol value, as this model tends to diverge a bit more
|
||||
super().check_pt_tf_outputs(tf_outputs, pt_outputs, model_class, tol, name, attributes)
|
||||
|
||||
def setUp(self):
|
||||
self.model_tester = TFGroupViTModelTester(self)
|
||||
|
||||
@@ -616,25 +583,6 @@ class TFGroupViTModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.Test
|
||||
def test_keras_fit(self):
|
||||
super().test_keras_fit()
|
||||
|
||||
@is_pt_tf_cross_test
|
||||
def test_pt_tf_model_equivalence(self):
|
||||
# `GroupViT` computes some indices using argmax, uses them as
|
||||
# one-hot encoding for further computation. The problem is
|
||||
# while PT/TF have very small difference in `y_soft` (~ 1e-9),
|
||||
# the argmax could be totally different, if there are at least
|
||||
# 2 indices with almost identical values. This leads to very
|
||||
# large difference in the outputs. We need specific seeds to
|
||||
# avoid almost identical values happening in `y_soft`.
|
||||
import torch
|
||||
|
||||
seed = 158
|
||||
random.seed(seed)
|
||||
np.random.seed(seed)
|
||||
torch.manual_seed(seed)
|
||||
torch.cuda.manual_seed_all(seed)
|
||||
tf.random.set_seed(seed)
|
||||
return super().test_pt_tf_model_equivalence()
|
||||
|
||||
# overwrite from common since `TFGroupViTModelTester` set `return_loss` to `True` and causes the preparation of
|
||||
# `symbolic_inputs` failed.
|
||||
def test_keras_save_load(self):
|
||||
|
||||
Reference in New Issue
Block a user