Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wejoncy committed Dec 20, 2024
1 parent 7c466a1 commit d1e7633
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
9 changes: 6 additions & 3 deletions onnxruntime/core/providers/coreml/builders/model_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,12 @@ std::string GetModelOutputPath(const CoreMLOptions& coreml_options,
main_graph = main_graph->ParentGraph();
}
std::ofstream file(path + "/model.txt");
ORT_ENFORCE(file.is_open(), "Failed to open file ", path + "/model.txt");
file << main_graph->ModelPath().string();
file.close();
if (!file.is_open()) {
LOGS(logger, ERROR) << "Failed to open file " << path + "/model.txt";
} else {
file << main_graph->ModelPath().string();
file.close();
}
}

path = MakeString(path, "/", subgraph_short_name);
Expand Down
25 changes: 12 additions & 13 deletions onnxruntime/core/providers/coreml/coreml_execution_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,22 @@ CoreMLExecutionProvider::GetCapability(const onnxruntime::GraphViewer& graph_vie
[&]() {
HashValue model_hash;
int metadef_id = metadef_id_generator_.GenerateId(graph_viewer, model_hash);
std::string user_provided_key;

const Graph* main_graph = &graph_viewer.GetGraph();
while (main_graph->IsSubgraph()) {
main_graph = main_graph->ParentGraph();
}
if (main_graph->GetModel().MetaData().count(kCOREML_CACHE_KEY) > 0) {
user_provided_key = graph_viewer.GetGraph().GetModel().MetaData().at(kCOREML_CACHE_KEY);
if (user_provided_key.size() > 64 ||
std::any_of(user_provided_key.begin(), user_provided_key.end(),
[](unsigned char c) { return !std::isalnum(c); })) {
LOGS(logger, ERROR) << "[" << kCOREML_CACHE_KEY << ":" << user_provided_key << "] is not a valid cache key."
<< " It should be alphanumeric and less than 64 characters.";
}
// invalid cache-key
if (user_provided_key.size() == 0) {
user_provided_key = std::to_string(model_hash);
}
// use model_hash as the key if user doesn't provide one
std::string user_provided_key = main_graph->GetModel().MetaData().count(kCOREML_CACHE_KEY) > 0
? graph_viewer.GetGraph().GetModel().MetaData().at(kCOREML_CACHE_KEY)
: std::to_string(model_hash);

if (user_provided_key.size() > 64 ||
std::any_of(user_provided_key.begin(), user_provided_key.end(),
[](unsigned char c) { return !std::isalnum(c); })) {
LOGS(logger, ERROR) << "[" << kCOREML_CACHE_KEY << ":" << user_provided_key << "] is not a valid cache key."
<< " It should be alphanumeric and less than 64 characters.";

} else {
// model_hash is a 64-bit hash value of model_path if model_path is not empty,
// otherwise it hashes the graph input names and all the node output names.
Expand Down

0 comments on commit d1e7633

Please sign in to comment.