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

[rfc] modify cummax / cummin API design #531

Merged
merged 1 commit into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 7 additions & 10 deletions rfcs/APIs/20220316_api_design_for_cummax.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,8 @@ gpu:
template <typename T, typename Context>
void CummaxKernel(const Context& dev_ctx,
const DenseTensor& x,
const Scalar& axis,
DataType dtype,
bool flatten,
Copy link
Contributor

Choose a reason for hiding this comment

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

这里为什么去掉了flatten呢?cummin同

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cumsum的flatten用于反向算子执行前调整形状,而cummax/cummin的反向不依赖flatten,所以就去掉了

Copy link
Contributor

Choose a reason for hiding this comment

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

嗯,我看见你把flatten操作在python层做了,解决一下代码pr的 windows ci问题吧

int axis,
int dtype,
DenseTensor* out,
DenseTensor* indices);
~~~
Expand All @@ -315,8 +314,8 @@ void CummaxGradKernel(const Context& dev_ctx,
const DenseTensor& x,
const DenseTensor& indices,
const DenseTensor& out_grad,
const Scalar& axis,
bool flatten,
int axis,
int dtype,
DenseTensor* x_grad);
~~~

Expand All @@ -332,13 +331,11 @@ Python 接口实现位置为`paddle/tesnor/math.py`。
- 正确性验证:可以与 NumPy 的结果对齐;
- 不同 shape;
- 前向计算和反向计算;
- axis 维度:0,1,默认(None),-1等;
- dtype 类型:验证 `float64`,`int32`等;

- 边界情况:对 NaN 等异常值的处理,参考 `paddle.cumsum` 的测试,这里选择与 NumPy 保持一致,即遇到 NaN 结果也为 NaN;
- 含有 NaN 的用例;
- 计算dtype类型:验证 `float64`,`int32`等;
- 索引dtype类型:验证指定索引数据类型是否正确,测试`int64`和`int32`

- 不同计算设备:覆盖 CPU 和 GPU 等实现;
- API调用和OP计算分别测试
- 错误检查:输入参数类型、形状的有效性校验。

# 七、可行性分析及规划排期
Expand Down
16 changes: 7 additions & 9 deletions rfcs/APIs/20230302_api_design_for_cummin.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,8 @@ gpu:
template <typename T, typename Context>
void CumminKernel(const Context& dev_ctx,
const DenseTensor& x,
const Scalar& axis,
DataType dtype,
bool flatten,
int axis,
int dtype,
DenseTensor* out,
DenseTensor* indices);
~~~
Expand All @@ -312,8 +311,8 @@ void CumminGradKernel(const Context& dev_ctx,
const DenseTensor& x,
const DenseTensor& indices,
const DenseTensor& out_grad,
const Scalar& axis,
bool flatten,
int axis,
int dtype,
DenseTensor* x_grad);
~~~

Expand All @@ -330,12 +329,11 @@ Python 接口实现位置为`paddle/tesnor/math.py`。
- 不同 shape;
- 前向计算和反向计算;
- axis 维度:0,1,默认(None),-1等;
- dtype 类型:验证 `float64`,`int32`等;

- 边界情况:对 NaN 等异常值的处理,参考 `paddle.cumsum` 的测试,这里选择与 NumPy 保持一致,即遇到 NaN 结果也为 NaN;
- 含有 NaN 的用例;
- 计算dtype类型:验证 `float64`,`int32`等;
- 索引dtype类型:验证指定索引数据类型是否正确,测试`int64`和`int32`

- 不同计算设备:覆盖 CPU 和 GPU 等实现;
- API调用和OP计算分别测试
- 错误检查:输入参数类型、形状的有效性校验。

# 七、可行性分析及规划排期
Expand Down