From ae8f06feb885457a91dfc9da360355e0b6b7adba Mon Sep 17 00:00:00 2001 From: Sergii Dymchenko Date: Wed, 19 Jul 2023 16:17:09 -0700 Subject: [PATCH] Fix require_grad typo (#1771) Summary: Fix require_grad typos (should be requires_grad). Before the fix, the code doesn't cause any errors but doesn't do what it's supposed to do. Fixed with TorchFix https://github.com/pytorch/test-infra/tree/main/tools/torchfix Upstream PR: https://github.com/codertimo/BERT-pytorch/pull/104 Pull Request resolved: https://github.com/pytorch/benchmark/pull/1771 Reviewed By: xuzhao9 Differential Revision: D47531187 Pulled By: kit1980 fbshipit-source-id: 738b1866cc5cd3fedfa878cc40827236717f6f27 --- .../BERT_pytorch/bert_pytorch/model/embedding/position.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/torchbenchmark/models/BERT_pytorch/bert_pytorch/model/embedding/position.py b/torchbenchmark/models/BERT_pytorch/bert_pytorch/model/embedding/position.py index d55c224b5c..0f615b6def 100644 --- a/torchbenchmark/models/BERT_pytorch/bert_pytorch/model/embedding/position.py +++ b/torchbenchmark/models/BERT_pytorch/bert_pytorch/model/embedding/position.py @@ -10,7 +10,8 @@ def __init__(self, d_model, max_len=512): # Compute the positional encodings once in log space. pe = torch.zeros(max_len, d_model).float() - pe.require_grad = False + # Changed from upstream, see https://github.com/codertimo/BERT-pytorch/pull/104 + pe.requires_grad = False position = torch.arange(0, max_len).float().unsqueeze(1) div_term = (torch.arange(0, d_model, 2).float() * -(math.log(10000.0) / d_model)).exp()