Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable int8 if there is no quant info #36900

Merged
merged 2 commits into from
Nov 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions paddle/fluid/inference/tensorrt/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,21 @@ void TensorRTEngine::FreezeNetwork() {
// and outputs have scales,
// this layer's precision and output type are set to float32.
// This step has no effect if this layer is fused during TRT optimization.
int layers_no_int8 = 0;
for (int i = 0; i < network()->getNbLayers(); i++) {
auto layer = network()->getLayer(i);
if (!is_layer_int8(layer)) {
layer->setPrecision(nvinfer1::DataType::kFLOAT);
++layers_no_int8;
}
}
// Disable int8 or build engine failed if all layers aren't int8
if (layers_no_int8 == network()->getNbLayers()) {
nvinfer1::BuilderFlags flags = infer_builder_config_->getFlags();
flags = flags & ~(1U << static_cast<int>(nvinfer1::BuilderFlag::kINT8));
// reset flags
infer_builder_config_->setFlags(flags);
}
#else
LOG(WARNING) << "If your TensorRT version is lower than 5.1.2.2, you "
"must provide quantization scales for all tensors using "
Expand Down