Created by: chenwhql
原有Paddle的报错类别仅有PaddleEnforceFailed(之前改为PaddleCheckError)一种,单独一个检查失败,含有的信息量很少,而任何平台、系统级的产品,都应该有合理的错误代码设计,例如TensorFlow有17种自定义的C++错误类型,包括InvalidArgumentError,NotFoundError等。
因此为了使Paddle的报错体系更加规范化,本PR为Paddle增加了指定报错类别的功能,具体地,增加了13种错误类型、以及相应的指定错误类型的接口,便于为PADDLE_ENFORCE类检查指定错误类型
13种错误类型见新增的文件:error_codes.proto
修改前后报错示例对比
case 1:
original:
----------------------
Error Message Summary:
----------------------
PaddleCheckError: Expected x_mat_dims[1] == y_mat_dims[0], but received x_mat_dims[1]:13 != y_mat_dims[0]:12.
ShapeError: After flatten the input tensor X and Y to 2-D dimensions matrix X1 and Y1, the matrix X1's width must be equal with matrix Y1's height. But received X's shape = [10, 13], X1's shape = [10, 13], X1's width = 13; Y's shape = [12, 1], Y1's shape = [12, 1], Y1's height = 12. at [/work/paddle/paddle/fluid/operators/mul_op.cc:78]
[operator < mul > error]
new:
----------------------
Error Message Summary:
----------------------
InvalidArgumentError: After flatten the input tensor X and Y to 2-D dimensions matrix X1 and Y1, the matrix X1's width must be equal with matrix Y1's height. But received X's shape = [10, 13], X1's shape = [10, 13], X1's width = 13; Y's shape = [12, 1], Y1's shape = [12, 1], Y1's height = 12.
[Hint: Expected x_mat_dims[1] == y_mat_dims[0], but received x_mat_dims[1]:13 != y_mat_dims[0]:12.] at (/work/paddle/paddle/fluid/operators/mul_op.cc:78)
[operator < mul > error]
这里将PADDLE_ENFORCE_EQ/NE...模板生成的信息移至第二行,用hint标明,原因如下:
- 开发者写明的是最直接的错误提示信息,最重要的信息应该放在最前面,之前有过用户反馈首先看到模板信息,又觉得模板信息里面用的变量缩写过于隐晦,不易理解,导致体验差的情况
case 2:
original:
----------------------
Error Message Summary:
----------------------
PaddleCheckError: Expected framework::product(y_dims) != 0, but received framework::product(y_dims):0 == 0:0.
Maybe the Input variable Y(fc_0.w_0) has not been initialized. You may need to confirm if you put exe.run(startup_program) after optimizer.minimize function. at [/work/paddle/paddle/fluid/operators/mul_op.cc:57]
[operator < mul > error]
new:
----------------------
Error Message Summary:
----------------------
PreconditionNotMetError: Maybe the Input variable Y(fc_0.w_0) has not been initialized. You may need to confirm if you put exe.run(startup_program) after optimizer.minimize function.
[Hint: Expected framework::product(y_dims) != 0, but received framework::product(y_dims):0 == 0:0.] at (/work/paddle/paddle/fluid/operators/mul_op.cc:57)
[operator < mul > error]
English:
The original Paddle error category is only PaddleEnforceFailed (formerly changed to PaddleCheckError). A single error type contains a small amount of information. Any platform or system-level product should have a reasonable error code design, such as TensorFlow. There are 17 custom C++ error types, including InvalidArgumentError, NotFoundError, and so on.
Therefore, in order to make Paddle's error reporting system more standardized, this PR adds the function of specifying the error category to Paddle. Specifically, 13 types of errors and corresponding interfaces of the specified error type are added, which is convenient for specifying the error type for the PADDLE_ENFORCE class check.
See the new file for 13 error types: error_codes.proto