Created by: Xreki
fetch_op报错信息增强 [仅C++端]
1. 使用OP_INOUT_CHECK,增加输入、输出是否设置的检查
由于fetch_op继承的是OperatorBase,当输入或者输出没有设置时,在进入RunImpl函数之前就会报错,因此修改前后报错信息一样,具体如下:
-
没有设置输入
Error: Operator fetch's input, X, is not set at (/paddle/paddle/fluid/framework/operator.cc:382)
-
没有设置输出
Error: Operator fetch's output, Out, is not set at (/paddle/paddle/fluid/framework/operator.cc:390)
2. 增强scope中,输入、输出变量是否存在的检查
- 检查scope中输入变量是否存在
- 修改前
Error: Cannot find fetch variable in scope, fetch_var_name is in_0 at (/paddle/paddle/fluid/operators/controlflow/fetch_op.cc:38) [operator < fetch > error]
- 修改后
NotFoundError: Input variable(in_0) cannot be found in scope for operator 'Fetch'. [Hint: fetch_var should not be null.] at (/paddle/paddle/fluid/operators/controlflow/fetch_op.cc:43) [operator < fetch > error]
- 检查scope中输出变量是否存在
- 修改前
Error: Cannot find out_var in scope, out_var_name is fetch at (/paddle/paddle/fluid/operators/controlflow/fetch_op.cc:44) [operator < fetch > error]
- 修改后
NotFoundError: Output variable(fetch) cannot be found in scope for operator 'Fetch'. [Hint: out_var should not be null.] at (/paddle/paddle/fluid/operators/controlflow/fetch_op.cc:50) [operator < fetch > error]
- 增加属性
col >= 0
的检查- 修改前
W0408 05:43:54.087884 59585 operator.cc:187] fetch raises an exception std::out_of_range, vector::_M_range_check
- 修改后
InvalidArgumentError: Expected the column index (the attribute 'col' of operator 'Fetch') of current fetching variable to be no less than 0. But received column index = -1. [Hint: Expected col >= 0, but received col:-1 < 0:0.] at (/paddle/paddle/fluid/operators/controlflow/fetch_op.cc:59) [operator < fetch > error]
说明
fetch op不是普通op,使用executor执行时,由executor根据用户的fetch需求自动插入fetch_op来取回计算的结果数据。没有Python API,错误示例难以构造,因此不提供错误示例。