From 0467168316568a9e863da4c92e3ff12571f47433 Mon Sep 17 00:00:00 2001 From: txyugood Date: Wed, 21 Jun 2023 15:17:01 +0800 Subject: [PATCH 1/5] Fix torch.utils.data.random_split.md --- .../utils/torch.utils.data.random_split.md | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md index ca4e3ab089f..b460573c66a 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md @@ -1,4 +1,4 @@ -## [ 参数完全一致 ]torch.utils.data.random_split +## [ 参数不一致 ]torch.utils.data.random_split ### [torch.utils.data.random_split](https://pytorch.org/docs/1.13/data.html?highlight=torch+utils+data+random_split#torch.utils.data.random_split) ```python @@ -15,10 +15,27 @@ paddle.io.random_split(dataset, generator=None) ``` -两者参数和用法完全一致,具体如下: -### 参数映射 -| PyTorch | PaddlePaddle | 备注 | -| ------------- | ------------ | ------------------------------------------------------ | -| dataset | dataset | 表示可迭代数据集。 | -| lengths | lengths | 总和为原数组长度的,子集合长度数组。 | -| generator | generator | 指定采样 data_source 的采样器。默认值为 None。 | +两者参数除 lengths 外用法一致,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ |---------------------------------------------------------------------| +| dataset | dataset | 表示可迭代数据集。 | +| lengths | lengths | PyTorch:总和为原数组长度或 1.0,子集合长度或总长度比例数组。PaddlePaddle: 总和为原数组长度的,子集合长度数组。 | +| generator | generator | 指定采样 data_source 的采样器。默认值为 None。 | + +### 转写示例 +当参数 lenghts 为总长度的比例数组时,转写如下: +```python +# Pytorch 写法 +lengths = [0.3, 0.3, 0.4] +datasets = torch.utils.data.random_split(range(30), + lengths, + generator=) + +# Paddle 写法 +lengths = [0.3, 0.3, 0.4] +lengths = [length * datasets.__len__() for length in lengths] +datasets = paddle.io.random_split(dataset, + lengths, + generator=None) +``` From 5b07e26a9fcdb47f4907465a8e75f2edbb542e7e Mon Sep 17 00:00:00 2001 From: txyugood Date: Tue, 27 Jun 2023 22:40:50 +0800 Subject: [PATCH 2/5] Fix torch.utils.data.random_split.md. --- .../api_difference/utils/torch.utils.data.random_split.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md index b460573c66a..3cc8edb59cb 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md @@ -28,14 +28,14 @@ paddle.io.random_split(dataset, ```python # Pytorch 写法 lengths = [0.3, 0.3, 0.4] -datasets = torch.utils.data.random_split(range(30), +datasets = torch.utils.data.random_split(dataset, lengths, - generator=) + generator=torch.Generator().manual_seed(0)) # Paddle 写法 lengths = [0.3, 0.3, 0.4] lengths = [length * datasets.__len__() for length in lengths] datasets = paddle.io.random_split(dataset, lengths, - generator=None) + generator=paddle.fluid.core.default_cpu_generator().manual_seed(0)) ``` From 113e0d7f377aafa6631a01cb781e4ca0bbbdf050 Mon Sep 17 00:00:00 2001 From: txyugood Date: Tue, 27 Jun 2023 22:46:22 +0800 Subject: [PATCH 3/5] Fix torch.utils.data.random_split.md. --- .../api_difference/utils/torch.utils.data.random_split.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md index 3cc8edb59cb..ba30d746d4c 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md @@ -34,7 +34,7 @@ datasets = torch.utils.data.random_split(dataset, # Paddle 写法 lengths = [0.3, 0.3, 0.4] -lengths = [length * datasets.__len__() for length in lengths] +lengths = [length * dataset.__len__() for length in lengths] datasets = paddle.io.random_split(dataset, lengths, generator=paddle.fluid.core.default_cpu_generator().manual_seed(0)) From 28648c045593ccb59f41e02d8cca9dc2d1203119 Mon Sep 17 00:00:00 2001 From: txyugood Date: Thu, 29 Jun 2023 21:03:49 +0800 Subject: [PATCH 4/5] Fix torch.utils.data.random_split.md. --- .../utils/torch.utils.data.random_split.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md index ba30d746d4c..11e4c046c3f 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md @@ -20,22 +20,22 @@ paddle.io.random_split(dataset, | PyTorch | PaddlePaddle | 备注 | | ------------- | ------------ |---------------------------------------------------------------------| | dataset | dataset | 表示可迭代数据集。 | -| lengths | lengths | PyTorch:总和为原数组长度或 1.0,子集合长度或总长度比例数组。PaddlePaddle: 总和为原数组长度的,子集合长度数组。 | +| lengths | lengths | PyTorch:可为子集合长度列表,列表总和为原数组长度。也可为子集合所占比例列表,列表总和为 1.0。PaddlePaddle: 子集合长度列表,列表总和为原数组长度 | | generator | generator | 指定采样 data_source 的采样器。默认值为 None。 | ### 转写示例 -当参数 lenghts 为总长度的比例数组时,转写如下: +lenghts: 子集合长度列表 ```python # Pytorch 写法 lengths = [0.3, 0.3, 0.4] datasets = torch.utils.data.random_split(dataset, lengths, - generator=torch.Generator().manual_seed(0)) + generator=torch.manual_seed(0)) # Paddle 写法 lengths = [0.3, 0.3, 0.4] -lengths = [length * dataset.__len__() for length in lengths] +lengths = [length * len(dataset) for length in lengths] datasets = paddle.io.random_split(dataset, lengths, - generator=paddle.fluid.core.default_cpu_generator().manual_seed(0)) + generator=paddle.seed(0)) ``` From 7c5d2e7ac88d2dc1d132c91fbb382d3c571590b5 Mon Sep 17 00:00:00 2001 From: txyugood Date: Wed, 5 Jul 2023 11:54:53 +0800 Subject: [PATCH 5/5] Update torch.utils.data.random_split.md --- .../api_difference/utils/torch.utils.data.random_split.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md index 11e4c046c3f..bbcd5040806 100644 --- a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md @@ -24,7 +24,7 @@ paddle.io.random_split(dataset, | generator | generator | 指定采样 data_source 的采样器。默认值为 None。 | ### 转写示例 -lenghts: 子集合长度列表 +#### lenghts: 子集合长度列表 ```python # Pytorch 写法 lengths = [0.3, 0.3, 0.4]