From fbd02d46939f8c1779d06b0881c41a4355d725ff Mon Sep 17 00:00:00 2001 From: patrickvonplaten Date: Sun, 8 Mar 2020 21:45:55 +0100 Subject: [PATCH] fixed all tests, still need to check ctrl tf and pt and xlm tf --- tests/test_modeling_ctrl.py | 2 +- tests/test_modeling_tf_gpt2.py | 2 +- tests/test_modeling_tf_openai_gpt.py | 2 +- tests/test_modeling_tf_transfo_xl.py | 2 +- tests/test_modeling_tf_xlm.py | 43 ++++++++++++------------- tests/test_modeling_tf_xlnet.py | 2 +- tests/test_modeling_xlm.py | 47 ++++++++++++++-------------- 7 files changed, 51 insertions(+), 49 deletions(-) diff --git a/tests/test_modeling_ctrl.py b/tests/test_modeling_ctrl.py index 78d341cee7..506bd2b344 100644 --- a/tests/test_modeling_ctrl.py +++ b/tests/test_modeling_ctrl.py @@ -246,4 +246,4 @@ class CTRLModelLanguageGenerationTest(unittest.TestCase): ] # Legal My neighbor is refusing to pay rent after 2 years and we are having to force him to pay output_ids = model.generate(input_ids, do_sample=False) - self.assertListEqual(output_ids[0].tolist(), expected_output_ids) + self.assertListEqual(output_ids[0].numpy().tolist(), expected_output_ids) diff --git a/tests/test_modeling_tf_gpt2.py b/tests/test_modeling_tf_gpt2.py index 7b2d356cf0..6399a60f57 100644 --- a/tests/test_modeling_tf_gpt2.py +++ b/tests/test_modeling_tf_gpt2.py @@ -356,7 +356,7 @@ class TFGPT2ModelLanguageGenerationTest(unittest.TestCase): 3290, ] # The dog was found in a field near the intersection of West and West Streets.\n\nThe dog output_ids = model.generate(input_ids, do_sample=False) - self.assertListEqual(output_ids[0].tolist(), expected_output_ids) + self.assertListEqual(output_ids[0].numpy().tolist(), expected_output_ids) @slow def test_lm_generate_distilgpt2(self): diff --git a/tests/test_modeling_tf_openai_gpt.py b/tests/test_modeling_tf_openai_gpt.py index f83b5aed50..605a1d6d45 100644 --- a/tests/test_modeling_tf_openai_gpt.py +++ b/tests/test_modeling_tf_openai_gpt.py @@ -269,4 +269,4 @@ class TFOPENAIGPTModelLanguageGenerationTest(unittest.TestCase): ] # the president is a very good man. " \n " i\'m sure he is, " said the output_ids = model.generate(input_ids, do_sample=False) - self.assertListEqual(output_ids[0].tolist(), expected_output_ids) + self.assertListEqual(output_ids[0].numpy().tolist(), expected_output_ids) diff --git a/tests/test_modeling_tf_transfo_xl.py b/tests/test_modeling_tf_transfo_xl.py index fbe04f4b9d..51de2a6a36 100644 --- a/tests/test_modeling_tf_transfo_xl.py +++ b/tests/test_modeling_tf_transfo_xl.py @@ -573,4 +573,4 @@ class TFTransfoXLModelLanguageGenerationTest(unittest.TestCase): # TODO: add this test when trasnfo-xl-lmhead is implemented with self.assertRaises(NotImplementedError): model.generate(input_ids, max_length=200, do_sample=False) - # self.assertListEqual(output_ids[0].tolist(), expected_output_ids) TODO: (PVP) to add when transfo-xl is implemented + # self.assertListEqual(output_ids[0].numpy().tolist(), expected_output_ids) TODO: (PVP) to add when transfo-xl is implemented diff --git a/tests/test_modeling_tf_xlm.py b/tests/test_modeling_tf_xlm.py index 67ed6b86bc..c2557cff38 100644 --- a/tests/test_modeling_tf_xlm.py +++ b/tests/test_modeling_tf_xlm.py @@ -317,28 +317,29 @@ class TFXLMModelLanguageGenerationTest(unittest.TestCase): @slow def test_lm_generate_xlm_mlm_en_2048(self): model = TFXLMWithLMHeadModel.from_pretrained("xlm-mlm-en-2048") - input_ids = tf.convert_to_tensor([[1, 14, 2232, 26, 1]], dtype=tf.int32) # the dog is cute + input_ids = tf.convert_to_tensor([[14, 447]], dtype=tf.int32) # the president expected_output_ids = [ - 1, 14, - 2232, - 26, - 1, - 567, - 26, - 32, - 149, - 149, - 149, - 149, - 149, - 149, - 149, - 149, - 149, - 149, - 149, - 149, - ] # The dog is nothing is it!!!!!!!!!!!! TODO (PVP): this sentence (and others I tried) does not make much sense, there seems to be a problem with xlm language generation. + 447, + 14, + 447, + 14, + 447, + 14, + 447, + 14, + 447, + 14, + 447, + 14, + 447, + 14, + 447, + 14, + 447, + 14, + 447, + ] # the president the president the president the president the president the president the president the president the president the president + # TODO(PVP): this and other input_ids I tried for generation give pretty bad results. Not sure why. Model might just not be made for auto-regressive inference output_ids = model.generate(input_ids) self.assertListEqual(output_ids[0].tolist(), expected_output_ids, do_sample=False) diff --git a/tests/test_modeling_tf_xlnet.py b/tests/test_modeling_tf_xlnet.py index ed2d94b93e..a66e6a47c1 100644 --- a/tests/test_modeling_tf_xlnet.py +++ b/tests/test_modeling_tf_xlnet.py @@ -814,4 +814,4 @@ class TFXLNetModelLanguageGenerationTest(unittest.TestCase): output_ids = model.generate(input_ids, max_length=200, do_sample=False) - self.assertListEqual(output_ids[0].tolist(), expected_output_ids) + self.assertListEqual(output_ids[0].numpy().tolist(), expected_output_ids) diff --git a/tests/test_modeling_xlm.py b/tests/test_modeling_xlm.py index 875b691cd3..6db1408c15 100644 --- a/tests/test_modeling_xlm.py +++ b/tests/test_modeling_xlm.py @@ -403,28 +403,29 @@ class XLMModelLanguageGenerationTest(unittest.TestCase): @slow def test_lm_generate_xlm_mlm_en_2048(self): model = XLMWithLMHeadModel.from_pretrained("xlm-mlm-en-2048") - input_ids = torch.tensor([[1, 14, 2232, 26, 1]], dtype=torch.long, device=torch_device) # The dog is cute + input_ids = torch.tensor([[14, 447]], dtype=torch.long, device=torch_device) # the president expected_output_ids = [ - 1, 14, - 2232, - 26, - 1, - 567, - 26, - 32, - 149, - 149, - 149, - 149, - 149, - 149, - 149, - 149, - 149, - 149, - 149, - 149, - ] # The dog is nothing is it!!!!!!!!!!!! TODO (PVP): this sentence (and others I tried) does not make much sense, there seems to be a problem with xlm language generation. - output_ids = model.generate(input_ids) - self.assertListEqual(output_ids[0].tolist(), expected_output_ids, do_sample=False) + 447, + 14, + 447, + 14, + 447, + 14, + 447, + 14, + 447, + 14, + 447, + 14, + 447, + 14, + 447, + 14, + 447, + 14, + 447, + ] # the president the president the president the president the president the president the president the president the president the president + # TODO(PVP): this and other input_ids I tried for generation give pretty bad results. Not sure why. Model might just not be made for auto-regressive inference + output_ids = model.generate(input_ids, do_sample=False) + self.assertListEqual(output_ids[0].numpy().tolist(), expected_output_ids)