the TRTIS could not load tf-trt frozen model
I build a tf-trt model with tf1.12 an tensorrt 5.0.2, i can run the model on tensorflow for inference. But when i load it with nvcr.io/nvidia/tensorrtserver:18.12-py3, error as below:
E0121 11:17:43.947746 1 trt_logger.cc:38] DefaultLogger ../builder/cudnnBuilder2.cpp (1508) - Misc Error in buildEngine: -1 (Could not find tensor resnet_model/Pad in tensorScales.) W0121 11:17:43.948121 1 trt_engine_op.cc:516] Engine creation for batch size 2 failed Internal: Failed to build TensorRT engine W0121 11:17:43.948140 1 trt_engine_op.cc:287] Engine retrieval for batch size 1 failed. Running native segment for resnet_model/my_trt_op_0
Could you give me any suggestion?
Can you tell us a little more about the model and how it was generated. Did you use int8 calibration? Does the same model work (using the exact same model configuration file) if you just use the TF model (without TF-TRT optimization)?
@deadeyegoodwin 1.I use int8 calibraion 2.the same model work when i just use the TF model 3.the same model work when i use tf1.8 and tensorrt4 5.the model is resnet_v1_50 from tensorflow official model
Are you using the same GPU for building the model and for inference with the inference server?
@trevor-m yes, and the gpu is P4.
Can you share the scripts you are using to generate the TF-TRT model? If you can share the model itself that would be very helpful and allow us to reproduce the issue.
https://github.com/tensorflow/tensorrt.git just run the tensorrt/tftrt/examples/image-classification/image_classification.py with int8 parameter like the follow command and get the frozen model from graphs directory. python image_classification.py --model resnet_v1_50 --data_dir ~/data/ImageNet/ --precision int8 --cache --calib_data_dir ~/data/ImageNetVal/ --use_trt --model_dir ~/tensorrt/tftrt/examples/image-classification/data/resnet_v1_50/resnet_imagenet_v1_fp32_20181001 --num_calib_inputs=50 --batch_size=1
I was unable to reproduce the error on my machine using your command. Could you try this command:
python image_classification.py --model resnet_v1_50 --data_dir ~/data/ImageNet/ --precision int8 --calib_data_dir ~/data/ImageNetVal/ --use_trt --num_calib_inputs=50 --batch_size=1
I couldn't reproduce the error with your command neither. Update: I did the conversion inside the container
@GuanLuo @trevor-m Guanluo's idea make sense. I did conversion inside the container and the exported model worked. After that I found that the cuda version on my machine is cuda 9.0 and the one on trtis is cuda10.0,may it is the reason.
By the way, do you have any idea about this log: 2019-01-30 14:27:33.178021: W tensorflow/contrib/tensorrt/convert/convert_graph.cc:161] Construction of static int8 engine is not implemented yet!. Dynamic engine will be constructed
It seems that when build int8 model, only dynamic model could be exported which needs a lot of time to construct a runtime engine for the first request on trtis.
Is there any solution to export a static model when do int8 quantification?
Or is there any solution to auto construct runtime engine before request coming?
thanks.
@rankeey You can try to add the second argument here in image_classification.py. This argument set is_dyn_op, which is a condition of not showing this message. Maybe you should change it to frozen_graph = trt.calib_graph_to_infer_graph(calib_graph, use_dynamic_op) because in a couple lines above, create_inference_graph, use_dynamic_op is used for the same purpose.
However, I think the engine is not going to be generated during execution in your case. Because by default, use_dynamic_op = false, and if you trace down to the documentation for create_inference_graph(), "no more engines will be created on the fly".
I know the parameter is_dyn_op,from the code we can know that if we set is_dyn_op to False, it always print the message.
Is it means is_dyn_op = False and is_dyn_op=True both will generate a dynamic model and the parameter is useless?
Hey @rankeey, static mode is currently not supported for int8 due to how calibration is performed, so we always fall back to dynamic mode when using int8 with calibration.
In the meantime, it is possible to use int8 with static mode with use_calibration=False, but there are other challenges there.
You can also construct the engine in advance with dynamic mode by simply sending some data through, for example some random inputs generated with numpy.
@trevor-m thank you very much for your reply.