Skip to content

Add docs torch.Tensor.requires_grad #7374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## [组合替代实现]torch.Tensor.requires_grad

### [torch.Tensor.requires_grad](https://docs.pytorch.org/docs/stable/generated/torch.Tensor.requires_grad.html#torch-tensor-requires-grad)

```python
torch.Tensor.requires_grad
```

### [paddle.Tensor.stop_gradient](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#stop-gradient)

```python
paddle.Tensor.stop_gradient
```

Paddle 无此 API,需要组合实现。

### 转写示例
#### requires_grad:是否计算梯度
Copy link
Collaborator

@zhwesky2010 zhwesky2010 Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个API没有参数,这里就不写

下面只给给了 左值的用法,右值的示例也给下

### torch 写法
x.requires_grad

### paddle 写法
not x.stop_gradient

```python
# 当 torch 写法
x.requires_grad = True

# paddle 写法
x.stop_gradient = False

# 当 torch 写法
x.requires_grad = False

# paddle 写法
x.stop_gradient = True
```