MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / test_run

Method test_run

test/tensorrt/test_export.py:240–305  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

238 )
239
240 def test_run(self):
241 with paddle.pir_utils.IrGuard():
242 input_config = Input(
243 min_input_shape=(1, 1, 28, 28),
244 optim_input_shape=(1, 1, 28, 28),
245 max_input_shape=(1, 1, 28, 28),
246 )
247 input_config2 = Input(
248 min_input_shape=(1, 1, 28, 28),
249 optim_input_shape=(1, 1, 28, 28),
250 max_input_shape=(1, 1, 28, 28),
251 )
252 trt_config = TensorRTConfig(inputs=[input_config, input_config2])
253 trt_config.save_model_dir = os.path.join(self.temp_dir.name, 'trt')
254
255 min_data_list = []
256 max_data_list = []
257 for i, input_instance in enumerate(trt_config.inputs):
258 min_data, _, max_data = input_instance.generate_input_data()
259
260 min_data_list.append(min_data)
261 max_data_list.append(max_data)
262 paddle.disable_static()
263
264 x = [paddle.to_tensor(md) for md in min_data_list]
265 net = LeNetMultiInput()
266 out = net(*x)
267
268 input_spec = [
269 InputSpec(
270 shape=min_data_list[0].shape, dtype='float32', name='input1'
271 ),
272 InputSpec(
273 shape=min_data_list[1].shape, dtype='float32', name='input2'
274 ),
275 ]
276
277 program_with_trt, scope = _convert_(
278 net,
279 input_spec=input_spec,
280 config=trt_config,
281 full_graph=True,
282 )
283
284 config = paddle_infer.Config(
285 trt_config.save_model_dir + '.json',
286 trt_config.save_model_dir + '.pdiparams',
287 )
288
289 if paddle.is_compiled_with_cuda():
290 config.enable_use_gpu(100, 0)
291 else:
292 config.disable_gpu()
293
294 predictor = paddle_infer.create_predictor(config)
295 output_converted = predictor.run(x)
296 output_converted_np = output_converted[0]
297 output_expected = out.numpy()

Callers

nothing calls this directly

Calls 14

InputClass · 0.90
TensorRTConfigClass · 0.90
InputSpecClass · 0.90
_convert_Function · 0.90
LeNetMultiInputClass · 0.85
to_tensorMethod · 0.80
create_predictorMethod · 0.80
numpyMethod · 0.80
netFunction · 0.50
joinMethod · 0.45
generate_input_dataMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected