Skip to content

Commit fde2b70

Browse files
jiweibopiotrekobi
authored andcommitted
enable trt test check and fix trt ut error(3/3) (PaddlePaddle#36581)
1 parent d8b343b commit fde2b70

13 files changed

+87
-21
lines changed

paddle/fluid/framework/ir/graph_viz_pass.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,14 @@ void GraphVizPass::ApplyImpl(ir::Graph* graph) const {
6262
}
6363
}
6464
}
65+
const std::string& optim_cache_dir = Get<std::string>("optim_cache_dir");
6566
std::string program_bytes = program_desc.Proto()->SerializeAsString();
6667
// rename from "17_ir_fc_fuse_pass.dot" to "fc_fuse_pass.pdmodel"
6768
program_path =
6869
graph_viz_path.substr(found1 + 4, found2 - found1 - 4) + ".pdmodel";
70+
if (!optim_cache_dir.empty()) {
71+
program_path = optim_cache_dir + "/" + program_path;
72+
}
6973
std::ofstream file(program_path.c_str(), std::ios::binary);
7074
file.write(program_bytes.c_str(), program_bytes.size());
7175
file.close();

paddle/fluid/inference/analysis/ir_pass_manager.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,18 @@ void IRPassManager::CreatePasses(Argument *argument,
5656
auto pass = framework::ir::PassRegistry::Instance().Get(pass_name);
5757

5858
if (pass_name == "graph_viz_pass") {
59-
std::string dot_file_path = std::to_string(pass_num) + "_ir_" +
60-
(pre_pass.empty() ? "origin" : pre_pass) +
61-
".dot";
59+
std::string optim_cache_dir = argument->optim_cache_dir();
60+
std::string dot_file_path;
61+
if (optim_cache_dir.empty()) {
62+
dot_file_path = std::to_string(pass_num) + "_ir_" +
63+
(pre_pass.empty() ? "origin" : pre_pass) + ".dot";
64+
} else {
65+
dot_file_path = optim_cache_dir + "/" + std::to_string(pass_num) +
66+
"_ir_" + (pre_pass.empty() ? "origin" : pre_pass) +
67+
".dot";
68+
}
6269
pass->Set("graph_viz_path", new std::string(std::move(dot_file_path)));
70+
pass->Set("optim_cache_dir", new std::string(std::move(optim_cache_dir)));
6371
pass_num++;
6472
} else if (pass_name == "mkldnn_placement_pass") {
6573
pass->Set("mkldnn_enabled_op_types",

paddle/fluid/inference/api/analysis_config.cc

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include <sstream>
1516
#include <string>
17+
#include <tuple>
1618
#include "paddle/fluid/inference/api/paddle_analysis_config.h"
1719
#include "paddle/fluid/inference/api/paddle_pass_builder.h"
1820
#include "paddle/fluid/inference/utils/table_printer.h"
1921
#include "paddle/fluid/platform/cpu_info.h"
2022
#include "paddle/fluid/platform/enforce.h"
2123
#include "paddle/fluid/platform/gpu_info.h"
2224

25+
#ifdef PADDLE_WITH_TENSORRT
26+
#include "paddle/fluid/inference/tensorrt/helper.h"
27+
#endif
28+
2329
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
2430
DECLARE_uint64(initial_gpu_memory_in_mb);
2531
#endif
@@ -758,17 +764,6 @@ std::string AnalysisConfig::Summary() {
758764
{"mkldnn_cache_capacity", std::to_string(mkldnn_cache_capacity_)});
759765
os.InsetDivider();
760766

761-
auto Precision2String =
762-
[](paddle::AnalysisConfig::Precision prec) -> std::string {
763-
if (prec == Precision::kFloat32)
764-
return "fp32";
765-
else if (prec == Precision::kHalf)
766-
return "fp16";
767-
else if (prec == Precision::kInt8)
768-
return "int8";
769-
else
770-
return "None";
771-
};
772767
// gpu info
773768
os.InsertRow({"use_gpu", use_gpu_ ? "true" : "false"});
774769
if (use_gpu_) {
@@ -780,6 +775,33 @@ std::string AnalysisConfig::Summary() {
780775

781776
os.InsertRow({"use_tensorrt", use_tensorrt_ ? "true" : "false"});
782777
if (use_tensorrt_) {
778+
#ifdef PADDLE_WITH_TENSORRT
779+
auto Precision2String =
780+
[](paddle::AnalysisConfig::Precision prec) -> std::string {
781+
if (prec == Precision::kFloat32)
782+
return "fp32";
783+
else if (prec == Precision::kHalf)
784+
return "fp16";
785+
else if (prec == Precision::kInt8)
786+
return "int8";
787+
else
788+
return "None";
789+
};
790+
auto version2string =
791+
[](const std::tuple<int, int, int> &ver) -> std::string {
792+
std::ostringstream os;
793+
int major = std::get<0>(ver);
794+
int minor = std::get<1>(ver);
795+
int patch = std::get<2>(ver);
796+
os << major << "." << minor << "." << patch;
797+
return os.str();
798+
};
799+
os.InsertRow(
800+
{"trt_compile_version",
801+
version2string(inference::tensorrt::GetTrtCompileVersion())});
802+
os.InsertRow(
803+
{"trt_runtime_version",
804+
version2string(inference::tensorrt::GetTrtRuntimeVersion())});
783805
os.InsertRow({"tensorrt_precision_mode",
784806
Precision2String(tensorrt_precision_mode_)});
785807
os.InsertRow({"tensorrt_workspace_size",
@@ -805,6 +827,7 @@ std::string AnalysisConfig::Summary() {
805827
if (trt_use_dla_) {
806828
os.InsertRow({"tensorrt_dla_core", std::to_string(trt_dla_core_)});
807829
}
830+
#endif
808831
}
809832
}
810833
os.InsetDivider();

paddle/scripts/paddle_build.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2388,6 +2388,25 @@ function find_temporary_files() {
23882388
fi
23892389
}
23902390

2391+
function trt_convert_test() {
2392+
set +e
2393+
cd ${PADDLE_ROOT}
2394+
result_num=0
2395+
export PYTHONPATH=$PYTHONPATH:${PADDLE_ROOT}/build/python
2396+
for file_name in `find python/ -name 'test_trt_convert*'`;do
2397+
echo "----- test trt ut: $file_name -----"
2398+
python $file_name
2399+
res=$?
2400+
if [ "$res" != "0" ];then
2401+
echo "$file_name convert test failed " >&2
2402+
result_num=11
2403+
fi
2404+
done
2405+
if [ "$result_num" != "0" ];then
2406+
exit 11
2407+
fi
2408+
}
2409+
23912410
function build_pr_and_develop() {
23922411
cmake_gen_and_build ${PYTHON_ABI:-""} ${parallel_number}
23932412
mkdir ${PADDLE_ROOT}/build/pr_whl && cp ${PADDLE_ROOT}/build/python/dist/*.whl ${PADDLE_ROOT}/build/pr_whl
@@ -2656,6 +2675,10 @@ function main() {
26562675
test_model_benchmark)
26572676
test_model_benchmark
26582677
;;
2678+
trt_convert_test)
2679+
# only test trt convert.
2680+
trt_convert_test
2681+
;;
26592682
*)
26602683
print_usage
26612684
exit 1

python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_conv2d.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from trt_layer_auto_scan_test import TrtLayerAutoScanTest, SkipReasons
1616
from program_config import TensorConfig, ProgramConfig
1717
import numpy as np
18+
import unittest
1819
import paddle.inference as paddle_infer
1920
from functools import partial
2021
from typing import Optional, List, Callable, Dict, Any, Set

python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_conv2d_fusion.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import paddle.inference as paddle_infer
1919
from functools import partial
2020
from typing import Optional, List, Callable, Dict, Any, Set
21+
import unittest
2122

2223

2324
class TrtConvertConv2dFusionTest(TrtLayerAutoScanTest):

python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_conv2d_transpose.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from trt_layer_auto_scan_test import TrtLayerAutoScanTest, SkipReasons
1616
from program_config import TensorConfig, ProgramConfig
1717
import numpy as np
18+
import unittest
1819
import paddle.inference as paddle_infer
1920
from functools import partial
2021
from typing import Optional, List, Callable, Dict, Any, Set

python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_depthwise_conv2d.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import paddle.inference as paddle_infer
1919
from functools import partial
2020
from typing import Optional, List, Callable, Dict, Any, Set
21+
import unittest
2122

2223

2324
class TrtConvertDepthwiseConv2dTest(TrtLayerAutoScanTest):

python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_depthwise_conv2d_transpose.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import paddle.inference as paddle_infer
1919
from functools import partial
2020
from typing import Optional, List, Callable, Dict, Any, Set
21+
import unittest
2122

2223

2324
class TrtConvertDepthwiseConv2dTransposeTest(TrtLayerAutoScanTest):

python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_nearest_interp_v2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import paddle.inference as paddle_infer
1919
from functools import partial
2020
from typing import Optional, List, Callable, Dict, Any, Set
21+
import unittest
2122

2223

2324
class TrtConvertNearestInterpV2Test(TrtLayerAutoScanTest):

0 commit comments

Comments
 (0)