-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[VitisAI] bugfix model_clone optimization #25707
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -311,19 +311,30 @@ | |
| } | ||
| auto ORT_MEM_ADDR_tag = process_ext_address(*original_tensor); | ||
| if (!ORT_MEM_ADDR_tag.empty()) { | ||
| cloned_tensor->set_data_location(ONNX_NAMESPACE::TensorProto_DataLocation_EXTERNAL); | ||
| auto external_data = cloned_tensor->mutable_external_data(); | ||
| auto p = external_data->Add(); | ||
| *p->mutable_key() = "location"; | ||
| *p->mutable_value() = std::string("<") + graph_ptr; | ||
| } else if (size >= external_data_threshold) { | ||
| cloned_tensor->set_data_location(ONNX_NAMESPACE::TensorProto_DataLocation_EXTERNAL); | ||
| auto external_data = cloned_tensor->mutable_external_data(); | ||
| auto p = external_data->Add(); | ||
| *p->mutable_key() = "location"; | ||
| *p->mutable_value() = std::string("<") + graph_ptr; | ||
| // ORT 1.23 intializer handling | ||
| if (size >= external_data_threshold) { | ||
| cloned_tensor->set_data_location(ONNX_NAMESPACE::TensorProto_DataLocation_EXTERNAL); | ||
| auto external_data = cloned_tensor->mutable_external_data(); | ||
| auto p = external_data->Add(); | ||
| *p->mutable_key() = "location"; | ||
| *p->mutable_value() = std::string("<") + graph_ptr; | ||
| } else { | ||
| // Under threshold: get the data from ORT_MEM_ADDR and add it to cloned graph | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not rely on threshold. Some big initializers may not be converted. Use utils to test if the data is external. We generally do not want YOU to make the decision of what is expected to be an external data in memory. Use utilities to test and convert. You can also get a corresponding OrtValue from the graph. |
||
| std::unique_ptr<ONNX_NAMESPACE::TensorProto> tensor_proto; | ||
|
Check warning on line 323 in onnxruntime/core/providers/vitisai/imp/graph.cc
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ORT_THROW_IF_ERROR(utils::GetTensorProtoWithDataIfInMemory(*original_tensor, tensor_proto)); | ||
| *cloned_tensor = *tensor_proto; | ||
| } | ||
| } else { | ||
| *cloned_tensor = *original_tensor; | ||
| // ORT 1.22 or ealier intializer handling | ||
|
Check warning on line 328 in onnxruntime/core/providers/vitisai/imp/graph.cc
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if (size >= external_data_threshold) { | ||
| cloned_tensor->set_data_location(ONNX_NAMESPACE::TensorProto_DataLocation_EXTERNAL); | ||
| auto external_data = cloned_tensor->mutable_external_data(); | ||
| auto p = external_data->Add(); | ||
| *p->mutable_key() = "location"; | ||
| *p->mutable_value() = std::string("<") + graph_ptr; | ||
| } else { | ||
| *cloned_tensor = *original_tensor; | ||
| } | ||
| } | ||
| } | ||
| auto ret = Model::Create(std::move(*model_proto), file_path, &local_registries, logger); | ||
|
|
||
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.
Use utils::HasExternalDataInMemory() to see if data is in OrtValue.