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

@@ -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