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:
Yih-Dar
2023-03-21 19:22:01 +01:00
committed by GitHub
parent 86c7931a70
commit 67c2dbdb54
42 changed files with 61 additions and 149 deletions

View File

@@ -32,7 +32,6 @@ if is_torch_available():
DisjunctiveConstraint,
PhrasalConstraint,
)
from transformers.pytorch_utils import torch_int_div
class BeamSearchTester:
@@ -161,7 +160,9 @@ class BeamSearchTester:
expected_output_scores = cut_expected_tensor(next_scores)
# add num_beams * batch_idx
offset = torch_int_div(torch.arange(self.num_beams * self.batch_size, device=torch_device), self.num_beams)
offset = torch.div(
torch.arange(self.num_beams * self.batch_size, device=torch_device), self.num_beams, rounding_mode="floor"
)
expected_output_indices = cut_expected_tensor(next_indices) + offset * self.num_beams
self.parent.assertListEqual(expected_output_tokens.tolist(), output_tokens.tolist())
@@ -398,7 +399,9 @@ class ConstrainedBeamSearchTester:
expected_output_scores = cut_expected_tensor(next_scores)
# add num_beams * batch_idx
offset = torch_int_div(torch.arange(self.num_beams * self.batch_size, device=torch_device), self.num_beams)
offset = torch.div(
torch.arange(self.num_beams * self.batch_size, device=torch_device), self.num_beams, rounding_mode="floor"
)
expected_output_indices = cut_expected_tensor(next_indices) + offset * self.num_beams
self.parent.assertListEqual(expected_output_tokens.tolist(), output_tokens.tolist())