Skip to content
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

add support for model outputs without names #2850

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Conversation

dtrawins
Copy link
Collaborator

@dtrawins dtrawins commented Nov 18, 2024

🛠 Summary

CVS-159002
When models have outputs without assigned names, add the name in the model initialization. The following format will be applied OUT_

🧪 Checklist

  • Unit tests added.
  • The documentation updated.
  • Change follows security best practices.
    ``

@dtrawins dtrawins requested a review from mzegla December 18, 2024 09:15
try {
OV_LOGGER("ov::Output<ov::Node> output: {}, output.get_any_name()", reinterpret_cast<const void*>(&output));
if (output.get_names().size() == 0) {
std::unordered_set<std::string> dummy_name{"OUT_" + std::to_string(outputIndex)};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use lowercase? Isn't it a standard in input/output naming?

# See the License for the specific language governing permissions and
# limitations under the License.
#

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this script meant to be used only manually by developers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a reference how the test model got created in case some changes should be applied.


input_data = np.ones((1, 10),dtype=np.int8)*10
results = compiled_model({"INPUT1": input_data, "INPUT2": input_data})

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could have some assertion here instead of prints?
I suppose the goal of this script is to generate a model and check if it's valid. In such case checking if output looks as expected would be good.

try {
OV_LOGGER("ov::Output<ov::Node> output: {}, output.get_any_name()", reinterpret_cast<const void*>(&output));
if (output.get_names().size() == 0) {
std::unordered_set<std::string> dummy_name{"OUT_" + std::to_string(outputIndex)};
output.add_names(dummy_name);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not logic related to "applyLayoutConfiguration". Move those changes outside of this method.

@@ -0,0 +1,55 @@
#
# Copyright (c) 2020 Intel Corporation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change year

@dtrawins dtrawins requested review from atobiszei and mzegla January 13, 2025 11:03
Copy link
Collaborator

@mzegla mzegla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does it look like for inputs without names?

@@ -79,6 +79,7 @@ const std::string passthrough_string_model_location = getGenericFullPathForSrcTe
const std::string dummy_saved_model_location = getGenericFullPathForSrcTest(std::filesystem::current_path().u8string() + "/src/test/dummy_saved_model", false);
const std::string dummy_tflite_location = getGenericFullPathForSrcTest(std::filesystem::current_path().u8string() + "/src/test/dummy_tflite", false);
const std::string scalar_model_location = getGenericFullPathForSrcTest(std::filesystem::current_path().u8string() + "/src/test/scalar", false);
const std::string no_name_output_model_location = std::filesystem::current_path().u8string() + "/src/test/no_name_output";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will likely not work on windows, see usage of getGenericFullPathForSrcTest above

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tests on windows are passing

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's strange. This new variable seems to have the same purpose as all the above and yet it works without wrapping in getGenericFullPathForSrcTest function? @rasapala can you take a look? Because to me, they all should be constructed in the same manner. Either with or without wrapper function.

Comment on lines +4 to +13
<layer id="1" name="input1" type="Parameter" version="opset1">
<data shape="1,10" element_type="i8" />
<output>
<port id="0" precision="I8" names="input1">
<dim>1</dim>
<dim>10</dim>
</port>
</output>
</layer>
<layer id="0" name="input2" type="Parameter" version="opset1">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use name "input_1" and "input_2" to follow the convention?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but this is barely a test model ;-)

@@ -305,7 +306,7 @@ static Status applyLayoutConfiguration(const ModelConfig& config, std::shared_pt
}

OV_LOGGER("ov::Model: {}, model->outputs()", reinterpret_cast<void*>(model.get()));
for (const ov::Output<ov::Node>& output : model->outputs()) {
for (ov::Output<ov::Node>& output : model->outputs()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this change required?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we are changing the outputs by adding name

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but not in this for loop, i dont think we need to remove const in this for loop

@@ -413,6 +414,29 @@ Status ModelInstance::loadTensors(const ModelConfig& config, bool needsToApplyLa
SPDLOG_LOGGER_ERROR(modelmanager_logger, "Error during configuration validation against model");
return status;
}
// add output names if not present in the model
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment and make function
adjustForEmptyOutputNames/addOutputNamesIfNotPresent or sth similar to operate on similar level of abstraction inthis function - see loadInputTensors/applyLayoutConfiguration etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants