Skip to content
Merged
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,36 @@
## [组合替代实现]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,需要组合实现。

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

# paddle 写法
x.stop_gradient = False

# 当 torch 写法
x.requires_grad = False

# paddle 写法
x.stop_gradient = True

# torch 写法
x.requires_grad

# paddle 写法
not x.stop_gradient
```