Time to Say Goodbye, torch 1.7 and 1.8 (#22291)
* time to say goodbye, torch 1.7 and 1.8 * clean up torch_int_div * clean up is_torch_less_than_1_8-9 * update --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
This commit is contained in:
@@ -38,10 +38,9 @@ if is_torch_available():
|
||||
BloomModel,
|
||||
BloomTokenizerFast,
|
||||
)
|
||||
from transformers.pytorch_utils import is_torch_greater_or_equal_than_1_10, is_torch_less_than_1_9
|
||||
from transformers.pytorch_utils import is_torch_greater_or_equal_than_1_10
|
||||
else:
|
||||
is_torch_greater_or_equal_than_1_10 = False
|
||||
is_torch_less_than_1_9 = True
|
||||
|
||||
|
||||
@require_torch
|
||||
@@ -751,9 +750,6 @@ class BloomEmbeddingTest(unittest.TestCase):
|
||||
self.assertAlmostEqual(EMBEDDINGS_DS_AFTER_LN[key][idx], output_dict_norm[key][idx], places=1)
|
||||
|
||||
@require_torch
|
||||
@unittest.skipIf(
|
||||
is_torch_less_than_1_9, reason="Test failed with torch < 1.9 (`min_cuda` not implemented for `BFloat16`)"
|
||||
)
|
||||
def test_hidden_states_transformers(self):
|
||||
cuda_available = torch.cuda.is_available()
|
||||
model = BloomModel.from_pretrained(self.path_bigscience_model, use_cache=False, torch_dtype="auto").to(
|
||||
|
||||
@@ -32,9 +32,6 @@ if is_torch_available():
|
||||
import torch
|
||||
|
||||
from transformers import MCTCTForCTC, MCTCTModel, MCTCTProcessor
|
||||
from transformers.pytorch_utils import is_torch_less_than_1_9
|
||||
else:
|
||||
is_torch_less_than_1_9 = True
|
||||
|
||||
|
||||
class MCTCTModelTester:
|
||||
@@ -265,7 +262,6 @@ class MCTCTModelTester:
|
||||
|
||||
|
||||
@require_torch
|
||||
@unittest.skipIf(is_torch_less_than_1_9, "MCTCT is only available in torch v1.9+")
|
||||
class MCTCTModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase):
|
||||
all_model_classes = (MCTCTForCTC, MCTCTModel) if is_torch_available() else ()
|
||||
pipeline_model_mapping = (
|
||||
|
||||
@@ -33,9 +33,7 @@ if is_torch_available():
|
||||
|
||||
from transformers import SwinBackbone, SwinForImageClassification, SwinForMaskedImageModeling, SwinModel
|
||||
from transformers.models.swin.modeling_swin import SWIN_PRETRAINED_MODEL_ARCHIVE_LIST
|
||||
from transformers.pytorch_utils import is_torch_less_than_1_9
|
||||
else:
|
||||
is_torch_less_than_1_9 = True
|
||||
|
||||
|
||||
if is_vision_available():
|
||||
from PIL import Image
|
||||
@@ -266,7 +264,6 @@ class SwinModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase):
|
||||
def test_multi_gpu_data_parallel_forward(self):
|
||||
pass
|
||||
|
||||
@unittest.skipIf(is_torch_less_than_1_9, reason="This test fails for SwinModel when torch < 1.9")
|
||||
def test_training_gradient_checkpointing(self):
|
||||
super().test_training_gradient_checkpointing()
|
||||
|
||||
|
||||
@@ -36,9 +36,6 @@ if is_torch_available():
|
||||
from transformers.models.trajectory_transformer.modeling_trajectory_transformer import (
|
||||
TRAJECTORY_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
|
||||
)
|
||||
from transformers.pytorch_utils import is_torch_less_than_1_9
|
||||
else:
|
||||
is_torch_less_than_1_9 = True
|
||||
|
||||
|
||||
class TrajectoryTransformerModelTester:
|
||||
@@ -199,7 +196,6 @@ class TrajectoryTransformerModelTest(ModelTesterMixin, GenerationTesterMixin, Pi
|
||||
).loss
|
||||
loss.backward()
|
||||
|
||||
@unittest.skipIf(is_torch_less_than_1_9, reason="This test fails for TrajectoryTransformerModel when torch < 1.9")
|
||||
def test_training_gradient_checkpointing(self):
|
||||
if not self.model_tester.is_training:
|
||||
return
|
||||
|
||||
@@ -71,9 +71,6 @@ if is_torch_available():
|
||||
_compute_mask_indices,
|
||||
_sample_negative_indices,
|
||||
)
|
||||
from transformers.pytorch_utils import is_torch_less_than_1_9, torch_int_div
|
||||
else:
|
||||
is_torch_less_than_1_9 = True
|
||||
|
||||
|
||||
if is_torchaudio_available():
|
||||
@@ -1217,7 +1214,9 @@ class Wav2Vec2UtilsTest(unittest.TestCase):
|
||||
sequence_length = 10
|
||||
hidden_size = 4
|
||||
num_negatives = 3
|
||||
sequence = torch_int_div(torch.arange(sequence_length * hidden_size, device=torch_device), hidden_size)
|
||||
sequence = torch.div(
|
||||
torch.arange(sequence_length * hidden_size, device=torch_device), hidden_size, rounding_mode="floor"
|
||||
)
|
||||
features = sequence.view(sequence_length, hidden_size) # each value in vector consits of same value
|
||||
features = features[None, :].expand(batch_size, sequence_length, hidden_size).contiguous()
|
||||
|
||||
@@ -1245,7 +1244,9 @@ class Wav2Vec2UtilsTest(unittest.TestCase):
|
||||
mask = torch.ones((batch_size, sequence_length), dtype=torch.long, device=torch_device)
|
||||
mask[-1, sequence_length // 2 :] = 0
|
||||
|
||||
sequence = torch_int_div(torch.arange(sequence_length * hidden_size, device=torch_device), hidden_size)
|
||||
sequence = torch.div(
|
||||
torch.arange(sequence_length * hidden_size, device=torch_device), hidden_size, rounding_mode="floor"
|
||||
)
|
||||
features = sequence.view(sequence_length, hidden_size) # each value in vector consits of same value
|
||||
features = features[None, :].expand(batch_size, sequence_length, hidden_size).contiguous()
|
||||
|
||||
@@ -1651,10 +1652,6 @@ class Wav2Vec2ModelIntegrationTest(unittest.TestCase):
|
||||
|
||||
@require_pyctcdecode
|
||||
@require_torchaudio
|
||||
@unittest.skipIf(
|
||||
is_torch_less_than_1_9,
|
||||
reason="`torchaudio.functional.resample` needs torchaudio >= 0.9 which requires torch >= 0.9",
|
||||
)
|
||||
def test_wav2vec2_with_lm(self):
|
||||
ds = load_dataset("common_voice", "es", split="test", streaming=True)
|
||||
sample = next(iter(ds))
|
||||
@@ -1679,10 +1676,6 @@ class Wav2Vec2ModelIntegrationTest(unittest.TestCase):
|
||||
|
||||
@require_pyctcdecode
|
||||
@require_torchaudio
|
||||
@unittest.skipIf(
|
||||
is_torch_less_than_1_9,
|
||||
reason="`torchaudio.functional.resample` needs torchaudio >= 0.9 which requires torch >= 0.9",
|
||||
)
|
||||
def test_wav2vec2_with_lm_pool(self):
|
||||
ds = load_dataset("common_voice", "es", split="test", streaming=True)
|
||||
sample = next(iter(ds))
|
||||
|
||||
Reference in New Issue
Block a user