ptrendx commented on a change in pull request #19011: URL: https://github.com/apache/incubator-mxnet/pull/19011#discussion_r486613508
########## File path: tests/python/tensorrt/test_tensorrt.py ########## @@ -0,0 +1,202 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import os +import ctypes +import mxnet as mx +from mxnet.base import SymbolHandle, check_call, _LIB, mx_uint, c_str_array, c_str, mx_real_t +from mxnet.symbol import Symbol +import numpy as np +from mxnet.test_utils import assert_almost_equal +from mxnet import gluon +from mxnet.gluon import nn +from mxnet import nd +from mxnet.gluon.model_zoo import vision + +#################################### +######### FP32/FP16 tests ########## +#################################### + +# Using RN50 to test TRT integration +def get_model(batch_shape, gluon_model=False): + if not gluon_model: + path = 'resnet50_v2' + if not os.path.exists(path): + model = vision.resnet50_v2(pretrained=True) + model.hybridize() + model.forward(mx.nd.zeros(batch_shape)) + model.export(path) + sym, arg_params, aux_params = mx.model.load_checkpoint(path, 0) + return sym, arg_params, aux_params + else: + model = vision.resnet50_v2(pretrained=True) + model.hybridize() + return model + + +def get_default_executor(input_data): + sym, arg_params, aux_params = get_model(batch_shape=input_data.shape) + executor = sym.simple_bind(ctx=mx.gpu(0), data=input_data.shape, grad_req='null', force_rebind=True) + executor.copy_params_from(arg_params, aux_params) + return executor + +def get_baseline(input_data): + executor = get_default_executor(input_data) + output = executor.forward(is_train=False, data=input_data) + return output + + +def check_tensorrt_symbol(baseline, input_data, fp16_mode, tol): + sym, arg_params, aux_params = get_model(batch_shape=input_data.shape) + trt_sym = sym.optimize_for('TensorRT', args=arg_params, aux=aux_params, ctx=mx.gpu(0), + fp16_mode=fp16_mode) Review comment: :unamused: Maybe `precision=some enum` instead of those `fp16_mode` and `int8_mode`? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
