Skip to content

Commit 3586d08

Browse files
authored
Add docs torch.Tensor.requires_grad (#7374)
* add tensorRequires_grad * add TensorRequires_grad * update docs
1 parent df7b358 commit 3586d08

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## [组合替代实现]torch.Tensor.requires_grad
2+
3+
### [torch.Tensor.requires_grad](https://docs.pytorch.org/docs/stable/generated/torch.Tensor.requires_grad.html#torch-tensor-requires-grad)
4+
5+
```python
6+
torch.Tensor.requires_grad
7+
```
8+
9+
### [paddle.Tensor.stop_gradient](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#stop-gradient)
10+
11+
```python
12+
paddle.Tensor.stop_gradient
13+
```
14+
15+
Paddle 无此 API,需要组合实现。
16+
17+
### 转写示例
18+
```python
19+
# 当 torch 写法
20+
x.requires_grad = True
21+
22+
# paddle 写法
23+
x.stop_gradient = False
24+
25+
# 当 torch 写法
26+
x.requires_grad = False
27+
28+
# paddle 写法
29+
x.stop_gradient = True
30+
31+
# torch 写法
32+
x.requires_grad
33+
34+
# paddle 写法
35+
not x.stop_gradient
36+
```

0 commit comments

Comments
 (0)