diff --git a/onnxruntime/core/providers/qnn/builder/onnx_ctx_model_helper.cc b/onnxruntime/core/providers/qnn/builder/onnx_ctx_model_helper.cc index 884b2368ba11d..86e1c2d241007 100644 --- a/onnxruntime/core/providers/qnn/builder/onnx_ctx_model_helper.cc +++ b/onnxruntime/core/providers/qnn/builder/onnx_ctx_model_helper.cc @@ -156,31 +156,6 @@ Status LoadQnnCtxFromOnnxGraph(const onnxruntime::GraphViewer& graph_viewer, return Status::OK(); } -Status GetMetadataFromEpContextModel(const onnxruntime::PathString& ctx_onnx_model_path, - std::string& model_name, - std::string& model_description, - std::vector& graph_partition_names, - std::string& cache_source, - const logging::Logger& logger) { - using namespace onnxruntime; - std::shared_ptr model; - ORT_RETURN_IF_ERROR(Model::Load(ctx_onnx_model_path, model, {}, logger)); - const auto& graph = GraphViewer(model->MainGraph()); - model_name = graph.Name(); - model_description = graph.Description(); - - for (const auto& ep_context_node : graph.Nodes()) { - if (EPCONTEXT_OP != ep_context_node.OpType()) { - continue; - } - NodeAttrHelper node_helper(ep_context_node); - cache_source = node_helper.Get(SOURCE, ""); - graph_partition_names.push_back(node_helper.Get(PARTITION_NAME, "")); - } - - return Status::OK(); -} - bool IsContextCacheFileExists(const std::string& customer_context_cache_path, const onnxruntime::PathString& model_pathstring, onnxruntime::PathString& context_cache_path) { @@ -194,66 +169,6 @@ bool IsContextCacheFileExists(const std::string& customer_context_cache_path, return std::filesystem::is_regular_file(context_cache_path) && std::filesystem::exists(context_cache_path); } -Status ValidateWithContextFile(const std::vector& fused_nodes_and_graphs, - const onnxruntime::PathString& context_cache_path, - const std::string& model_name, - const std::string& model_description, - const logging::Logger& logger) { - std::string model_name_from_ctx_cache; - std::string model_description_from_ctx_cache; - std::vector graph_partition_names; - std::string cache_source; - - auto status = GetMetadataFromEpContextModel(context_cache_path, - model_name_from_ctx_cache, - model_description_from_ctx_cache, - graph_partition_names, - cache_source, - logger); - if (!status.IsOK()) { - return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_GRAPH, "Failed to get metadata from EpContext model."); - } - - // The source attribute from the skeleton onnx file indicate whether it's generated from QNN toolchain or ORT - if (cache_source != kQnnExecutionProvider) { - LOGS(logger, VERBOSE) << "Context binary cache is not generated by Ort."; - return Status::OK(); - } - - bool partition_names_matched = true; - for (const auto& fused_node_graph : fused_nodes_and_graphs) { - const Node& fused_node = fused_node_graph.fused_node; - const std::string& graph_meta_id = fused_node.Name(); - bool name_found = false; - for (auto partition_name_from_ctx : graph_partition_names) { - if (partition_name_from_ctx == graph_meta_id) { - name_found = true; - break; - } - } - - if (!name_found) { - LOGS(logger, ERROR) << "Partition meta_id not found from any EPContext node: " << graph_meta_id; - partition_names_matched = false; - break; - } - } - - if (model_name != model_name_from_ctx_cache || - model_description != model_description_from_ctx_cache || - !partition_names_matched) { - std::string message = onnxruntime::MakeString("Metadata mismatch. onnx: ", - model_name, " ", model_description, - " vs epcontext: ", - model_name_from_ctx_cache, " ", - model_description_from_ctx_cache, - " or the partition name not match."); - return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_GRAPH, message); - } - - return Status::OK(); -} - Status GenerateCtxCacheOnnxModel(Model* model, unsigned char* buffer, uint64_t buffer_size, diff --git a/onnxruntime/core/providers/qnn/builder/onnx_ctx_model_helper.h b/onnxruntime/core/providers/qnn/builder/onnx_ctx_model_helper.h index 80252043e414d..5ad375fb9dcb5 100644 --- a/onnxruntime/core/providers/qnn/builder/onnx_ctx_model_helper.h +++ b/onnxruntime/core/providers/qnn/builder/onnx_ctx_model_helper.h @@ -57,19 +57,6 @@ Status LoadQnnCtxFromOnnxGraph(const onnxruntime::GraphViewer& graph_viewer, QnnBackendManager* qnn_backend_manager, std::unordered_map>& qnn_models); -Status ValidateWithContextFile(const std::vector& fused_nodes_and_graphs, - const onnxruntime::PathString& context_cache_path, - const std::string& model_name, - const std::string& model_description, - const logging::Logger& logger); - -Status GetMetadataFromEpContextModel(const onnxruntime::PathString& ctx_onnx_model_path, - std::string& model_name, - std::string& model_description, - std::vector& graph_partition_names, - std::string& cache_source, - const logging::Logger& logger); - Status GenerateCtxCacheOnnxModel(Model* model, unsigned char* buffer, uint64_t buffer_size,