Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

映射文档 No.240 #5951

Merged
merged 5 commits into from
Jul 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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: 总和为原数组长度的,子集合长度数组。 |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉原来的API文档写的不太直白:
可为子集合长度列表,列表总和为原数组长度。也可为子集合所占比例列表,列表总和为1.0
子集合长度列表,列表总和为原数组长度。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

| generator | generator | 指定采样 data_source 的采样器。默认值为 None。 |

### 转写示例
当参数 lenghts 为总长度的比例数组时,转写如下:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个按咱们格式来,先表明转写的是哪个:参数

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

```python
# Pytorch 写法
lengths = [0.3, 0.3, 0.4]
datasets = torch.utils.data.random_split(range(30),
lengths,
generator=<torch._C.Generator object>)

# Paddle 写法
lengths = [0.3, 0.3, 0.4]
lengths = [length * datasets.__len__() for length in lengths]
datasets = paddle.io.random_split(dataset,
lengths,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

range(30)和dataset转化参数名不一致,容易引起误解,generator也要保持一致

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

generator=None)
```