-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[TensorRT] Support Multiple EP Context #23294
base: main
Are you sure you want to change the base?
Conversation
onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc
Outdated
Show resolved
Hide resolved
You should modify tensorrt_execution_provider.cc line # 3853 to 3856 // dump ep context model
if (dump_ep_context_model_ && ep_context_embed_mode_) {
UpdateCtxNodeModelEngineContext(model_proto_.get(), reinterpret_cast<char*>(serialized_engine->data()), serialized_engine->size());
DumpCtxModel(model_proto_.get(), ctx_model_path_);
} The code above handles the case when the graph has dynamic shape input(s) and the engine is being updated during inference. |
I added a warning in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can commit the suggested changes from lintrunner.
onnxruntime/core/providers/tensorrt/tensorrt_execution_provider.cc
Outdated
Show resolved
Hide resolved
…r.cc Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…nferenceWithMultiThreads
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can commit the suggested changes from lintrunner.
ASSERT_TRUE(status.IsOK()); | ||
// run inference | ||
// TRT engine will be created and cached | ||
// TRT profile will be created and cached only for dynamic input shape | ||
// Data in profile, | ||
// X: 1, 3, 3, 2, 2, 2 | ||
// Y: 1, 3, 3, 2, 2, 2 | ||
// Z: 1, 3, 3, 2, 2, 2 | ||
RunSession(session_object3, run_options, feeds, output_names, expected_dims_mul_m, expected_values_mul_m); | ||
|
||
// Test engine cache path: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ASSERT_TRUE(status.IsOK()); | |
// run inference | |
// TRT engine will be created and cached | |
// TRT profile will be created and cached only for dynamic input shape | |
// Data in profile, | |
// X: 1, 3, 3, 2, 2, 2 | |
// Y: 1, 3, 3, 2, 2, 2 | |
// Z: 1, 3, 3, 2, 2, 2 | |
RunSession(session_object3, run_options, feeds, output_names, expected_dims_mul_m, expected_values_mul_m); | |
// Test engine cache path: | |
ASSERT_TRUE(status.IsOK()); | |
// Test engine cache path: |
onnxruntime/test/python/onnxruntime_test_python_nested_control_flow_op.py
Fixed
Show fixed
Hide fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can commit the suggested changes from lintrunner.
|
||
|
||
std::vector<char> ReadFileFromDisk(const PathString& path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::vector<char> ReadFileFromDisk(const PathString& path) { | |
std::vector<char> ReadFileFromDisk(const PathString& path) { |
std::vector<int> dims = {1, 3, 2}; | ||
|
||
remove(ctx_model_path.c_str()); // remove the context model file generated by previous test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::vector<int> dims = {1, 3, 2}; | |
remove(ctx_model_path.c_str()); // remove the context model file generated by previous test | |
std::vector<int> dims = {1, 3, 2}; | |
remove(ctx_model_path.c_str()); // remove the context model file generated by previous test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can commit the suggested changes from lintrunner.
std::vector<int64_t> expected_dims_mul_m = {3, 6}; | ||
std::vector<int64_t> expected_values_mul_m = { 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 13, 14, 14, 16, 16, 18, 0, 1 }; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::vector<int64_t> expected_dims_mul_m = {3, 6}; | |
std::vector<int64_t> expected_values_mul_m = { 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 13, 14, 14, 16, 16, 18, 0, 1 }; | |
std::vector<int64_t> expected_dims_mul_m = {3, 6}; | |
std::vector<int64_t> expected_values_mul_m = {1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 13, 14, 14, 16, 16, 18, 0, 1}; | |
…o run remaining tests
…ut and change graph_view access
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can commit the suggested changes from lintrunner.
bool GraphHasCtxNode(const GraphViewer& graph_viewer) { | ||
for (int i = 0; i < graph_viewer.MaxNodeIndex(); ++i) { | ||
auto node = graph_viewer.GetNode(i); | ||
for (auto node_index: graph_viewer.GetNodesInTopologicalOrder()) { | ||
auto node = graph_viewer.GetNode(node_index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool GraphHasCtxNode(const GraphViewer& graph_viewer) { | |
for (int i = 0; i < graph_viewer.MaxNodeIndex(); ++i) { | |
auto node = graph_viewer.GetNode(i); | |
for (auto node_index: graph_viewer.GetNodesInTopologicalOrder()) { | |
auto node = graph_viewer.GetNode(node_index); | |
bool GraphHasCtxNode(const GraphViewer& graph_viewer) { | |
for (auto node_index : graph_viewer.GetNodesInTopologicalOrder()) { | |
auto node = graph_viewer.GetNode(node_index); |
const auto& subgraph_node_list = graph_viewer.GetNodesInTopologicalOrder(); | ||
assert(subgraph_node_list.size() == 1); // There should only be 1 node in filtered graph | ||
const auto node = graph_viewer.GetNode(subgraph_node_list[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const auto& subgraph_node_list = graph_viewer.GetNodesInTopologicalOrder(); | |
assert(subgraph_node_list.size() == 1); // There should only be 1 node in filtered graph | |
const auto node = graph_viewer.GetNode(subgraph_node_list[0]); | |
const auto& subgraph_node_list = graph_viewer.GetNodesInTopologicalOrder(); | |
assert(subgraph_node_list.size() == 1); // There should only be 1 node in filtered graph | |
const auto node = graph_viewer.GetNode(subgraph_node_list[0]); |
LOGS_DEFAULT(VERBOSE) << "[TensorRT EP] TensorRT provider options: " | ||
<< "device_id: " << device_id_ | ||
<< ", trt_max_partition_iterations: " << max_partition_iterations_ | ||
<< ", trt_min_subgraph_size: " << min_subgraph_size_ | ||
<< ", trt_max_workspace_size: " << max_workspace_size_ | ||
<< ", trt_fp16_enable: " << fp16_enable_ | ||
<< ", trt_int8_enable: " << int8_enable_ | ||
<< ", trt_int8_calibration_cache_name: " << int8_calibration_cache_name_ | ||
<< ", int8_calibration_cache_available: " << int8_calibration_cache_available_ | ||
<< ", trt_int8_use_native_tensorrt_calibration_table: " << int8_use_native_tensorrt_calibration_table_ | ||
<< ", trt_dla_enable: " << dla_enable_ | ||
<< ", trt_dla_core: " << dla_core_ | ||
<< ", trt_dump_subgraphs: " << dump_subgraphs_ | ||
<< ", trt_engine_cache_enable: " << engine_cache_enable_ | ||
<< ", trt_weight_stripped_engine_enable: " << weight_stripped_engine_enable_ | ||
<< ", trt_onnx_model_folder_path: " << onnx_model_folder_path_ | ||
<< ", trt_cache_path: " << cache_path_ | ||
<< ", trt_global_cache_path: " << global_cache_path_ | ||
<< ", trt_engine_decryption_enable: " << engine_decryption_enable_ | ||
<< ", trt_engine_decryption_lib_path: " << engine_decryption_lib_path_ | ||
<< ", trt_force_sequential_engine_build: " << force_sequential_engine_build_ | ||
<< ", trt_context_memory_sharing_enable: " << context_memory_sharing_enable_ | ||
<< ", trt_layer_norm_fp32_fallback: " << layer_norm_fp32_fallback_ | ||
<< ", trt_build_heuristics_enable: " << build_heuristics_enable_ | ||
<< ", trt_sparsity_enable: " << sparsity_enable_ | ||
<< ", trt_builder_optimization_level: " << builder_optimization_level_ | ||
<< ", trt_auxiliary_streams: " << auxiliary_streams_ | ||
<< ", trt_tactic_sources: " << tactic_sources_ | ||
<< ", trt_profile_min_shapes: " << profile_min_shapes | ||
<< ", trt_profile_max_shapes: " << profile_max_shapes | ||
<< ", trt_profile_opt_shapes: " << profile_opt_shapes | ||
<< ", trt_cuda_graph_enable: " << cuda_graph_enable_ | ||
<< ", trt_dump_ep_context_model: " << dump_ep_context_model_ | ||
<< ", trt_ep_context_file_path: " << ep_context_file_path_ | ||
<< ", trt_ep_context_embed_mode: " << ep_context_embed_mode_ | ||
<< ", trt_cache_prefix: " << cache_prefix_ | ||
<< ", trt_engine_hw_compatible: " << engine_hw_compatible_ | ||
<< ", trt_onnx_model_bytestream_size_: " << onnx_model_bytestream_size_; | ||
<< "device_id: " << device_id_ | ||
<< ", trt_max_partition_iterations: " << max_partition_iterations_ | ||
<< ", trt_min_subgraph_size: " << min_subgraph_size_ | ||
<< ", trt_max_workspace_size: " << max_workspace_size_ | ||
<< ", trt_fp16_enable: " << fp16_enable_ | ||
<< ", trt_int8_enable: " << int8_enable_ | ||
<< ", trt_int8_calibration_cache_name: " << int8_calibration_cache_name_ | ||
<< ", int8_calibration_cache_available: " << int8_calibration_cache_available_ | ||
<< ", trt_int8_use_native_tensorrt_calibration_table: " << int8_use_native_tensorrt_calibration_table_ | ||
<< ", trt_dla_enable: " << dla_enable_ | ||
<< ", trt_dla_core: " << dla_core_ | ||
<< ", trt_dump_subgraphs: " << dump_subgraphs_ | ||
<< ", trt_engine_cache_enable: " << engine_cache_enable_ | ||
<< ", trt_weight_stripped_engine_enable: " << weight_stripped_engine_enable_ | ||
<< ", trt_onnx_model_folder_path: " << onnx_model_folder_path_ | ||
<< ", trt_cache_path: " << cache_path_ | ||
<< ", trt_global_cache_path: " << global_cache_path_ | ||
<< ", trt_engine_decryption_enable: " << engine_decryption_enable_ | ||
<< ", trt_engine_decryption_lib_path: " << engine_decryption_lib_path_ | ||
<< ", trt_force_sequential_engine_build: " << force_sequential_engine_build_ | ||
<< ", trt_context_memory_sharing_enable: " << context_memory_sharing_enable_ | ||
<< ", trt_layer_norm_fp32_fallback: " << layer_norm_fp32_fallback_ | ||
<< ", trt_build_heuristics_enable: " << build_heuristics_enable_ | ||
<< ", trt_sparsity_enable: " << sparsity_enable_ | ||
<< ", trt_builder_optimization_level: " << builder_optimization_level_ | ||
<< ", trt_auxiliary_streams: " << auxiliary_streams_ | ||
<< ", trt_tactic_sources: " << tactic_sources_ | ||
<< ", trt_profile_min_shapes: " << profile_min_shapes | ||
<< ", trt_profile_max_shapes: " << profile_max_shapes | ||
<< ", trt_profile_opt_shapes: " << profile_opt_shapes | ||
<< ", trt_cuda_graph_enable: " << cuda_graph_enable_ | ||
<< ", trt_dump_ep_context_model: " << dump_ep_context_model_ | ||
<< ", trt_ep_context_file_path: " << ep_context_file_path_ | ||
<< ", trt_ep_context_embed_mode: " << ep_context_embed_mode_ | ||
<< ", trt_cache_prefix: " << cache_prefix_ | ||
<< ", trt_engine_hw_compatible: " << engine_hw_compatible_ | ||
<< ", trt_onnx_model_bytestream_size_: " << onnx_model_bytestream_size_; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOGS_DEFAULT(VERBOSE) << "[TensorRT EP] TensorRT provider options: " | |
<< "device_id: " << device_id_ | |
<< ", trt_max_partition_iterations: " << max_partition_iterations_ | |
<< ", trt_min_subgraph_size: " << min_subgraph_size_ | |
<< ", trt_max_workspace_size: " << max_workspace_size_ | |
<< ", trt_fp16_enable: " << fp16_enable_ | |
<< ", trt_int8_enable: " << int8_enable_ | |
<< ", trt_int8_calibration_cache_name: " << int8_calibration_cache_name_ | |
<< ", int8_calibration_cache_available: " << int8_calibration_cache_available_ | |
<< ", trt_int8_use_native_tensorrt_calibration_table: " << int8_use_native_tensorrt_calibration_table_ | |
<< ", trt_dla_enable: " << dla_enable_ | |
<< ", trt_dla_core: " << dla_core_ | |
<< ", trt_dump_subgraphs: " << dump_subgraphs_ | |
<< ", trt_engine_cache_enable: " << engine_cache_enable_ | |
<< ", trt_weight_stripped_engine_enable: " << weight_stripped_engine_enable_ | |
<< ", trt_onnx_model_folder_path: " << onnx_model_folder_path_ | |
<< ", trt_cache_path: " << cache_path_ | |
<< ", trt_global_cache_path: " << global_cache_path_ | |
<< ", trt_engine_decryption_enable: " << engine_decryption_enable_ | |
<< ", trt_engine_decryption_lib_path: " << engine_decryption_lib_path_ | |
<< ", trt_force_sequential_engine_build: " << force_sequential_engine_build_ | |
<< ", trt_context_memory_sharing_enable: " << context_memory_sharing_enable_ | |
<< ", trt_layer_norm_fp32_fallback: " << layer_norm_fp32_fallback_ | |
<< ", trt_build_heuristics_enable: " << build_heuristics_enable_ | |
<< ", trt_sparsity_enable: " << sparsity_enable_ | |
<< ", trt_builder_optimization_level: " << builder_optimization_level_ | |
<< ", trt_auxiliary_streams: " << auxiliary_streams_ | |
<< ", trt_tactic_sources: " << tactic_sources_ | |
<< ", trt_profile_min_shapes: " << profile_min_shapes | |
<< ", trt_profile_max_shapes: " << profile_max_shapes | |
<< ", trt_profile_opt_shapes: " << profile_opt_shapes | |
<< ", trt_cuda_graph_enable: " << cuda_graph_enable_ | |
<< ", trt_dump_ep_context_model: " << dump_ep_context_model_ | |
<< ", trt_ep_context_file_path: " << ep_context_file_path_ | |
<< ", trt_ep_context_embed_mode: " << ep_context_embed_mode_ | |
<< ", trt_cache_prefix: " << cache_prefix_ | |
<< ", trt_engine_hw_compatible: " << engine_hw_compatible_ | |
<< ", trt_onnx_model_bytestream_size_: " << onnx_model_bytestream_size_; | |
<< "device_id: " << device_id_ | |
<< ", trt_max_partition_iterations: " << max_partition_iterations_ | |
<< ", trt_min_subgraph_size: " << min_subgraph_size_ | |
<< ", trt_max_workspace_size: " << max_workspace_size_ | |
<< ", trt_fp16_enable: " << fp16_enable_ | |
<< ", trt_int8_enable: " << int8_enable_ | |
<< ", trt_int8_calibration_cache_name: " << int8_calibration_cache_name_ | |
<< ", int8_calibration_cache_available: " << int8_calibration_cache_available_ | |
<< ", trt_int8_use_native_tensorrt_calibration_table: " << int8_use_native_tensorrt_calibration_table_ | |
<< ", trt_dla_enable: " << dla_enable_ | |
<< ", trt_dla_core: " << dla_core_ | |
<< ", trt_dump_subgraphs: " << dump_subgraphs_ | |
<< ", trt_engine_cache_enable: " << engine_cache_enable_ | |
<< ", trt_weight_stripped_engine_enable: " << weight_stripped_engine_enable_ | |
<< ", trt_onnx_model_folder_path: " << onnx_model_folder_path_ | |
<< ", trt_cache_path: " << cache_path_ | |
<< ", trt_global_cache_path: " << global_cache_path_ | |
<< ", trt_engine_decryption_enable: " << engine_decryption_enable_ | |
<< ", trt_engine_decryption_lib_path: " << engine_decryption_lib_path_ | |
<< ", trt_force_sequential_engine_build: " << force_sequential_engine_build_ | |
<< ", trt_context_memory_sharing_enable: " << context_memory_sharing_enable_ | |
<< ", trt_layer_norm_fp32_fallback: " << layer_norm_fp32_fallback_ | |
<< ", trt_build_heuristics_enable: " << build_heuristics_enable_ | |
<< ", trt_sparsity_enable: " << sparsity_enable_ | |
<< ", trt_builder_optimization_level: " << builder_optimization_level_ | |
<< ", trt_auxiliary_streams: " << auxiliary_streams_ | |
<< ", trt_tactic_sources: " << tactic_sources_ | |
<< ", trt_profile_min_shapes: " << profile_min_shapes | |
<< ", trt_profile_max_shapes: " << profile_max_shapes | |
<< ", trt_profile_opt_shapes: " << profile_opt_shapes | |
<< ", trt_cuda_graph_enable: " << cuda_graph_enable_ | |
<< ", trt_dump_ep_context_model: " << dump_ep_context_model_ | |
<< ", trt_ep_context_file_path: " << ep_context_file_path_ | |
<< ", trt_ep_context_embed_mode: " << ep_context_embed_mode_ | |
<< ", trt_cache_prefix: " << cache_prefix_ | |
<< ", trt_engine_hw_compatible: " << engine_hw_compatible_ | |
<< ", trt_onnx_model_bytestream_size_: " << onnx_model_bytestream_size_; | |
} | |
LOGS_DEFAULT(VERBOSE) << "[TensorRT EP] TensorRT provider options: " | |
<< "device_id: " << device_id_ | |
<< ", trt_max_partition_iterations: " << max_partition_iterations_ | |
<< ", trt_min_subgraph_size: " << min_subgraph_size_ | |
<< ", trt_max_workspace_size: " << max_workspace_size_ | |
<< ", trt_fp16_enable: " << fp16_enable_ | |
<< ", trt_int8_enable: " << int8_enable_ | |
<< ", trt_int8_calibration_cache_name: " << int8_calibration_cache_name_ | |
<< ", int8_calibration_cache_available: " << int8_calibration_cache_available_ | |
<< ", trt_int8_use_native_tensorrt_calibration_table: " << int8_use_native_tensorrt_calibration_table_ | |
<< ", trt_dla_enable: " << dla_enable_ | |
<< ", trt_dla_core: " << dla_core_ | |
<< ", trt_dump_subgraphs: " << dump_subgraphs_ | |
<< ", trt_engine_cache_enable: " << engine_cache_enable_ | |
<< ", trt_weight_stripped_engine_enable: " << weight_stripped_engine_enable_ | |
<< ", trt_onnx_model_folder_path: " << onnx_model_folder_path_ | |
<< ", trt_cache_path: " << cache_path_ | |
<< ", trt_global_cache_path: " << global_cache_path_ | |
<< ", trt_engine_decryption_enable: " << engine_decryption_enable_ | |
<< ", trt_engine_decryption_lib_path: " << engine_decryption_lib_path_ | |
<< ", trt_force_sequential_engine_build: " << force_sequential_engine_build_ | |
<< ", trt_context_memory_sharing_enable: " << context_memory_sharing_enable_ | |
<< ", trt_layer_norm_fp32_fallback: " << layer_norm_fp32_fallback_ | |
<< ", trt_build_heuristics_enable: " << build_heuristics_enable_ | |
<< ", trt_sparsity_enable: " << sparsity_enable_ | |
<< ", trt_builder_optimization_level: " << builder_optimization_level_ | |
<< ", trt_auxiliary_streams: " << auxiliary_streams_ | |
<< ", trt_tactic_sources: " << tactic_sources_ | |
<< ", trt_profile_min_shapes: " << profile_min_shapes | |
<< ", trt_profile_max_shapes: " << profile_max_shapes | |
<< ", trt_profile_opt_shapes: " << profile_opt_shapes | |
<< ", trt_cuda_graph_enable: " << cuda_graph_enable_ | |
<< ", trt_dump_ep_context_model: " << dump_ep_context_model_ | |
<< ", trt_ep_context_file_path: " << ep_context_file_path_ | |
<< ", trt_ep_context_embed_mode: " << ep_context_embed_mode_ | |
<< ", trt_cache_prefix: " << cache_prefix_ | |
<< ", trt_engine_hw_compatible: " << engine_hw_compatible_ | |
<< ", trt_onnx_model_bytestream_size_: " << onnx_model_bytestream_size_; | |
} |
// Generate file name for dumping ep context model | ||
if (dump_ep_context_model_ && ctx_model_path_.empty()) { | ||
ctx_model_path_ = GetCtxModelPath(ep_context_file_path_, model_path_); | ||
} | ||
|
||
|
||
if (!has_dynamic_shape) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Generate file name for dumping ep context model | |
if (dump_ep_context_model_ && ctx_model_path_.empty()) { | |
ctx_model_path_ = GetCtxModelPath(ep_context_file_path_, model_path_); | |
} | |
if (!has_dynamic_shape) { | |
// Generate file name for dumping ep context model | |
if (!has_dynamic_shape) { |
bool is_single_node_epcontext_graph = false; | ||
|
||
std::unordered_set<std::string> control_flow_op_set_ = {"If", "Loop", "Scan"}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool is_single_node_epcontext_graph = false; | |
std::unordered_set<std::string> control_flow_op_set_ = {"If", "Loop", "Scan"}; | |
bool is_single_node_epcontext_graph = false; | |
std::unordered_set<std::string> control_flow_op_set_ = {"If", "Loop", "Scan"}; |
Description
Supported scenarios:
Unsupported scenarios:
This does not work because tensorrt engine might be updated during run time because of input size change but ORT does not have a call back mechanism to call CreateEpContextModel to update embedded ep context. Supporting this will require significant changes in the existing infrastructure.
Motivation and Context