Skip to content

Commit a890738

Browse files
authored
[Inference]Support control trt_glog_info in PIR (#72429)
* add_debug_trt * Update paddle_analysis_config.h * fix codestyle * fix codestyle * Update tensorrt_test_base.py * fix * Update paddle_analysis_config.h * Update paddle_analysis_config.h * update * fix codestyle * update * fix codestyle
1 parent 3d507f6 commit a890738

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

paddle/fluid/inference/api/analysis_config.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#include "glog/logging.h"
2121
#include "paddle/common/errors.h"
22-
#include "paddle/common/flags.h"
2322
#include "paddle/fluid/inference/api/helper.h"
2423
#include "paddle/fluid/inference/api/paddle_analysis_config.h"
2524
#include "paddle/fluid/inference/api/paddle_pass_builder.h"

python/paddle/tensorrt/converter.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ def convert_subgraph_to_trt(self, program, group_op):
135135
if self.trt_config is not None and self.trt_config.ops_run_float:
136136
_logger.info(f"force_fp32_ops: {trt_manager.get_force_fp32_ops()}")
137137

138-
_logger.info(f"start process {group_op}")
138+
if not self.trt_config.disable_loggling:
139+
_logger.info(f"start process {group_op}")
139140

140141
operations = next(iter(group_op.blocks())).ops
141142
input_values, output_values = self.find_graph_inputs_outputs(group_op)
@@ -326,9 +327,10 @@ def convert_subgraph_to_trt(self, program, group_op):
326327
# constant/parameter condition, needn't get min/opt/max shape
327328
continue
328329
input_name = trt_input.name
329-
_logger.info(
330-
f"set shape of {value}, op is: {value.get_defining_op()}"
331-
)
330+
if not self.trt_config.disable_loggling:
331+
_logger.info(
332+
f"set shape of {value}, op is: {value.get_defining_op()}"
333+
)
332334
min_shape = []
333335
opt_shape = []
334336
max_shape = []
@@ -372,22 +374,24 @@ def convert_subgraph_to_trt(self, program, group_op):
372374
value, True, paddle.base.core.ShapeMode.kMAX
373375
)
374376
if not trt_input.is_shape_tensor:
375-
_logger.info(f"set min_shape of {value} as {min_shape}")
376-
_logger.info(f"set opt_shape of {value} as {opt_shape}")
377-
_logger.info(f"set max_shape of {value} as {max_shape}")
377+
if not self.trt_config.disable_loggling:
378+
_logger.info(f"set min_shape of {value} as {min_shape}")
379+
_logger.info(f"set opt_shape of {value} as {opt_shape}")
380+
_logger.info(f"set max_shape of {value} as {max_shape}")
378381
profile.set_shape(
379382
input_name, min=min_shape, opt=opt_shape, max=max_shape
380383
)
381384
else:
382-
_logger.info(
383-
f"set min_value of shape input: {value} as {min_value}"
384-
)
385-
_logger.info(
386-
f"set opt_value of shape input: {value} as {opt_value}"
387-
)
388-
_logger.info(
389-
f"set max_value of shape input: {value} as {max_value}"
390-
)
385+
if not self.trt_config.disable_loggling:
386+
_logger.info(
387+
f"set min_value of shape input: {value} as {min_value}"
388+
)
389+
_logger.info(
390+
f"set opt_value of shape input: {value} as {opt_value}"
391+
)
392+
_logger.info(
393+
f"set max_value of shape input: {value} as {max_value}"
394+
)
391395
profile.set_shape_input(
392396
input_name, min=min_value, opt=opt_value, max=max_value
393397
)
@@ -610,7 +614,8 @@ def convert(self, network, paddle_op, inputs):
610614
def convert_program_to_trt(self):
611615
for op in self.program.global_block().ops:
612616
if op.name() == "cinn_op.group" or op.name() == "builtin.group":
613-
_logger.info(f"start process {op.name()}")
617+
if not self.trt_config.disable_loggling:
618+
_logger.info(f"start process {op.name()}")
614619
self.engine_num += 1
615620
new_out = self.convert_subgraph_to_trt(self.program, op)
616621
orin_out_values = op.results()

python/paddle/tensorrt/export.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ def __init__(
242242
workspace_size: int | None = 1 << 30,
243243
use_cuda_graph: bool | None = False,
244244
refit_params_path: str | None = None,
245+
disable_loggling: bool | None = True,
245246
) -> None:
246247
"""
247248
A class for configuring TensorRT optimizations.
@@ -273,6 +274,8 @@ def __init__(
273274
Specify whether TensorRT enables cuda_graph during the optimization process (default is false).
274275
refit_params_path(str, optional):
275276
The path to the weights that need to be refitted.
277+
disable_loggling (bool, optional):
278+
Specifies whether to enable GLOG info output during the optimization process (default is true).
276279
Returns:
277280
None
278281
@@ -330,6 +333,7 @@ def __init__(
330333
self.workspace_size = workspace_size
331334
self.use_cuda_graph = use_cuda_graph
332335
self.refit_params_path = refit_params_path
336+
self.disable_loggling = disable_loggling
333337
if self.refit_params_path:
334338
self.disable_passes.append("constant_folding_pass")
335339
paddle.framework.set_flags(

test/tensorrt/tensorrt_test_base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ def check_trt_result(self, rtol=1e-5, atol=1e-5, precision_mode="fp32"):
303303
max_input_shape=self.max_shape,
304304
)
305305
trt_config = TensorRTConfig(inputs=[input])
306+
trt_config.disable_loggling = False
306307
if precision_mode == "fp16":
307308
trt_config.precision_mode = PrecisionMode.FP16
308309

0 commit comments

Comments
 (0)