forked from PaddlePaddle/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update docs/guides/model_convert/convert_from_pytorch/api_difference/…
…cuda
- Loading branch information
Showing
27 changed files
with
111 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 11 additions & 30 deletions
41
...l_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.amp.GradScaler.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,27 @@ | ||
## [paddle 参数更多]torch.cuda.amp.GradScaler | ||
## [仅参数默认值不一致]torch.cuda.amp.GradScaler | ||
|
||
### [torch.cuda.amp.GradScaler](https://pytorch.org/docs/stable/amp.html#torch.cuda.amp.GradScaler) | ||
|
||
```python | ||
torch.cuda.amp.GradScaler(init_scale=65536.0, growth_factor=2.0, backoff_factor=0.5, growth_interval=2000, enabled=True) | ||
``` | ||
|
||
### [paddle.amp.GradScaler](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/amp/GradScaler_cn.html) | ||
### [paddle.amp.GradScaler](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/amp/GradScaler_cn.html) | ||
|
||
```python | ||
paddle.amp.GradScaler(enable=True, init_loss_scaling=32768.0, incr_ratio=2.0, decr_ratio=0.5, incr_every_n_steps=1000, decr_every_n_nan_or_inf=2, use_dynamic_loss_scaling=True) | ||
``` | ||
|
||
其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: | ||
其中 Paddle 相比 PyTorch 支持更多其他参数且参数默认值不一致,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| --------------- | ------------------------ | ------------------------------------------------------------ | | ||
| init_scale | init_loss_scaling | 初始 loss scaling 因子。与 Pytorch 默认值不同,需要转写。 | | ||
| growth_factor | incr_ratio | 增大 loss scaling 时使用的乘数。 | | ||
| backoff_factor | decr_ratio | 减小 loss scaling 时使用的小于 1 的乘数。 | | ||
| growth_interval | incr_every_n_steps | 连续 n 个 steps 的梯度都是有限值时,增加 loss scaling。与 Pytorch 默认值不同,需要转写。 | | ||
| enabled | enable | 是否使用 loss scaling。 | | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| --------------- | ------------------------ |-----------------------------------------------------------------------------| | ||
| init_scale | init_loss_scaling | 初始 loss scaling 因子。与 Pytorch 默认值不同, Paddle 需设为 32768.0。 | | ||
| growth_factor | incr_ratio | 增大 loss scaling 时使用的乘数。 | | ||
| backoff_factor | decr_ratio | 减小 loss scaling 时使用的小于 1 的乘数。 | | ||
| growth_interval | incr_every_n_steps | 连续 n 个 steps 的梯度都是有限值时,增加 loss scaling。与 Pytorch 默认值不同, Paddle 需设为 1000。 | | ||
| enabled | enable | 是否使用 loss scaling。 | | ||
| - | decr_every_n_nan_or_inf | 累计出现 n 个 steps 的梯度为 nan 或者 inf 时,减小 loss scaling,PyTorch 无此参数,Paddle 保持默认即可。 | | ||
| - | use_dynamic_loss_scaling | 是否使用动态的 loss scaling,PyTorch 无此参数,Paddle 保持默认即可。 | | ||
|
||
|
||
### 转写示例 | ||
#### init_scale:表示初始化 loss scaling 因子 | ||
```python | ||
# Pytorch 写法 | ||
scale = torch.cuda.amp.GradScaler(init_scale=65536.0) | ||
|
||
# Paddle 写法 | ||
scale = torch.cuda.amp.GradScaler(init_loss_scaling=65536.0) | ||
``` | ||
#### growth_interval:连续 n 个 steps 的梯度都是有限值时 | ||
```python | ||
# Pytorch 写法 | ||
scale = torch.cuda.amp.GradScaler(growth_interval=2000) | ||
|
||
# Paddle 写法 | ||
scale = torch.cuda.amp.GradScaler(incr_every_n_steps=2000) | ||
``` | ||
| - | use_dynamic_loss_scaling | 是否使用动态的 loss scaling,PyTorch 无此参数,Paddle 保持默认即可。 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 19 additions & 6 deletions
25
...odel_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.manual_seed.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
## [参数完全一致]torch.cuda.manual_seed | ||
## [参数不一致]torch.cuda.manual_seed | ||
|
||
### [torch.cuda.manual_seed](https://pytorch.org/docs/stable/generated/torch.cuda.manual_seed.html#torch.cuda.manual_seed) | ||
|
||
```python | ||
torch.cuda.manual_seed(seed) | ||
``` | ||
|
||
### [paddle.seed](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/seed_cn.html) | ||
### [paddle.seed](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/seed_cn.html) | ||
|
||
```python | ||
paddle.seed(seed) | ||
``` | ||
|
||
功能一致,参数完全一致,具体如下: | ||
功能一致,返回类型不一致,具体如下: | ||
|
||
### 参数映射 | ||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------ | | ||
| seed | seed | 表示设置的的随机种子。| | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
|---------|--------------|----------------------------------------------------| | ||
| seed | seed | 表示设置的的随机种子(int)。 | | ||
| - | 返回值 | Pytorch 无返回值,Paddle 返回 Generator(全局默认 generator 对象)。 | | ||
|
||
### 转写示例 | ||
#### 返回值 | ||
```python | ||
# torch 写法 | ||
torch.cuda.manual_seed(100) | ||
|
||
# paddle 写法 | ||
gen = paddle.seed(100) | ||
``` |
Oops, something went wrong.