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

【Hackathon 5 No.5】为 Paddle 增强 scatter API #57748

Closed
wants to merge 42 commits into from

Conversation

lisamhy
Copy link
Contributor

@lisamhy lisamhy commented Sep 26, 2023

PR types

Function optimization

PR changes

APIs

Description

PaddlePaddle/community#631
#57262

  • scatter with axis, reduce and include_self
  • index dim must be 1-D

声明,版权归个人所有,仅供本人用于参加Hackthon 5 的比赛使用,其它个人或组织不得已任何形式基于此PR修复使用。

The declaration, copyrighted by the individual, is only for personal use in participating in Hackthon 5 competition. No other individual or organization is allowed to modify or use this PR in any form.

@paddle-bot
Copy link

paddle-bot bot commented Sep 26, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Sep 26, 2023
@lisamhy lisamhy changed the title test 【Hackathon 5 No.5】为 Paddle 增强 scatter API Sep 27, 2023
@paddle-ci-bot
Copy link

paddle-ci-bot bot commented Oct 5, 2023

Sorry to inform you that 7dff65c's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

@paddle-ci-bot
Copy link

paddle-ci-bot bot commented Oct 21, 2023

Sorry to inform you that b7aafba's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

Copy link
Contributor

@zoooo0820 zoooo0820 left a comment

Choose a reason for hiding this comment

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

抱歉因为这个PR比较复杂,内部评估耽误了一些时间,使用当前这个写法是OK的。辛苦处理下冲突,并再按意见修改下呢~

old = atomicCAS(address_as_ui, assumed, old);
} while (assumed != old);
hsum.x = (size_t)address & 2 ? (old >> 16) : (old & 0xffff); // NOLINT
return hsum;
Copy link
Contributor

Choose a reason for hiding this comment

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

这几个新增的atomic操作的实现算法,有对应的参考的地方吗;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

参考stackoverflow里的写的。

paddle/phi/kernels/cpu/scatter_kernel_impl.h Outdated Show resolved Hide resolved
paddle/phi/kernels/cpu/scatter_kernel_impl.h Show resolved Hide resolved
paddle/phi/kernels/cpu/scatter_kernel_impl.h Outdated Show resolved Hide resolved
def test_check_output(self):
self.check_output()

def test_check_grad(self):
self.check_grad(["X", "Updates"], "Out", check_prim=True)
self.check_grad(["X", "Updates"], "Out")
Copy link
Contributor

Choose a reason for hiding this comment

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

是新增的单侧,具体不清楚为什么会出错。 试了单独调用api看结果,都是正确的。按套路加上optest后会出错。 看了结果应该是这里面自动推导梯度的结果不正确导致的。实际执行的梯度是正确的,和torch比对过了。

这里要不贴一下这个地方测试的情况吧

paddle/phi/kernels/gpu/scatter_grad_kernel.cu Show resolved Hide resolved
paddle/phi/kernels/cpu/scatter_grad_kernel.cc Show resolved Hide resolved
@lisamhy
Copy link
Contributor Author

lisamhy commented Oct 27, 2023

@luotao1 @zoooo0820 麻烦再review下,谢谢。

@zoooo0820
Copy link
Contributor

@luotao1 @zoooo0820 麻烦再review下,谢谢。

@lisamhy 你好,目前还有几个问题

  • prim的单测checkgrad问题,这个我找下相关负责同学帮忙看下
  • xpu的单测报错,辛苦再看下呢
  • APIbenchmark显示性能有下降,理论上这个PR属于新增功能,不影响已有case;这里需要排查下正反向kernel是否在原有逻辑上增加了额外的耗时内容
  • third_party的内容不用加入到PR里

@lisamhy
Copy link
Contributor Author

lisamhy commented Oct 30, 2023

  • APIbenchmark显示性能有下降,理论上这个PR属于新增功能,不影响已有case;这里需要排查下正反向kernel是否在原有逻辑上增加了额外的耗时内容

相比原有API增加很多功能,所以新能下降是合理的。

@lisamhy
Copy link
Contributor Author

lisamhy commented Oct 30, 2023

  • xpu的单测报错,辛苦再看下呢

没有xpu的机器无法测试。不过从单侧看应该是之前就存在的bug。麻烦也帮忙找相关同事看看问题吧。

xpu的代码不变,放在cpu上跑,结果是正常的。

@lisamhy
Copy link
Contributor Author

lisamhy commented Oct 30, 2023

  • third_party的内容不用加入到PR里

这个我处理下。

@lisamhy
Copy link
Contributor Author

lisamhy commented Nov 3, 2023

@zoooo0820 @luotao1 麻烦review下,谢谢。

@zoooo0820
Copy link
Contributor

  • APIbenchmark显示性能有下降,理论上这个PR属于新增功能,不影响已有case;这里需要排查下正反向kernel是否在原有逻辑上增加了额外的耗时内容

相比原有API增加很多功能,所以新能下降是合理的。

你好,从之前CI测试的数据来看,在原测试用例的场景下慢了2.x倍,性能下降比较严重。而理论上新增功能是额外扩展的功能,能辛苦分析下这部分性能问题是哪里带来的吗,以及是否可以优化呢

@lisamhy
Copy link
Contributor Author

lisamhy commented Nov 8, 2023

  • APIbenchmark显示性能有下降,理论上这个PR属于新增功能,不影响已有case;这里需要排查下正反向kernel是否在原有逻辑上增加了额外的耗时内容

相比原有API增加很多功能,所以新能下降是合理的。

你好,从之前CI测试的数据来看,在原测试用例的场景下慢了2.x倍,性能下降比较严重。而理论上新增功能是额外扩展的功能,能辛苦分析下这部分性能问题是哪里带来的吗,以及是否可以优化呢

  1. 之前grad的计算完全是错误的。之计算x_grad,而且赋值0,不支持source_grad。
  2. 功能上新增很多,比如不同的reduce操作。
  3. 实现上是以调用kernel实现的,这些被调用的kernel是否高效,不确定。
  4. 之前的reduce op也没有加原子操作。

光代码量就可以看出来功能增加很多。PR时间过长了,以上可能有遗漏处。所以慢是合理的。

@zoooo0820 @luotao1 这个PR什么时候可以合入。一直有conflict。

@lisamhy
Copy link
Contributor Author

lisamhy commented Nov 17, 2023

@luotao1 @zoooo0820 麻烦review下,谢谢。

Copy link

paddle-ci-bot bot commented Nov 19, 2023

Sorry to inform you that 25b7d8f's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

@zoooo0820
Copy link
Contributor

Details

你好,从之前api-benchmark的数据来看是前向慢了2倍左右,这个问题还是需要确认下的。

  • 关于grad的问题, grad的计算方式看起来会影响反向但不会影响前向。
  • 新增的功能理论上不会影响原有功能,原来的测例也不会跑在新增的代码上,这些测例应该也没有依赖reduce操作,所以这里耗时增长还是需要确认下的。可以实际写个case跑1k次测试下平均值是否和流水线测试的情况一致,再分析下代码是否跑在了预期位置上呢

@lisamhy
Copy link
Contributor Author

lisamhy commented Nov 21, 2023

image 之前只有一个assign 的功能(纯赋值,没有任何计算操作),后面新增了6个功能。

新增的功能还用了原子操作。
image

image

为了支撑0-dim又新增了一些操作。

最后调用了这个函数。
image

新增这么多功能,前向怎么可能还是原来的速度呢?

@zoooo0820 @luotao1 麻烦评估下。谢谢。

if (index_type == phi::DataType::INT32) {
phi::funcs::ScatterAssign<T, int32_t>(ctx, updates, index, out);
} else {
phi::funcs::ScatterAssign<T, int64_t>(ctx, updates, index, out);
Copy link
Contributor

Choose a reason for hiding this comment

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

reduce是'assign'时的场景,整合到IndexReduceBaseKernel是否必要呢,看起来是IndexReduceBaseKernel因为计算需求调用了很多其他kernel导致的性能问题。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

有必要呀,代码可以统一,也便于维护。IndexReduceBaseKernel性能提升了,这个kernel就提升了。而且ci里的性能是统计这一个api的调用,功能都有,不会只比较assign的。

image 已经按要求完成了功能,麻烦合入,谢谢。 @luotao1 @zoooo0820

@luotao1
Copy link
Contributor

luotao1 commented Nov 30, 2023

@lisamhy 建议不要整合到 IndexReduceBaseKernel 内,避免影响原来功能

@lisamhy
Copy link
Contributor Author

lisamhy commented Nov 30, 2023

@lisamhy 建议不要整合到 IndexReduceBaseKernel 内,避免影响原来功能

新增功能,且ci都过了,所以不会影响原有的功能。

@luotao1
Copy link
Contributor

luotao1 commented Nov 30, 2023

api_benchmark ci 之前是没有过的。
image

@lisamhy
Copy link
Contributor Author

lisamhy commented Dec 4, 2023

api_benchmark ci 之前是没有过的。
image

功能增加了,所以这个不是问题。豁免就可以了。
No.5 的功能已经添加了。这个新需求你们来做吧。

@zoooo0820
Copy link
Contributor

感谢对黑客松的支持以及付出的精力,关于这个PR中提出的问题,有这么几点需要解释下:

  1. CI是否能豁免:CI的设立是为了避免代码修改对已有模块带来额外的影响。豁免则是需要一个明确具有说服力的理由,如非CI流水线本身的问题,需要说明当前修改的必要性(必须要加)以及唯一性(权衡考虑后不得不这么做)。以目前的api-benchmark检测到性能下降为例,使用到这个API的所有模型的速度都将受影响,需要明确指出目前是否没有其他优化改进的办法了,仅仅“新增了功能,所以性能下降是正常的”是不够的。
  2. 其他单测的问题,各个单测的设置本身也是为了帮助检查对已有模块的影响,单测用例同样也是非必要不修改的。从这个PR此前的情况来看,组合算子,XPU设备上都仍然有未过的测试case。当然,这存在是单测或是机制本身问题的可能性,但在合入前仍然需要有明确结论,而非直接修改单测以通过CI。如果是已有机制本身的问题,确认可以反馈出来,我们会及时联系负责人修复。

诚然,这个PR完成了题目要求的功能内容,但对于该PR带来的一些问题是仍然需要解决的,这是对每一个PR的要求而非“新需求”,仍然需要解决上述问题后才能合入。

@lisamhy
Copy link
Contributor Author

lisamhy commented Dec 12, 2023

感谢对黑客松的支持以及付出的精力,关于这个PR中提出的问题,有这么几点需要解释下:

  1. CI是否能豁免:CI的设立是为了避免代码修改对已有模块带来额外的影响。豁免则是需要一个明确具有说服力的理由,如非CI流水线本身的问题,需要说明当前修改的必要性(必须要加)以及唯一性(权衡考虑后不得不这么做)。以目前的api-benchmark检测到性能下降为例,使用到这个API的所有模型的速度都将受影响,需要明确指出目前是否没有其他优化改进的办法了,仅仅“新增了功能,所以性能下降是正常的”是不够的。
  2. 其他单测的问题,各个单测的设置本身也是为了帮助检查对已有模块的影响,单测用例同样也是非必要不修改的。从这个PR此前的情况来看,组合算子,XPU设备上都仍然有未过的测试case。当然,这存在是单测或是机制本身问题的可能性,但在合入前仍然需要有明确结论,而非直接修改单测以通过CI。如果是已有机制本身的问题,确认可以反馈出来,我们会及时联系负责人修复。

诚然,这个PR完成了题目要求的功能内容,但对于该PR带来的一些问题是仍然需要解决的,这是对每一个PR的要求而非“新需求”,仍然需要解决上述问题后才能合入。

  1. IndexReduceBaseKernel 原有的api并未有性能问题。还有之前api实现逻辑完全错误,修复后引入新的逻辑,处理速度在错误的基础上变慢了,不是很正常的事情吗?为什么是PR的问题呢?如果觉得慢,也麻烦paddle的同学帮忙修复吧,这个PR已经是4个月前的工作了。
  2. XPU ci 为什么会错呢?为什么CPU和GPU的都过了呢?之前已经测试过了,xpu单侧本身机制有问题。需要paddle的人解决。

@lisamhy
Copy link
Contributor Author

lisamhy commented Dec 28, 2023

声明,版权归个人所有,仅供本人用于参加Hackthon 5 的比赛使用,其它个人或组织不得已任何形式基于此PR修改使用。

The declaration, copyrighted by the individual, is only for personal use in participating in Hackthon 5 competition. No other individual or organization is allowed to modify or use this PR in any form.

@luotao1 luotao1 closed this Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants