Added with torch.no_grad() to XLM-Roberta integration test (#21547)

* added with torch.no_grad() to the integration tests and applied make style

* added with torch.no_grad() to xlm roberta forward pass

---------

Co-authored-by: Bibi <Bibi@katies-mac.local>
This commit is contained in:
Katie Le
2023-02-09 15:49:54 -05:00
committed by GitHub
parent 04b2f13c37
commit 23c146c38b

View File

@@ -43,7 +43,7 @@ class XLMRobertaModelIntegrationTest(unittest.TestCase):
# xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.base')
# xlmr.eval()
# expected_output_values_last_dim = xlmr.extract_features(input_ids[0])[:, :, -1]
with torch.no_grad():
output = model(input_ids)["last_hidden_state"].detach()
self.assertEqual(output.shape, expected_output_shape)
# compare the actual values for a slice of last dim
@@ -62,7 +62,7 @@ class XLMRobertaModelIntegrationTest(unittest.TestCase):
# xlmr = torch.hub.load('pytorch/fairseq', 'xlmr.large')
# xlmr.eval()
# expected_output_values_last_dim = xlmr.extract_features(input_ids[0])[:, :, -1]
with torch.no_grad():
output = model(input_ids)["last_hidden_state"].detach()
self.assertEqual(output.shape, expected_output_shape)
# compare the actual values for a slice of last dim