From 11fcc40c22800380373bf7a57cf5a3ac6b284992 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Mon, 16 May 2022 11:00:10 -0400 Subject: [PATCH 1/5] fix opt tests --- tests/models/opt/test_modeling_opt.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/models/opt/test_modeling_opt.py b/tests/models/opt/test_modeling_opt.py index 6494f2604d69..6e5ae98410bc 100644 --- a/tests/models/opt/test_modeling_opt.py +++ b/tests/models/opt/test_modeling_opt.py @@ -284,7 +284,7 @@ def test_inference_no_head(self): expected_shape = torch.Size((1, 11, 512)) self.assertEqual(output.shape, expected_shape) expected_slice = torch.tensor( - [[0.7144, 0.8143, -1.2813], [0.7144, 0.8143, -1.2813], [-0.0467, 2.5911, -2.1845]], device=torch_device + [[-0.2873, -1.9218, -0.3033], [-1.2710, -0.1338, -0.1902], [0.4095, 0.1214, -1.3121]], device=torch_device ) self.assertTrue(torch.allclose(output[:, :3, :3], expected_slice, atol=1e-3)) @@ -307,7 +307,6 @@ def test_logits(self): model = OPTForCausalLM.from_pretrained(self.path_model) model = model.eval() tokenizer = GPT2Tokenizer.from_pretrained(self.path_model) - tokenizer.add_special_tokens({"pad_token": ""}) prompts = [ "Today is a beautiful day and I want to", @@ -315,8 +314,8 @@ def test_logits(self): "Paris is the capital of France and", "Computers and mobile phones have taken", ] - input_ids = tokenizer(prompts, return_tensors="pt", padding=True).input_ids - logits = model(input_ids)[0].mean(dim=-1) + inputs = tokenizer(prompts, return_tensors="pt", padding=True, add_special_tokens=False) + logits = model(inputs.input_ids, attention_mask=inputs.attention_mask)[0].mean(dim=-1) # logits_meta = torch.load(self.path_logits_meta) logits_meta = torch.Tensor( [ @@ -326,7 +325,6 @@ def test_logits(self): [6.4783, -1.9913, -10.7926, -2.3336, 1.5092, -0.9974, -6.8213, 1.3477, 1.3477], ] ) - assert torch.allclose(logits, logits_meta, atol=1e-4) From aba2e185fab55a9205baca77b52883ac5500620f Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Mon, 16 May 2022 11:02:14 -0400 Subject: [PATCH 2/5] remove unused tok --- tests/models/opt/test_modeling_opt.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/models/opt/test_modeling_opt.py b/tests/models/opt/test_modeling_opt.py index 6e5ae98410bc..a9fe9802ae96 100644 --- a/tests/models/opt/test_modeling_opt.py +++ b/tests/models/opt/test_modeling_opt.py @@ -270,9 +270,6 @@ def _long_tensor(tok_lst): @require_sentencepiece @require_tokenizers class OPTModelIntegrationTests(unittest.TestCase): - @cached_property - def default_tokenizer(self): - return GPT2Tokenizer.from_pretrained("patrickvonplaten/opt_gpt2_tokenizer") @slow def test_inference_no_head(self): From 992d3f4d2d2af48e1056e18850f759c64af7694e Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Mon, 16 May 2022 11:09:48 -0400 Subject: [PATCH 3/5] make style --- tests/models/opt/test_modeling_opt.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/models/opt/test_modeling_opt.py b/tests/models/opt/test_modeling_opt.py index a9fe9802ae96..fae61bb631d4 100644 --- a/tests/models/opt/test_modeling_opt.py +++ b/tests/models/opt/test_modeling_opt.py @@ -270,7 +270,6 @@ def _long_tensor(tok_lst): @require_sentencepiece @require_tokenizers class OPTModelIntegrationTests(unittest.TestCase): - @slow def test_inference_no_head(self): model = OPTModel.from_pretrained("facebook/opt-350m").to(torch_device) From d732c719096a2b0a39ce616ed18e2610081d72b8 Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Mon, 16 May 2022 11:27:02 -0400 Subject: [PATCH 4/5] make flake8 happy --- tests/models/opt/test_modeling_opt.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/models/opt/test_modeling_opt.py b/tests/models/opt/test_modeling_opt.py index fae61bb631d4..f344110dba71 100644 --- a/tests/models/opt/test_modeling_opt.py +++ b/tests/models/opt/test_modeling_opt.py @@ -23,7 +23,6 @@ from transformers import OPTConfig, is_torch_available from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device -from transformers.utils import cached_property from ...generation.test_generation_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester From 400cd601db074e3ff7ceb86c4492db54cc184acf Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Mon, 16 May 2022 22:03:47 +0200 Subject: [PATCH 5/5] Update tests/models/opt/test_modeling_opt.py --- tests/models/opt/test_modeling_opt.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/models/opt/test_modeling_opt.py b/tests/models/opt/test_modeling_opt.py index f344110dba71..7a844da559ac 100644 --- a/tests/models/opt/test_modeling_opt.py +++ b/tests/models/opt/test_modeling_opt.py @@ -309,6 +309,7 @@ def test_logits(self): "Paris is the capital of France and", "Computers and mobile phones have taken", ] + # verify that prompt without BOS token is identical to Metaseq -> add_special_tokens=False inputs = tokenizer(prompts, return_tensors="pt", padding=True, add_special_tokens=False) logits = model(inputs.input_ids, attention_mask=inputs.attention_mask)[0].mean(dim=-1) # logits_meta = torch.load(self.path_logits_meta)