@@ -556,6 +556,11 @@ TensorrtExecutionProvider::TensorrtExecutionProvider(const TensorrtExecutionProv
556
556
engine_decryption_ = (int (*)(const char *, char *, size_t *))LIBFUNC (handle, " decrypt" );
557
557
engine_encryption_ = (int (*)(const char *, char *, size_t ))LIBFUNC (handle, " encrypt" );
558
558
}
559
+
560
+ if (int8_enable_) {
561
+ int8_calibration_cache_available_ = !int8_calibration_cache_name_.empty ();
562
+ }
563
+
559
564
LOGS_DEFAULT (VERBOSE) << " [TensorRT EP] TensorRT provider options: "
560
565
<< " device_id: " << device_id_
561
566
<< " , trt_max_partition_iterations: " << max_partition_iterations_
@@ -564,6 +569,7 @@ TensorrtExecutionProvider::TensorrtExecutionProvider(const TensorrtExecutionProv
564
569
<< " , trt_fp16_enable: " << fp16_enable_
565
570
<< " , trt_int8_enable: " << int8_enable_
566
571
<< " , trt_int8_calibration_cache_name: " << int8_calibration_cache_name_
572
+ << " , int8_calibration_cache_available: " << int8_calibration_cache_available_
567
573
<< " , trt_int8_use_native_tensorrt_calibration_table: " << int8_use_native_tensorrt_calibration_table_
568
574
<< " , trt_dla_enable: " << dla_enable_
569
575
<< " , trt_dla_core: " << dla_core_
@@ -1206,7 +1212,7 @@ common::Status TensorrtExecutionProvider::Compile(const std::vector<Node*>& fuse
1206
1212
1207
1213
// Load INT8 calibration table
1208
1214
std::unordered_map<std::string, float > dynamic_range_map;
1209
- if (int8_enable_) {
1215
+ if (int8_enable_ && int8_calibration_cache_available_ ) {
1210
1216
const std::string calibration_cache_path = GetCachePath (cache_path_, int8_calibration_cache_name_);
1211
1217
if (!ReadDynamicRange (calibration_cache_path, int8_use_native_tensorrt_calibration_table_, dynamic_range_map)) {
1212
1218
throw std::runtime_error (" Failed to read INT8 calibration table " + calibration_cache_path);
@@ -1291,7 +1297,7 @@ common::Status TensorrtExecutionProvider::Compile(const std::vector<Node*>& fuse
1291
1297
}
1292
1298
} else {
1293
1299
// Set INT8 per tensor dynamic range
1294
- if (int8_enable_ && trt_builder->platformHasFastInt8 ()) {
1300
+ if (int8_enable_ && trt_builder->platformHasFastInt8 () && int8_calibration_cache_available_ ) {
1295
1301
trt_config->setInt8Calibrator (nullptr );
1296
1302
if (!SetDynamicRange (*trt_network, dynamic_range_map)) {
1297
1303
return ORT_MAKE_STATUS (ONNXRUNTIME, EP_FAIL,
@@ -1375,9 +1381,9 @@ common::Status TensorrtExecutionProvider::Compile(const std::vector<Node*>& fuse
1375
1381
*p = {context->allocate_func , context->release_func , context->allocator_handle , &parsers_[context->node_name ],
1376
1382
&engines_[context->node_name ], &contexts_[context->node_name ], &builders_[context->node_name ],
1377
1383
&networks_[context->node_name ], input_info_[context->node_name ], output_info_[context->node_name ],
1378
- input_shape_ranges_[context->node_name ], &tensorrt_mu_, fp16_enable_, int8_enable_, dla_enable_ ,
1379
- dla_core_, &max_workspace_size_, trt_node_name_with_precision, engine_cache_enable_, cache_path_, runtime_. get (), nullptr ,
1380
- allocator_, dynamic_range_map, engine_decryption_enable_, engine_decryption_, engine_encryption_};
1384
+ input_shape_ranges_[context->node_name ], &tensorrt_mu_, fp16_enable_, int8_enable_, int8_calibration_cache_available_ ,
1385
+ dla_enable_, dla_core_, &max_workspace_size_, trt_node_name_with_precision, engine_cache_enable_, cache_path_,
1386
+ runtime_. get (), nullptr , allocator_, dynamic_range_map, engine_decryption_enable_, engine_decryption_, engine_encryption_};
1381
1387
*state = p.release ();
1382
1388
return 0 ;
1383
1389
};
@@ -1617,7 +1623,7 @@ common::Status TensorrtExecutionProvider::Compile(const std::vector<Node*>& fuse
1617
1623
trt_config->addOptimizationProfile (*trt_profile);
1618
1624
1619
1625
// Set INT8 Per Tensor Dynamic range
1620
- if (trt_state->int8_enable && trt_builder->platformHasFastInt8 ()) {
1626
+ if (trt_state->int8_enable && trt_builder->platformHasFastInt8 () && trt_state-> int8_calibration_cache_available ) {
1621
1627
trt_config->setInt8Calibrator (nullptr );
1622
1628
if (!SetDynamicRange (*trt_state->network ->get (), trt_state->dynamic_range_map )) {
1623
1629
return ORT_MAKE_STATUS (ONNXRUNTIME, EP_FAIL, " TensorRT EP failed to set INT8 dynamic range." );
0 commit comments