test_analyzer_transformer runs into assertion failure when ngraph is used
Created by: LeoZhao-Intel
System information -PaddlePaddle branch: develop
-CPU: Yes
-GPU: No
-OS Platform: Linux
-Cmake orders: cmake .. -DCMAKE_BUILD_TYPE=Release -DWITH_DSO=ON -DWITH_AMD_GPU=OFF -DWITH_DISTRIBUTE=ON -DWITH_MKL=ON -DWITH_NGRAPH=ON -DWITH_AVX=ON -DWITH_GOLANG=OFF -DWITH_PYTHON=ON -DWITH_TESTING=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DWITH_CONTRIB=ON -DWITH_INFERENCE_API_TEST=ON -DPY_VERSION=2.7 -DWITH_JEMALLOC=OFF -DWITH_GRPC=ON
To Reproduce run cmd below: ./paddle/fluid/inference/tests/api/test_analyzer_transformer --infer_model=./third_party/inference_demo/transformer/model --infer_data=third_party/inference_demo/transformer/data.txt --batch_size=8 --num_threads=1 --gtest_filter=Analyzer_Transformer.profile --repeat=1 --use_ngraph --use_analysis=false
Describe your current behavior Attention: This issue happens only after Issue #17147 (closed) gets fixed by PR #17148, otherwise you will meet Issue #17147 (closed) first
program will get assertion failure as shown below
C++ exception with description "While validating node 'Dot[Dot_23034](Reshape_23033: float{8,1024}, Parameter_23027: undefined{1024,1024}) -> (??)' of type 'Dot':
Assertion 'element::Type::merge(result_et, get_input_element_type(0), get_input_element_type(1))' failed at /home/leozhao/Paddle/build/third_party/ngraph/src/extern_ng
raph/src/ngraph/op/dot.cpp:53:
Arguments do not have the same element type (arg0 element type: element::Type{32, 1, 1, 0, "float"}, arg1 element type: element::Type{18446744073709551615, 0, 0, 0, "u
ndefined"})." thrown in the test body.
By my investigation, this issue is caused by block, some variables only defined in block(0), while in this path, original ops are in block(1), and ngraph can't find variables in block description. see below code
void NgraphEngine::GetNgInputShape() {
for (auto& var_name : var_in_) {
auto* var = scope_.FindVar(var_name);
if (var && var->IsType<framework::LoDTensor>()) {
auto* tensor_pd = GetLoDTensorOrSelectedRowsValueFromVar(*var);
auto sp = Ddim2Shape(tensor_pd->dims());
auto ng_type = var_type_map_[var_name];
auto prm = std::make_shared<ngraph::op::Parameter>(ng_type, sp, true);
(*var_node_map_)[var_name] = prm;
(*var_in_node_map_)[var_name] = prm;
}
}
}
var_type_map_[var_name] returns "undefined" type. To solve this issue, I think there may have 2 potential options:
- depending on framework feature block(0/1) support in paddlepaddle, then add similar support in ngraph, it is also transformer common requirement to baidu folks for DO.
- add block(0) into ngraph bridge as well when ctx->block_id_ ==1 in paddle::operators::NgraphEngine::FuseNgraphOps(), but not sure if it can really works