Skip to content

Commit

Permalink
[VitisAI] fix graph save (#21293)
Browse files Browse the repository at this point in the history
### Description
<!-- Describe your changes. -->
Revert the wrong change in
#20920


### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
It would save the data at a wrong position
  • Loading branch information
BoarQing authored Jul 16, 2024
1 parent 5df4ddd commit dcc0436
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 3 additions & 3 deletions onnxruntime/core/providers/vitisai/imp/global_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static std::string config_to_json_str(const onnxruntime::ProviderOptions& config

vaip_core::DllSafe<std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>> compile_onnx_model(
const onnxruntime::GraphViewer& graph_viewer, const logging::Logger& logger, const ProviderOptions& options) {
auto model_path = PathToUTF8String(ToPathString(graph_viewer.ModelPath().string()));
auto model_path = graph_viewer.ModelPath().string();
if (s_library_vitisaiep.compile_onnx_model_with_options) {
return vaip_core::DllSafe(s_library_vitisaiep.compile_onnx_model_with_options(model_path, graph_viewer.GetGraph(), options));
} else {
Expand Down Expand Up @@ -227,9 +227,9 @@ vaip_core::OrtApiForVaip* create_org_api_hook() {
auto& logger = logging::LoggingManager::DefaultLogger();
auto& model = const_cast<onnxruntime::Model&>(const_model);
auto model_proto = model.ToProto();
auto file_path = ToPathString(model.MainGraph().ModelPath().string());
auto file_path = model.MainGraph().ModelPath();
auto local_registries = IOnnxRuntimeOpSchemaRegistryList{model.MainGraph().GetSchemaRegistry()};
auto ret = Model::Create(std::move(*model_proto), file_path, &local_registries, logger);
auto ret = Model::Create(std::move(*model_proto), ToPathString(file_path), &local_registries, logger);
auto status = ret->MainGraph().Resolve();
vai_assert(status.IsOK(), status.ErrorMessage());
return ret.release();
Expand Down
5 changes: 2 additions & 3 deletions onnxruntime/core/providers/vitisai/imp/graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,11 @@ void graph_save(const Graph& graph, const std::string& filename, const std::stri
auto graph_proto_subgraph = graph.ToGraphProto();
*model_proto->mutable_graph() = *graph_proto_subgraph;
auto& logger = logging::LoggingManager::DefaultLogger();
auto filename_data_relative_path = std::filesystem::path();
auto model = Model::Create(std::move(*model_proto), ToPathString(filename), nullptr, logger);
if (initializer_size_threshold == std::numeric_limits<size_t>::max()) {
model_proto = model->ToProto();
} else {
model_proto = model->ToGraphProtoWithExternalInitializers(filename_dat, graph.ModelPath(), initializer_size_threshold);
model_proto = model->ToGraphProtoWithExternalInitializers(ToPathString(filename_dat), ToPathString(filename), initializer_size_threshold);
}
auto& metadata = model->MetaData();
if (!metadata.empty()) {
Expand All @@ -124,7 +123,7 @@ void graph_save(const Graph& graph, const std::string& filename, const std::stri
*prop->mutable_value() = m.second;
}
}
std::fstream output(filename, std::ios::out | std::ios::trunc | std::ios::binary);
std::fstream output(ToPathString(filename), std::ios::out | std::ios::trunc | std::ios::binary);
bool result = model_proto->SerializeToOstream(output);
output << std::flush;
vai_assert(result, "model serialize to ostream error");
Expand Down

0 comments on commit dcc0436

Please sign in to comment.