From d2a1ed3c48de7754e8a7d9f8285371de33295854 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Sat, 29 Mar 2025 14:37:57 +0800 Subject: [PATCH 01/15] update docs --- .../distributed/torch.distributed.P2POP.md | 24 ++++++++++++++++++ .../distributed/torch.distributed.P2POp.md | 25 +++++++++++++++++++ .../torch/torch._foreach_ceil_.md | 24 ++++++++++++++++++ .../torch/torch._foreach_erfc.md | 19 ++++++++++++++ .../torch/torch._foreach_erfc_.md | 25 +++++++++++++++++++ .../torch/torch._foreach_exp_.md | 24 ++++++++++++++++++ .../torch/torch._foreach_floor_.md | 24 ++++++++++++++++++ .../torch/torch._foreach_log.md | 19 ++++++++++++++ .../torch/torch._foreach_log_.md | 19 ++++++++++++++ .../pytorch_api_mapping_cn.md | 24 ++++++------------ 10 files changed, 211 insertions(+), 16 deletions(-) create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.P2POP.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.P2POp.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_ceil_.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erfc.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erfc_.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_exp_.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_floor_.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_log.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_log_.md diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.P2POP.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.P2POP.md new file mode 100644 index 00000000000..2827c88f708 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.P2POP.md @@ -0,0 +1,24 @@ +## [torch 参数更多]torch.distributed.P2POp + +### [torch.distributed.P2POp](https://pytorch.org/docs/stable/distributed.html#torch.distributed.P2POp) + +```python +torch.distributed.P2POp(op, tensor, peer=None, group=None, tag=0) +``` + +### [paddle.distributed.P2POp](https://github.com/PaddlePaddle/Paddle/blob/develop/python/paddle/distributed/communication/batch_isend_irecv.py) + +```python +paddle.distributed.P2POp(op, tensor, peer, group=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | --------------- | ----------------------------------------------------------------- | +| op | op | 表示执行的操作类型。 | +| tensor | tensor | 表示进行通信的张量。 | +| peer | peer | 表示通信的目标进程的 rank。 | +| tag | - | 表示匹配接收标签,Paddle 无此参数,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.P2POp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.P2POp.md new file mode 100644 index 00000000000..c6d83d73a39 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.P2POp.md @@ -0,0 +1,25 @@ +## [torch 参数更多]torch.distributed.P2POp + +### [torch.distributed.P2POp](https://pytorch.org/docs/stable/distributed.html#torch.distributed.P2POp) + +```python +torch.distributed.recv(tensor, src=None, group=None, tag=0) +``` + +### [paddle.distributed.recv](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/recv_cn.html) + +```python +paddle.distributed.recv(tensor, src=0, group=None, sync_op=True) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | --------------- | ----------------------------------------------------------------- | +| tensor | tensor | 表示用于接收数据的 Tensor。 | +| src | src | 表示目标进程的 rank。 | +| group | group | 表示执行该操作的进程组实例。 | +| tag | - | 表示匹配接收标签,Paddle 无此参数,暂无转写方式。 | +| - | sync_op | 表示该操作是否为同步操作,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_ceil_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_ceil_.md new file mode 100644 index 00000000000..275863b3cdb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_ceil_.md @@ -0,0 +1,24 @@ +## [组合替代实现]torch.\_foreach_ceil_ + +### [torch.\_foreach_ceil_](https://pytorch.org/docs/stable/generated/torch._foreach_ceil_.html#torch-foreach-ceil) + +```python +torch._foreach_ceil_(self) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +torch._foreach_ceil_(tensors) + +# Paddle 写法 +def foreach_operator_(func, tensors): + result = [] + for x in tensors: + result.append(paddle.assign(func(x), x)) + return result +foreach_operator_(tensors, paddle.ceil) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erfc.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erfc.md new file mode 100644 index 00000000000..7b544db125b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erfc.md @@ -0,0 +1,19 @@ +## [组合替代实现]torch.\_foreach_erfc + +### [torch.\_foreach_erfc](https://pytorch.org/docs/stable/generated/torch._foreach_erfc.html#torch-foreach-erfc) + +```python +torch._foreach_erfc(self) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +torch._foreach_erfc(tensors) + +# Paddle 写法 +tuple([(1-paddle.erf(x)) for x in tensors]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erfc_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erfc_.md new file mode 100644 index 00000000000..e6d7a953aac --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erfc_.md @@ -0,0 +1,25 @@ +## [组合替代实现]torch.\_foreach_erfc_ + +### [torch.\_foreach_erfc_](https://pytorch.org/docs/stable/generated/torch._foreach_erfc_.html#torch-foreach-erfc) + +```python +torch._foreach_erfc_(self) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +torch._foreach_erfc_(tensors) + +# Paddle 写法 +def foreach_erfc_(tensors): + result = [] + for x in tensors: + result.append(paddle.assign(1-paddle.erf(x), x)) + return result + +foreach_erfc_(tensors) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_exp_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_exp_.md new file mode 100644 index 00000000000..16bd618a01c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_exp_.md @@ -0,0 +1,24 @@ +## [组合替代实现]torch.\_foreach_exp + +### [torch.\_foreach_exp](https://pytorch.org/docs/stable/generated/torch._foreach_exp_.html#torch-foreach-exp) + +```python +torch._foreach_exp_(self) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +torch._foreach_exp_(tensors) + +# Paddle 写法 +def foreach_operator_(func, tensors): + result = [] + for x in tensors: + result.append(paddle.assign(func(x), x)) + return result +foreach_operator_(tensors, paddle.exp) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_floor_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_floor_.md new file mode 100644 index 00000000000..2a0e2438ad1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_floor_.md @@ -0,0 +1,24 @@ +## [组合替代实现]torch.\_foreach_floor_ + +### [torch.\_foreach_floor_](https://pytorch.org/docs/stable/generated/torch._foreach_floor_.html#torch-foreach-floor) + +```python +torch._foreach_floor_(self) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +torch._foreach_floor_(tensors) + +# Paddle 写法 +def foreach_operator_(func, tensors): + result = [] + for x in tensors: + result.append(paddle.assign(func(x), x)) + return result +foreach_operator_(tensors, paddle.floor) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_log.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_log.md new file mode 100644 index 00000000000..d5bbcf37009 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_log.md @@ -0,0 +1,19 @@ +## [组合替代实现]torch.\_foreach_log + +### [torch.\_foreach_log](https://pytorch.org/docs/stable/generated/torch._foreach_log.html#torch-foreach-log) + +```python +torch._foreach_log(self) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +torch._foreach_log(tensors) + +# Paddle 写法 +[paddle.log(x) for x in tensors] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_log_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_log_.md new file mode 100644 index 00000000000..bd6611da00e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_log_.md @@ -0,0 +1,19 @@ +## [组合替代实现]torch.\_foreach_log_ + +### [torch.\_foreach_log_](https://pytorch.org/docs/stable/generated/torch._foreach_log_.html#torch-foreach-log) + +```python +torch._foreach_log_(self) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +torch._foreach_log_(tensors) + +# Paddle 写法 +[paddle.log_(x) for x in tensors] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md b/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md index 46329f00cc0..3fbe87f0418 100644 --- a/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md +++ b/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md @@ -1042,22 +1042,20 @@ | NOT-IMPLEMENTED-ITEM(`torch.jit.trace`, https://pytorch.org/docs/stable/generated/torch.jit.trace.html#torch-jit-trace, 可新增,但框架底层无相关设计,成本高) | | NOT-IMPLEMENTED-ITEM(`torch.jit.unused`, https://pytorch.org/docs/stable/generated/torch.jit.unused.html#torch-jit-unused, 可新增,但框架底层无相关设计,成本高) | | NOT-IMPLEMENTED-ITEM(`torch.utils.checkpoint.checkpoint_sequential`, https://pytorch.org/docs/stable/checkpoint.html#torch.utils.checkpoint.checkpoint_sequential, 可新增,但框架底层无相关设计,成本高) | +| NOT-IMPLEMENTED-ITEM(`torch.nn.parameter.UninitializedBuffer`, https://pytorch.org/docs/stable/generated/torch.nn.parameter.UninitializedBuffer.html#torch.nn.parameter.UninitializedBuffer, 可新增,但框架底层无相关设计,成本高) | +| NOT-IMPLEMENTED-ITEM(`torch.autograd.Function.jvp`, https://pytorch.org/docs/stable/generated/torch.autograd.Function.jvp.html#torch-autograd-function-jvp, 可新增,但框架底层无相关设计,成本高) | +| NOT-IMPLEMENTED-ITEM(`torch.memory_format`, https://pytorch.org/docs/stable/tensor_attributes.html#torch.memory_format, 可新增,但框架底层无相关设计,成本高) | +| NOT-IMPLEMENTED-ITEM(`torch.distributed.is_gloo_available`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.is_gloo_available, 可新增,但框架底层无相关设计,成本高) | +| NOT-IMPLEMENTED-ITEM(`torch.distributed.get_group_rank`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.get_group_rank, 可新增,且框架底层有相关设计,成本低) | +| NOT-IMPLEMENTED-ITEM(`torch.distributed.get_global_rank`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.get_process_group_ranks, 可新增,且框架底层有相关设计,成本低) | +| NOT-IMPLEMENTED-ITEM(`torch.set_deterministic_debug_mode`, https://pytorch.org/docs/stable/generated/torch.set_deterministic_debug_mode.html#torch-set-deterministic-debug-mode, 可新增,但框架底层无相关设计,成本高) | +| NOT-IMPLEMENTED-ITEM(`torch.get_deterministic_debug_mode`, https://pytorch.org/docs/stable/generated/torch.get_deterministic_debug_mode.html#torch-get-deterministic-debug-mode, 可新增,但框架底层无相关设计,成本高) | ## 映射关系开发中的 API 列表 | 序号 | Pytorch 最新 release | Paddle develop | 映射关系分类 | 备注 | | ----- | ----------- | ----------------- | ----------- | ------- | | IN-DEVELOPMENT-PATTERN(`torch.utils.tensorboard.writer.SummaryWriter`, https://pytorch.org/docs/stable/tensorboard.html#torch.utils.tensorboard.writer.SummaryWriter) | -| IN-DEVELOPMENT-PATTERN(`torch.nn.parameter.UninitializedBuffer`, https://pytorch.org/docs/stable/generated/torch.nn.parameter.UninitializedBuffer.html#torch.nn.parameter.UninitializedBuffer) | -| IN-DEVELOPMENT-PATTERN(`torch.autograd.Function.jvp`, https://pytorch.org/docs/stable/generated/torch.autograd.Function.jvp.html#torch-autograd-function-jvp) | -| IN-DEVELOPMENT-PATTERN(`torch.memory_format`, https://pytorch.org/docs/stable/tensor_attributes.html#torch.memory_format) | -| IN-DEVELOPMENT-PATTERN(`torch._foreach_ceil_`, https://pytorch.org/docs/stable/generated/torch._foreach_ceil_.html#torch-foreach-ceil) | -| IN-DEVELOPMENT-PATTERN(`torch._foreach_erfc`, https://pytorch.org/docs/stable/generated/torch._foreach_erfc.html#torch-foreach-erfc) | -| IN-DEVELOPMENT-PATTERN(`torch._foreach_erfc_`, https://pytorch.org/docs/stable/generated/torch._foreach_erfc_.html#torch-foreach-erfc) | -| IN-DEVELOPMENT-PATTERN(`torch._foreach_exp_`, https://pytorch.org/docs/stable/generated/torch._foreach_exp_.html#torch-foreach-exp) | -| IN-DEVELOPMENT-PATTERN(`torch._foreach_floor_`, https://pytorch.org/docs/stable/generated/torch._foreach_floor_.html#torch-foreach-floor) | -| IN-DEVELOPMENT-PATTERN(`torch._foreach_log`, https://pytorch.org/docs/stable/generated/torch._foreach_log.html#torch-foreach-log) | -| IN-DEVELOPMENT-PATTERN(`torch._foreach_log_`, https://pytorch.org/docs/stable/generated/torch._foreach_log_.html#torch-foreach-log) | | IN-DEVELOPMENT-PATTERN(`torch._foreach_log10`, https://pytorch.org/docs/stable/generated/torch._foreach_log10.html#torch-foreach-log10) | | IN-DEVELOPMENT-PATTERN(`torch._foreach_log10_`, https://pytorch.org/docs/stable/generated/torch._foreach_log10_.html#torch-foreach-log10) | | IN-DEVELOPMENT-PATTERN(`torch._foreach_log1p`, https://pytorch.org/docs/stable/generated/torch._foreach_log1p.html#torch-foreach-log1p) | @@ -1094,10 +1092,6 @@ | IN-DEVELOPMENT-PATTERN(`torch.autograd.graph.Node.register_prehook`, https://pytorch.org/docs/stable/generated/torch.autograd.graph.Node.register_prehook.html#torch-autograd-graph-node-register-prehook) | | IN-DEVELOPMENT-PATTERN(`torch.cuda.OutOfMemoryError`, https://pytorch.org/docs/stable/generated/torch.cuda.OutOfMemoryError.html#torch-cuda-outofmemoryerror) | | IN-DEVELOPMENT-PATTERN(`torch.backends.cpu.get_cpu_capability`, https://pytorch.org/docs/stable/backends.html#torch.backends.cpu.get_cpu_capability) | -| IN-DEVELOPMENT-PATTERN(`torch.distributed.P2POp`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.P2POp) | -| IN-DEVELOPMENT-PATTERN(`torch.distributed.is_gloo_available`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.is_gloo_available) | -| IN-DEVELOPMENT-PATTERN(`torch.distributed.get_group_rank`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.get_group_rank) | -| IN-DEVELOPMENT-PATTERN(`torch.distributed.get_global_rank`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.get_global_rank) | | IN-DEVELOPMENT-PATTERN(`torch.distributed.get_process_group_ranks`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.get_process_group_ranks) | | IN-DEVELOPMENT-PATTERN(`torch.distributed.batch_isend_irecv`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.batch_isend_irecv) | | IN-DEVELOPMENT-PATTERN(`torch.distributed.all_gather_into_tensor`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.all_gather_into_tensor) | @@ -1119,5 +1113,3 @@ | IN-DEVELOPMENT-PATTERN(`torch.distributions.continuous_bernoulli.ContinuousBernoulli`, https://pytorch.org/docs/stable/distributions.html#torch.distributions.continuous_bernoulli.ContinuousBernoulli) | | IN-DEVELOPMENT-PATTERN(`torch.distributions.exponential.Exponential`, https://pytorch.org/docs/stable/distributions.html#torch.distributions.exponential.Exponential) | | IN-DEVELOPMENT-PATTERN(`torch.cuda.StreamContext`, https://pytorch.org/docs/stable/generated/torch.cuda.StreamContext.html#torch.cuda.StreamContext) | -| IN-DEVELOPMENT-PATTERN(`torch.set_deterministic_debug_mode`, https://pytorch.org/docs/stable/generated/torch.set_deterministic_debug_mode.html#torch-set-deterministic-debug-mode) | -| IN-DEVELOPMENT-PATTERN(`torch.get_deterministic_debug_mode`, https://pytorch.org/docs/stable/generated/torch.get_deterministic_debug_mode.html#torch-get-deterministic-debug-mode) | From d2c742fb0493cbd2f931f7b0c6d3d63b5e995a42 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Sat, 29 Mar 2025 14:39:40 +0800 Subject: [PATCH 02/15] update docs --- .../distributed/torch.distributed.P2POP.md | 24 ------------------- 1 file changed, 24 deletions(-) delete mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.P2POP.md diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.P2POP.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.P2POP.md deleted file mode 100644 index 2827c88f708..00000000000 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.P2POP.md +++ /dev/null @@ -1,24 +0,0 @@ -## [torch 参数更多]torch.distributed.P2POp - -### [torch.distributed.P2POp](https://pytorch.org/docs/stable/distributed.html#torch.distributed.P2POp) - -```python -torch.distributed.P2POp(op, tensor, peer=None, group=None, tag=0) -``` - -### [paddle.distributed.P2POp](https://github.com/PaddlePaddle/Paddle/blob/develop/python/paddle/distributed/communication/batch_isend_irecv.py) - -```python -paddle.distributed.P2POp(op, tensor, peer, group=None) -``` - -PyTorch 相比 Paddle 支持更多其他参数,具体如下: - -### 参数映射 - -| PyTorch | PaddlePaddle | 备注 | -| ------- | --------------- | ----------------------------------------------------------------- | -| op | op | 表示执行的操作类型。 | -| tensor | tensor | 表示进行通信的张量。 | -| peer | peer | 表示通信的目标进程的 rank。 | -| tag | - | 表示匹配接收标签,Paddle 无此参数,暂无转写方式。 | From ad22ee7a14d63947eef5030712b00bb0c7235605 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Sat, 29 Mar 2025 16:50:16 +0800 Subject: [PATCH 03/15] update P2POp --- .../distributed/torch.distributed.P2POp.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.P2POp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.P2POp.md index c6d83d73a39..a25fb608ff5 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.P2POp.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.P2POp.md @@ -3,13 +3,13 @@ ### [torch.distributed.P2POp](https://pytorch.org/docs/stable/distributed.html#torch.distributed.P2POp) ```python -torch.distributed.recv(tensor, src=None, group=None, tag=0) +torch.distributed.P2POp(op, tensor, peer, group=None, tag=0) ``` -### [paddle.distributed.recv](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/recv_cn.html) +### [paddle.distributed.P2POp](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/Overview_cn.html#paddle-distributed) ```python -paddle.distributed.recv(tensor, src=0, group=None, sync_op=True) +paddle.distributed.P2POp(op, tensor, peer, group=None) ``` PyTorch 相比 Paddle 支持更多其他参数,具体如下: @@ -18,8 +18,8 @@ PyTorch 相比 Paddle 支持更多其他参数,具体如下: | PyTorch | PaddlePaddle | 备注 | | ------- | --------------- | ----------------------------------------------------------------- | -| tensor | tensor | 表示用于接收数据的 Tensor。 | -| src | src | 表示目标进程的 rank。 | -| group | group | 表示执行该操作的进程组实例。 | +| op | op | 表示操作类型。 | +| tensor | tensor | 表示发送或接收的 Tensor。 | +| peer | peer | 表示目标进程的 rank。 | +| group | group | 指定通信的进程组。 | | tag | - | 表示匹配接收标签,Paddle 无此参数,暂无转写方式。 | -| - | sync_op | 表示该操作是否为同步操作,PyTorch 无此参数,Paddle 保持默认即可。 | From 9b1b8a82773fe53ab748546440c90a5597eba423 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Sat, 29 Mar 2025 18:41:50 +0800 Subject: [PATCH 04/15] fix docs --- .../api_difference/torch/torch._foreach_exp_.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_exp_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_exp_.md index 16bd618a01c..6cf5df45751 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_exp_.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_exp_.md @@ -1,6 +1,6 @@ ## [组合替代实现]torch.\_foreach_exp -### [torch.\_foreach_exp](https://pytorch.org/docs/stable/generated/torch._foreach_exp_.html#torch-foreach-exp) +### [torch.\_foreach_exp_](https://pytorch.org/docs/stable/generated/torch._foreach_exp_.html#torch._foreach_exp_) ```python torch._foreach_exp_(self) From 516499bb473a991ef71dbece365b5295af18f235 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Sat, 29 Mar 2025 21:08:41 +0800 Subject: [PATCH 05/15] fix bugs --- .../api_difference/torch/torch._foreach_exp_.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_exp_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_exp_.md index 6cf5df45751..ac058919795 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_exp_.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_exp_.md @@ -1,4 +1,4 @@ -## [组合替代实现]torch.\_foreach_exp +## [组合替代实现]torch.\_foreach_exp_ ### [torch.\_foreach_exp_](https://pytorch.org/docs/stable/generated/torch._foreach_exp_.html#torch._foreach_exp_) From de2851d2807477e42c569259a9e27ff419e83d5e Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Wed, 2 Apr 2025 13:24:10 +0800 Subject: [PATCH 06/15] update docs --- .../api_difference/torch/torch._foreach_ceil_.md | 7 +------ .../api_difference/torch/torch._foreach_erfc_.md | 8 +------- .../api_difference/torch/torch._foreach_exp_.md | 7 +------ .../api_difference/torch/torch._foreach_floor_.md | 7 +------ .../convert_from_pytorch/pytorch_api_mapping_cn.md | 6 +++--- 5 files changed, 7 insertions(+), 28 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_ceil_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_ceil_.md index 275863b3cdb..a4e800ce1cc 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_ceil_.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_ceil_.md @@ -15,10 +15,5 @@ Paddle 无此 API,需要组合实现。 torch._foreach_ceil_(tensors) # Paddle 写法 -def foreach_operator_(func, tensors): - result = [] - for x in tensors: - result.append(paddle.assign(func(x), x)) - return result -foreach_operator_(tensors, paddle.ceil) +[paddle.assign(paddle.ceil(x), x) for x in tensors] ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erfc_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erfc_.md index e6d7a953aac..7f83684d46d 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erfc_.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_erfc_.md @@ -15,11 +15,5 @@ Paddle 无此 API,需要组合实现。 torch._foreach_erfc_(tensors) # Paddle 写法 -def foreach_erfc_(tensors): - result = [] - for x in tensors: - result.append(paddle.assign(1-paddle.erf(x), x)) - return result - -foreach_erfc_(tensors) +[paddle.assign(1-paddle.erf(x), x) for x in tensors] ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_exp_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_exp_.md index ac058919795..5166e989f32 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_exp_.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_exp_.md @@ -15,10 +15,5 @@ Paddle 无此 API,需要组合实现。 torch._foreach_exp_(tensors) # Paddle 写法 -def foreach_operator_(func, tensors): - result = [] - for x in tensors: - result.append(paddle.assign(func(x), x)) - return result -foreach_operator_(tensors, paddle.exp) +[paddle.assign(paddle.exp(x), x) for x in tensors] ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_floor_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_floor_.md index 2a0e2438ad1..363de3f0e85 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_floor_.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch._foreach_floor_.md @@ -15,10 +15,5 @@ Paddle 无此 API,需要组合实现。 torch._foreach_floor_(tensors) # Paddle 写法 -def foreach_operator_(func, tensors): - result = [] - for x in tensors: - result.append(paddle.assign(func(x), x)) - return result -foreach_operator_(tensors, paddle.floor) +[paddle.assign(paddle.floor(x), x) for x in tensors] ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md b/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md index 3fbe87f0418..1f6effbe9be 100644 --- a/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md +++ b/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md @@ -1042,10 +1042,10 @@ | NOT-IMPLEMENTED-ITEM(`torch.jit.trace`, https://pytorch.org/docs/stable/generated/torch.jit.trace.html#torch-jit-trace, 可新增,但框架底层无相关设计,成本高) | | NOT-IMPLEMENTED-ITEM(`torch.jit.unused`, https://pytorch.org/docs/stable/generated/torch.jit.unused.html#torch-jit-unused, 可新增,但框架底层无相关设计,成本高) | | NOT-IMPLEMENTED-ITEM(`torch.utils.checkpoint.checkpoint_sequential`, https://pytorch.org/docs/stable/checkpoint.html#torch.utils.checkpoint.checkpoint_sequential, 可新增,但框架底层无相关设计,成本高) | -| NOT-IMPLEMENTED-ITEM(`torch.nn.parameter.UninitializedBuffer`, https://pytorch.org/docs/stable/generated/torch.nn.parameter.UninitializedBuffer.html#torch.nn.parameter.UninitializedBuffer, 可新增,但框架底层无相关设计,成本高) | -| NOT-IMPLEMENTED-ITEM(`torch.autograd.Function.jvp`, https://pytorch.org/docs/stable/generated/torch.autograd.Function.jvp.html#torch-autograd-function-jvp, 可新增,但框架底层无相关设计,成本高) | +| NOT-IMPLEMENTED-ITEM(`torch.nn.parameter.UninitializedBuffer`, https://pytorch.org/docs/stable/generated/torch.nn.parameter.UninitializedBuffer.html#torch.nn.parameter.UninitializedBuffer, 可新增,且框架底层有相关设计,成本低) | +| NOT-IMPLEMENTED-ITEM(`torch.autograd.Function.jvp`, https://pytorch.org/docs/stable/generated/torch.autograd.Function.jvp.html#torch-autograd-function-jvp, 可新增,且框架底层有相关设计,成本低) | | NOT-IMPLEMENTED-ITEM(`torch.memory_format`, https://pytorch.org/docs/stable/tensor_attributes.html#torch.memory_format, 可新增,但框架底层无相关设计,成本高) | -| NOT-IMPLEMENTED-ITEM(`torch.distributed.is_gloo_available`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.is_gloo_available, 可新增,但框架底层无相关设计,成本高) | +| NOT-IMPLEMENTED-ITEM(`torch.distributed.is_gloo_available`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.is_gloo_available, 可新增,且框架底层有相关设计,成本低) | | NOT-IMPLEMENTED-ITEM(`torch.distributed.get_group_rank`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.get_group_rank, 可新增,且框架底层有相关设计,成本低) | | NOT-IMPLEMENTED-ITEM(`torch.distributed.get_global_rank`, https://pytorch.org/docs/stable/distributed.html#torch.distributed.get_process_group_ranks, 可新增,且框架底层有相关设计,成本低) | | NOT-IMPLEMENTED-ITEM(`torch.set_deterministic_debug_mode`, https://pytorch.org/docs/stable/generated/torch.set_deterministic_debug_mode.html#torch-set-deterministic-debug-mode, 可新增,但框架底层无相关设计,成本高) | From 6782048fbf978916e0b72a2744e551219c5661cc Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Tue, 8 Apr 2025 18:16:21 +0800 Subject: [PATCH 07/15] update cuda docs --- .../Tensor/torch.Tensor.cuda.md | 46 +++++++++++++++++-- .../cuda/torch.cuda.Stream__upper.md | 23 ++++++++++ .../cuda/torch.cuda.current_device.md | 4 +- .../cuda/torch.cuda.current_stream.md | 34 ++++++++++++-- .../api_difference/cuda/torch.cuda.device.md | 24 ++++++---- .../cuda/torch.cuda.get_device_properties.md | 30 ++++++++++-- .../cuda/torch.cuda.set_device.md | 29 +++++++++++- .../cuda/torch.cuda.synchronize.md | 31 +++++++++++-- .../torch/torch.cpu.current_device.md | 15 ++++++ .../torch/torch.cpu.set_device.md | 39 ++++++++++++++++ .../api_difference/torch/torch.device.md | 27 ++++++++++- .../torch/torch.set_default_device.md | 27 +++++++++++ .../pytorch_api_mapping_cn.md | 2 - 13 files changed, 301 insertions(+), 30 deletions(-) create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.cpu.current_device.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.cpu.set_device.md diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cuda.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cuda.md index 0504298c46f..df743dd6997 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cuda.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cuda.md @@ -1,4 +1,4 @@ -## [torch 参数更多]torch.Tensor.cuda +## [输入参数类型不一致]torch.Tensor.cuda ### [torch.Tensor.cuda](https://pytorch.org/docs/stable/generated/torch.Tensor.cuda.html#torch.Tensor.cuda) @@ -12,12 +12,52 @@ torch.Tensor.cuda(device=None, non_blocking=False, memory_format=torch.preserve_ paddle.Tensor.cuda(device_id=None, blocking=False) ``` -PyTorch 相比 Paddle 支持更多其他参数,具体如下: +两者功能一致但参数类型不一致,具体如下: ### 参数映射 | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ | ------------------------------------------------------------------------ | -| device | device_id | 目标 GPU 设备,仅参数名不一致。 | +| device | device_id | 目标 GPU 设备,输入参数类型不一致,需要转写。 | | non_blocking | blocking | 是否同步或异步拷贝,PyTorch 和 Paddle 取值相反,需要转写。 | | memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + + +### 转写示例 + +#### non_blocking: 同步或异步拷贝 + +```python +# PyTorch 写法 +tensor.cuda(non_blocking=True) + +# Paddle 写法 +tensor.cuda(non_blocking=not True) +``` + +#### device: 目标 GPU 设备 + +```python +# PyTorch 写法 +tensor.cuda("cuda:0") + +# Paddle 写法 +tensor.cuda(0) + +# PyTorch 写法 +device = "cuda:0" +tensor.cuda(device) + +# Paddle 写法 +device = "cuda:0" +device.replace("cuda:"," ") +tensor.cuda(device) + +# PyTorch 写法 +device = 0 +tensor.cuda(device) + +# Paddle 写法 +device = 0 +tensor.cuda(device) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.Stream__upper.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.Stream__upper.md index cae6c35d932..fdf38e3f9c9 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.Stream__upper.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.Stream__upper.md @@ -36,3 +36,26 @@ high_priority = 1 default_priority = 2 y = paddle.device.Stream(priority=default_priority) ``` + +#### device: 希望分配 stream 的设备 + +```python +# PyTorch 写法 +torch.cuda.Stream('cuda:0') + +# Paddle 写法 +paddle.device.Stream('gpu:0') + +# PyTorch 写法 +num=2 +torch.cuda.Stream(num) + +# Paddle 写法 +paddle.device.Stream(device=f'gpu:{type}') + +# PyTorch 写法 +torch.cuda.Stream(device=0 if 2 > 1 else 1) + +# Paddle 写法 +paddle.device.Stream('gpu:0') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_device.md index b2613355bff..74735ce0cee 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_device.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_device.md @@ -6,10 +6,10 @@ torch.cuda.current_device() ``` -### [paddle.framework._current_expected_place]() +### [paddle.get_device](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/get_device_cn.html#get-device) ```python -paddle.framework._current_expected_place() +paddle.get_device() ``` 功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md index 2882e14c31f..74c7318900e 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md @@ -1,4 +1,4 @@ -## [参数完全一致]torch.cuda.current_stream +## [输入参数类型不一致]torch.cuda.current_stream ### [torch.cuda.current_stream](https://pytorch.org/docs/stable/generated/torch.cuda.current_stream.html#torch.cuda.current_stream) @@ -6,15 +6,39 @@ torch.cuda.current_stream(device=None) ``` -### [paddle.device.cuda.current_stream](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/cuda/current_stream_cn.html) +### [paddle.device.current_stream](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/cuda/current_stream_cn.html) ```python -paddle.device.cuda.current_stream(device=None) +paddle.device.current_stream(device=None) ``` -功能一致,参数完全一致,具体如下: +功能一致,参数类型不一致,具体如下: ### 参数映射 | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ | ------------------------------------------------------ | -| device | device | 表示希望获取 stream 的设备或者设备 ID。如果为 None,则为当前的设备。默认值为 None。 | +| device | device | 表示希望获取 stream 的设备或者设备 ID。如果为 None,则为当前的设备。默认值为 None,需要转写。 | + +### 转写示例 +#### device: 特定的运行设备 + +```python +# PyTorch 写法 +torch.cuda.current_stream('cuda:0') + +# Paddle 写法 +paddle.device.current_stream('gpu:0') + +# PyTorch 写法 +num=2 +torch.cuda.current_stream(num) + +# Paddle 写法 +paddle.device.current_stream(device=f'gpu:{type}') + +# PyTorch 写法 +torch.cuda.current_stream(device=0 if 2 > 1 else 1) + +# Paddle 写法 +paddle.device.current_stream('gpu:0') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device.md index 6a8818f687a..d127de0e74c 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device.md @@ -6,10 +6,10 @@ torch.cuda.device(device) ``` -### [paddle.CUDAPlace](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/CUDAPlace_cn.html) +### [paddle.device._convert_to_place](https://github.com/PaddlePaddle/Paddle/blob/c8ccc9b154632ef41ade1b8e97b87d54fde7e8f8/python/paddle/device/__init__.py#L174) ```python -paddle.CUDAPlace(id) +paddle.device._convert_to_place(device) ``` 其中 PyTorch 与 Paddle 的参数支持类型不一致,具体如下: @@ -18,23 +18,29 @@ paddle.CUDAPlace(id) | PyTorch | PaddlePaddle | 备注 | | ------- | ------------ | -------------------------------------------------------------------------------- | -| device | id | GPU 的设备 ID, PyTorch 支持 torch.device 和 int,Paddle 支持 int,需要转写。 | +| device | device | GPU 的设备 ID, PyTorch 支持 torch.device 和 int,Paddle 支持 str,需要转写。 | ### 转写示例 -#### device: 获取 device 参数,对其取 device.index 值 +#### device: 特定的运行设备 ```python # PyTorch 写法 -torch.cuda.device(torch.device('cuda')) +torch.cuda.device('cuda:0') # Paddle 写法 -paddle.CUDAPlace(0) +paddle.device._convert_to_place('gpu:0') -# 增加 index # PyTorch 写法 -torch.cuda.device(torch.device('cuda', index=index)) +num=2 +torch.cuda.device(num) # Paddle 写法 -paddle.CUDAPlace(index) +paddle.device._convert_to_place(device=f'gpu:{type}') + +# PyTorch 写法 +torch.cuda.device(device=0 if 2 > 1 else 1) + +# Paddle 写法 +paddle.device._convert_to_place('gpu:0') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md index b67e7672cf2..9edb1d8f2af 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md @@ -1,4 +1,4 @@ -## [参数完全一致]torch.cuda.get_device_properties +## [输入参数用法不一致]torch.cuda.get_device_properties ### [torch.cuda.get_device_properties](https://pytorch.org/docs/stable/generated/torch.cuda.get_device_properties.html#torch.cuda.get_device_properties) @@ -12,9 +12,33 @@ torch.cuda.get_device_properties(device) paddle.device.cuda.get_device_properties(device) ``` -功能一致,参数完全一致,具体如下: +功能一致,输入参数用法不一致,具体如下: ### 参数映射 | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ | ------------------------------------------------------ | -| device | device | 表示设备、设备 ID 和类似于 gpu:x 的设备名称。如果 device 为空,则 device 为当前的设备。默认值为 None。| +| device | device | 表示设备、设备 ID 和类似于 gpu:x 的设备名称。如果 device 为空,则 device 为当前的设备。默认值为 None,需要转写。| + +### 转写示例 +#### device: 设备 + +```python +# PyTorch 写法 +torch.cuda.get_device_properties('cuda:0') + +# Paddle 写法 +paddle.device.cuda.get_device_properties('gpu:0') + +# PyTorch 写法 +num=2 +torch.cuda.get_device_properties(num) + +# Paddle 写法 +paddle.device.cuda.get_device_properties(device=f'gpu:{type}') + +# PyTorch 写法 +torch.cuda.get_device_properties(device=0 if 2 > 1 else 1) + +# Paddle 写法 +paddle.device.cuda.get_device_properties('gpu:0') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_device.md index bfb98afe3e3..61ab5a2e28f 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_device.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_device.md @@ -6,10 +6,10 @@ torch.cuda.set_device(device) ``` -### [paddle.device.set_device](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/device/set_device_cn.html) +### [paddle.set_device](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/device/set_device_cn.html) ```python -paddle.device.set_device(device) +paddle.set_device(device) ``` 功能一致,参数类型不一致,具体如下: @@ -18,3 +18,28 @@ paddle.device.set_device(device) | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ |------------------------------------------------| | device | device | PyTorch 支持 torch.device 或 int。PaddlePaddle 支持 str。 | + + +### 转写示例 +#### device: 特定的运行设备 + +```python +# PyTorch 写法 +torch.cuda.set_device('cuda:0') + +# Paddle 写法 +paddle.set_device('gpu:0') + +# PyTorch 写法 +num=2 +torch.cuda.set_device(num) + +# Paddle 写法 +paddle.set_device(device=f'gpu:{type}') + +# PyTorch 写法 +torch.cuda.set_device(device=0 if 2 > 1 else 1) + +# Paddle 写法 +paddle.set_device('gpu:0') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.synchronize.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.synchronize.md index 9bd33ebd7d0..f52c0ab7394 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.synchronize.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.synchronize.md @@ -1,4 +1,4 @@ -## [参数完全一致]torch.cuda.synchronize +## [ 输入参数用法不一致 ]torch.cuda.synchronize ### [torch.cuda.synchronize](https://pytorch.org/docs/stable/generated/torch.cuda.synchronize.html#torch.cuda.synchronize) @@ -12,9 +12,34 @@ torch.cuda.synchronize(device) paddle.device.cuda.synchronize(device) ``` -功能一致,参数完全一致(PyTorch 参数是 PaddlePaddle 参数子集),具体如下: +功能一致,输入参数用法不一致,具体如下: + ### 参数映射 | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ |-----------------------------------------------------------------------| -| device | device | PyTorch 支持 torch.device 和 int。 PaddlePaddle 支持 paddle.CUDAPlace、int 、str。 | +| device | device | PyTorch 支持 torch.device 和 int。 PaddlePaddle 支持 paddle.CUDAPlace、int 、str,需要转写 | + +### 转写示例 +#### device: 特定的运行设备 + +```python +# PyTorch 写法 +torch.cuda.synchronize('cuda:0') + +# Paddle 写法 +paddle.device.cuda.synchronize('gpu:0') + +# PyTorch 写法 +num=2 +torch.cuda.synchronize(num) + +# Paddle 写法 +paddle.device.cuda.synchronize(device=f'gpu:{type}') + +# PyTorch 写法 +torch.cuda.synchronize(device=0 if 2 > 1 else 1) + +# Paddle 写法 +paddle.device.cuda.synchronize('gpu:0') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.cpu.current_device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.cpu.current_device.md new file mode 100644 index 00000000000..98e4f5c29c4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.cpu.current_device.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.cpu.current_device + +### [torch.cpu.current_device](https://pytorch.org/docs/stable/generated/torch.cpu.current_device.html) + +```python +torch.cpu.current_device() +``` + +### [paddle.get_device](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/get_device_cn.html#get-device) + +```python +paddle.get_device() +``` + +功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.cpu.set_device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.cpu.set_device.md new file mode 100644 index 00000000000..54ea6a8f077 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.cpu.set_device.md @@ -0,0 +1,39 @@ +## [ 输入参数类型不一致 ]torch.cpu.set_device + +### [torch.cpu.set_device](https://pytorch.org/docs/stable/generated/torch.cpu.set_device.html) + +```python +torch.cpu.set_device(device) +``` + +### [paddle.set_device](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/set_device_cn.html#set-device) + +```python +paddle.set_device(device) +``` + +功能一致,参数类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ |------------------------------------------------| +| device | device | PyTorch 支持 torch.device 。PaddlePaddle 支持 str。 | + + +### 转写示例 +#### device: 特定的运行设备 + +```python +# PyTorch 写法 +device = 'cpu:1' +torch.cpu.set_device(device=device) + +# Paddle 写法 +paddle.set_device('cpu') + +# PyTorch 写法 +torch.cpu.set_device(device='cpu:0') + +# Paddle 写法 +paddle.set_device('cpu') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.device.md index f84adb5e303..9fcd4c312a2 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.device.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.device.md @@ -3,7 +3,7 @@ ### [torch.device](https://pytorch.org/docs/stable/tensor_attributes.html#torch-device) ```python -torch.device(type, index) +torch.device(type, index, device) ``` Paddle 无此 API,需要组合实现。 @@ -23,4 +23,29 @@ torch.device('cpu') # Paddle 写法 'cpu' + +# PyTorch 写法 +type = 'cuda' +index = 0 +torch.device(index=index, type=type) + +# Paddle 写法 +type = type.replace('cuda', 'gpu') +f'{type}:{index}' + +# PyTorch 写法 +type = 'cuda' +index = 0 +torch.device(index=index, type=type) + +# Paddle 写法 +type = type.replace('cuda', 'gpu') +f'{type}:{index}' + +# PyTorch 写法 +a = 1 +torch.device(a) + +# Paddle 写法 +type = f'gpu:{type}' ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md index ed831e09731..903ec5f6946 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md @@ -18,3 +18,30 @@ paddle.set_device(device) | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ |------------------------------------------------| | device | device | PyTorch 支持 torch.device 。PaddlePaddle 支持 str。 | + + +### 转写示例 +#### device: 特定的运行设备 + +```python +# PyTorch 写法 +torch.set_default_device('cuda:0') + +# Paddle 写法 +paddle.set_device('gpu:0') + +# PyTorch 写法 +num=2 +torch.set_default_device(num) + +# Paddle 写法 +paddle.set_device(device=f'gpu:{type}') + +# PyTorch 写法 +device='cpu' +torch.set_default_device(device) + +# Paddle 写法 +device='cpu' +paddle.set_device(device=device) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md b/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md index 1f6effbe9be..df415b79eda 100644 --- a/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md +++ b/docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md @@ -799,11 +799,9 @@ | NOT-IMPLEMENTED-ITEM(`torch.SymBool`, https://pytorch.org/docs/stable/torch.html#torch.SymBool, 可新增,且框架底层有相关设计,成本低) | | NOT-IMPLEMENTED-ITEM(`torch.SymFloat`, https://pytorch.org/docs/stable/torch.html#torch.SymFloat, 可新增,且框架底层有相关设计,成本低) | | NOT-IMPLEMENTED-ITEM(`torch.SymInt`, https://pytorch.org/docs/stable/torch.html#torch.SymInt, 可新增,且框架底层有相关设计,成本低) | -| NOT-IMPLEMENTED-ITEM(`torch.cpu.current_device`, https://pytorch.org/docs/stable/generated/torch.cpu.current_device.html#torch-cpu-current-device, 可新增,但框架底层无相关设计,成本高) | | NOT-IMPLEMENTED-ITEM(`torch.cpu.current_stream`, https://pytorch.org/docs/stable/generated/torch.cpu.current_stream.html#torch.cpu.current_stream, 可新增,但框架底层无相关设计,成本高) | | NOT-IMPLEMENTED-ITEM(`torch.cpu.device_count`, https://pytorch.org/docs/stable/generated/torch.cpu.device_count.html#torch-cpu-device-count, 可新增,但框架底层无相关设计,成本高) | | NOT-IMPLEMENTED-ITEM(`torch.cpu.is_available`, https://pytorch.org/docs/stable/generated/torch.cpu.is_available.html#torch-cpu-is-available, 可新增,但框架底层无相关设计,成本高) | -| NOT-IMPLEMENTED-ITEM(`torch.cpu.set_device`, https://pytorch.org/docs/stable/generated/torch.cpu.set_device.html#torch-cpu-set-device, 可新增,但框架底层无相关设计,成本高) | | NOT-IMPLEMENTED-ITEM(`torch.cpu.stream`, https://pytorch.org/docs/stable/generated/torch.cpu.stream.html#torch-cpu-stream, 可新增,但框架底层无相关设计,成本高) | | NOT-IMPLEMENTED-ITEM(`torch.cpu.Stream`, https://pytorch.org/docs/stable/generated/torch.cpu.Stream.html#torch.cpu.Stream, 可新增,但框架底层无相关设计,成本高) | | NOT-IMPLEMENTED-ITEM(`torch.cpu.StreamContext`, https://pytorch.org/docs/stable/generated/torch.cpu.StreamContext.html#torch.cpu.StreamContext, 可新增,但框架底层无相关设计,成本高) | From 3e9c1c0b648008cc2a2471fc062e4171dcadc426 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Wed, 9 Apr 2025 08:53:01 +0800 Subject: [PATCH 08/15] add torch.Size --- .../api_difference/torch/torch.Size.count.md | 21 ++++++++++++++++ .../api_difference/torch/torch.Size.index.md | 22 ++++++++++++++++ .../api_difference/torch/torch.Size.numel.md | 25 +++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.count.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.index.md create mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.numel.md diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.count.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.count.md new file mode 100644 index 00000000000..0be7fc772dd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.count.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.Size.count + +### [torch.Size.count](https://pytorch.org/docs/stable/size.html) + +```python +torch.Size.count(value) +``` + +### [tuple.count]() + +```python +tuple.count(value) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------- | +| value | value | 表示获取的数值,。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.index.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.index.md new file mode 100644 index 00000000000..1ee84e7d632 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.index.md @@ -0,0 +1,22 @@ +## [ 参数完全一致 ]torch.Size.index + +### [torch.Size.index](https://pytorch.org/docs/stable/size.html) + +```python +torch.Size.index(value, start=0) +``` + +### [tuple.index]() + +```python +tuple.index(value, start=0) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------- | +| value | value | 查找的数值。 | +| start | start | 查找索引的起点,默认为 0。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.numel.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.numel.md new file mode 100644 index 00000000000..d4e0c4d2b18 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.numel.md @@ -0,0 +1,25 @@ +## [ 组合替代实现 ]torch.Size.numel + +### [torch.Size.numel](https://pytorch.org/docs/stable/size.html) + +```python +torch.Size.numel() +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +x = torch.ones(10, 20, 30) +s = x.size() +s.numel() + +# Paddle 写法 +x = paddle.ones([10, 20, 30]) +result = tuple(x.shape) +out = 1 +for x in result: + out *= x +``` From 4267d4f4653e160e7125de79402db26e90a44901 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Wed, 9 Apr 2025 15:51:24 +0800 Subject: [PATCH 09/15] update docs --- .../api_difference/torch/torch.Size.count.md | 23 +++++++++-------- .../api_difference/torch/torch.Size.index.md | 25 ++++++++++--------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.count.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.count.md index 0be7fc772dd..26e35c3fa21 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.count.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.count.md @@ -1,4 +1,4 @@ -## [ 参数完全一致 ]torch.Size.count +## [ 组合替代实现 ]torch.Size.count ### [torch.Size.count](https://pytorch.org/docs/stable/size.html) @@ -6,16 +6,17 @@ torch.Size.count(value) ``` -### [tuple.count]() +Paddle 无此 API,需要组合实现。 -```python -tuple.count(value) -``` +### 转写示例 -两者功能一致,参数完全一致,具体如下: - -### 参数映射 +```python +# PyTorch 写法 +x = torch.ones(10, 20, 30) +s = x.size() +s.count(30,) -| PyTorch | PaddlePaddle | 备注 | -| ------- | ------------ | ------- | -| value | value | 表示获取的数值,。 | +# Paddle 写法 +x = paddle.ones([10, 20, 30]) +s = tuple(x.shape) +s.count(30) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.index.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.index.md index 1ee84e7d632..3d4f89e533b 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.index.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.index.md @@ -1,4 +1,4 @@ -## [ 参数完全一致 ]torch.Size.index +## [ 组合替代实现 ]torch.Size.index ### [torch.Size.index](https://pytorch.org/docs/stable/size.html) @@ -6,17 +6,18 @@ torch.Size.index(value, start=0) ``` -### [tuple.index]() +Paddle 无此 API,需要组合实现。 -```python -tuple.index(value, start=0) -``` - -两者功能一致,参数完全一致,具体如下: +### 转写示例 -### 参数映射 +```python +# PyTorch 写法 +x = torch.ones(10, 20, 30) +s = x.size() +s.index(30, 1) -| PyTorch | PaddlePaddle | 备注 | -| ------- | ------------ | ------- | -| value | value | 查找的数值。 | -| start | start | 查找索引的起点,默认为 0。 | +# Paddle 写法 +x = paddle.ones([10, 20, 30]) +s = tuple(x.shape) +s.index(30, 1) +``` From 7820092d97159e565721a48d5c67996bfc409cab Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Fri, 11 Apr 2025 13:08:38 +0800 Subject: [PATCH 10/15] fix docs with cuda --- .../Tensor/torch.Tensor.cuda.md | 17 +++----------- .../cuda/torch.cuda.Stream__upper.md | 19 ++++------------ .../cuda/torch.cuda.current_stream.md | 11 ++-------- .../api_difference/cuda/torch.cuda.device.md | 10 ++------- .../cuda/torch.cuda.get_device_properties.md | 10 ++------- .../cuda/torch.cuda.set_device.md | 11 ++-------- .../cuda/torch.cuda.synchronize.md | 11 ++-------- .../torch/torch.cpu.set_device.md | 7 ------ .../api_difference/torch/torch.device.md | 22 ++++--------------- .../torch/torch.set_default_device.md | 11 ++++------ 10 files changed, 25 insertions(+), 104 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cuda.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cuda.md index df743dd6997..c9fa082045f 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cuda.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cuda.md @@ -32,7 +32,7 @@ paddle.Tensor.cuda(device_id=None, blocking=False) tensor.cuda(non_blocking=True) # Paddle 写法 -tensor.cuda(non_blocking=not True) +tensor.cuda(non_blocking=False) ``` #### device: 目标 GPU 设备 @@ -45,19 +45,8 @@ tensor.cuda("cuda:0") tensor.cuda(0) # PyTorch 写法 -device = "cuda:0" -tensor.cuda(device) - -# Paddle 写法 -device = "cuda:0" -device.replace("cuda:"," ") -tensor.cuda(device) - -# PyTorch 写法 -device = 0 -tensor.cuda(device) +tensor.cuda(0) # Paddle 写法 -device = 0 -tensor.cuda(device) +tensor.cuda(0) ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.Stream__upper.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.Stream__upper.md index fdf38e3f9c9..d0afc0d7eb6 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.Stream__upper.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.Stream__upper.md @@ -27,14 +27,10 @@ paddle.device.Stream(device=None, priority=None) ```python # PyTorch 写法 -high_priority = -1 -default_priority = 0 -y = torch.cuda.Stream(priority=default_priority) +y = torch.cuda.Stream(priority=0) # Paddle 写法 -high_priority = 1 -default_priority = 2 -y = paddle.device.Stream(priority=default_priority) +y = paddle.device.Stream(priority=2) ``` #### device: 希望分配 stream 的设备 @@ -47,15 +43,8 @@ torch.cuda.Stream('cuda:0') paddle.device.Stream('gpu:0') # PyTorch 写法 -num=2 -torch.cuda.Stream(num) +torch.cuda.Stream(2) # Paddle 写法 -paddle.device.Stream(device=f'gpu:{type}') - -# PyTorch 写法 -torch.cuda.Stream(device=0 if 2 > 1 else 1) - -# Paddle 写法 -paddle.device.Stream('gpu:0') +paddle.device.Stream(device='gpu:2') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md index 74c7318900e..4e032c5e787 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md @@ -30,15 +30,8 @@ torch.cuda.current_stream('cuda:0') paddle.device.current_stream('gpu:0') # PyTorch 写法 -num=2 -torch.cuda.current_stream(num) +torch.cuda.current_stream(2) # Paddle 写法 -paddle.device.current_stream(device=f'gpu:{type}') - -# PyTorch 写法 -torch.cuda.current_stream(device=0 if 2 > 1 else 1) - -# Paddle 写法 -paddle.device.current_stream('gpu:0') +paddle.device.current_stream(device='gpu:2') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device.md index d127de0e74c..74375838a26 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device.md @@ -32,15 +32,9 @@ torch.cuda.device('cuda:0') paddle.device._convert_to_place('gpu:0') # PyTorch 写法 -num=2 -torch.cuda.device(num) +torch.cuda.device(2) # Paddle 写法 -paddle.device._convert_to_place(device=f'gpu:{type}') +paddle.device._convert_to_place(device='gpu:2') -# PyTorch 写法 -torch.cuda.device(device=0 if 2 > 1 else 1) - -# Paddle 写法 -paddle.device._convert_to_place('gpu:0') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md index 9edb1d8f2af..6b23e3a2651 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md @@ -30,15 +30,9 @@ torch.cuda.get_device_properties('cuda:0') paddle.device.cuda.get_device_properties('gpu:0') # PyTorch 写法 -num=2 -torch.cuda.get_device_properties(num) +torch.cuda.get_device_properties(2) # Paddle 写法 -paddle.device.cuda.get_device_properties(device=f'gpu:{type}') +paddle.device.cuda.get_device_properties(device='gpu:2') -# PyTorch 写法 -torch.cuda.get_device_properties(device=0 if 2 > 1 else 1) - -# Paddle 写法 -paddle.device.cuda.get_device_properties('gpu:0') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_device.md index 61ab5a2e28f..1d3d55d1769 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_device.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_device.md @@ -31,15 +31,8 @@ torch.cuda.set_device('cuda:0') paddle.set_device('gpu:0') # PyTorch 写法 -num=2 -torch.cuda.set_device(num) +torch.cuda.set_device(2) # Paddle 写法 -paddle.set_device(device=f'gpu:{type}') - -# PyTorch 写法 -torch.cuda.set_device(device=0 if 2 > 1 else 1) - -# Paddle 写法 -paddle.set_device('gpu:0') +paddle.set_device(device='gpu:2') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.synchronize.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.synchronize.md index f52c0ab7394..db1c1b6f13d 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.synchronize.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.synchronize.md @@ -31,15 +31,8 @@ torch.cuda.synchronize('cuda:0') paddle.device.cuda.synchronize('gpu:0') # PyTorch 写法 -num=2 -torch.cuda.synchronize(num) +torch.cuda.synchronize(2) # Paddle 写法 -paddle.device.cuda.synchronize(device=f'gpu:{type}') - -# PyTorch 写法 -torch.cuda.synchronize(device=0 if 2 > 1 else 1) - -# Paddle 写法 -paddle.device.cuda.synchronize('gpu:0') +paddle.device.cuda.synchronize(device='gpu:2') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.cpu.set_device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.cpu.set_device.md index 54ea6a8f077..bd18f29fb6e 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.cpu.set_device.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.cpu.set_device.md @@ -24,13 +24,6 @@ paddle.set_device(device) #### device: 特定的运行设备 ```python -# PyTorch 写法 -device = 'cpu:1' -torch.cpu.set_device(device=device) - -# Paddle 写法 -paddle.set_device('cpu') - # PyTorch 写法 torch.cpu.set_device(device='cpu:0') diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.device.md index 9fcd4c312a2..93591a0af72 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.device.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.device.md @@ -17,7 +17,6 @@ torch.device('cuda', 0) # Paddle 写法 'gpu:0' - # PyTorch 写法 torch.device('cpu') @@ -25,27 +24,14 @@ torch.device('cpu') 'cpu' # PyTorch 写法 -type = 'cuda' -index = 0 -torch.device(index=index, type=type) - -# Paddle 写法 -type = type.replace('cuda', 'gpu') -f'{type}:{index}' - -# PyTorch 写法 -type = 'cuda' -index = 0 -torch.device(index=index, type=type) +torch.device(1) # Paddle 写法 -type = type.replace('cuda', 'gpu') -f'{type}:{index}' +"gpu:1" # PyTorch 写法 -a = 1 -torch.device(a) +torch.device("cuda:0") # Paddle 写法 -type = f'gpu:{type}' +"gpu:0" ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md index 903ec5f6946..4fb9e2827e4 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md @@ -31,17 +31,14 @@ torch.set_default_device('cuda:0') paddle.set_device('gpu:0') # PyTorch 写法 -num=2 -torch.set_default_device(num) +torch.set_default_device(2) # Paddle 写法 -paddle.set_device(device=f'gpu:{type}') +paddle.set_device(device='gpu:2') # PyTorch 写法 -device='cpu' -torch.set_default_device(device) +torch.set_default_device("cpu") # Paddle 写法 -device='cpu' -paddle.set_device(device=device) +paddle.set_device("cpu") ``` From 91112714a018915c0481cbeb2e56dc0a5a669920 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Mon, 14 Apr 2025 22:08:13 +0800 Subject: [PATCH 11/15] fix docs --- .../Tensor/torch.Tensor.size.md | 27 +++++++++++++++++++ .../cuda/torch.cuda.Stream__upper.md | 4 +-- .../cuda/torch.cuda.current_stream.md | 6 +++++ .../cuda/torch.cuda.get_device_properties.md | 7 ++++- .../api_difference/torch/torch.Size.count.md | 22 --------------- .../api_difference/torch/torch.Size.index.md | 23 ---------------- .../api_difference/torch/torch.Size.md | 27 +++++++++++++++++++ .../api_difference/torch/torch.Size.numel.md | 25 ----------------- .../api_difference/torch/torch.device.md | 27 ++++++++++++++++++- 9 files changed, 94 insertions(+), 74 deletions(-) delete mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.count.md delete mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.index.md delete mode 100644 docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.numel.md diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.size.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.size.md index b0171744136..55d206995db 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.size.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.size.md @@ -29,3 +29,30 @@ torch.tensor([-1, -2, 3]).size(0) # Paddle 写法 paddle.to_tensor([-0.4, -0.2, 0.1, 0.3]).shape[0] ``` + +```python +# PyTorch 写法 +torch.ones(10, 20, 30).size().count(30) + +# Paddle 写法 +tuple(paddle.ones([10, 20, 30]).shape).count(30) +``` + +```python +# PyTorch 写法 +torch.ones(10, 20, 30).size().index(30, 1) + +# Paddle 写法 +tuple(paddle.ones([10, 20, 30]).shape).index(30, 1) +``` + +```python +# PyTorch 写法 +torch.ones(10, 20, 30).size().numel() + +# Paddle 写法 +result = tuple(paddle.ones([10, 20, 30]).shape) +out = 1 +for x in result: + out *= x +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.Stream__upper.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.Stream__upper.md index d0afc0d7eb6..d1e95623fc0 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.Stream__upper.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.Stream__upper.md @@ -27,10 +27,10 @@ paddle.device.Stream(device=None, priority=None) ```python # PyTorch 写法 -y = torch.cuda.Stream(priority=0) +torch.cuda.Stream(priority=0) # Paddle 写法 -y = paddle.device.Stream(priority=2) +paddle.device.Stream(priority=2) ``` #### device: 希望分配 stream 的设备 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md index 4e032c5e787..fe4669f92fa 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md @@ -34,4 +34,10 @@ torch.cuda.current_stream(2) # Paddle 写法 paddle.device.current_stream(device='gpu:2') + +# PyTorch 写法 +torch.cuda.current_stream(device=None) + +# Paddle 写法 +paddle.device.current_stream(device=None) ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md index 6b23e3a2651..f2055d0ff37 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md @@ -17,7 +17,7 @@ paddle.device.cuda.get_device_properties(device) | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ | ------------------------------------------------------ | -| device | device | 表示设备、设备 ID 和类似于 gpu:x 的设备名称。如果 device 为空,则 device 为当前的设备。默认值为 None,需要转写。| +| device | device | 表示设备、设备 ID 和类似于 gpu:x 的设备名称。默认值为 None,需要转写。| ### 转写示例 #### device: 设备 @@ -35,4 +35,9 @@ torch.cuda.get_device_properties(2) # Paddle 写法 paddle.device.cuda.get_device_properties(device='gpu:2') +# PyTorch 写法 +torch.cuda.get_device_properties(device=None) + +# Paddle 写法 +paddle.device.cuda.get_device_properties(device=None) ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.count.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.count.md deleted file mode 100644 index 26e35c3fa21..00000000000 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.count.md +++ /dev/null @@ -1,22 +0,0 @@ -## [ 组合替代实现 ]torch.Size.count - -### [torch.Size.count](https://pytorch.org/docs/stable/size.html) - -```python -torch.Size.count(value) -``` - -Paddle 无此 API,需要组合实现。 - -### 转写示例 - -```python -# PyTorch 写法 -x = torch.ones(10, 20, 30) -s = x.size() -s.count(30,) - -# Paddle 写法 -x = paddle.ones([10, 20, 30]) -s = tuple(x.shape) -s.count(30) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.index.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.index.md deleted file mode 100644 index 3d4f89e533b..00000000000 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.index.md +++ /dev/null @@ -1,23 +0,0 @@ -## [ 组合替代实现 ]torch.Size.index - -### [torch.Size.index](https://pytorch.org/docs/stable/size.html) - -```python -torch.Size.index(value, start=0) -``` - -Paddle 无此 API,需要组合实现。 - -### 转写示例 - -```python -# PyTorch 写法 -x = torch.ones(10, 20, 30) -s = x.size() -s.index(30, 1) - -# Paddle 写法 -x = paddle.ones([10, 20, 30]) -s = tuple(x.shape) -s.index(30, 1) -``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.md index 8f428ee39d3..387a019e9ac 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.md @@ -25,3 +25,30 @@ torch.Size([2, 3]) # Paddle 写法 (2, 3) ``` + +```python +# PyTorch 写法 +torch.Size([2, 3]).count(2) + +# Paddle 写法 +(2, 3).count(2) +``` + +```python +# PyTorch 写法 +torch.Size([2, 3]).index(3,0) + +# Paddle 写法 +(2, 3).index(3,0) +``` + +```python +# PyTorch 写法 +torch.Size([2, 3]).numel() + +# Paddle 写法 +result = (2, 3) +out = 1 +for x in result: + out *= x +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.numel.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.numel.md deleted file mode 100644 index d4e0c4d2b18..00000000000 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.Size.numel.md +++ /dev/null @@ -1,25 +0,0 @@ -## [ 组合替代实现 ]torch.Size.numel - -### [torch.Size.numel](https://pytorch.org/docs/stable/size.html) - -```python -torch.Size.numel() -``` - -Paddle 无此 API,需要组合实现。 - -### 转写示例 - -```python -# PyTorch 写法 -x = torch.ones(10, 20, 30) -s = x.size() -s.numel() - -# Paddle 写法 -x = paddle.ones([10, 20, 30]) -result = tuple(x.shape) -out = 1 -for x in result: - out *= x -``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.device.md index 93591a0af72..be1f2359079 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.device.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.device.md @@ -1,9 +1,13 @@ ## [ 组合替代实现 ]torch.device +该 api 有两组参数列表重载,因此有两组差异分析。 + +----------------------------------------------- + ### [torch.device](https://pytorch.org/docs/stable/tensor_attributes.html#torch-device) ```python -torch.device(type, index, device) +torch.device(type, index) ``` Paddle 无此 API,需要组合实现。 @@ -20,6 +24,27 @@ torch.device('cuda', 0) # PyTorch 写法 torch.device('cpu') +# Paddle 写法 +'cpu' +``` + + +----------------------------------------------- + +### [torch.device](https://pytorch.org/docs/stable/tensor_attributes.html#torch-device) + +```python +torch.device(device) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +torch.device('cpu') + # Paddle 写法 'cpu' From 75bf305b5d379fe1c2200437b672ce957beede80 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Wed, 16 Apr 2025 12:35:35 +0800 Subject: [PATCH 12/15] fix torch.cuda.current_stream --- .../api_difference/cuda/torch.cuda.current_stream.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md index fe4669f92fa..98ce6750b48 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md @@ -17,7 +17,7 @@ paddle.device.current_stream(device=None) | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ | ------------------------------------------------------ | -| device | device | 表示希望获取 stream 的设备或者设备 ID。如果为 None,则为当前的设备。默认值为 None,需要转写。 | +| device | device | 表示希望获取 stream 的设备或者设备 ID。如果为 None,则为当前的设备。默认值为 None,需要转写。 | ### 转写示例 #### device: 特定的运行设备 @@ -36,8 +36,8 @@ torch.cuda.current_stream(2) paddle.device.current_stream(device='gpu:2') # PyTorch 写法 -torch.cuda.current_stream(device=None) +torch.cuda.current_stream() # Paddle 写法 -paddle.device.current_stream(device=None) +paddle.device.current_stream() ``` From 7aa320796030574819ac30a9ed84816e37277455 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Fri, 25 Apr 2025 21:44:42 +0800 Subject: [PATCH 13/15] fix some docs --- .../api_difference/Tensor/torch.Tensor.size.md | 5 +---- .../api_difference/cuda/torch.cuda.get_device_properties.md | 6 ------ .../api_difference/torch/torch.device.md | 4 ++-- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.size.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.size.md index 55d206995db..29de1493e6b 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.size.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.size.md @@ -51,8 +51,5 @@ tuple(paddle.ones([10, 20, 30]).shape).index(30, 1) torch.ones(10, 20, 30).size().numel() # Paddle 写法 -result = tuple(paddle.ones([10, 20, 30]).shape) -out = 1 -for x in result: - out *= x +paddle.ones([10, 20, 30]).numel().item() ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md index f2055d0ff37..d5530e0bcc8 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md @@ -34,10 +34,4 @@ torch.cuda.get_device_properties(2) # Paddle 写法 paddle.device.cuda.get_device_properties(device='gpu:2') - -# PyTorch 写法 -torch.cuda.get_device_properties(device=None) - -# Paddle 写法 -paddle.device.cuda.get_device_properties(device=None) ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.device.md index be1f2359079..d4b42ac5e2f 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.device.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.device.md @@ -16,13 +16,13 @@ Paddle 无此 API,需要组合实现。 ```python # PyTorch 写法 -torch.device('cuda', 0) +torch.device(type='cuda', index=0) # Paddle 写法 'gpu:0' # PyTorch 写法 -torch.device('cpu') +torch.device(type='cpu') # Paddle 写法 'cpu' From ac9e7b3433fcf961f094c9b5390bd3a38647ccd2 Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Fri, 25 Apr 2025 22:06:54 +0800 Subject: [PATCH 14/15] fix cuda.get_device_properties --- .../api_difference/cuda/torch.cuda.get_device_properties.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md index d5530e0bcc8..6fabff6ad58 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md @@ -34,4 +34,10 @@ torch.cuda.get_device_properties(2) # Paddle 写法 paddle.device.cuda.get_device_properties(device='gpu:2') + +# PyTorch 写法 +torch.cuda.get_device_properties() + +# Paddle 写法 +paddle.device.cuda.get_device_properties() ``` From 76e7eabaafe2b94b0979ae3d139a7cc30054c55b Mon Sep 17 00:00:00 2001 From: xxa <1829994704@qq.com> Date: Sun, 27 Apr 2025 12:37:40 +0800 Subject: [PATCH 15/15] fix docs --- .../api_difference/Tensor/torch.Tensor.cuda.md | 2 +- .../api_difference/cuda/torch.cuda.current_stream.md | 2 +- .../api_difference/cuda/torch.cuda.device.md | 2 +- .../api_difference/cuda/torch.cuda.get_device_properties.md | 6 +++--- .../api_difference/cuda/torch.cuda.set_device.md | 2 +- .../api_difference/cuda/torch.cuda.synchronize.md | 6 +++--- .../api_difference/torch/torch.cpu.set_device.md | 2 +- .../api_difference/torch/torch.set_default_device.md | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cuda.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cuda.md index c9fa082045f..febf381d9b9 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cuda.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cuda.md @@ -32,7 +32,7 @@ paddle.Tensor.cuda(device_id=None, blocking=False) tensor.cuda(non_blocking=True) # Paddle 写法 -tensor.cuda(non_blocking=False) +tensor.cuda(blocking=False) ``` #### device: 目标 GPU 设备 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md index 98ce6750b48..fa3533ae66f 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md @@ -33,7 +33,7 @@ paddle.device.current_stream('gpu:0') torch.cuda.current_stream(2) # Paddle 写法 -paddle.device.current_stream(device='gpu:2') +paddle.device.current_stream('gpu:2') # PyTorch 写法 torch.cuda.current_stream() diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device.md index 74375838a26..90fca7b96f0 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device.md @@ -35,6 +35,6 @@ paddle.device._convert_to_place('gpu:0') torch.cuda.device(2) # Paddle 写法 -paddle.device._convert_to_place(device='gpu:2') +paddle.device._convert_to_place('gpu:2') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md index 6fabff6ad58..6e15d7aae51 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md @@ -1,4 +1,4 @@ -## [输入参数用法不一致]torch.cuda.get_device_properties +## [ 输入参数类型不一致 ]torch.cuda.get_device_properties ### [torch.cuda.get_device_properties](https://pytorch.org/docs/stable/generated/torch.cuda.get_device_properties.html#torch.cuda.get_device_properties) @@ -12,7 +12,7 @@ torch.cuda.get_device_properties(device) paddle.device.cuda.get_device_properties(device) ``` -功能一致,输入参数用法不一致,具体如下: +两者功能一致但参数类型不一致,具体如下: ### 参数映射 | PyTorch | PaddlePaddle | 备注 | @@ -33,7 +33,7 @@ paddle.device.cuda.get_device_properties('gpu:0') torch.cuda.get_device_properties(2) # Paddle 写法 -paddle.device.cuda.get_device_properties(device='gpu:2') +paddle.device.cuda.get_device_properties('gpu:2') # PyTorch 写法 torch.cuda.get_device_properties() diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_device.md index 1d3d55d1769..599a9d54115 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_device.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_device.md @@ -34,5 +34,5 @@ paddle.set_device('gpu:0') torch.cuda.set_device(2) # Paddle 写法 -paddle.set_device(device='gpu:2') +paddle.set_device('gpu:2') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.synchronize.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.synchronize.md index db1c1b6f13d..382f559299f 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.synchronize.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.synchronize.md @@ -1,4 +1,4 @@ -## [ 输入参数用法不一致 ]torch.cuda.synchronize +## [ 输入参数类型不一致 ]torch.cuda.synchronize ### [torch.cuda.synchronize](https://pytorch.org/docs/stable/generated/torch.cuda.synchronize.html#torch.cuda.synchronize) @@ -12,7 +12,7 @@ torch.cuda.synchronize(device) paddle.device.cuda.synchronize(device) ``` -功能一致,输入参数用法不一致,具体如下: +两者功能一致但参数类型不一致,具体如下: ### 参数映射 @@ -34,5 +34,5 @@ paddle.device.cuda.synchronize('gpu:0') torch.cuda.synchronize(2) # Paddle 写法 -paddle.device.cuda.synchronize(device='gpu:2') +paddle.device.cuda.synchronize('gpu:2') ``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.cpu.set_device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.cpu.set_device.md index bd18f29fb6e..4eafc1f93ca 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.cpu.set_device.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.cpu.set_device.md @@ -25,7 +25,7 @@ paddle.set_device(device) ```python # PyTorch 写法 -torch.cpu.set_device(device='cpu:0') +torch.cpu.set_device('cpu:0') # Paddle 写法 paddle.set_device('cpu') diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md index 4fb9e2827e4..01efcd8a7ba 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.set_default_device.md @@ -34,7 +34,7 @@ paddle.set_device('gpu:0') torch.set_default_device(2) # Paddle 写法 -paddle.set_device(device='gpu:2') +paddle.set_device('gpu:2') # PyTorch 写法 torch.set_default_device("cpu")