Fix integration slow tests (#10670)

* PoC

* Fix slow tests for the PT1.8 Embedding problem
This commit is contained in:
Sylvain Gugger
2021-03-11 13:43:53 -05:00
committed by GitHub
parent 3ab6820370
commit fda703a553
9 changed files with 47 additions and 55 deletions

View File

@@ -350,13 +350,14 @@ class ElectraModelTest(ModelTesterMixin, unittest.TestCase):
class ElectraModelIntegrationTest(unittest.TestCase):
@slow
def test_inference_no_head_absolute_embedding(self):
model = ElectraForPreTraining.from_pretrained("google/electra-small-discriminator")
model = ElectraModel.from_pretrained("google/electra-small-discriminator")
input_ids = torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]])
output = model(input_ids)[0]
expected_shape = torch.Size((1, 11))
attention_mask = torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
output = model(input_ids, attention_mask=attention_mask)[0]
expected_shape = torch.Size((1, 11, 256))
self.assertEqual(output.shape, expected_shape)
expected_slice = torch.tensor(
[[-8.9253, -4.0305, -3.9306, -3.8774, -4.1873, -4.1280, 0.9429, -4.1672, 0.9281, 0.0410, -3.4823]]
[[[0.4471, 0.6821, -0.3265], [0.4627, 0.5255, -0.3668], [0.4532, 0.3313, -0.4344]]]
)
self.assertTrue(torch.allclose(output, expected_slice, atol=1e-4))
self.assertTrue(torch.allclose(output[:, 1:4, 1:4], expected_slice, atol=1e-4))