Skip to content

Commit

Permalink
Add type hint for retains_grad (pytorch#103528)
Browse files Browse the repository at this point in the history
Fixes pytorch#103485

Type checkers don't know about the existence of `retains_grad` otherwise:

```python
torch.randn(10, 10).retains_grad  # Cannot access member "retains_grad" for type "Tensor"
```

Pull Request resolved: pytorch#103528
Approved by: https://github.com/albanD, https://github.com/Skylion007, https://github.com/janeyx99
  • Loading branch information
ringohoffman authored and pytorchmergebot committed Jun 13, 2023
1 parent d38b651 commit bc2caa7
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions torch/_C/__init__.pyi.in
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,7 @@ class _TensorMeta(type): ...
# Defined in torch/csrc/autograd/python_variable.cpp
class _TensorBase(metaclass=_TensorMeta):
requires_grad: _bool
retains_grad: _bool
shape: Size
data: Tensor
names: List[str]
Expand Down

0 comments on commit bc2caa7

Please sign in to comment.