Add torch >=1.12 requirement for Tapas (#24251)
* fix * fix * fix * Update src/transformers/models/tapas/modeling_tapas.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * fix --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com> Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
This commit is contained in:
@@ -32,6 +32,7 @@ from ...modeling_utils import PreTrainedModel
|
|||||||
from ...pytorch_utils import (
|
from ...pytorch_utils import (
|
||||||
apply_chunking_to_forward,
|
apply_chunking_to_forward,
|
||||||
find_pruneable_heads_and_indices,
|
find_pruneable_heads_and_indices,
|
||||||
|
is_torch_greater_or_equal_than_1_12,
|
||||||
prune_linear_layer,
|
prune_linear_layer,
|
||||||
)
|
)
|
||||||
from ...utils import (
|
from ...utils import (
|
||||||
@@ -46,6 +47,12 @@ from .configuration_tapas import TapasConfig
|
|||||||
|
|
||||||
logger = logging.get_logger(__name__)
|
logger = logging.get_logger(__name__)
|
||||||
|
|
||||||
|
if not is_torch_greater_or_equal_than_1_12:
|
||||||
|
logger.warning(
|
||||||
|
f"You are using torch=={torch.__version__}, but torch>=1.12.0 is required to use "
|
||||||
|
"TapasModel. Please upgrade torch."
|
||||||
|
)
|
||||||
|
|
||||||
_CONFIG_FOR_DOC = "TapasConfig"
|
_CONFIG_FOR_DOC = "TapasConfig"
|
||||||
_CHECKPOINT_FOR_DOC = "google/tapas-base"
|
_CHECKPOINT_FOR_DOC = "google/tapas-base"
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ logger = logging.get_logger(__name__)
|
|||||||
parsed_torch_version_base = version.parse(version.parse(torch.__version__).base_version)
|
parsed_torch_version_base = version.parse(version.parse(torch.__version__).base_version)
|
||||||
|
|
||||||
is_torch_greater_or_equal_than_2_0 = parsed_torch_version_base >= version.parse("2.0")
|
is_torch_greater_or_equal_than_2_0 = parsed_torch_version_base >= version.parse("2.0")
|
||||||
|
is_torch_greater_or_equal_than_1_12 = parsed_torch_version_base >= version.parse("1.12")
|
||||||
is_torch_greater_or_equal_than_1_10 = parsed_torch_version_base >= version.parse("1.10")
|
is_torch_greater_or_equal_than_1_10 = parsed_torch_version_base >= version.parse("1.10")
|
||||||
is_torch_less_than_1_11 = parsed_torch_version_base < version.parse("1.11")
|
is_torch_less_than_1_11 = parsed_torch_version_base < version.parse("1.11")
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ if is_torch_available():
|
|||||||
GPTBigCodeModel,
|
GPTBigCodeModel,
|
||||||
)
|
)
|
||||||
from transformers.models.gpt_bigcode.modeling_gpt_bigcode import GPTBigCodeAttention
|
from transformers.models.gpt_bigcode.modeling_gpt_bigcode import GPTBigCodeAttention
|
||||||
|
from transformers.pytorch_utils import is_torch_greater_or_equal_than_1_12
|
||||||
|
else:
|
||||||
|
is_torch_greater_or_equal_than_1_12 = False
|
||||||
|
|
||||||
|
|
||||||
class GPTBigCodeModelTester:
|
class GPTBigCodeModelTester:
|
||||||
@@ -530,6 +533,10 @@ class GPTBigCodeMHAModelTest(GPTBigCodeModelTest):
|
|||||||
multi_query = False
|
multi_query = False
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipIf(
|
||||||
|
not is_torch_greater_or_equal_than_1_12,
|
||||||
|
reason="`GPTBigCode` checkpoints use `PytorchGELUTanh` which requires `torch>=1.12.0`.",
|
||||||
|
)
|
||||||
@slow
|
@slow
|
||||||
@require_torch
|
@require_torch
|
||||||
class GPTBigCodeModelLanguageGenerationTest(unittest.TestCase):
|
class GPTBigCodeModelLanguageGenerationTest(unittest.TestCase):
|
||||||
|
|||||||
@@ -60,6 +60,9 @@ if is_torch_available():
|
|||||||
reduce_mean,
|
reduce_mean,
|
||||||
reduce_sum,
|
reduce_sum,
|
||||||
)
|
)
|
||||||
|
from transformers.pytorch_utils import is_torch_greater_or_equal_than_1_12
|
||||||
|
else:
|
||||||
|
is_torch_greater_or_equal_than_1_12 = False
|
||||||
|
|
||||||
|
|
||||||
class TapasModelTester:
|
class TapasModelTester:
|
||||||
@@ -408,6 +411,7 @@ class TapasModelTester:
|
|||||||
return config, inputs_dict
|
return config, inputs_dict
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipIf(not is_torch_greater_or_equal_than_1_12, reason="Tapas is only available in torch v1.12+")
|
||||||
@require_torch
|
@require_torch
|
||||||
class TapasModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase):
|
class TapasModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase):
|
||||||
all_model_classes = (
|
all_model_classes = (
|
||||||
@@ -562,6 +566,7 @@ def prepare_tapas_batch_inputs_for_training():
|
|||||||
return table, queries, answer_coordinates, answer_text, float_answer
|
return table, queries, answer_coordinates, answer_text, float_answer
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipIf(not is_torch_greater_or_equal_than_1_12, reason="Tapas is only available in torch v1.12+")
|
||||||
@require_torch
|
@require_torch
|
||||||
class TapasModelIntegrationTest(unittest.TestCase):
|
class TapasModelIntegrationTest(unittest.TestCase):
|
||||||
@cached_property
|
@cached_property
|
||||||
@@ -916,6 +921,7 @@ class TapasModelIntegrationTest(unittest.TestCase):
|
|||||||
# Below: tests for Tapas utilities which are defined in modeling_tapas.py.
|
# Below: tests for Tapas utilities which are defined in modeling_tapas.py.
|
||||||
# These are based on segmented_tensor_test.py of the original implementation.
|
# 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
|
# URL: https://github.com/google-research/tapas/blob/master/tapas/models/segmented_tensor_test.py
|
||||||
|
@unittest.skipIf(not is_torch_greater_or_equal_than_1_12, reason="Tapas is only available in torch v1.12+")
|
||||||
@require_torch
|
@require_torch
|
||||||
class TapasUtilitiesTest(unittest.TestCase):
|
class TapasUtilitiesTest(unittest.TestCase):
|
||||||
def _prepare_tables(self):
|
def _prepare_tables(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user