-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add api_difference docs * Fix * Fix
- Loading branch information
Showing
9 changed files
with
324 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...onvert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_rng_state_all.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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## [仅 paddle 参数更多]torch.cuda.get_rng_state_all | ||
|
||
### [torch.cuda.get_rng_state_all](https://pytorch.org/docs/1.13/generated/torch.cuda.get_rng_state_all.html#torch.cuda.get_rng_state_all) | ||
|
||
```python | ||
torch.cuda.get_rng_state_all() | ||
``` | ||
|
||
### [paddle.get_rng_state]() | ||
|
||
```python | ||
paddle.get_rng_state(device=None) | ||
``` | ||
|
||
其中 paddle 参数更多,Pytorch 与 Paddle 的返回参数类型不一致,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------ | -------------------------------------------------------------------------------------------------- | | ||
| - | device | 返回随机数生成器状态的设备,Paddle 取值 gpu。 | | ||
| 返回值 | 返回值 | 返回参数类型不一致, Pytorch 返回 torch.ByteTensor,Paddle 返回 GeneratorState 对象,暂无转写方式。 | | ||
|
||
### 转写示例 | ||
|
||
#### 返回参数类型不同 | ||
|
||
```python | ||
# PyTorch 写法 | ||
x = torch.cuda.get_rng_state_all() | ||
|
||
# Paddle 写法 | ||
x = paddle.get_rng_state(device='gpu') | ||
``` |
36 changes: 36 additions & 0 deletions
36
...onvert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_rng_state_all.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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
## [仅 paddle 参数更多]torch.cuda.set_rng_state_all | ||
|
||
### [torch.cuda.set_rng_state_all](https://pytorch.org/docs/1.13/generated/torch.cuda.set_rng_state_all.html#torch.cuda.set_rng_state_all) | ||
|
||
```python | ||
torch.cuda.set_rng_state_all(new_states) | ||
``` | ||
|
||
### [paddle.set_rng_state]() | ||
|
||
```python | ||
paddle.set_rng_state(state_list, device=None) | ||
``` | ||
|
||
其中 Pytorch 与 Paddle 的参数类型不一致,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ---------- | ------------ | --------------------------------------------------------------------------------------------------------------- | | ||
| new_states | state_list | 表示每个设备需要的状态,PyTorch 类型为 torch.ByteTensor 列表,Paddle 类型为 GeneratorState 列表,需要进行转写。 | | ||
| - | device | 返回随机数生成器状态的设备,Paddle 取值 gpu。 | | ||
|
||
### 转写示例 | ||
|
||
#### 参数类型不同 | ||
|
||
```python | ||
# PyTorch 写法 | ||
x = torch.cuda.get_rng_state_all() | ||
torch.cuda.set_rng_state_all(x) | ||
|
||
# Paddle 写法 | ||
x = paddle.get_rng_state() | ||
paddle.set_rng_state(x, device='gpu') | ||
``` |
22 changes: 22 additions & 0 deletions
22
...api_difference/distributions/torch.distributions.transforms.ComposeTransform.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## [torch 参数更多]torch.distributions.transforms.ComposeTransform | ||
|
||
### [torch.distributions.transforms.ComposeTransform](https://pytorch.org/docs/1.13/distributions.html#torch.distributions.transforms.ComposeTransform) | ||
|
||
```python | ||
torch.distributions.transforms.ComposeTransform(parts, cache_size=0) | ||
``` | ||
|
||
### [paddle.distribution.ChainTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/distribution/ChainTransform_cn.html) | ||
|
||
```python | ||
paddle.distribution.ChainTransform(transforms) | ||
``` | ||
|
||
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ---------- | ------------ | -------------------------------------------------------------------------- | | ||
| parts | transforms | 输入的变换序列,仅参数名不一致。 | | ||
| cache_size | - | 表示 cache 大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | |
21 changes: 21 additions & 0 deletions
21
...ides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Hardswish.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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## [torch 参数更多]torch.nn.Hardswish | ||
|
||
### [torch.nn.Hardswish](https://pytorch.org/docs/1.13/generated/torch.nn.Hardswish.html#torch.nn.Hardswish) | ||
|
||
```python | ||
torch.nn.Hardswish(inplace=False) | ||
``` | ||
|
||
### [paddle.nn.Hardswish](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/Hardswish_cn.html) | ||
|
||
```python | ||
paddle.nn.Hardswish(name=None) | ||
``` | ||
|
||
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------ | ----------------------------------------------------------------------------------------------------------- | | ||
| inplace | - | 在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | |
23 changes: 23 additions & 0 deletions
23
...uides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Hardtanh.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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
## [torch 参数更多]torch.nn.Hardtanh | ||
|
||
### [torch.nn.Hardtanh](https://pytorch.org/docs/1.13/generated/torch.nn.Hardtanh.html#torch.nn.Hardtanh) | ||
|
||
```python | ||
torch.nn.Hardtanh(min_val=- 1.0, max_val=1.0, inplace=False) | ||
``` | ||
|
||
### [paddle.nn.Hardtanh](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/Hardtanh_cn.html) | ||
|
||
```python | ||
paddle.nn.Hardtanh(min=- 1.0, max=1.0, name=None) | ||
``` | ||
|
||
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------- | ------------ | ----------------------------------------------------------------------------------------------------------- | | ||
| min_val | min | Hardtanh 激活计算公式中的 min 值,仅参数名不一致。 | | ||
| max_val | max | Hardtanh 激活计算公式中的 max 值,仅参数名不一致。 | | ||
| inplace | - | 在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | |
36 changes: 36 additions & 0 deletions
36
...ides/model_convert/convert_from_pytorch/api_difference/others/torch.jit.load.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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
## [torch 参数更多]torch.jit.load | ||
|
||
### [torch.jit.load](https://pytorch.org/docs/1.13/generated/torch.jit.load.html#torch.jit.load) | ||
|
||
```python | ||
torch.jit.load(f, map_location=None, _extra_files=None) | ||
``` | ||
|
||
### [paddle.jit.load](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/jit/load_cn.html) | ||
|
||
```python | ||
paddle.jit.load(path, **configs) | ||
``` | ||
|
||
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------- | ------------ | ------------------------------------------------------------------- | | ||
| f | path | Pytorch 为文件对象或文件名包含后缀,Paddle 为文件名不包含后缀,读取 .pdiparams,.pdmodel 等后缀文件。 | | ||
| map_location | - | 存储位置,Paddle 无此参数,暂无转写方式。 | | ||
| \_extra_files | - | 额外加载的文件,Paddle 无此参数,暂无转写方式。 | | ||
| - | configs | 其他用于兼容的载入配置选项,PyTorch 无此参数,Paddle 保持默认即可。 | | ||
|
||
### 转写示例 | ||
|
||
#### f 参数用法不同 | ||
|
||
```python | ||
# PyTorch 写法: | ||
torch.jit.load('scriptmodule.pt') | ||
|
||
# Paddle 写法: | ||
paddle.jit.load('example_model/linear') | ||
``` |
63 changes: 63 additions & 0 deletions
63
...s/model_convert/convert_from_pytorch/api_difference/others/torch.onnx.export.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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
## [torch 参数更多]torch.onnx.export | ||
|
||
### [torch.onnx.export](https://pytorch.org/docs/1.13/onnx.html#torch.onnx.export) | ||
|
||
```python | ||
torch.onnx.export(model, args, f, export_params=True, verbose=False, training=<TrainingMode.EVAL: 0>, input_names=None, output_names=None, operator_export_type=<OperatorExportTypes.ONNX: 0>, opset_version=None, do_constant_folding=True, dynamic_axes=None, keep_initializers_as_inputs=None, custom_opsets=None, export_modules_as_functions=False) | ||
``` | ||
|
||
### [paddle.onnx.export](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/onnx/export_cn.html) | ||
|
||
```python | ||
paddle.onnx.export(layer, path, input_spec=None, opset_version=9, **configs) | ||
``` | ||
|
||
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| --------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------ | | ||
| model | layer | 导出的模型,PyTorch 类型为 torch.nn.Module, torch.jit.ScriptModule 或 torch.jit.ScriptFunction,Paddle 为 Layer 对象,需要进行转写。 | | ||
| args | - | 模型参数,Paddle 无此参数,暂无转写方式。 | | ||
| f | path | PyTorch 为存储模型路径,Paddle 为存储模型的路径前缀,需要进行转写。 | | ||
| export_params | - | 是否导出参数,Paddle 无此参数,暂无转写方式。 | | ||
| verbose | - | 是否输出详细信息,Paddle 无此参数,暂无转写方式。 | | ||
| training | - | 训练模式,Paddle 无此参数,暂无转写方式。 | | ||
| input_names | - | 输入节点名称列表,Paddle 无此参数,暂无转写方式。 | | ||
| output_names | - | 输出节点名称列表,Paddle 无此参数,暂无转写方式。 | | ||
| operator_export_type | - | 操作导出类型,Paddle 无此参数,暂无转写方式。 | | ||
| opset_version | opset_version | opset 版本。 | | ||
| do_constant_folding | - | 是否进行 constant-folding 优化,Paddle 无此参数,暂无转写方式。 | | ||
| dynamic_axes | - | 是否动态维度,Paddle 无此参数,暂无转写方式。 | | ||
| keep_initializers_as_inputs | - | 是否增加初始化器到输入,Paddle 无此参数,暂无转写方式。 | | ||
| custom_opsets | - | 自定义 opset,Paddle 无此参数,暂无转写方式。 | | ||
| export_modules_as_functions | - | 是否导出模型为 functions,Paddle 无此参数,暂无转写方式。 | | ||
| - | input_spec | 描述存储模型 forward 方法的输入,PyTorch 无此参数,Paddle 保持默认即可。 | | ||
| - | configs | 其他用于兼容的存储配置选项,PyTorch 无此参数,Paddle 保持默认即可。 | | ||
|
||
### 转写示例 | ||
|
||
#### 参数类型不同 | ||
|
||
```python | ||
# PyTorch 写法 | ||
torch.onnx.export( | ||
model, | ||
( | ||
x, | ||
{y: z}, | ||
{} | ||
), | ||
"test.onnx.pb" | ||
) | ||
|
||
# Paddle 写法 | ||
model = Logic() | ||
x = paddle.to_tensor([1]) | ||
y = paddle.to_tensor([2]) | ||
# Static and run model. | ||
paddle.jit.to_static(model) | ||
out = model(x, y, z=True) | ||
paddle.onnx.export(model, 'pruned', input_spec=[x], output_spec=[out]) | ||
``` |
64 changes: 64 additions & 0 deletions
64
...el_convert/convert_from_pytorch/api_difference/others/torch.profiler.profile.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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
## [torch 参数更多]torch.profiler.profile | ||
|
||
### [torch.profiler.profile](https://pytorch.org/docs/1.13/profiler.html#torch.profiler.profile) | ||
|
||
```python | ||
torch.profiler.profile(*, activities=None, schedule=None, on_trace_ready=None, record_shapes=False, profile_memory=False, with_stack=False, with_flops=False, with_modules=False, experimental_config=None, use_cuda=None) | ||
``` | ||
|
||
### [paddle.profiler.Profiler](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/profiler/Profiler_cn.html) | ||
|
||
```python | ||
paddle.profiler.Profiler(*, targets=None, scheduler=None, on_trace_ready=None, record_shapes=False, profile_memory=False, timer_only=False) | ||
``` | ||
|
||
其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------- | | ||
| activities | targets | 指定性能分析所要分析的设备,PyTorch 为 torch.profiler.ProfilerActivity 类型,Paddle 为 paddle.profiler.ProfilerTarget 类型。 | | ||
| schedule | scheduler | 如果是 Callable 对象,代表是性能分析器状态的调度器,仅参数名不一致。 | | ||
| on_trace_ready | on_trace_ready | 处理性能分析器的回调函数。 | | ||
| record_shapes | record_shapes | 如果设置为 True, 则会开启收集框架算子输入张量的 shape。 | | ||
| profile_memory | profile_memory | 如果设置为 True, 则会开启收集显存分析的数据。 | | ||
| with_stack | - | 记录 source 信息,Paddle 无此参数,暂无转写方式。 | | ||
| with_flops | - | 使用公式来估计浮点计算,Paddle 无此参数,暂无转写方式。 | | ||
| with_modules | - | 记录模块层次,Paddle 无此参数,暂无转写方式。 | | ||
| experimental_config | - | 实验性特征配置,Paddle 无此参数,暂无转写方式。 | | ||
| use_cuda | - | 已废弃,Paddle 无此参数,暂无转写方式。 | | ||
| - | timer_only | 如果设置为 True,将只统计模型的数据读取和每一个迭代所消耗的时间,而不进行性能分析,PyTorch 无此参数,Paddle 保持默认即可。 | | ||
|
||
### 转写示例 | ||
|
||
#### 参数类型不同 | ||
|
||
```python | ||
# PyTorch 写法: | ||
with torch.profiler.profile( | ||
activities=[ | ||
torch.profiler.ProfilerActivity.CPU, | ||
torch.profiler.ProfilerActivity.CUDA, | ||
], | ||
schedule=torch.profiler.schedule( | ||
wait=1, | ||
warmup=1, | ||
active=2), | ||
on_trace_ready=torch.profiler.tensorboard_trace_handler('./log') | ||
) as p: | ||
for iter in range(10): | ||
p.step() | ||
|
||
# Paddle 写法: | ||
with paddle.profiler.Profiler( | ||
targets=[ | ||
paddle.profiler.ProfilerTarget.CPU, | ||
paddle.profiler.ProfilerTarget.GPU | ||
], | ||
scheduler=(2, 5), | ||
on_trace_ready = paddle.profiler.export_chrome_tracing('./log') | ||
) as p: | ||
for iter in range(10): | ||
p.step() | ||
``` |
25 changes: 25 additions & 0 deletions
25
...l_convert/convert_from_pytorch/api_difference/others/torch.profiler.schedule.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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
## [仅参数名不一致]torch.profiler.schedule | ||
|
||
### [torch.profiler.schedule](https://pytorch.org/docs/1.13/profiler.html#torch.profiler.schedule) | ||
|
||
```python | ||
torch.profiler.schedule(*, wait, warmup, active, repeat=0, skip_first=0) | ||
``` | ||
|
||
### [paddle.profiler.make_scheduler](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/profiler/make_scheduler_cn.html) | ||
|
||
```python | ||
paddle.profiler.make_scheduler(*, closed, ready, record, repeat=0, skip_first=0) | ||
``` | ||
|
||
两者功能一致,参数名不一致,具体如下: | ||
|
||
### 参数映射 | ||
|
||
| PyTorch | PaddlePaddle | 备注 | | ||
| ---------- | ------------ | ------------------------------------------------------------------- | | ||
| wait | closed | 处于 wait/ProfilerState.CLOSED 状态的 step 数量,仅参数名不一致。 | | ||
| warmup | ready | 处于 warmup/ProfilerState.READY 状态的 step 数量,仅参数名不一致。 | | ||
| active | record | 处于 active/ProfilerState.RECORD 状态的 step 数量,仅参数名不一致。 | | ||
| repeat | repeat | 重复次数。 | | ||
| skip_first | skip_first | 首次 skip 步骤数量。 | |