[API-Compat] paddle.compat.split is added and tested #74506
+632
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Category
Operator Mechanism
PR Types
New features
Description
#74446 re-open 的 PR。
增加了
paddle.compat.split
。此 API 的函数签名、行为与torch.split
完全一致。具体见torch.split
文档以及后续更新的 paddle doc。增加了如下机制:split_size_or_sections
在各种情况下(动、静态图)正确计算num_or_sections
的方法。此API不再要求分成相同大小的 tensor(最后一个tensor可以略小,取决于 int 类型的 split size 是否能整除 shape 对应维度)。ForbidKeywordsDecorator
装饰器:此装饰器接收一个或者多个禁止用户输入(可能混淆)的 keyword arguments,并接收一个“建议调用函数的名称”。当用户输入错误的 keyword arguments 时,将会报错提示。例子:报错如下:
对于
paddle.compat.split
误用为paddle.split
同样有此操作。test_compat_split.py
用于测试输入输出 shape,size 以及是否能正确报错test_compat_split_static.py
用于测试静态图正确性Pcard-89620