From 4d727bd2dff377caeab21ff4e1bf4b26c2397c8a Mon Sep 17 00:00:00 2001 From: Yih-Dar <2521628+ydshieh@users.noreply.github.com> Date: Wed, 25 May 2022 11:19:06 +0200 Subject: [PATCH] Fix expected value for OPT test `test_inference_no_head` (#17395) * Fix expected value * 5e-5 Co-authored-by: ydshieh --- tests/models/opt/test_modeling_opt.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/models/opt/test_modeling_opt.py b/tests/models/opt/test_modeling_opt.py index 6b5b2f0933..9a64878765 100644 --- a/tests/models/opt/test_modeling_opt.py +++ b/tests/models/opt/test_modeling_opt.py @@ -277,19 +277,16 @@ class OPTModelIntegrationTests(unittest.TestCase): expected_shape = torch.Size((1, 11, 512)) self.assertEqual(output.shape, expected_shape) + # expected value works for CPU, as well as GPU (with TF32 disabled) expected_slice = torch.tensor( - [[-0.2873, -1.9242, -0.3059], [-1.2738, -0.1333, -0.1877], [0.4116, 0.1192, -1.3107]], + [ + [-0.28726277, -1.9241608, -0.3058734], + [-1.2737825, -0.13332152, -0.18766522], + [0.41159445, 0.1191957, -1.3107123], + ], device=torch_device, ) - # Getting different logits results on GPU depending on PyTorch version (1.10+cu11.0 vs. 1.11+cu11.4) - # and results also differ between CPU and GPU. Only on CPU it seems to be deterministic. - - # It's not because the weights are saved & loaded in FP16 - # checked that the same happens when weights are stored in fp32 and loaded in fp32. - # The differences start to creep in in the first linear projection matrix project_in_dim - # It however also happens for BART (maybe related to training model in fp16?) - atol = 1e-2 if torch_device != "cpu" else 1e-3 - assert_tensors_close(output[0, :3, :3], expected_slice, atol=atol) + assert_tensors_close(output[0, :3, :3], expected_slice, atol=5e-5) @require_torch