-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Enrich the python error types of paddle & polish format #28124
Enrich the python error types of paddle & polish format #28124
Conversation
… easyuse/refactor_exception_types
Thanks for your contribution! |
… easyuse/refactor_exception_types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
New features
PR changes
Others
Describe
Paddle框架中C++端5000余条不合规报错的逐条完善工作已经基本收尾,框架的报错质量相比一年前已经有了显著的提升,一年前,框架中仍有数千条过短的、表意不明的、甚至没有提示的报错,所以基于我们当时的状况,是不具备隐藏C++栈的条件的,一旦隐藏,很多原本就没有报错提示的出错基本就无法调试了,尽管那时竞品默认都是没有C++报错栈的。
但这一年经过大量同学的完善,报错整体的质量提升明显,我们是时候需要正视C++栈给大多数普通用户带来的困扰了。
依据婉婷的问卷调研和深访,C++栈大多数用户并不关心,且长期以来也一直被AIStudio的用户诟病,因此我们基本得出了:要在2.0正式版发布时,默认隐藏C++栈的结论。
但考虑到研发人员和资深用户可能仍然会依赖C++栈,我们也提供了便利的重新打开C++栈的方法:
配置环境变量:
export FLAGS_call_stack_level=2
基于以上背景,现在将paddle内部定义的报错类型映射至python端原生报错类型,以较为丰富的python原生报错类型替代原先理解成本较高的自定义异常
paddle.fluid.core_avx.EnforceNotMet
,使paddle 2.0的报错更加规范。主要改动包括以下几点:
paddle.fluid.core_avx.EnforceNotMet
paddle截至目前为止,整个C++端都在使用这个不易理解的异常类型,这个类型和python的
ValueError
、TypeError
是同级别的,但我们的EnforceNotMet
着实生僻,统一使用python原生异常是更加标准的做法Error Message Summary
Error Message Summary
确实在让用户更明显地看到的报错信息这一点上是有效果的,但是不够标准,这只是paddle独有的一种比较low的标志,一般python用户会找关键词***Error
确认报错信息的位置,额外的分隔不是刚需,从长远考虑,我们应该保持自己的标准性,而不是引入一些奇怪的标志,因此本PR改为直接和原生python栈保持一样的报错效果不增加自定义的异常类型是目前的趋势,本PR将paddle内定义的报错类型按如下规则映射到的python原生的异常类型上,paddle内的错误类型作为子类型附在主报错类型之后,降低用户理解成本。
注意:本PR仅针对隐藏C++栈时的报错格式进行完善!以下示例为设置
FLAGS_call_stack_level=1
时的显示效果,目前FLAGS_call_stack_level
默认仍为2,即默认显示C++栈,在显示C++栈的情况下,报错格式仍与之前一致,基本无变化。Dynamic mode Example
Before this PR:
After this PR:
Static mode Example
Before this PR:
After this PR: