[PT FE] Fix behavior of convert_partially method to align with new description (#19147)

* [PT FE] Fix behaivior of convert_partially method to align with new description

* Simplify

* Do not add a message to exception of get_converted_model

* Update src/frontends/pytorch/src/frontend.cpp

* Supress normalize exception only when model is valid

* Create TranslateSession in own scope
This commit is contained in:
Maxim Vafin 2023-08-14 18:56:06 +02:00 committed by GitHub
parent f1d61f72ac
commit e49b2c05f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -119,8 +119,13 @@ FrontEnd::FrontEnd() {
}
}
std::shared_ptr<Model> FrontEnd::convert(const InputModel::Ptr& model) const {
auto converted_model = convert_partially(model);
std::shared_ptr<Model> FrontEnd::convert(const ov::frontend::InputModel::Ptr& model) const {
FRONT_END_GENERAL_CHECK(std::dynamic_pointer_cast<pytorch::InputModel>(model), "Invalid input model");
std::shared_ptr<Model> converted_model;
{
TranslateSession translate_session(model, m_op_translators, m_telemetry);
converted_model = translate_session.get_converted_model();
}
std::string norm_err;
try {
@ -146,14 +151,19 @@ void FrontEnd::convert(const std::shared_ptr<Model>& partiallyConverted) const {
std::shared_ptr<Model> FrontEnd::convert_partially(const ov::frontend::InputModel::Ptr& model) const {
FRONT_END_GENERAL_CHECK(std::dynamic_pointer_cast<pytorch::InputModel>(model), "Invalid input model");
try {
std::shared_ptr<Model> partial_model;
{
TranslateSession translate_session(model, m_op_translators, m_telemetry);
return translate_session.get_converted_model();
} catch (const std::runtime_error& e) {
std::cerr << "[ ERROR ] Unexpected error while converting pytorch model: " << e.what() << '\n';
std::cerr << "Rethrowing. Misleading error message from pybind11 may come next. TODO.";
throw;
partial_model = translate_session.get_converted_model();
}
try {
normalize(partial_model);
} catch (...) {
// normalize can fail on transformation, but the model is still valid. We can return such model.
// If model can be validated we suppress normalize exception.
partial_model->validate_nodes_and_infer_types();
}
return partial_model;
}
std::shared_ptr<Model> FrontEnd::decode(const InputModel::Ptr& model) const {