Fix tapas scatter (#20149)

* First draft

* Remove scatter dependency

* Add require_torch

* update vectorized sum test, add clone call

* remove artifacts

* fix style

* fix style v2

* remove "scatter" mentions from the code base

* fix isort error

Co-authored-by: Niels Rogge <nielsrogge@Nielss-MacBook-Pro.local>
Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
This commit is contained in:
Bartosz Szmelczynski
2022-11-14 07:04:26 +01:00
committed by GitHub
parent f711d683b5
commit 78a471ff71
19 changed files with 77 additions and 194 deletions

View File

@@ -130,8 +130,7 @@ SPEECH_TO_TEXT_TINY = "hf-internal-testing/tiny-random-speech_to_text"
# models with low usage, unstable API, things about to change - do nothing about the following until someone runs into a problem
TAPAS_TINY = "hf-internal-testing/tiny-random-tapas"
# additional notes on tapas
# 1. requires torch_scatter - skip if it's not installed?
# 2. "Table must be of type pd.DataFrame" failure
# 1. "Table must be of type pd.DataFrame" failure
# TODO: new models to add:

View File

@@ -28,7 +28,6 @@ from transformers.testing_utils import (
DUMMY_UNKNOWN_IDENTIFIER,
SMALL_MODEL_IDENTIFIER,
RequestCounter,
require_scatter,
require_torch,
slow,
)
@@ -197,7 +196,6 @@ class AutoModelTest(unittest.TestCase):
self.assertIsInstance(model, BertForQuestionAnswering)
@slow
@require_scatter
def test_table_question_answering_model_from_pretrained(self):
for model_name in TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST[5:6]:
config = AutoConfig.from_pretrained(model_name)

View File

@@ -32,7 +32,6 @@ from transformers.testing_utils import (
get_tests_dir,
is_pt_tf_cross_test,
require_pandas,
require_scatter,
require_sentencepiece,
require_tokenizers,
require_torch,
@@ -1176,7 +1175,6 @@ class LayoutXLMTokenizationTest(TokenizerTesterMixin, unittest.TestCase):
@require_torch
@slow
@require_scatter
def test_torch_encode_plus_sent_to_model(self):
import torch

View File

@@ -32,13 +32,7 @@ from transformers import (
is_torch_available,
)
from transformers.models.auto import get_values
from transformers.testing_utils import (
require_scatter,
require_tensorflow_probability,
require_torch,
slow,
torch_device,
)
from transformers.testing_utils import require_tensorflow_probability, require_torch, slow, torch_device
from transformers.utils import cached_property
from ...test_configuration_common import ConfigTester
@@ -414,7 +408,6 @@ class TapasModelTester:
@require_torch
@require_scatter
class TapasModelTest(ModelTesterMixin, unittest.TestCase):
all_model_classes = (
@@ -553,7 +546,6 @@ def prepare_tapas_batch_inputs_for_training():
@require_torch
@require_scatter
class TapasModelIntegrationTest(unittest.TestCase):
@cached_property
def default_tokenizer(self):
@@ -907,7 +899,7 @@ class TapasModelIntegrationTest(unittest.TestCase):
# Below: tests for Tapas utilities which are defined in modeling_tapas.py.
# These are based on segmented_tensor_test.py of the original implementation.
# URL: https://github.com/google-research/tapas/blob/master/tapas/models/segmented_tensor_test.py
@require_scatter
@require_torch
class TapasUtilitiesTest(unittest.TestCase):
def _prepare_tables(self):
"""Prepares two tables, both with three distinct rows.
@@ -1064,11 +1056,11 @@ class TapasUtilitiesTest(unittest.TestCase):
def test_reduce_sum_vectorized(self):
values = torch.as_tensor([[1.0, 2.0, 3.0], [2.0, 3.0, 4.0], [3.0, 4.0, 5.0]])
index = IndexMap(indices=torch.as_tensor([0, 0, 1]), num_segments=2, batch_dims=0)
index = IndexMap(indices=torch.as_tensor([[0, 0, 1]]), num_segments=2, batch_dims=0)
sums, new_index = reduce_sum(values, index)
# We use np.testing.assert_allclose rather than Tensorflow's assertAllClose
np.testing.assert_allclose(sums.numpy(), [[3.0, 5.0, 7.0], [3.0, 4.0, 5.0]])
np.testing.assert_allclose(sums.numpy(), [3.0, 3.0])
# We use np.testing.assert_array_equal rather than Tensorflow's assertAllEqual
np.testing.assert_array_equal(new_index.indices.numpy(), [0, 1])
np.testing.assert_array_equal(new_index.num_segments.numpy(), 2)

View File

@@ -35,7 +35,6 @@ from transformers.models.tapas.tokenization_tapas import (
from transformers.testing_utils import (
is_pt_tf_cross_test,
require_pandas,
require_scatter,
require_tensorflow_probability,
require_tokenizers,
require_torch,
@@ -1031,7 +1030,6 @@ class TapasTokenizationTest(TokenizerTesterMixin, unittest.TestCase):
@require_torch
@slow
@require_scatter
def test_torch_encode_plus_sent_to_model(self):
import torch

View File

@@ -50,7 +50,6 @@ from transformers.testing_utils import (
RequestCounter,
is_staging_test,
nested_simplify,
require_scatter,
require_tensorflow_probability,
require_tf,
require_torch,
@@ -749,7 +748,6 @@ class PipelineUtilsTest(unittest.TestCase):
@slow
@require_torch
@require_scatter
def test_load_default_pipelines_pt_table_qa(self):
import torch

View File

@@ -22,14 +22,7 @@ from transformers import (
TFAutoModelForTableQuestionAnswering,
pipeline,
)
from transformers.testing_utils import (
require_pandas,
require_tensorflow_probability,
require_tf,
require_torch,
require_torch_scatter,
slow,
)
from transformers.testing_utils import require_pandas, require_tensorflow_probability, require_tf, require_torch, slow
from .test_pipelines_common import PipelineTestCaseMeta
@@ -145,7 +138,6 @@ class TQAPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta):
)
@require_torch
@require_torch_scatter
def test_small_model_pt(self):
model_id = "lysandre/tiny-tapas-random-wtq"
model = AutoModelForTableQuestionAnswering.from_pretrained(model_id)
@@ -248,7 +240,6 @@ class TQAPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta):
)
@require_torch
@require_torch_scatter
def test_slow_tokenizer_sqa_pt(self):
model_id = "lysandre/tiny-tapas-random-sqa"
model = AutoModelForTableQuestionAnswering.from_pretrained(model_id)
@@ -490,7 +481,6 @@ class TQAPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta):
)
@slow
@require_torch_scatter
def test_integration_wtq_pt(self):
table_querier = pipeline("table-question-answering")
@@ -584,7 +574,6 @@ class TQAPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta):
self.assertListEqual(results, expected_results)
@slow
@require_torch_scatter
def test_integration_sqa_pt(self):
table_querier = pipeline(
"table-question-answering",