File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
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
+ ```
You can’t perform that action at this time.
0 commit comments