Created by: chenwhql
PR types: Function optimization
PR changes: Others
Describe:
The paddle C ++ error stack has always had the problem that the error info is too long and difficult to read. I have tried to solve this problem twice before:
- The first time, I made the C ++ error stack clearer by deleting almost useless information and useless entries, https://github.com/PaddlePaddle/Paddle/pull/19895.
- And the second time, I rewritten
Place
to reduce too much useless information due to the too longboost
variable name introduced byPlace
, https://github.com/PaddlePaddle/Paddle/pull/21093.
However, the above methods cannot completely solve this problem.
Now in dygraph mode, the C ++ error stack is still very long and almost unreadable!
For example:
- code:
import numpy
import paddle.fluid as fluid
with fluid.dygraph.guard():
x = numpy.random.random(size=(10, 2)).astype('float32')
linear = fluid.dygraph.Linear(1, 10)
data = fluid.dygraph.to_variable(x)
res = linear(data)
This is terrible!
So I simplified the C ++ error stack once again. Example as follow:
This solution has three advantages:
- the error information expression efficiency has been significantly improved!
- no lost usefull information
- if more complex variable types added again, we can easily add processing to it.
备注:这里没有使用std::string*
直接在一个字符串上操作,报错过程中copy 字符串不是性能瓶颈,在这种情况下最好避免std::string*
的使用,这里用指针会在CI并行跑单测的时候导致一部分单测意外挂掉