Skip to content

Commit

Permalink
wrap forward passes with torch.no_grad() (huggingface#19413)
Browse files Browse the repository at this point in the history
  • Loading branch information
daspartho authored and amyeroberts committed Oct 18, 2022
1 parent d3c0436 commit 5b02525
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/models/fnet/test_modeling_fnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@ def test_inference_for_masked_lm(self):
model.to(torch_device)

input_ids = torch.tensor([[0, 1, 2, 3, 4, 5]], device=torch_device)
output = model(input_ids)[0]
with torch.no_grad():
output = model(input_ids)[0]

vocab_size = 32000

Expand Down Expand Up @@ -536,7 +537,8 @@ def test_inference_for_next_sentence_prediction(self):
model.to(torch_device)

input_ids = torch.tensor([[0, 1, 2, 3, 4, 5]], device=torch_device)
output = model(input_ids)[0]
with torch.no_grad():
output = model(input_ids)[0]

expected_shape = torch.Size((1, 2))
self.assertEqual(output.shape, expected_shape)
Expand All @@ -551,7 +553,8 @@ def test_inference_model(self):
model.to(torch_device)

input_ids = torch.tensor([[0, 1, 2, 3, 4, 5]], device=torch_device)
output = model(input_ids)[0]
with torch.no_grad():
output = model(input_ids)[0]

expected_shape = torch.Size((1, 6, model.config.hidden_size))
self.assertEqual(output.shape, expected_shape)
Expand Down

0 comments on commit 5b02525

Please sign in to comment.